use of ca.bc.gov.educ.penreg.api.model.v1.SagaEvent in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchArchiveAndReturnOrchestrator method archivePenRequestBatch.
private void archivePenRequestBatch(Event event, Saga saga, PenRequestBatchArchiveAndReturnSagaData penRequestBatchArchiveAndReturnSagaData) throws IOException {
SagaEvent eventStates = this.createEventState(saga, event.getEventType(), event.getEventOutcome(), event.getEventPayload());
saga.setSagaState(ARCHIVE_PEN_REQUEST_BATCH.toString());
List<Student> students = obMapper.readValue(event.getEventPayload(), new TypeReference<>() {
});
penRequestBatchArchiveAndReturnSagaData.setStudents(event, students);
// save the updated payload to DB...
saga.setPayload(JsonUtil.getJsonStringFromObject(penRequestBatchArchiveAndReturnSagaData));
this.getSagaService().updateAttachedSagaWithEvents(saga, eventStates);
var penRequestBatchArchive = PenRequestBatchArchive.builder().penRequestBatchID(penRequestBatchArchiveAndReturnSagaData.getPenRequestBatchID()).updateUser(penRequestBatchArchiveAndReturnSagaData.getUpdateUser()).build();
Event nextEvent = Event.builder().sagaId(saga.getSagaId()).eventType(EventType.ARCHIVE_PEN_REQUEST_BATCH).replyTo(this.getTopicToSubscribe()).eventPayload(JsonUtil.getJsonStringFromObject(penRequestBatchArchive)).build();
this.postMessageToTopic(PEN_REQUEST_BATCH_API_TOPIC.toString(), nextEvent);
log.info("message sent to PEN_REQUEST_BATCH_API_TOPIC for ARCHIVE_PEN_REQUEST_BATCH Event. :: {}", saga.getSagaId());
}
use of ca.bc.gov.educ.penreg.api.model.v1.SagaEvent in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchRepostReportsOrchestrator method generatePDFReport.
private void generatePDFReport(Event event, Saga saga, PenRequestBatchRepostReportsFilesSagaData penRequestBatchRepostReportsFilesSagaData) throws IOException {
SagaEvent eventStates = this.createEventState(saga, event.getEventType(), event.getEventOutcome(), event.getEventPayload());
saga.setSagaState(GENERATE_PEN_REQUEST_BATCH_REPORTS.toString());
List<Student> students = obMapper.readValue(event.getEventPayload(), new TypeReference<>() {
});
penRequestBatchRepostReportsFilesSagaData.setStudents(event, students);
// save the updated payload to DB...
saga.setPayload(JsonUtil.getJsonStringFromObject(penRequestBatchRepostReportsFilesSagaData));
this.getSagaService().updateAttachedSagaWithEvents(saga, eventStates);
Event nextEvent = Event.builder().sagaId(saga.getSagaId()).eventType(GENERATE_PEN_REQUEST_BATCH_REPORTS).replyTo(this.getTopicToSubscribe()).eventPayload(JsonUtil.getJsonStringFromObject(ReportGenerationEventPayload.builder().reportType("PEN_REG_BATCH_RESPONSE_REPORT").reportExtension("pdf").reportName(penRequestBatchRepostReportsFilesSagaData.getPenRequestBatch().getSubmissionNumber()).data(reportMapper.toReportData(penRequestBatchRepostReportsFilesSagaData)).build())).build();
this.postMessageToTopic(SagaTopicsEnum.PEN_REPORT_GENERATION_API_TOPIC.toString(), nextEvent);
log.info("message sent to PEN_REPORT_GENERATION_API_TOPIC for {} Event. :: {}", GENERATE_PEN_REQUEST_BATCH_REPORTS.toString(), saga.getSagaId());
}
use of ca.bc.gov.educ.penreg.api.model.v1.SagaEvent in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchSagaControllerTest method testGetSagaEventsBySagaID_whenSagaIDIsValid_shouldReturnStatusOk.
@Test
@SuppressWarnings("java:S100")
public void testGetSagaEventsBySagaID_whenSagaIDIsValid_shouldReturnStatusOk() throws Exception {
final File sagEventsFile = new File(Objects.requireNonNull(this.getClass().getClassLoader().getResource("mock-saga-events.json")).getFile());
final File sagFile = new File(Objects.requireNonNull(this.getClass().getClassLoader().getResource("mock-saga.json")).getFile());
val sagaEvents = Arrays.asList(JsonUtil.mapper.readValue(sagEventsFile, ca.bc.gov.educ.penreg.api.model.v1.SagaEvent[].class));
val saga = JsonUtil.mapper.readValue(sagFile, ca.bc.gov.educ.penreg.api.model.v1.Saga.class);
saga.setSagaId(null);
saga.setCreateDate(LocalDateTime.now());
saga.setUpdateDate(LocalDateTime.now());
this.repository.save(saga);
for (val sagaEvent : sagaEvents) {
sagaEvent.setSaga(saga);
sagaEvent.setCreateDate(LocalDateTime.now());
sagaEvent.setUpdateDate(LocalDateTime.now());
}
this.sagaEventRepository.saveAll(sagaEvents);
this.mockMvc.perform(get("/api/v1/pen-request-batch-saga/{sagaId}/saga-events", saga.getSagaId()).with(jwt().jwt((jwt) -> jwt.claim("scope", "PEN_REQUEST_BATCH_READ_SAGA")))).andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$", hasSize(8)));
}
use of ca.bc.gov.educ.penreg.api.model.v1.SagaEvent in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchArchiveAndReturnOrchestrator method generatePDFReport.
private void generatePDFReport(Event event, Saga saga, PenRequestBatchArchiveAndReturnSagaData penRequestBatchArchiveAndReturnSagaData) throws JsonProcessingException {
SagaEvent eventStates = this.createEventState(saga, event.getEventType(), event.getEventOutcome(), event.getEventPayload());
saga.setSagaState(GENERATE_PEN_REQUEST_BATCH_REPORTS.toString());
penRequestBatchArchiveAndReturnSagaData.setPenRequestBatch(JsonUtil.getJsonObjectFromString(PenRequestBatch.class, event.getEventPayload()));
// save the updated payload to DB...
saga.setPayload(JsonUtil.getJsonStringFromObject(penRequestBatchArchiveAndReturnSagaData));
this.getSagaService().updateAttachedSagaWithEvents(saga, eventStates);
if (penRequestBatchArchiveAndReturnSagaData.getStudents() == null) {
log.info("students in saga data is null or empty for batch id :: {} and saga id :: {}, setting it from event states table", penRequestBatchArchiveAndReturnSagaData.getPenRequestBatchID(), saga.getSagaId());
SagaEvent sagaEvent = SagaEvent.builder().sagaEventState(GET_STUDENTS.toString()).sagaEventOutcome(STUDENTS_FOUND.toString()).sagaStepNumber(3).build();
val sagaEventOptional = this.getSagaService().findSagaEvent(saga, sagaEvent);
if (sagaEventOptional.isPresent()) {
List<Student> students = obMapper.readValue(sagaEventOptional.get().getSagaEventResponse(), new TypeReference<>() {
});
penRequestBatchArchiveAndReturnSagaData.setStudents(event, students);
} else {
throw new PenRegAPIRuntimeException("students not found in event states table for saga id :: " + saga.getSagaId());
}
}
Event nextEvent = Event.builder().sagaId(saga.getSagaId()).eventType(GENERATE_PEN_REQUEST_BATCH_REPORTS).replyTo(this.getTopicToSubscribe()).eventPayload(JsonUtil.getJsonStringFromObject(ReportGenerationEventPayload.builder().reportType("PEN_REG_BATCH_RESPONSE_REPORT").reportExtension("pdf").reportName(penRequestBatchArchiveAndReturnSagaData.getPenRequestBatch().getSubmissionNumber()).data(reportMapper.toReportData(penRequestBatchArchiveAndReturnSagaData)).build())).build();
this.postMessageToTopic(SagaTopicsEnum.PEN_REPORT_GENERATION_API_TOPIC.toString(), nextEvent);
log.info("message sent to PEN_REPORT_GENERATION_API_TOPIC for {} Event. :: {}", GENERATE_PEN_REQUEST_BATCH_REPORTS.toString(), saga.getSagaId());
}
use of ca.bc.gov.educ.penreg.api.model.v1.SagaEvent in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchRepostReportsOrchestrator method saveReportsWithoutPDF.
private void saveReportsWithoutPDF(Event event, Saga saga, PenRequestBatchRepostReportsFilesSagaData penRequestBatchRepostReportsFilesSagaData) throws IOException, TimeoutException, InterruptedException {
SagaEvent eventStates = this.createEventState(saga, event.getEventType(), event.getEventOutcome(), event.getEventPayload());
saga.setSagaState(SAVE_REPORTS.toString());
List<Student> students = obMapper.readValue(event.getEventPayload(), new TypeReference<>() {
});
penRequestBatchRepostReportsFilesSagaData.setStudents(event, students);
// save the updated payload to DB...
saga.setPayload(JsonUtil.getJsonStringFromObject(penRequestBatchRepostReportsFilesSagaData));
this.getSagaService().updateAttachedSagaWithEvents(saga, eventStates);
this.getResponseFileGeneratorService().saveReports(mapper.toModel(penRequestBatchRepostReportsFilesSagaData.getPenRequestBatch()), penRequestBatchRepostReportsFilesSagaData.getPenRequestBatchStudents(), penRequestBatchRepostReportsFilesSagaData.getStudents(), reportMapper.toReportData(penRequestBatchRepostReportsFilesSagaData));
val nextEvent = Event.builder().sagaId(saga.getSagaId()).eventType(SAVE_REPORTS).eventOutcome(REPORTS_SAVED).build();
this.handleEvent(nextEvent);
}
Aggregations