Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OLMIS-7995: Changed supervisory node assignment to required for authorization process #62

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/org/openlmis/buq/i18n/MessageKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,9 @@ public BottomUpQuantificationDataBuilder withBottomUpQuantificationFundingDetail
return this;
}

public BottomUpQuantificationDataBuilder withSupervisoryNodeId(UUID supervisoryNodeId) {
this.supervisoryNodeId = supervisoryNodeId;
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading