diff --git a/src/integration-test/java/org/openlmis/requisition/web/RequisitionControllerIntegrationTest.java b/src/integration-test/java/org/openlmis/requisition/web/RequisitionControllerIntegrationTest.java index 5fcacc276..b3b582fb6 100644 --- a/src/integration-test/java/org/openlmis/requisition/web/RequisitionControllerIntegrationTest.java +++ b/src/integration-test/java/org/openlmis/requisition/web/RequisitionControllerIntegrationTest.java @@ -24,6 +24,7 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.mockito.BDDMockito.given; import static org.mockito.Matchers.any; @@ -76,6 +77,7 @@ import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; +import org.openlmis.requisition.domain.RequisitionStatsData; import org.openlmis.requisition.domain.RequisitionTemplate; import org.openlmis.requisition.domain.requisition.Requisition; import org.openlmis.requisition.domain.requisition.RequisitionStatus; @@ -109,6 +111,7 @@ import org.openlmis.requisition.testutils.OrderableDtoDataBuilder; import org.openlmis.requisition.testutils.ProgramDtoDataBuilder; import org.openlmis.requisition.testutils.ReleasableRequisitionDtoDataBuilder; +import org.openlmis.requisition.testutils.UserDtoDataBuilder; import org.openlmis.requisition.utils.DateHelper; import org.openlmis.requisition.utils.Message; import org.openlmis.requisition.utils.Pagination; @@ -147,6 +150,8 @@ public class RequisitionControllerIntegrationTest extends BaseRequisitionWebInte + "/requisitionsForConvert"; private static final String NUMBER_OF_REQ_FOR_APPROVAL_URL = RESOURCE_URL + "/numberOfRequisitionsForApproval"; + private static final String STATUSES_STATS_DATA_URL = RESOURCE_URL + + "/statusesStatsData"; private static final String FACILITY = "facility"; private static final String PROGRAM = "program"; @@ -1966,6 +1971,57 @@ public void shouldGetNumberOfRequisitionsForApprovalForSpecificUserAndProgram() assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); } + // GET /api/requisitions/statusesStatsData + + @Test + public void shouldGetRequisitionStatsData() { + // given + RequisitionStatsData requisitionStatsData = new RequisitionStatsData(); + requisitionStatsData.setRequisitionsToBeCreated(10L); + FacilityDto facility = mockFacility(); + + given(facilityReferenceDataService.findOne(eq(user.getHomeFacilityId()))) + .willReturn(facility); + given(requisitionService.getStatusesStatsData(facility)) + .willReturn(requisitionStatsData); + + // when + RequisitionStatsData result = restAssured.given() + .header(HttpHeaders.AUTHORIZATION, getTokenHeader()) + .contentType(MediaType.APPLICATION_JSON_VALUE) + .when() + .get(STATUSES_STATS_DATA_URL) + .then() + .statusCode(200) + .extract().as(RequisitionStatsData.class); + + // then + assertEquals(Long.valueOf(10), result.getRequisitionsToBeCreated()); + assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); + } + + @Test + public void shouldGetRequisitionStatsDataIfNoHomeFacilityAssigned() { + // given + UserDto userWithoutHomeFacility = new UserDtoDataBuilder().withoutHomeFacility().buildAsDto(); + + given(authenticationHelper.getCurrentUser()).willReturn(userWithoutHomeFacility); + + // when + RequisitionStatsData result = restAssured.given() + .header(HttpHeaders.AUTHORIZATION, getTokenHeader()) + .contentType(MediaType.APPLICATION_JSON_VALUE) + .when() + .get(STATUSES_STATS_DATA_URL) + .then() + .statusCode(200) + .extract().as(RequisitionStatsData.class); + + // then + assertNull(result.getFacilityId()); + assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); + } + // GET /api/requisitions/requisitionsForConvert @Test diff --git a/src/main/java/org/openlmis/requisition/domain/RequisitionStatsData.java b/src/main/java/org/openlmis/requisition/domain/RequisitionStatsData.java new file mode 100644 index 000000000..9a3df8b62 --- /dev/null +++ b/src/main/java/org/openlmis/requisition/domain/RequisitionStatsData.java @@ -0,0 +1,36 @@ +/* + * This program is part of the OpenLMIS logistics management information system platform software. + * Copyright © 2017 VillageReach + * + * This program is free software: you can redistribute it and/or modify it under the terms + * of the GNU Affero General Public License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Affero General Public License for more details. You should have received a copy of + * the GNU Affero General Public License along with this program. If not, see + * http://www.gnu.org/licenses.  For additional information contact info@OpenLMIS.org. + */ + +package org.openlmis.requisition.domain; + +import java.util.Map; +import java.util.UUID; +import lombok.Getter; +import lombok.Setter; + +/** + * The object contains statistical data about requisitions: + * number of requisitions to be created for current periods + * and number of requisitions with each status available in the system. + */ +@Getter +@Setter +public class RequisitionStatsData { + + private UUID facilityId; + private Long requisitionsToBeCreated; + private Map statusesStats; + +} diff --git a/src/main/java/org/openlmis/requisition/repository/custom/RequisitionRepositoryCustom.java b/src/main/java/org/openlmis/requisition/repository/custom/RequisitionRepositoryCustom.java index 57281e614..f21657d37 100644 --- a/src/main/java/org/openlmis/requisition/repository/custom/RequisitionRepositoryCustom.java +++ b/src/main/java/org/openlmis/requisition/repository/custom/RequisitionRepositoryCustom.java @@ -22,6 +22,7 @@ import org.apache.commons.lang3.tuple.Pair; import org.openlmis.requisition.domain.requisition.Requisition; import org.openlmis.requisition.domain.requisition.RequisitionPeriod; +import org.openlmis.requisition.domain.requisition.RequisitionStatus; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -34,6 +35,12 @@ Page searchRequisitions(RequisitionSearchParams params, List searchRequisitions(UUID processingPeriod, UUID facility, UUID program, Boolean emergency); + Long countRequisitions(UUID processingPeriod, UUID facility, UUID program, Boolean emergency, + RequisitionStatus status); + + Long countRequisitions(List processingPeriods, UUID facility, List programs, + Boolean emergency, List statuses); + Optional findRegularRequisition(UUID processingPeriod, UUID facility, UUID program); List searchRequisitionIdAndStatusPairs(UUID facility, UUID program, diff --git a/src/main/java/org/openlmis/requisition/repository/custom/impl/RequisitionRepositoryImpl.java b/src/main/java/org/openlmis/requisition/repository/custom/impl/RequisitionRepositoryImpl.java index 7183d8710..5e2d16d85 100644 --- a/src/main/java/org/openlmis/requisition/repository/custom/impl/RequisitionRepositoryImpl.java +++ b/src/main/java/org/openlmis/requisition/repository/custom/impl/RequisitionRepositoryImpl.java @@ -170,6 +170,74 @@ public List searchRequisitions(UUID processingPeriod, UUID facility return entityManager.createQuery(query).getResultList(); } + /** + * Method returns number of all Requisitions with matched parameters. + * + * @param processingPeriod ProcessingPeriod of searched Requisitions. + * @param facility Facility of searched Requisitions. + * @param program Program of searched Requisitions. + * @param status Status of searched Requisitions. + * @param emergency if {@code true}, the method will look only for emergency requisitions, + * if {@code false}, the method will look only for standard requisitions, + * if {@code null} the method will check all requisitions. + * @return Number of Requisitions with matched parameters. + */ + @Override + public Long countRequisitions(UUID processingPeriod, UUID facility, + UUID program, Boolean emergency, RequisitionStatus status) { + CriteriaBuilder builder = getCriteriaBuilder(); + + CriteriaQuery query = builder.createQuery(Long.class); + Root root = query.from(Requisition.class); + + query = query.select(builder.count(root)); + + Predicate predicate = builder.conjunction(); + predicate = addEqualFilter(predicate, builder, root, EMERGENCY, emergency); + predicate = addEqualFilter(predicate, builder, root, PROCESSING_PERIOD_ID, processingPeriod); + predicate = addEqualFilter(predicate, builder, root, FACILITY_ID, facility); + predicate = addEqualFilter(predicate, builder, root, PROGRAM_ID, program); + predicate = addEqualFilter(predicate, builder, root, STATUS, status); + + query.where(predicate); + + return countEntities(query); + } + + /** + * Method returns number of all Requisitions with matched parameters. + * + * @param facility Facility of searched Requisitions. + * @param programs Program IDs of searched Requisitions. + * @param processingPeriods ProcessingPeriod IDs of searched Requisitions. + * @param statuses Statuses of searched Requisitions. + * @param emergency if {@code true}, the method will look only for emergency requisitions, + * if {@code false}, the method will look only for standard requisitions, + * if {@code null} the method will check all requisitions. + * @return Number of Requisitions with matched parameters. + */ + @Override + public Long countRequisitions(List processingPeriods, UUID facility, + List programs, Boolean emergency, List statuses) { + CriteriaBuilder builder = getCriteriaBuilder(); + + CriteriaQuery query = builder.createQuery(Long.class); + Root root = query.from(Requisition.class); + + query = query.select(builder.count(root)); + + Predicate predicate = builder.conjunction(); + predicate = addEqualFilter(predicate, builder, root, EMERGENCY, emergency); + predicate = addEqualFilter(predicate, builder, root, FACILITY_ID, facility); + predicate = addInFilter(predicate, builder, root, PROGRAM_ID, programs); + predicate = addInFilter(predicate, builder, root, PROCESSING_PERIOD_ID, processingPeriods); + predicate = addInFilter(predicate, builder, root, STATUS, statuses); + + query.where(predicate); + + return countEntities(query); + } + /** * Method returns Requisition with matched parameters. * diff --git a/src/main/java/org/openlmis/requisition/service/PeriodService.java b/src/main/java/org/openlmis/requisition/service/PeriodService.java index dd3e9ae00..52479dd3f 100644 --- a/src/main/java/org/openlmis/requisition/service/PeriodService.java +++ b/src/main/java/org/openlmis/requisition/service/PeriodService.java @@ -69,6 +69,11 @@ public Collection searchByProgramAndFacility(UUID programId return periodReferenceDataService.searchByProgramAndFacility(programId, facilityId); } + public Collection searchByProgramAndFacilityAndDateRange(UUID programId, + UUID facilityId, LocalDate startDate, LocalDate endDate) { + return periodReferenceDataService.search(programId, facilityId, startDate, endDate); + } + public ProcessingPeriodDto getPeriod(UUID periodId) { return periodReferenceDataService.findOne(periodId); } diff --git a/src/main/java/org/openlmis/requisition/service/RequisitionService.java b/src/main/java/org/openlmis/requisition/service/RequisitionService.java index be23c02f6..9db2a7369 100644 --- a/src/main/java/org/openlmis/requisition/service/RequisitionService.java +++ b/src/main/java/org/openlmis/requisition/service/RequisitionService.java @@ -42,6 +42,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Locale; @@ -50,11 +51,11 @@ import java.util.Optional; import java.util.Set; import java.util.UUID; - import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; import org.openlmis.requisition.domain.Rejection; import org.openlmis.requisition.domain.RejectionReason; +import org.openlmis.requisition.domain.RequisitionStatsData; import org.openlmis.requisition.domain.RequisitionTemplate; import org.openlmis.requisition.domain.requisition.ApprovedProductReference; import org.openlmis.requisition.domain.requisition.Requisition; @@ -807,6 +808,60 @@ private boolean isRequisitionNewest(Requisition requisition) { return null == recentRequisition || requisition.getId().equals(recentRequisition.getId()); } + + /** + * Returns statistics data regarding requisitions statuses for a specified facility: + * number of requisitions to be created for current periods and number of requisitions + * with each status available in the system. + * + * @param facility FacilityDto object. + * @return RequisitionStatsData object. + */ + public RequisitionStatsData getStatusesStatsData(FacilityDto facility) { + Profiler profiler = new Profiler("GET_STATUSES_STATS_DATA"); + profiler.setLogger(LOGGER); + + UUID facilityId = facility.getId(); + List postSubmittedStatuses = new ArrayList<>(); + Map statusesStats = new HashMap<>(); + profiler.start("COUNT_REQUISITIONS_FOR_STATUSES"); + for (RequisitionStatus status : RequisitionStatus.values()) { + countRequisitionsForStatus(status, statusesStats, facilityId); + if (status.isPostSubmitted()) { + postSubmittedStatuses.add(status); + } + } + RequisitionStatsData requisitionStatsData = new RequisitionStatsData(); + requisitionStatsData.setStatusesStats(statusesStats); + requisitionStatsData.setFacilityId(facilityId); + + // The maximum number of combinations of actively supported programs and periods for a given + // facility will be the number of requisitions that can be created for that facility. + Set currentFacilityPeriods = new HashSet<>(); + profiler.start("GET_ACTIVELY_SUPPORTED_PROGRAMS"); + List activelySupportedPrograms = facility.getSupportedPrograms() + .stream() + .filter(SupportedProgramDto::isSupportActive) + .filter(SupportedProgramDto::isProgramActive) + .collect(toList()); + profiler.start("GET_CURRENT_PERIODS_FOR_FACILITY"); + getCurrentPeriodsForFacility(activelySupportedPrograms, facilityId, currentFacilityPeriods); + + profiler.start("CALCULATE_REQUISITIONS_TO_BE_CREATED"); + long maxRequisitionForFacility = currentFacilityPeriods.size(); + if (maxRequisitionForFacility == 0) { + requisitionStatsData.setRequisitionsToBeCreated(0L); + } else { + Long createdRequisitions = calculateCurrentlyCreatedRequisitions(activelySupportedPrograms, + currentFacilityPeriods, facilityId, postSubmittedStatuses); + long requisitionsToBeCreated = maxRequisitionForFacility - createdRequisitions; + requisitionStatsData.setRequisitionsToBeCreated(requisitionsToBeCreated); + } + + profiler.stop().log(); + return requisitionStatsData; + } + /** * Returns requisition associated with the most recent period for given program and facility. * @@ -931,6 +986,7 @@ private static Set> getProgramNodePairs(UUID programId, /** * Adds approver details to unskipped requisition line items. + * * @param requisition object */ public void processUnSkippedRequisitionLineItems(Requisition requisition,Locale locale) { @@ -943,6 +999,7 @@ public void processUnSkippedRequisitionLineItems(Requisition requisition,Locale /** * Updates patientsData of requisition. + * * @param requisitionId - id of requisition * @param patientsData - stringified JSON string to store patients data * @return requisition object. @@ -954,4 +1011,50 @@ public Requisition updatePatientsData(UUID requisitionId, String patientsData) { requisition.setPatientsData(patientsData); return requisition; } + + private void countRequisitionsForStatus(RequisitionStatus status, + Map statusesStats, UUID facilityId) { + statusesStats.put( + status.name(), + requisitionRepository.countRequisitions(null, facilityId, + null, null, status) + ); + } + + private void getCurrentPeriodsForFacility(List activelySupportedPrograms, + UUID facilityId, Set currentFacilityPeriods) { + activelySupportedPrograms.forEach(program -> { + if (program.isSupportActive()) { + List foundPeriods = + new ArrayList<>(periodService.searchByProgramAndFacilityAndDateRange( + program.getId(), facilityId, + LocalDate.now(), LocalDate.now())); + currentFacilityPeriods.addAll(foundPeriods); + } + }); + } + + private Long calculateCurrentlyCreatedRequisitions( + List activelySupportedPrograms, + Set currentFacilityPeriods, UUID facilityId, + List postSubmittedStatuses) { + Profiler profiler = new Profiler("CALCULATE_CURRENTLY_CREATED_REQUISITIONS"); + profiler.setLogger(LOGGER); + + profiler.start("GET_ACTIVELY_SUPPORTED_PROGRAMS_IDS"); + List activelySupportedProgramsIds = activelySupportedPrograms.stream() + .map(SupportedProgramDto::getId) + .collect(toList()); + profiler.start("GET_CURRENT_FACILITY_PERIODS_IDS"); + List currentFacilityPeriodsIds = currentFacilityPeriods.stream() + .map(ProcessingPeriodDto::getId) + .collect(toList()); + + profiler.stop().log(); + return requisitionRepository.countRequisitions( + currentFacilityPeriodsIds, facilityId, activelySupportedProgramsIds, null, + postSubmittedStatuses + ); + } + } diff --git a/src/main/java/org/openlmis/requisition/service/referencedata/PeriodReferenceDataService.java b/src/main/java/org/openlmis/requisition/service/referencedata/PeriodReferenceDataService.java index 70421cb85..9e97851b9 100644 --- a/src/main/java/org/openlmis/requisition/service/referencedata/PeriodReferenceDataService.java +++ b/src/main/java/org/openlmis/requisition/service/referencedata/PeriodReferenceDataService.java @@ -55,6 +55,28 @@ public Collection search(UUID processingScheduleId, LocalDa return search(processingScheduleId, endDate, PageRequest.of(0, Integer.MAX_VALUE)); } + /** + * Retrieves periods from the reference data service by start date, end date, program ID + * and facility ID. + * + * @param programId UUID of the program + * @param facilityId UUID of the facility + * @param startDate the start date + * @param endDate the end date + * @return A list of periods matching search criteria + */ + public Collection search(UUID programId, UUID facilityId, + LocalDate startDate, LocalDate endDate) { + RequestParameters parameters = RequestParameters + .init() + .set("programId", programId) + .set("facilityId", facilityId) + .set("startDate", startDate) + .set("endDate", endDate); + + return getPage(parameters).getContent(); + } + /** * Retrieves periods from the reference data service by schedule ID and end date. * diff --git a/src/main/java/org/openlmis/requisition/web/RequisitionController.java b/src/main/java/org/openlmis/requisition/web/RequisitionController.java index 70fdb79b4..bb68afd10 100644 --- a/src/main/java/org/openlmis/requisition/web/RequisitionController.java +++ b/src/main/java/org/openlmis/requisition/web/RequisitionController.java @@ -26,6 +26,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.openlmis.requisition.domain.RequisitionStatsData; import org.openlmis.requisition.domain.RequisitionTemplate; import org.openlmis.requisition.domain.requisition.Requisition; import org.openlmis.requisition.domain.requisition.RequisitionStatus; @@ -514,6 +515,29 @@ public long countRequisitionsForApproval( return numberOfRequisitionsForApproval; } + /** + * Returns data on the number of requisitions of each status for user's home facility. + * + * @return Requisitions statistics data. + */ + @GetMapping(RESOURCE_URL + "/statusesStatsData") + @ResponseStatus(HttpStatus.OK) + public RequisitionStatsData getRequisitionsStatusesStatsData() { + Profiler profiler = getProfiler("GET_REQUISITIONS_STATUSES_STATS_DATA"); + UUID homeFacilityId = getCurrentUser(profiler).getHomeFacilityId(); + if (homeFacilityId == null) { + return new RequisitionStatsData(); + } + FacilityDto homeFacility = findFacility(homeFacilityId, profiler); + + profiler.start("REQUISITION_SERVICE_GET_STATUSES_STATS"); + RequisitionStatsData requisitionStatusesData = + requisitionService.getStatusesStatsData(homeFacility); + + stopProfiler(profiler); + return requisitionStatusesData; + } + /** * Get all submitted Requisitions. * diff --git a/src/main/resources/api-definition.yaml b/src/main/resources/api-definition.yaml index 59d92ec1d..4cac92181 100644 --- a/src/main/resources/api-definition.yaml +++ b/src/main/resources/api-definition.yaml @@ -201,6 +201,7 @@ schemas: "type": "array", "items": { "type": "object", "$ref": "schemas/rejectionDto.json" } } + - requisitionStatsData: !include schemas/requisitionStatsData.json traits: - secured: queryParameters: @@ -843,6 +844,18 @@ resourceTypes: body: application/json: "500": + /statusesStatsData: + get: + is: [ secured, paginated, sorted ] + description: Get statistics on the number of requisitions depending on the status. + responses: + "200": + headers: + Keep-Alive: + body: + application/json: + schema: requisitionStatsData + "500": /requisitionsForConvert: get: is: [ secured, paginated, sorted ] diff --git a/src/main/resources/schemas/requisitionStatsData.json b/src/main/resources/schemas/requisitionStatsData.json new file mode 100644 index 000000000..b1c25896c --- /dev/null +++ b/src/main/resources/schemas/requisitionStatsData.json @@ -0,0 +1,29 @@ +{ + "type": "object", + "$schema": "http://json-schema.org/draft-04/schema", + "title": "RequisitionStatsData", + "description": "A single requisitionStatsData", + "properties": { + "requisitionsToBeCreated": { + "type": [ + "number", + "null" + ], + "title": "requisitionsToBeCreated" + }, + "statusesStats": { + "type": [ + "object", + "null" + ], + "title": "statusesStats" + }, + "facilityId": { + "type": [ + "string", + "null" + ], + "title": "facilityId" + } + } +} \ No newline at end of file diff --git a/src/test/java/org/openlmis/requisition/service/RequisitionServiceTest.java b/src/test/java/org/openlmis/requisition/service/RequisitionServiceTest.java index ee532505e..96ba5e5fa 100644 --- a/src/test/java/org/openlmis/requisition/service/RequisitionServiceTest.java +++ b/src/test/java/org/openlmis/requisition/service/RequisitionServiceTest.java @@ -88,6 +88,7 @@ import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.OngoingStubbing; +import org.openlmis.requisition.domain.RequisitionStatsData; import org.openlmis.requisition.domain.RequisitionTemplate; import org.openlmis.requisition.domain.RequisitionTemplateDataBuilder; import org.openlmis.requisition.domain.requisition.ApprovedProductReference; @@ -1606,6 +1607,58 @@ public void shouldNotReleaseRequisitionsWithoutOrderIfInIncorrectStatus() { requisitionService.releaseWithoutOrder(requisitions); } + @Test + public void shouldReturnRequisitionStatsData() { + // given + when(requisitionRepository.countRequisitions( + eq(null), eq(facility.getId()), eq(null), eq(null), any(RequisitionStatus.class))) + .thenReturn(10L); + UUID programId = UUID.randomUUID(); + mockFacilitySupportedProgramActivate(programId); + when(periodService.searchByProgramAndFacilityAndDateRange(eq(programId), eq(facility.getId()), + any(LocalDate.class), any(LocalDate.class))) + .thenReturn(singletonList(DtoGenerator.of(ProcessingPeriodDto.class))); + when(requisitionRepository.countRequisitions(any(List.class), eq(facility.getId()), + any(List.class), eq(null), any(List.class))) + .thenReturn(0L); + + // when + RequisitionStatsData result = requisitionService.getStatusesStatsData(facility); + + // then + assertEquals(facility.getId(), result.getFacilityId()); + assertEquals(Long.valueOf(1L), result.getRequisitionsToBeCreated()); + assertEquals(RequisitionStatus.values().length, result.getStatusesStats().size()); + } + + @Test + public void shouldReturnRequisitionStatsDataWithZeroReqToBeCreatedIfNoAssignedPeriods() { + // given + when(requisitionRepository.countRequisitions( + eq(null), eq(facility.getId()), eq(null), eq(null), any(RequisitionStatus.class))) + .thenReturn(10L); + UUID programId = UUID.randomUUID(); + mockFacilitySupportedProgramActivate(programId); + when(periodService.searchByProgramAndFacilityAndDateRange(eq(programId), eq(facility.getId()), + any(LocalDate.class), any(LocalDate.class))) + .thenReturn(emptyList()); + + // when + RequisitionStatsData result = requisitionService.getStatusesStatsData(facility); + + // then + assertEquals(facility.getId(), result.getFacilityId()); + assertEquals(Long.valueOf(0L), result.getRequisitionsToBeCreated()); + assertEquals(RequisitionStatus.values().length, result.getStatusesStats().size()); + } + + private void mockFacilitySupportedProgramActivate(UUID programId) { + facility.setSupportedPrograms(singletonList(supportedProgram)); + when(supportedProgram.isProgramActive()).thenReturn(true); + when(supportedProgram.isSupportActive()).thenReturn(true); + when(supportedProgram.getId()).thenReturn(programId); + } + private void validateRequisitionDeleteWithStatus(RequisitionStatus status) { requisition.setStatus(status); when(statusMessageRepository.findByRequisitionId(requisition.getId())) diff --git a/src/test/java/org/openlmis/requisition/testutils/UserDtoDataBuilder.java b/src/test/java/org/openlmis/requisition/testutils/UserDtoDataBuilder.java index 91f46673a..64469c279 100644 --- a/src/test/java/org/openlmis/requisition/testutils/UserDtoDataBuilder.java +++ b/src/test/java/org/openlmis/requisition/testutils/UserDtoDataBuilder.java @@ -23,6 +23,7 @@ import org.openlmis.requisition.dto.UserDto; import org.openlmis.requisition.testutils.api.DtoDataBuilder; +@SuppressWarnings("PMD.TooManyMethods") public class UserDtoDataBuilder implements DtoDataBuilder { private UUID id = UUID.randomUUID(); private String username = RandomStringUtils.randomAlphanumeric(5); @@ -70,6 +71,11 @@ public UserDtoDataBuilder withoutLastName() { return this; } + public UserDtoDataBuilder withoutHomeFacility() { + homeFacilityId = null; + return this; + } + public UserDtoDataBuilder withRoleAssignment(UUID roleId, UUID supervisoryNodeId, UUID programId) { roleAssignments.add(new RoleAssignmentDto(roleId, programId, supervisoryNodeId, null));