From a4e187d78d0abf7b75f7599534d63a254fbf0e5f Mon Sep 17 00:00:00 2001 From: Szymon Radziszewski Date: Mon, 9 Sep 2024 23:43:46 +0200 Subject: [PATCH] OLMIS-7995: Changed supervisory node assignment to required for authorization process --- .../org/openlmis/buq/i18n/MessageKeys.java | 2 ++ .../buq/BottomUpQuantificationService.java | 5 ++++ src/main/resources/messages_en.properties | 1 + .../BottomUpQuantificationDataBuilder.java | 5 ++++ .../BottomUpQuantificationServiceTest.java | 27 +++++++++++++++++++ 5 files changed, 40 insertions(+) diff --git a/src/main/java/org/openlmis/buq/i18n/MessageKeys.java b/src/main/java/org/openlmis/buq/i18n/MessageKeys.java index 81d029b..8bc5a3a 100644 --- a/src/main/java/org/openlmis/buq/i18n/MessageKeys.java +++ b/src/main/java/org/openlmis/buq/i18n/MessageKeys.java @@ -114,6 +114,8 @@ public abstract class MessageKeys { public static final String ERROR_MUST_BE_AUTHORIZED_IN_APPROVAL_OR_APPROVED_TO_BE_REJECTED = join(ERROR_PREFIX, REJECT, "mustBeAuthorizedInApprovalOrApprovedToBeRejected"); + public static final String ERROR_SUPERVISORY_NODE_CANNOT_BE_NULL_TO_BE_AUTHORIZED = join( + ERROR_PREFIX, AUTHORIZE, "supervisoryNodeCannotBeNull"); public static final String ERROR_LINE_ITEM_FIELD_REQUIRED = join(ERROR_PREFIX, LINE_ITEM, FIELD, REQUIRED); public static final String ERROR_LINE_ITEM_FIELD_MUST_BE_NON_NEGATIVE = join(ERROR_PREFIX, diff --git a/src/main/java/org/openlmis/buq/service/buq/BottomUpQuantificationService.java b/src/main/java/org/openlmis/buq/service/buq/BottomUpQuantificationService.java index bd02aa8..7342d64 100644 --- a/src/main/java/org/openlmis/buq/service/buq/BottomUpQuantificationService.java +++ b/src/main/java/org/openlmis/buq/service/buq/BottomUpQuantificationService.java @@ -24,6 +24,7 @@ import static org.openlmis.buq.i18n.MessageKeys.ERROR_PROCESSING_PERIOD_NOT_FOUND; import static org.openlmis.buq.i18n.MessageKeys.ERROR_PROGRAM_NOT_FOUND; import static org.openlmis.buq.i18n.MessageKeys.ERROR_SOURCE_OF_FUND_NOT_FOUND; +import static org.openlmis.buq.i18n.MessageKeys.ERROR_SUPERVISORY_NODE_CANNOT_BE_NULL_TO_BE_AUTHORIZED; import java.io.IOException; import java.time.ZonedDateTime; @@ -309,6 +310,10 @@ public BottomUpQuantification authorize(BottomUpQuantificationDto bottomUpQuanti updatedBottomUpQuantification.setStatus(BottomUpQuantificationStatus.AUTHORIZED); addNewStatusChange(updatedBottomUpQuantification); assignInitialSupervisoryNode(updatedBottomUpQuantification); + if (Objects.isNull(updatedBottomUpQuantification.getSupervisoryNodeId())) { + throw new ValidationMessageException( + ERROR_SUPERVISORY_NODE_CANNOT_BE_NULL_TO_BE_AUTHORIZED); + } return updatedBottomUpQuantification; } diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index eaf3797..c0c24c7 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -3,6 +3,7 @@ buq.error.bottomUpQuantification.notFound=Bottom-up quantification not found! buq.error.prepare.missingParameters=Facility, program and processing period must be specified when preparing a bottom-up quantification. Missing parameter(s): {0}. buq.error.submit.mustBeDraftOrRejectedToBeSubmitted=Unable to submit bottom-up quantification, it must have status 'DRAFT' or 'REJECTED' to be submitted. buq.error.authorize.mustBeSubmittedOrRejectedToBeAuthorized=Unable to authorize bottom-up quantification, it must have status 'SUBMITTED' or 'REJECTED' to be authorized. +buq.error.authorize.supervisoryNodeCannotBeNull=Unable to authorize bottom-up quantification. The system was unable to assign initial supervisory node for this bottom-up quantification. Make sure all configuration steps have been completed, including facility supporting program, processing schedule, and requisition group. buq.error.approve.mustBeAuthorizedOrInApprovalToBeApproved=Unable to approve bottom-up quantification, it must have status 'AUTHORIZED' or 'IN_APPROVAL' to be approved. buq.error.reject.mustBeAuthorizedInApprovalOrApprovedToBeRejected=Unable to reject bottom-up quantification, it must have status 'AUTHORIZED', 'IN_APPROVAL' OR 'APPROVED' to be rejected. buq.error.lineItem.field.mustBeNonNegative=The {0} field of the bottom-up quantification line item must be non-negative. diff --git a/src/test/java/org/openlmis/buq/builder/BottomUpQuantificationDataBuilder.java b/src/test/java/org/openlmis/buq/builder/BottomUpQuantificationDataBuilder.java index 2cb566f..edb3386 100644 --- a/src/test/java/org/openlmis/buq/builder/BottomUpQuantificationDataBuilder.java +++ b/src/test/java/org/openlmis/buq/builder/BottomUpQuantificationDataBuilder.java @@ -123,4 +123,9 @@ public BottomUpQuantificationDataBuilder withBottomUpQuantificationFundingDetail return this; } + public BottomUpQuantificationDataBuilder withSupervisoryNodeId(UUID supervisoryNodeId) { + this.supervisoryNodeId = supervisoryNodeId; + return this; + } + } diff --git a/src/test/java/org/openlmis/buq/service/buq/BottomUpQuantificationServiceTest.java b/src/test/java/org/openlmis/buq/service/buq/BottomUpQuantificationServiceTest.java index 826f4c6..1e3060e 100644 --- a/src/test/java/org/openlmis/buq/service/buq/BottomUpQuantificationServiceTest.java +++ b/src/test/java/org/openlmis/buq/service/buq/BottomUpQuantificationServiceTest.java @@ -450,6 +450,33 @@ public void shouldThrowValidationMessageExceptionIfBuqIsInvalidForAuthorize() { invalidBottomUpQuantificationId); } + @Test(expected = ValidationMessageException.class) + public void shouldNotAuthorizeBottomUpQuantificationIfSupervisoryNodeNotAssigned() { + UUID bottomUpQuantificationId = UUID.randomUUID(); + BottomUpQuantification bottomUpQuantification = new BottomUpQuantificationDataBuilder() + .withId(bottomUpQuantificationId) + .withSupervisoryNodeId(null) + .build(); + BottomUpQuantificationDto bottomUpQuantificationDto = BottomUpQuantificationDto + .newInstance(bottomUpQuantification); + mockUserHomeFacilityPermission(bottomUpQuantificationDto); + doNothing().when(validator).validateCanBeAuthorized(bottomUpQuantificationDto, + bottomUpQuantificationId); + mockUpdateBottomUpQuantification(bottomUpQuantificationId, bottomUpQuantification); + when(bottomUpQuantificationLineItemRepository + .saveAll(bottomUpQuantification.getBottomUpQuantificationLineItems())) + .thenReturn(new ArrayList<>()); + BottomUpQuantificationStatusChange statusChange = + new BottomUpQuantificationStatusChange(); + statusChange.setStatus(BottomUpQuantificationStatus.AUTHORIZED); + when(bottomUpQuantificationStatusChangeRepository + .save(any(BottomUpQuantificationStatusChange.class))) + .thenReturn(statusChange); + + bottomUpQuantificationService + .authorize(bottomUpQuantificationDto, bottomUpQuantificationId); + } + @Test public void shouldCallDelete() { BottomUpQuantification bottomUpQuantification = new BottomUpQuantificationDataBuilder()