@Test public void test_should_return_assignee_for_complaint_from_positionhierarcy() { final PositionResponse expectedPosition = new PositionResponse(); expectedPosition.setId(3L); when(positionRepository.getById(3L, "tenantId")). thenReturn(expectedPosition); final PositionResponse actualPosition = complaintRouterService.getAssignee(1L, "C001", 2L, "tenantId"); assertEquals(expectedPosition, actualPosition); }
public PositionResponse getAssignee(final Long boundaryId, final String complaintTypeCode, final Long assigneeId, final String tenantId) { PositionResponse positionResponse = null; Employee employeeResponse = null; ComplaintRouter complaintRouter = null; PositionHierarchyResponse positionHierarchies = null; final List<BoundaryResponse> boundaries = new ArrayList<>(); if (assigneeId == null) { LOG.info("BoundaryId::" + boundaryId); if (null != boundaryId) { getParentBoundaries(boundaryId, boundaries, tenantId); if (StringUtils.isNotBlank(complaintTypeCode)) { for (final BoundaryResponse bndry : boundaries) { final ComplaintTypeResponse complaintType = complaintTypeRepository .fetchComplaintTypeByCode(complaintTypeCode, tenantId); complaintRouter = complaintRouterRepository .findByComplaintTypeAndBoundary(complaintType.getId(), bndry.getId()); if (null != complaintRouter) break; } if (null == complaintRouter) { final ComplaintTypeResponse complaintType = complaintTypeRepository .fetchComplaintTypeByCode(complaintTypeCode, tenantId); complaintRouter = complaintRouterRepository.findByOnlyComplaintType(complaintType.getId()); } if (null == complaintRouter) for (final BoundaryResponse bndry : boundaries) { complaintRouter = complaintRouterRepository.findByOnlyBoundary(bndry.getId()); if (null != complaintRouter) break; } } } else { final ComplaintTypeResponse complaintType = complaintTypeRepository.fetchComplaintTypeByCode(complaintTypeCode, tenantId); complaintRouter = complaintRouterRepository.findByOnlyComplaintType(complaintType.getId()); if (null == complaintRouter) complaintRouter = complaintRouterRepository.findCityAdminGrievanceOfficer("ADMINISTRATION", tenantId); } if (complaintRouter != null) positionResponse = positionRepository.getById(complaintRouter.getPosition(), tenantId); else throw new ApplicationRuntimeException("PGR.001"); } else try { positionHierarchies = positionHierarchyRepository.getByPositionByComplaintTypeAndFromPosition(assigneeId, complaintTypeCode, tenantId); if (positionHierarchies.getEscalationHierarchies().isEmpty() || positionHierarchies.getEscalationHierarchies().contains(null)) { final List<Employee> employees = employeeRepository.getByRoleCode("GRO", tenantId); if (!employees.isEmpty()) employeeResponse = employees.iterator().next(); if (employeeResponse != null) { employeeResponse.getAssignments().stream().anyMatch(assignment -> assignment.getPosition().equals(Boolean.TRUE)); positionResponse = positionRepository.getById(employeeResponse.getAssignments().get(0).getPosition(), tenantId); } } else positionResponse = PositionResponse.builder() .id(positionHierarchies.getEscalationHierarchies().iterator().next().getToPosition()) .build(); } catch (final EscalationException e) { LOG.error("An error occurred, escalation can't be completed ", e); throw new ApplicationRuntimeException("PGR.001", e); } return positionResponse; }
ComplaintRouterService { public PositionResponse getAssignee(final Long boundaryId, final String complaintTypeCode, final Long assigneeId, final String tenantId) { PositionResponse positionResponse = null; Employee employeeResponse = null; ComplaintRouter complaintRouter = null; PositionHierarchyResponse positionHierarchies = null; final List<BoundaryResponse> boundaries = new ArrayList<>(); if (assigneeId == null) { LOG.info("BoundaryId::" + boundaryId); if (null != boundaryId) { getParentBoundaries(boundaryId, boundaries, tenantId); if (StringUtils.isNotBlank(complaintTypeCode)) { for (final BoundaryResponse bndry : boundaries) { final ComplaintTypeResponse complaintType = complaintTypeRepository .fetchComplaintTypeByCode(complaintTypeCode, tenantId); complaintRouter = complaintRouterRepository .findByComplaintTypeAndBoundary(complaintType.getId(), bndry.getId()); if (null != complaintRouter) break; } if (null == complaintRouter) { final ComplaintTypeResponse complaintType = complaintTypeRepository .fetchComplaintTypeByCode(complaintTypeCode, tenantId); complaintRouter = complaintRouterRepository.findByOnlyComplaintType(complaintType.getId()); } if (null == complaintRouter) for (final BoundaryResponse bndry : boundaries) { complaintRouter = complaintRouterRepository.findByOnlyBoundary(bndry.getId()); if (null != complaintRouter) break; } } } else { final ComplaintTypeResponse complaintType = complaintTypeRepository.fetchComplaintTypeByCode(complaintTypeCode, tenantId); complaintRouter = complaintRouterRepository.findByOnlyComplaintType(complaintType.getId()); if (null == complaintRouter) complaintRouter = complaintRouterRepository.findCityAdminGrievanceOfficer("ADMINISTRATION", tenantId); } if (complaintRouter != null) positionResponse = positionRepository.getById(complaintRouter.getPosition(), tenantId); else throw new ApplicationRuntimeException("PGR.001"); } else try { positionHierarchies = positionHierarchyRepository.getByPositionByComplaintTypeAndFromPosition(assigneeId, complaintTypeCode, tenantId); if (positionHierarchies.getEscalationHierarchies().isEmpty() || positionHierarchies.getEscalationHierarchies().contains(null)) { final List<Employee> employees = employeeRepository.getByRoleCode("GRO", tenantId); if (!employees.isEmpty()) employeeResponse = employees.iterator().next(); if (employeeResponse != null) { employeeResponse.getAssignments().stream().anyMatch(assignment -> assignment.getPosition().equals(Boolean.TRUE)); positionResponse = positionRepository.getById(employeeResponse.getAssignments().get(0).getPosition(), tenantId); } } else positionResponse = PositionResponse.builder() .id(positionHierarchies.getEscalationHierarchies().iterator().next().getToPosition()) .build(); } catch (final EscalationException e) { LOG.error("An error occurred, escalation can't be completed ", e); throw new ApplicationRuntimeException("PGR.001", e); } return positionResponse; } }
ComplaintRouterService { public PositionResponse getAssignee(final Long boundaryId, final String complaintTypeCode, final Long assigneeId, final String tenantId) { PositionResponse positionResponse = null; Employee employeeResponse = null; ComplaintRouter complaintRouter = null; PositionHierarchyResponse positionHierarchies = null; final List<BoundaryResponse> boundaries = new ArrayList<>(); if (assigneeId == null) { LOG.info("BoundaryId::" + boundaryId); if (null != boundaryId) { getParentBoundaries(boundaryId, boundaries, tenantId); if (StringUtils.isNotBlank(complaintTypeCode)) { for (final BoundaryResponse bndry : boundaries) { final ComplaintTypeResponse complaintType = complaintTypeRepository .fetchComplaintTypeByCode(complaintTypeCode, tenantId); complaintRouter = complaintRouterRepository .findByComplaintTypeAndBoundary(complaintType.getId(), bndry.getId()); if (null != complaintRouter) break; } if (null == complaintRouter) { final ComplaintTypeResponse complaintType = complaintTypeRepository .fetchComplaintTypeByCode(complaintTypeCode, tenantId); complaintRouter = complaintRouterRepository.findByOnlyComplaintType(complaintType.getId()); } if (null == complaintRouter) for (final BoundaryResponse bndry : boundaries) { complaintRouter = complaintRouterRepository.findByOnlyBoundary(bndry.getId()); if (null != complaintRouter) break; } } } else { final ComplaintTypeResponse complaintType = complaintTypeRepository.fetchComplaintTypeByCode(complaintTypeCode, tenantId); complaintRouter = complaintRouterRepository.findByOnlyComplaintType(complaintType.getId()); if (null == complaintRouter) complaintRouter = complaintRouterRepository.findCityAdminGrievanceOfficer("ADMINISTRATION", tenantId); } if (complaintRouter != null) positionResponse = positionRepository.getById(complaintRouter.getPosition(), tenantId); else throw new ApplicationRuntimeException("PGR.001"); } else try { positionHierarchies = positionHierarchyRepository.getByPositionByComplaintTypeAndFromPosition(assigneeId, complaintTypeCode, tenantId); if (positionHierarchies.getEscalationHierarchies().isEmpty() || positionHierarchies.getEscalationHierarchies().contains(null)) { final List<Employee> employees = employeeRepository.getByRoleCode("GRO", tenantId); if (!employees.isEmpty()) employeeResponse = employees.iterator().next(); if (employeeResponse != null) { employeeResponse.getAssignments().stream().anyMatch(assignment -> assignment.getPosition().equals(Boolean.TRUE)); positionResponse = positionRepository.getById(employeeResponse.getAssignments().get(0).getPosition(), tenantId); } } else positionResponse = PositionResponse.builder() .id(positionHierarchies.getEscalationHierarchies().iterator().next().getToPosition()) .build(); } catch (final EscalationException e) { LOG.error("An error occurred, escalation can't be completed ", e); throw new ApplicationRuntimeException("PGR.001", e); } return positionResponse; } @Autowired  ComplaintRouterService(final ComplaintRouterRepository complaintRouterRepository,
                                  final BoundaryRepository boundaryRepository, final PositionRepository positionRepository,
                                  final ComplaintTypeRepository complaintTypeRepository, final EmployeeRepository employeeRepository,
                                  final PositionHierarchyRepository positionHierarchyRepository); }
ComplaintRouterService { public PositionResponse getAssignee(final Long boundaryId, final String complaintTypeCode, final Long assigneeId, final String tenantId) { PositionResponse positionResponse = null; Employee employeeResponse = null; ComplaintRouter complaintRouter = null; PositionHierarchyResponse positionHierarchies = null; final List<BoundaryResponse> boundaries = new ArrayList<>(); if (assigneeId == null) { LOG.info("BoundaryId::" + boundaryId); if (null != boundaryId) { getParentBoundaries(boundaryId, boundaries, tenantId); if (StringUtils.isNotBlank(complaintTypeCode)) { for (final BoundaryResponse bndry : boundaries) { final ComplaintTypeResponse complaintType = complaintTypeRepository .fetchComplaintTypeByCode(complaintTypeCode, tenantId); complaintRouter = complaintRouterRepository .findByComplaintTypeAndBoundary(complaintType.getId(), bndry.getId()); if (null != complaintRouter) break; } if (null == complaintRouter) { final ComplaintTypeResponse complaintType = complaintTypeRepository .fetchComplaintTypeByCode(complaintTypeCode, tenantId); complaintRouter = complaintRouterRepository.findByOnlyComplaintType(complaintType.getId()); } if (null == complaintRouter) for (final BoundaryResponse bndry : boundaries) { complaintRouter = complaintRouterRepository.findByOnlyBoundary(bndry.getId()); if (null != complaintRouter) break; } } } else { final ComplaintTypeResponse complaintType = complaintTypeRepository.fetchComplaintTypeByCode(complaintTypeCode, tenantId); complaintRouter = complaintRouterRepository.findByOnlyComplaintType(complaintType.getId()); if (null == complaintRouter) complaintRouter = complaintRouterRepository.findCityAdminGrievanceOfficer("ADMINISTRATION", tenantId); } if (complaintRouter != null) positionResponse = positionRepository.getById(complaintRouter.getPosition(), tenantId); else throw new ApplicationRuntimeException("PGR.001"); } else try { positionHierarchies = positionHierarchyRepository.getByPositionByComplaintTypeAndFromPosition(assigneeId, complaintTypeCode, tenantId); if (positionHierarchies.getEscalationHierarchies().isEmpty() || positionHierarchies.getEscalationHierarchies().contains(null)) { final List<Employee> employees = employeeRepository.getByRoleCode("GRO", tenantId); if (!employees.isEmpty()) employeeResponse = employees.iterator().next(); if (employeeResponse != null) { employeeResponse.getAssignments().stream().anyMatch(assignment -> assignment.getPosition().equals(Boolean.TRUE)); positionResponse = positionRepository.getById(employeeResponse.getAssignments().get(0).getPosition(), tenantId); } } else positionResponse = PositionResponse.builder() .id(positionHierarchies.getEscalationHierarchies().iterator().next().getToPosition()) .build(); } catch (final EscalationException e) { LOG.error("An error occurred, escalation can't be completed ", e); throw new ApplicationRuntimeException("PGR.001", e); } return positionResponse; } @Autowired  ComplaintRouterService(final ComplaintRouterRepository complaintRouterRepository,
                                  final BoundaryRepository boundaryRepository, final PositionRepository positionRepository,
                                  final ComplaintTypeRepository complaintTypeRepository, final EmployeeRepository employeeRepository,
                                  final PositionHierarchyRepository positionHierarchyRepository); PositionResponse getAssignee(final Long boundaryId, final String complaintTypeCode, final Long assigneeId, final String tenantId); void getParentBoundaries(final Long bndryId, final List<BoundaryResponse> boundaryList, final String tenantId); }
ComplaintRouterService { public PositionResponse getAssignee(final Long boundaryId, final String complaintTypeCode, final Long assigneeId, final String tenantId) { PositionResponse positionResponse = null; Employee employeeResponse = null; ComplaintRouter complaintRouter = null; PositionHierarchyResponse positionHierarchies = null; final List<BoundaryResponse> boundaries = new ArrayList<>(); if (assigneeId == null) { LOG.info("BoundaryId::" + boundaryId); if (null != boundaryId) { getParentBoundaries(boundaryId, boundaries, tenantId); if (StringUtils.isNotBlank(complaintTypeCode)) { for (final BoundaryResponse bndry : boundaries) { final ComplaintTypeResponse complaintType = complaintTypeRepository .fetchComplaintTypeByCode(complaintTypeCode, tenantId); complaintRouter = complaintRouterRepository .findByComplaintTypeAndBoundary(complaintType.getId(), bndry.getId()); if (null != complaintRouter) break; } if (null == complaintRouter) { final ComplaintTypeResponse complaintType = complaintTypeRepository .fetchComplaintTypeByCode(complaintTypeCode, tenantId); complaintRouter = complaintRouterRepository.findByOnlyComplaintType(complaintType.getId()); } if (null == complaintRouter) for (final BoundaryResponse bndry : boundaries) { complaintRouter = complaintRouterRepository.findByOnlyBoundary(bndry.getId()); if (null != complaintRouter) break; } } } else { final ComplaintTypeResponse complaintType = complaintTypeRepository.fetchComplaintTypeByCode(complaintTypeCode, tenantId); complaintRouter = complaintRouterRepository.findByOnlyComplaintType(complaintType.getId()); if (null == complaintRouter) complaintRouter = complaintRouterRepository.findCityAdminGrievanceOfficer("ADMINISTRATION", tenantId); } if (complaintRouter != null) positionResponse = positionRepository.getById(complaintRouter.getPosition(), tenantId); else throw new ApplicationRuntimeException("PGR.001"); } else try { positionHierarchies = positionHierarchyRepository.getByPositionByComplaintTypeAndFromPosition(assigneeId, complaintTypeCode, tenantId); if (positionHierarchies.getEscalationHierarchies().isEmpty() || positionHierarchies.getEscalationHierarchies().contains(null)) { final List<Employee> employees = employeeRepository.getByRoleCode("GRO", tenantId); if (!employees.isEmpty()) employeeResponse = employees.iterator().next(); if (employeeResponse != null) { employeeResponse.getAssignments().stream().anyMatch(assignment -> assignment.getPosition().equals(Boolean.TRUE)); positionResponse = positionRepository.getById(employeeResponse.getAssignments().get(0).getPosition(), tenantId); } } else positionResponse = PositionResponse.builder() .id(positionHierarchies.getEscalationHierarchies().iterator().next().getToPosition()) .build(); } catch (final EscalationException e) { LOG.error("An error occurred, escalation can't be completed ", e); throw new ApplicationRuntimeException("PGR.001", e); } return positionResponse; } @Autowired  ComplaintRouterService(final ComplaintRouterRepository complaintRouterRepository,
                                  final BoundaryRepository boundaryRepository, final PositionRepository positionRepository,
                                  final ComplaintTypeRepository complaintTypeRepository, final EmployeeRepository employeeRepository,
                                  final PositionHierarchyRepository positionHierarchyRepository); PositionResponse getAssignee(final Long boundaryId, final String complaintTypeCode, final Long assigneeId, final String tenantId); void getParentBoundaries(final Long bndryId, final List<BoundaryResponse> boundaryList, final String tenantId);  }