Search in sources :

Example 16 with Saga

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());
}
Also used : SagaEvent(ca.bc.gov.educ.penreg.api.model.v1.SagaEvent) Event(ca.bc.gov.educ.penreg.api.struct.Event) Student(ca.bc.gov.educ.penreg.api.struct.Student) SagaEvent(ca.bc.gov.educ.penreg.api.model.v1.SagaEvent)

Example 17 with Saga

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());
}
Also used : SagaEvent(ca.bc.gov.educ.penreg.api.model.v1.SagaEvent) Event(ca.bc.gov.educ.penreg.api.struct.Event) Student(ca.bc.gov.educ.penreg.api.struct.Student) SagaEvent(ca.bc.gov.educ.penreg.api.model.v1.SagaEvent)

Example 18 with Saga

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)));
}
Also used : lombok.val(lombok.val) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) java.util(java.util) MockMvcResultMatchers.jsonPath(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath) LocalDateTime(java.time.LocalDateTime) AND(ca.bc.gov.educ.penreg.api.struct.v1.Condition.AND) Autowired(org.springframework.beans.factory.annotation.Autowired) PenRequestBatchTestUtils(ca.bc.gov.educ.penreg.api.support.PenRequestBatchTestUtils) SagaRepository(ca.bc.gov.educ.penreg.api.repository.SagaRepository) JsonUtil(ca.bc.gov.educ.penreg.api.util.JsonUtil) SagaMapper(ca.bc.gov.educ.penreg.api.mappers.v1.SagaMapper) PenRequestBatchEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity) MockMvc(org.springframework.test.web.servlet.MockMvc) SagaEnum(ca.bc.gov.educ.penreg.api.constants.SagaEnum) MockitoAnnotations(org.mockito.MockitoAnnotations) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) MvcResult(org.springframework.test.web.servlet.MvcResult) Matchers.hasSize(org.hamcrest.Matchers.hasSize) APPLICATION_JSON(org.springframework.http.MediaType.APPLICATION_JSON) TypeReference(com.fasterxml.jackson.core.type.TypeReference) PenRequestBatchRepository(ca.bc.gov.educ.penreg.api.repository.PenRequestBatchRepository) Before(org.junit.Before) ValueType(ca.bc.gov.educ.penreg.api.struct.v1.ValueType) SecurityMockMvcRequestPostProcessors.jwt(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.jwt) FilterOperation(ca.bc.gov.educ.penreg.api.filter.FilterOperation) SagaEventRepository(ca.bc.gov.educ.penreg.api.repository.SagaEventRepository) MockMvcResultHandlers.print(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print) MediaType(org.springframework.http.MediaType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) lombok.val(lombok.val) SagaService(ca.bc.gov.educ.penreg.api.service.SagaService) SearchCriteria(ca.bc.gov.educ.penreg.api.struct.v1.SearchCriteria) Test(org.junit.Test) Collectors(java.util.stream.Collectors) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) Saga(ca.bc.gov.educ.penreg.api.struct.v1.Saga) File(java.io.File) Search(ca.bc.gov.educ.penreg.api.struct.v1.Search) Matchers.is(org.hamcrest.Matchers.is) MvcResult(org.springframework.test.web.servlet.MvcResult) SearchCriteria(ca.bc.gov.educ.penreg.api.struct.v1.SearchCriteria) Saga(ca.bc.gov.educ.penreg.api.struct.v1.Saga) Search(ca.bc.gov.educ.penreg.api.struct.v1.Search) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) Test(org.junit.Test)

Example 19 with Saga

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());
}
Also used : lombok.val(lombok.val) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) java.util(java.util) MockMvcResultMatchers.jsonPath(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath) LocalDateTime(java.time.LocalDateTime) AND(ca.bc.gov.educ.penreg.api.struct.v1.Condition.AND) Autowired(org.springframework.beans.factory.annotation.Autowired) PenRequestBatchTestUtils(ca.bc.gov.educ.penreg.api.support.PenRequestBatchTestUtils) SagaRepository(ca.bc.gov.educ.penreg.api.repository.SagaRepository) JsonUtil(ca.bc.gov.educ.penreg.api.util.JsonUtil) SagaMapper(ca.bc.gov.educ.penreg.api.mappers.v1.SagaMapper) PenRequestBatchEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity) MockMvc(org.springframework.test.web.servlet.MockMvc) SagaEnum(ca.bc.gov.educ.penreg.api.constants.SagaEnum) MockitoAnnotations(org.mockito.MockitoAnnotations) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) MvcResult(org.springframework.test.web.servlet.MvcResult) Matchers.hasSize(org.hamcrest.Matchers.hasSize) APPLICATION_JSON(org.springframework.http.MediaType.APPLICATION_JSON) TypeReference(com.fasterxml.jackson.core.type.TypeReference) PenRequestBatchRepository(ca.bc.gov.educ.penreg.api.repository.PenRequestBatchRepository) Before(org.junit.Before) ValueType(ca.bc.gov.educ.penreg.api.struct.v1.ValueType) SecurityMockMvcRequestPostProcessors.jwt(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.jwt) FilterOperation(ca.bc.gov.educ.penreg.api.filter.FilterOperation) SagaEventRepository(ca.bc.gov.educ.penreg.api.repository.SagaEventRepository) MockMvcResultHandlers.print(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print) MediaType(org.springframework.http.MediaType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) lombok.val(lombok.val) SagaService(ca.bc.gov.educ.penreg.api.service.SagaService) SearchCriteria(ca.bc.gov.educ.penreg.api.struct.v1.SearchCriteria) Test(org.junit.Test) Collectors(java.util.stream.Collectors) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) Saga(ca.bc.gov.educ.penreg.api.struct.v1.Saga) File(java.io.File) Search(ca.bc.gov.educ.penreg.api.struct.v1.Search) Matchers.is(org.hamcrest.Matchers.is) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) Test(org.junit.Test)

Example 20 with Saga

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)));
}
Also used : lombok.val(lombok.val) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) java.util(java.util) MockMvcResultMatchers.jsonPath(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath) LocalDateTime(java.time.LocalDateTime) AND(ca.bc.gov.educ.penreg.api.struct.v1.Condition.AND) Autowired(org.springframework.beans.factory.annotation.Autowired) PenRequestBatchTestUtils(ca.bc.gov.educ.penreg.api.support.PenRequestBatchTestUtils) SagaRepository(ca.bc.gov.educ.penreg.api.repository.SagaRepository) JsonUtil(ca.bc.gov.educ.penreg.api.util.JsonUtil) SagaMapper(ca.bc.gov.educ.penreg.api.mappers.v1.SagaMapper) PenRequestBatchEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity) MockMvc(org.springframework.test.web.servlet.MockMvc) SagaEnum(ca.bc.gov.educ.penreg.api.constants.SagaEnum) MockitoAnnotations(org.mockito.MockitoAnnotations) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) MvcResult(org.springframework.test.web.servlet.MvcResult) Matchers.hasSize(org.hamcrest.Matchers.hasSize) APPLICATION_JSON(org.springframework.http.MediaType.APPLICATION_JSON) TypeReference(com.fasterxml.jackson.core.type.TypeReference) PenRequestBatchRepository(ca.bc.gov.educ.penreg.api.repository.PenRequestBatchRepository) Before(org.junit.Before) ValueType(ca.bc.gov.educ.penreg.api.struct.v1.ValueType) SecurityMockMvcRequestPostProcessors.jwt(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.jwt) FilterOperation(ca.bc.gov.educ.penreg.api.filter.FilterOperation) SagaEventRepository(ca.bc.gov.educ.penreg.api.repository.SagaEventRepository) MockMvcResultHandlers.print(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print) MediaType(org.springframework.http.MediaType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) lombok.val(lombok.val) SagaService(ca.bc.gov.educ.penreg.api.service.SagaService) SearchCriteria(ca.bc.gov.educ.penreg.api.struct.v1.SearchCriteria) Test(org.junit.Test) Collectors(java.util.stream.Collectors) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) Saga(ca.bc.gov.educ.penreg.api.struct.v1.Saga) File(java.io.File) Search(ca.bc.gov.educ.penreg.api.struct.v1.Search) Matchers.is(org.hamcrest.Matchers.is) File(java.io.File) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) Test(org.junit.Test)

Aggregations

SagaEvent (ca.bc.gov.educ.penreg.api.model.v1.SagaEvent)24 Event (ca.bc.gov.educ.penreg.api.struct.Event)18 lombok.val (lombok.val)16 Student (ca.bc.gov.educ.penreg.api.struct.Student)11 PenRegAPIRuntimeException (ca.bc.gov.educ.penreg.api.exception.PenRegAPIRuntimeException)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 SagaService (ca.bc.gov.educ.penreg.api.service.SagaService)5 PenRequestBatchStudent (ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent)5 JsonUtil (ca.bc.gov.educ.penreg.api.util.JsonUtil)5 LocalDateTime (java.time.LocalDateTime)5 Collectors (java.util.stream.Collectors)5 BasePenRegAPITest (ca.bc.gov.educ.penreg.api.BasePenRegAPITest)4 PenRequestBatchEntity (ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity)4 Saga (ca.bc.gov.educ.penreg.api.struct.v1.Saga)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 EventOutcome (ca.bc.gov.educ.penreg.api.constants.EventOutcome)3 EventType (ca.bc.gov.educ.penreg.api.constants.EventType)3 SagaEnum (ca.bc.gov.educ.penreg.api.constants.SagaEnum)3 FilterOperation (ca.bc.gov.educ.penreg.api.filter.FilterOperation)3