Skip to content

Commit

Permalink
added pull period by suggested period from UI
Browse files Browse the repository at this point in the history
  • Loading branch information
hassanhussein committed Jul 27, 2024
1 parent c764749 commit 29435fe
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
17 changes: 15 additions & 2 deletions src/main/java/org/openlmis/requisition/service/PeriodService.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,21 @@ public ProcessingPeriodDto findPeriod(UUID programId, UUID facilityId, UUID sugg
period = findCurrentPeriodForInitiate(programId, facilityId);
}

if (period == null
|| (null != suggestedPeriodId && !suggestedPeriodId.equals(period.getId()))) {
if (suggestedPeriodId != null && period != null) {

ProcessingPeriodDto proposedPeriod = periodReferenceDataService
.searchById(suggestedPeriodId);

if (!proposedPeriod.getId().equals(period.getId())) {
period = proposedPeriod;
} else {
throw new ValidationMessageException(new Message(
ERROR_PERIOD_SHOULD_BE_OLDEST_AND_NOT_ASSOCIATED));
}

}

if (period == null) {
throw new ValidationMessageException(new Message(
ERROR_PERIOD_SHOULD_BE_OLDEST_AND_NOT_ASSOCIATED));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,10 @@ InitiateResult doInitiate(UUID programId, UUID facilityId, UUID suggestedPeriod,
profiler.start("CHECK_FACILITY_SUPPORTS_PROGRAM");
facilitySupportsProgramHelper.checkIfFacilitySupportsProgram(facility, programId);

profiler.start("SKIP_FIND_PROCESSING_PERIOD_WHEN_NO_SUGGESTED");
ProcessingPeriodDto period;
profiler.start("FIND_PROCESSING_PERIOD");

if (suggestedPeriod != null) {

period = periodService.getPeriod(suggestedPeriod);
} else {

profiler.start("FIND_PROCESSING_PERIOD");

period = periodService
ProcessingPeriodDto period = periodService
.findPeriod(programId, facilityId, suggestedPeriod, emergency);
}

boolean reportOnly = period.isReportOnly();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class PeriodServiceTest {
private UUID requisitionId = UUID.randomUUID();

private ProcessingPeriodDto currentPeriod;
private ProcessingPeriodDto suggestedPeriod;
private ProcessingPeriodDto period1;
private ProcessingPeriodDto period2;
private ProcessingPeriodDto period3;
Expand All @@ -115,6 +116,7 @@ public void setUp() throws Exception {
period2 = createPeriod(2);
period3 = createPeriod(3);
period4 = createPeriod(4);
suggestedPeriod = createPeriod(5);
}

@Test
Expand Down Expand Up @@ -406,7 +408,33 @@ public void shouldThrowExceptionIfPeriodIsNotTheOldest() {
when(periodReferenceDataService.searchByProgramAndFacility(programId, facilityId))
.thenReturn(Lists.newArrayList(currentPeriod));

periodService.findPeriod(programId, facilityId, UUID.randomUUID(), false);
when(periodReferenceDataService.searchById(currentPeriod.getId()))
.thenReturn(currentPeriod);

periodService.findPeriod(programId, facilityId, currentPeriod.getId(), false);
}

@Test
public void shouldThrowExceptionIfPeriodHasNoSuggestedPeriod() {
ProcessingScheduleDto processingScheduleDto = new ProcessingScheduleDtoDataBuilder()
.buildAsDto();

currentPeriod.setProcessingSchedule(processingScheduleDto);
currentPeriod.setId(UUID.randomUUID());
suggestedPeriod.setProcessingSchedule(processingScheduleDto);
suggestedPeriod.setId(UUID.randomUUID());

mockSupportedProgramStartDateNotSet();
when(periodReferenceDataService.searchByProgramAndFacility(programId, facilityId))
.thenReturn(Lists.newArrayList(currentPeriod));

when(periodReferenceDataService.searchById(suggestedPeriod.getId()))
.thenReturn(suggestedPeriod);

ProcessingPeriodDto period = periodService
.findPeriod(programId, facilityId, suggestedPeriod.getId(), false);

assertEquals(suggestedPeriod, period);
}

@Test(expected = ValidationMessageException.class)
Expand Down

0 comments on commit 29435fe

Please sign in to comment.