use of ca.bc.gov.educ.penreg.api.exception.InvalidPayloadException in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchAPIController method archiveBatchFiles.
@Override
public ResponseEntity<List<PenRequestBatch>> archiveBatchFiles(final List<PenRequestBatch> penRequestBatches) {
val batchIds = penRequestBatches.stream().map(PenRequestBatch::getPenRequestBatchID).map(UUID::fromString).collect(Collectors.toList());
val errorWithDupPenAssigned = this.sagaService.findDuplicatePenAssignedToDiffPRInSameBatchByBatchIds(batchIds);
if (errorWithDupPenAssigned.isPresent()) {
final ApiError error = ApiError.builder().timestamp(LocalDateTime.now()).message(errorWithDupPenAssigned.get()).status(BAD_REQUEST).build();
throw new InvalidPayloadException(error);
}
final var sagaInProgress = !this.getSagaService().findAllByPenRequestBatchIDInAndStatusIn(batchIds, this.getStatusesFilter()).isEmpty();
if (sagaInProgress) {
return ResponseEntity.status(HttpStatus.CONFLICT).build();
}
val penRequestBatchesFromDB = this.getService().findAllByBatchIds(batchIds);
if (penRequestBatchesFromDB.size() != batchIds.size()) {
final ApiError error = ApiError.builder().timestamp(LocalDateTime.now()).message("Invalid Batch Id provided in the payload.").status(BAD_REQUEST).build();
throw new InvalidPayloadException(error);
}
penRequestBatchesFromDB.forEach(el -> {
el.setPenRequestBatchStatusCode(PenRequestBatchStatusCodes.ARCHIVED.getCode());
el.setProcessDate(LocalDateTime.now());
});
this.getService().updateAllPenRequestBatchAttachedEntities(penRequestBatchesFromDB);
return ResponseEntity.ok(penRequestBatchesFromDB.stream().map(PenRequestBatchMapper.mapper::toStructure).collect(Collectors.toList()));
}
use of ca.bc.gov.educ.penreg.api.exception.InvalidPayloadException in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchStudentInfoRequestMacroController method validatePayload.
private void validatePayload(final PenRequestBatchStudentInfoRequestMacro penRequestMacro, final boolean isCreateOperation) {
val validationResult = this.getPenRequestBatchMacroPayloadValidator().validatePayload(penRequestMacro, isCreateOperation);
this.penRequestBatchMacroPayloadValidator.validatePayload(penRequestMacro, isCreateOperation);
if (!validationResult.isEmpty()) {
final ApiError error = ApiError.builder().timestamp(LocalDateTime.now()).message("Payload contains invalid data.").status(BAD_REQUEST).build();
error.addValidationErrors(validationResult);
throw new InvalidPayloadException(error);
}
}
Aggregations