@Test public void shouldFetchAllRequisitionsForFacilitiesAndProgramSupervisedByUserForApproval() throws Exception { final RoleAssignment firstAssignment = new RoleAssignment(1L, 1L, 1L, new SupervisoryNode()); final RoleAssignment secondAssignment = new RoleAssignment(2L, 2L, 2L, new SupervisoryNode()); final Rnr requisition = make(a(RequisitionBuilder.defaultRequisition)); final List<Rnr> requisitionsForFirstAssignment = new ArrayList<Rnr>() {{ add(requisition); }}; final List<Rnr> requisitionsForSecondAssignment = new ArrayList<>(); List<RoleAssignment> roleAssignments = new ArrayList<RoleAssignment>() {{ add(firstAssignment); add(secondAssignment); }}; when(roleAssignmentService.getRoleAssignments(APPROVE_REQUISITION, USER_ID)).thenReturn(roleAssignments); when(requisitionRepository.getAuthorizedRequisitions(firstAssignment)).thenReturn(requisitionsForFirstAssignment); when(requisitionRepository.getAuthorizedRequisitions(secondAssignment)).thenReturn(requisitionsForSecondAssignment); Program expectedProgram = new Program(); Facility expectedFacility = new Facility(); ProcessingPeriod expectedPeriod = new ProcessingPeriod(); when(programService.getById(3L)).thenReturn(expectedProgram); when(facilityService.getById(3L)).thenReturn(expectedFacility); when(processingScheduleService.getPeriodById(3L)).thenReturn(expectedPeriod); List<Rnr> requisitions = requisitionService.listForApproval(USER_ID); List<Rnr> expectedRequisitions = new ArrayList<Rnr>() {{ addAll(requisitionsForFirstAssignment); addAll(requisitionsForSecondAssignment); }}; assertThat(requisitions, is(expectedRequisitions)); assertThat(requisition.getProgram(), is(expectedProgram)); assertThat(requisition.getFacility(), is(expectedFacility)); assertThat(requisition.getPeriod(), is(expectedPeriod)); verify(requisitionRepository, times(1)).getAuthorizedRequisitions(firstAssignment); verify(requisitionRepository, times(1)).getAuthorizedRequisitions(secondAssignment); }
@Deprecated public List<Rnr> listForApproval(Long userId) { List<RoleAssignment> assignments = roleAssignmentService.getRoleAssignments(APPROVE_REQUISITION, userId); List<Rnr> requisitionsForApproval = new ArrayList<>(); for (RoleAssignment assignment : assignments) { final List<Rnr> requisitions = requisitionRepository.getAuthorizedRequisitions(assignment); requisitionsForApproval.addAll(requisitions); } fillFacilityPeriodProgramWithAuditFields(requisitionsForApproval); return requisitionsForApproval; }
RequisitionService { @Deprecated public List<Rnr> listForApproval(Long userId) { List<RoleAssignment> assignments = roleAssignmentService.getRoleAssignments(APPROVE_REQUISITION, userId); List<Rnr> requisitionsForApproval = new ArrayList<>(); for (RoleAssignment assignment : assignments) { final List<Rnr> requisitions = requisitionRepository.getAuthorizedRequisitions(assignment); requisitionsForApproval.addAll(requisitions); } fillFacilityPeriodProgramWithAuditFields(requisitionsForApproval); return requisitionsForApproval; } }
RequisitionService { @Deprecated public List<Rnr> listForApproval(Long userId) { List<RoleAssignment> assignments = roleAssignmentService.getRoleAssignments(APPROVE_REQUISITION, userId); List<Rnr> requisitionsForApproval = new ArrayList<>(); for (RoleAssignment assignment : assignments) { final List<Rnr> requisitions = requisitionRepository.getAuthorizedRequisitions(assignment); requisitionsForApproval.addAll(requisitions); } fillFacilityPeriodProgramWithAuditFields(requisitionsForApproval); return requisitionsForApproval; }  }
RequisitionService { @Deprecated public List<Rnr> listForApproval(Long userId) { List<RoleAssignment> assignments = roleAssignmentService.getRoleAssignments(APPROVE_REQUISITION, userId); List<Rnr> requisitionsForApproval = new ArrayList<>(); for (RoleAssignment assignment : assignments) { final List<Rnr> requisitions = requisitionRepository.getAuthorizedRequisitions(assignment); requisitionsForApproval.addAll(requisitions); } fillFacilityPeriodProgramWithAuditFields(requisitionsForApproval); return requisitionsForApproval; }  @Autowired void setRequisitionSearchStrategyFactory(RequisitionSearchStrategyFactory requisitionSearchStrategyFactory); @Transactional Rnr initiate(Facility facility, Program program, Long modifiedBy, Boolean emergency, ProcessingPeriod proposedPeriod); void populateProductsPriceBasedOnPriceSchedule(Long facilityId, Long programId, List<FacilityTypeApprovedProduct> facilityTypeApprovedProducts); @Transactional Rnr save(Rnr rnr); @Transactional Rnr submit(Rnr rnr); @Transactional Rnr authorize(Rnr rnr); @Transactional Rnr approve(Rnr requisition, String name); void releaseRequisitionsAsOrder(List<Rnr> requisitions, Long userId); List<Rnr> get(RequisitionSearchCriteria criteria); List<LossesAndAdjustmentsType> getLossesAndAdjustmentsTypes(); OpenLmisMessage getSubmitMessageBasedOnSupervisoryNode(Facility facility, Program program); OpenLmisMessage getAuthorizeMessageBasedOnSupervisoryNode(Facility facility, Program program); OpenLmisMessage getApproveMessageBasedOnParentNode(Rnr rnr); Rnr getFullRequisitionById(Long id); ProcessingPeriod getPeriodForInitiating(Facility facility, Program program); List<ProcessingPeriod> getAllPeriodsForInitiatingRequisition(Long facilityId, Long programId); @Deprecated List<Rnr> listForApproval(Long userId); List<RnrDTO> listForApprovalDto(Long userId); List<RnrLineItem> getNRnrLineItems(String productCode, Rnr rnr, Integer n, Date startDate); Integer getCategoryCount(Rnr requisition, boolean fullSupply); void insertComment(Comment comment); List getCommentsByRnrId(Long rnrId); Rnr getLWById(Long rnrId); Date getOperationDateFor(Long rnrId, String status); ProcessingPeriod getCurrentPeriod(RequisitionSearchCriteria criteria); List<Rnr> getApprovedRequisitionsForCriteriaAndPageNumber(String searchType, String searchVal, Integer pageNumber,
                                                                   Integer totalNumberOfPages, Long userId, String rightName,
                                                                   String sortBy, String sortDirection); Integer getNumberOfPagesOfApprovedRequisitionsForCriteria(String searchType, String searchVal, Long userId, String rightName); List<ProcessingPeriod> getProcessingPeriods(RequisitionSearchCriteria criteria); List<Rnr> getRequisitionsFor(RequisitionSearchCriteria criteria, List<ProcessingPeriod> periodList); Long getFacilityId(Long id); RnrLineItem getNonSkippedLineItem(Long rnrId, String productCode); String deleteRnR(Long rnrId); void skipRnR(Long rnrId, Long userId); void reOpenRnR(Long rnrId, Long userId); void rejectRnR(Long rnrId, Long userId); Integer findM(ProcessingPeriod period); Long getProgramId(Long rnrId); @Transactional void updateClientFields(Rnr rnr); @Transactional void insertPatientQuantificationLineItems(Rnr rnr); List<Rnr> getRequisitionsByFacility(Facility facility); @Transactional void insertRnrSignatures(Rnr rnr); }
RequisitionService { @Deprecated public List<Rnr> listForApproval(Long userId) { List<RoleAssignment> assignments = roleAssignmentService.getRoleAssignments(APPROVE_REQUISITION, userId); List<Rnr> requisitionsForApproval = new ArrayList<>(); for (RoleAssignment assignment : assignments) { final List<Rnr> requisitions = requisitionRepository.getAuthorizedRequisitions(assignment); requisitionsForApproval.addAll(requisitions); } fillFacilityPeriodProgramWithAuditFields(requisitionsForApproval); return requisitionsForApproval; }  @Autowired void setRequisitionSearchStrategyFactory(RequisitionSearchStrategyFactory requisitionSearchStrategyFactory); @Transactional Rnr initiate(Facility facility, Program program, Long modifiedBy, Boolean emergency, ProcessingPeriod proposedPeriod); void populateProductsPriceBasedOnPriceSchedule(Long facilityId, Long programId, List<FacilityTypeApprovedProduct> facilityTypeApprovedProducts); @Transactional Rnr save(Rnr rnr); @Transactional Rnr submit(Rnr rnr); @Transactional Rnr authorize(Rnr rnr); @Transactional Rnr approve(Rnr requisition, String name); void releaseRequisitionsAsOrder(List<Rnr> requisitions, Long userId); List<Rnr> get(RequisitionSearchCriteria criteria); List<LossesAndAdjustmentsType> getLossesAndAdjustmentsTypes(); OpenLmisMessage getSubmitMessageBasedOnSupervisoryNode(Facility facility, Program program); OpenLmisMessage getAuthorizeMessageBasedOnSupervisoryNode(Facility facility, Program program); OpenLmisMessage getApproveMessageBasedOnParentNode(Rnr rnr); Rnr getFullRequisitionById(Long id); ProcessingPeriod getPeriodForInitiating(Facility facility, Program program); List<ProcessingPeriod> getAllPeriodsForInitiatingRequisition(Long facilityId, Long programId); @Deprecated List<Rnr> listForApproval(Long userId); List<RnrDTO> listForApprovalDto(Long userId); List<RnrLineItem> getNRnrLineItems(String productCode, Rnr rnr, Integer n, Date startDate); Integer getCategoryCount(Rnr requisition, boolean fullSupply); void insertComment(Comment comment); List getCommentsByRnrId(Long rnrId); Rnr getLWById(Long rnrId); Date getOperationDateFor(Long rnrId, String status); ProcessingPeriod getCurrentPeriod(RequisitionSearchCriteria criteria); List<Rnr> getApprovedRequisitionsForCriteriaAndPageNumber(String searchType, String searchVal, Integer pageNumber,
                                                                   Integer totalNumberOfPages, Long userId, String rightName,
                                                                   String sortBy, String sortDirection); Integer getNumberOfPagesOfApprovedRequisitionsForCriteria(String searchType, String searchVal, Long userId, String rightName); List<ProcessingPeriod> getProcessingPeriods(RequisitionSearchCriteria criteria); List<Rnr> getRequisitionsFor(RequisitionSearchCriteria criteria, List<ProcessingPeriod> periodList); Long getFacilityId(Long id); RnrLineItem getNonSkippedLineItem(Long rnrId, String productCode); String deleteRnR(Long rnrId); void skipRnR(Long rnrId, Long userId); void reOpenRnR(Long rnrId, Long userId); void rejectRnR(Long rnrId, Long userId); Integer findM(ProcessingPeriod period); Long getProgramId(Long rnrId); @Transactional void updateClientFields(Rnr rnr); @Transactional void insertPatientQuantificationLineItems(Rnr rnr); List<Rnr> getRequisitionsByFacility(Facility facility); @Transactional void insertRnrSignatures(Rnr rnr); static final String RNR_AUTHORIZATION_ERROR; static final String RNR_SUBMISSION_ERROR; static final String RNR_OPERATION_UNAUTHORIZED; static final String RNR_AUTHORIZED_SUCCESSFULLY; static final String RNR_SUBMITTED_SUCCESSFULLY; static final String RNR_AUTHORIZED_SUCCESSFULLY_WITHOUT_SUPERVISOR; static final String RNR_APPROVED_SUCCESSFULLY_WITHOUT_SUPERVISOR; static final String NO_SUPERVISORY_NODE_CONTACT_ADMIN; static final String RNR_APPROVED_SUCCESSFULLY; static final String APPROVAL_NOT_ALLOWED; static final String SEARCH_ALL; static final String SEARCH_PROGRAM_NAME; static final String SEARCH_FACILITY_CODE; static final String SEARCH_FACILITY_NAME; static final String SEARCH_SUPPLYING_DEPOT_NAME; static final String CONVERT_TO_ORDER_PAGE_SIZE; static final String NUMBER_OF_PAGES; }