use of ca.bc.gov.educ.penreg.api.model.v1.Saga 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.Saga 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.Saga in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchSagaControllerTest method testGetSagaPaginated_givenSearchCriteria_shouldReturnStatusOk.
@Test
@SuppressWarnings("java:S100")
public void testGetSagaPaginated_givenSearchCriteria_shouldReturnStatusOk() throws Exception {
final File file = new File(Objects.requireNonNull(this.getClass().getClassLoader().getResource("mock_multiple_sagas.json")).getFile());
final List<Saga> sagaStructs = new ObjectMapper().readValue(file, new TypeReference<>() {
});
final List<ca.bc.gov.educ.penreg.api.model.v1.Saga> sagaEntities = sagaStructs.stream().map(mapper::toModel).collect(Collectors.toList());
for (val saga : sagaEntities) {
saga.setSagaId(null);
saga.setCreateDate(LocalDateTime.now());
saga.setUpdateDate(LocalDateTime.now());
}
this.repository.saveAll(sagaEntities);
final SearchCriteria criteria = SearchCriteria.builder().key("sagaState").operation(FilterOperation.IN).value("IN_PROGRESS").valueType(ValueType.STRING).build();
final SearchCriteria criteria2 = SearchCriteria.builder().key("sagaName").condition(AND).operation(FilterOperation.EQUAL).value("PEN_REQUEST_BATCH_ARCHIVE_AND_RETURN_SAGA").valueType(ValueType.STRING).build();
final List<SearchCriteria> criteriaList = new ArrayList<>();
criteriaList.add(criteria);
criteriaList.add(criteria2);
final List<Search> searches = new LinkedList<>();
searches.add(Search.builder().searchCriteriaList(criteriaList).build());
final ObjectMapper objectMapper = new ObjectMapper();
final String criteriaJSON = objectMapper.writeValueAsString(searches);
final MvcResult result = this.mockMvc.perform(get("/api/v1/pen-request-batch-saga/paginated").with(jwt().jwt((jwt) -> jwt.claim("scope", "PEN_REQUEST_BATCH_READ_SAGA"))).param("searchCriteriaList", criteriaJSON).contentType(APPLICATION_JSON)).andReturn();
this.mockMvc.perform(asyncDispatch(result)).andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.content", hasSize(1)));
}
use of ca.bc.gov.educ.penreg.api.model.v1.Saga in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchSagaControllerTest method testUpdateSaga_givenInvalidID_shouldReturn404.
@Test
public void testUpdateSaga_givenInvalidID_shouldReturn404() throws Exception {
val saga = createMockSaga();
this.mockMvc.perform(put("/api/v1/pen-request-batch-saga/{sagaId}", UUID.randomUUID()).content(JsonUtil.mapper.writeValueAsBytes(saga)).with(jwt().jwt((jwt) -> jwt.claim("scope", "PEN_REQUEST_BATCH_WRITE_SAGA"))).contentType(APPLICATION_JSON)).andDo(print()).andExpect(status().isNotFound());
}
use of ca.bc.gov.educ.penreg.api.model.v1.Saga 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)));
}
Aggregations