use of ca.bc.gov.educ.penreg.api.exception.SagaRuntimeException in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchSagaController method processBatchRequest.
private ResponseEntity<List<ArchiveAndReturnSagaResponse>> processBatchRequest(final SagaEnum sagaName, final PenRequestBatchArchiveAndReturnAllSagaData penRequestBatchArchiveAndReturnAllSagaData) {
final var penRequestBatchIDs = penRequestBatchArchiveAndReturnAllSagaData.getPenRequestBatchArchiveAndReturnSagaData().stream().map(PenRequestBatchArchiveAndReturnSagaData::getPenRequestBatchID).collect(Collectors.toList());
final var sagaInProgress = !this.getSagaService().findAllByPenRequestBatchIDInAndStatusIn(penRequestBatchIDs, this.getStatusesFilter()).isEmpty();
if (sagaInProgress) {
return ResponseEntity.status(HttpStatus.CONFLICT).build();
}
try {
final var updateUser = penRequestBatchArchiveAndReturnAllSagaData.getUpdateUser();
final var payloads = penRequestBatchArchiveAndReturnAllSagaData.getPenRequestBatchArchiveAndReturnSagaData().stream().map(sagaData -> {
sagaData.setUpdateUser(updateUser);
try {
val payload = JsonUtil.getJsonStringFromObject(sagaData);
return Pair.of(sagaData.getPenRequestBatchID(), payload);
} catch (final JsonProcessingException e) {
throw new InvalidParameterException(e.getMessage());
}
}).collect(Collectors.toList());
final var sagas = this.getOrchestratorMap().get(sagaName.toString()).saveMultipleSagas(payloads, penRequestBatchArchiveAndReturnAllSagaData.getCreateUser());
for (val saga : sagas) {
this.getOrchestratorMap().get(sagaName.toString()).startSaga(saga);
}
return ResponseEntity.ok(sagas.stream().map(archiveAndReturnSagaResponseMapper::toStruct).collect(Collectors.toList()));
} catch (final Exception e) {
throw new SagaRuntimeException(e.getMessage());
}
}
use of ca.bc.gov.educ.penreg.api.exception.SagaRuntimeException in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchSagaController method processStudentRequest.
private ResponseEntity<String> processStudentRequest(final SagaEnum sagaName, final BasePenRequestBatchStudentSagaData penRequestBatchStudentSagaData) {
final var penRequestBatchStudentID = penRequestBatchStudentSagaData.getPenRequestBatchStudentID();
final var penRequestBatchID = penRequestBatchStudentSagaData.getPenRequestBatchID();
final var sagaInProgress = !this.getSagaService().findAllByPenRequestBatchStudentIDAndStatusIn(penRequestBatchStudentID, this.getStatusesFilter()).isEmpty();
final var parentSagaInProgress = !this.getSagaService().findAllByPenRequestBatchIDInAndStatusIn(List.of(penRequestBatchID), this.getStatusesFilter()).isEmpty();
if (sagaInProgress || parentSagaInProgress) {
return ResponseEntity.status(HttpStatus.CONFLICT).build();
}
final var orchestrator = this.getOrchestratorMap().get(sagaName.toString());
try {
final var saga = orchestrator.createSaga(JsonUtil.getJsonStringFromObject(penRequestBatchStudentSagaData), penRequestBatchStudentID, penRequestBatchStudentSagaData.getPenRequestBatchID(), penRequestBatchStudentSagaData.getCreateUser());
orchestrator.startSaga(saga);
return ResponseEntity.ok(saga.getSagaId().toString());
} catch (final JsonProcessingException e) {
log.error("JsonProcessingException while processStudentRequest", e);
throw new SagaRuntimeException(e.getMessage());
}
}
use of ca.bc.gov.educ.penreg.api.exception.SagaRuntimeException in project EDUC-PEN-REG-BATCH-API by bcgov.
the class EventTaskSchedulerAsyncService method startArchiveAndReturnSaga.
private void startArchiveAndReturnSaga(final PenRequestBatchEntity penRequestBatchEntity) {
final var sagaData = PenRequestBatchArchiveAndReturnSagaData.builder().penRequestBatchID(penRequestBatchEntity.getPenRequestBatchID()).schoolName(penRequestBatchEntity.getSchoolName()).createUser(penRequestBatchEntity.getCreateUser()).build();
final var orchestrator = this.getSagaOrchestrators().get(PEN_REQUEST_BATCH_ARCHIVE_AND_RETURN_SAGA.toString());
try {
final var saga = orchestrator.createSaga(JsonUtil.getJsonStringFromObject(sagaData), null, penRequestBatchEntity.getPenRequestBatchID(), sagaData.getCreateUser());
orchestrator.startSaga(saga);
} catch (final JsonProcessingException e) {
log.error("JsonProcessingException while startArchiveAndReturnSaga", e);
throw new SagaRuntimeException(e.getMessage());
}
}
use of ca.bc.gov.educ.penreg.api.exception.SagaRuntimeException in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchSagaController method processBatchRequest.
private ResponseEntity<String> processBatchRequest(final SagaEnum sagaName, final PenRequestBatchRepostReportsFilesSagaData penRequestBatchSagaData) {
final var penRequestBatchID = penRequestBatchSagaData.getPenRequestBatchID();
final var sagaInProgress = !this.getSagaService().findAllByPenRequestBatchIDInAndStatusIn(List.of(penRequestBatchID), this.getStatusesFilter()).isEmpty();
if (sagaInProgress) {
return ResponseEntity.status(HttpStatus.CONFLICT).build();
}
final var orchestrator = this.getOrchestratorMap().get(sagaName.toString());
try {
final var saga = orchestrator.createSaga(JsonUtil.getJsonStringFromObject(penRequestBatchSagaData), null, penRequestBatchID, penRequestBatchSagaData.getCreateUser());
orchestrator.startSaga(saga);
return ResponseEntity.ok(saga.getSagaId().toString());
} catch (final JsonProcessingException e) {
log.error("JsonProcessingException while processStudentRequest", e);
throw new SagaRuntimeException(e.getMessage());
}
}
Aggregations