Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
firstline513267
linenumberstrue
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);}

Time consuming calls:

  • Line 537: Fetch all the orderables from reference data service.
  • Line 549: Build the response dto


Code Block
languagejava
firstline215
linenumberstrue
public RequisitionDto submitRequisition(@PathVariable("id") UUID requisitionId) {
  permissionService.canSubmitRequisition(requisitionId);
  Requisition requisition = requisitionRepository.findOne(requisitionId);
  if (requisition == null) {
    throw new ContentNotFoundMessageException(
        new Message(MessageKeys.ERROR_REQUISITION_NOT_FOUND, requisitionId));
  }

  BindingResult bindingResult = new BeanPropertyBindingResult(requisition, REQUISITION);
  validator.validate(requisition, bindingResult);

  if (bindingResult.hasErrors()) {
    LOGGER.warn("Validation for requisition failed: {}", getErrors(bindingResult));
    throw new BindingResultException(getErrors(bindingResult));
  }

  facilitySupportsProgramHelper.checkIfFacilitySupportsProgram(requisition.getFacilityId(),
      requisition.getProgramId());

  LOGGER.debug("Submitting a requisition with id " + requisition.getId());

  UserDto user = authenticationHelper.getCurrentUser();
  requisition.submit(orderableReferenceDataService.findAll(), user.getId());
  saveStatusMessage(requisition);
  
  requisitionRepository.save(requisition);
  requisitionStatusProcessor.statusChange(requisition);
  LOGGER.debug("Requisition: with id " + requisitionIdrequisition.getId() + " authorized.submitted");

  return requisitionDtoBuilder.build(requisition);
}

...