public RequisitionDto authorizeRequisition(updateRequisition(@RequestBody RequisitionDto requisitionDto,
@PathVariable("id") UUID requisitionId) {
permissionService.canAuthorizeRequisitioncanUpdateRequisition(requisitionId);
if (isNotTrue(isNull(requisitionDto.getId()))
&& isNotTrue(configurationSettingService.getBoolValue("skipAuthorization"requisitionId.equals(requisitionDto.getId()))) {
throw new ValidationMessageException(new Message(ERROR_AUTHORIZATION_TO_BE_SKIPPEDID_MISMATCH));
}
Requisition requisitionrequisitionToUpdate = requisitionRepository.findOne(requisitionId);
if (requisition == nullisNull(requisitionToUpdate)) {
throw new ContentNotFoundMessageException(new Message(
new Message(MessageKeys.ERROR_REQUISITION_NOT_FOUND, requisitionId));
}
Requisition requisition = RequisitionBuilder.newRequisition(requisitionDto,
requisitionToUpdate.getTemplate(), requisitionToUpdate.getProgramId(),
requisitionToUpdate.getStatus());
requisition.setId(requisitionId);
requisitionVersionValidator.validateRequisitionTimestamps(
requisition, requisitionToUpdate
);
RequisitionStatus status = requisitionToUpdate.getStatus();
if (status != RequisitionStatus.APPROVED
&& status != RequisitionStatus.SKIPPED
&& status != RequisitionStatus.RELEASED) {
LOGGER.debug("Updating requisition with id: {}", requisitionId);
BindingResult bindingResult = new BeanPropertyBindingResult(requisition, REQUISITION);
validator draftValidator.validate(requisition, bindingResult);
if (bindingResult.hasErrors()) {
LOGGER.warn("Validation for requisition failed: {}", getErrors(bindingResult));
throw new BindingResultException(getErrors(bindingResult));
}
facilitySupportsProgramHelperrequisitionToUpdate.checkIfFacilitySupportsProgramupdateFrom(requisition.getFacilityId(),,
stockAdjustmentReasonReferenceDataService.getStockAdjustmentReasonsByProgram(
requisitionrequisitionToUpdate.getProgramId()), orderableReferenceDataService.findAll());
UserDto userrequisitionToUpdate = authenticationHelperrequisitionRepository.getCurrentUsersave(requisitionToUpdate);
LOGGER.debug("Saved requisition.authorize(orderableReferenceDataService.findAll(), user.getId()) with id: " + requisitionToUpdate.getId());
return requisitionDtoBuilder.build(requisitionToUpdate);
} else {
throw new ValidationMessageException(new Message(ERROR_CANNOT_UPDATE_WITH_STATUS,
requisitionToUpdate.getStatus()));
}
UUID supervisoryNode = supervisoryNodeReferenceDataService.findSupervisoryNode(
requisition.getProgramId(), requisition.getFacilityId()).getId();
requisition.setSupervisoryNodeId(supervisoryNode);
saveStatusMessage(requisition);} |