...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
public RequisitionDto updateRequisition(@RequestBody RequisitionDto requisitionDto, @PathVariable("id") UUID requisitionId) { permissionService.canUpdateRequisition(requisitionId); if (isNotTrue(isNull(requisitionDto.getId())) && isNotTrue(requisitionId.equals(requisitionDto.getId()))) { throw new ValidationMessageException(new Message(ERROR_ID_MISMATCH)); } Requisition requisitionToUpdate = requisitionRepository.findOne(requisitionId); if (isNull(requisitionToUpdate)) { throw new ContentNotFoundMessageException(new Message( 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); draftValidator.validate(requisition, bindingResult); if (bindingResult.hasErrors()) { LOGGER.warn("Validation for requisition failed: {}", getErrors(bindingResult)); throw new BindingResultException(getErrors(bindingResult)); } requisitionToUpdate.updateFrom(requisition, stockAdjustmentReasonReferenceDataService.getStockAdjustmentReasonsByProgram( requisitionToUpdate.getProgramId()), orderableReferenceDataService.findAll()); requisitionToUpdate = requisitionRepository.save(requisitionToUpdate); LOGGER.debug("Saved requisition with id: " + requisitionToUpdate.getId()); return requisitionDtoBuilder.build(requisitionToUpdate); } else { throw new ValidationMessageException(new Message(ERROR_CANNOT_UPDATE_WITH_STATUS, requisitionToUpdate.getStatus())); } } |
Time consuming calls:
- Line 313: Build the response dto.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
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 " + requisition.getId() + " submitted"); return requisitionDtoBuilder.build(requisition); } |
Time consuming calls:
- Line 237: Fetch all the orderables from reference data service.
- Line 244: Build the response dto.
RequisitionDtoBuilder
Code Block | ||||
---|---|---|---|---|
| ||||
public RequisitionDto build(Requisition requisition) { if (null == requisition) { return null; } RequisitionDto requisitionDto = new RequisitionDto(); requisition.export(requisitionDto); List<RequisitionLineItemDto> requisitionLineItemDtoList = requisitionExportHelper.exportToDtos(requisition.getRequisitionLineItems()); requisitionDto.setTemplate(requisition.getTemplate()); requisitionDto.setFacility(facilityReferenceDataService.findOne(requisition.getFacilityId())); requisitionDto.setProgram(programReferenceDataService.findOne(requisition.getProgramId())); requisitionDto.setProcessingPeriod(periodService.getPeriod( requisition.getProcessingPeriodId())); requisitionDto.setRequisitionLineItems(requisitionLineItemDtoList); if (null != requisition.getAvailableNonFullSupplyProducts()) { requisitionDto.setAvailableNonFullSupplyProducts( requisition.getAvailableNonFullSupplyProducts() .stream() .filter(Objects::nonNull) .map(orderableReferenceDataService::findOne) .collect(Collectors.toSet()) ); } return requisitionDto; } |
...