Search in sources :

Example 1 with PenRequestBatchStudentStatusCodes

use of ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes in project EDUC-PEN-REG-BATCH-API by bcgov.

the class PenReqBatchStudentOrchestrator method saveDemogValidationResults.

/**
 * Save demog validation results.
 *
 * @param event    the event
 * @param sagaData the saga data
 */
protected void saveDemogValidationResults(final Event event, final PenRequestBatchStudentSagaData sagaData) {
    if (event.getEventType() == VALIDATE_STUDENT_DEMOGRAPHICS && StringUtils.isNotBlank(event.getEventPayload()) && !StringUtils.equalsIgnoreCase(VALIDATION_SUCCESS_NO_ERROR_WARNING.toString(), event.getEventPayload())) {
        final PenRequestBatchStudentStatusCodes statusCode;
        if (event.getEventOutcome() == VALIDATION_SUCCESS_WITH_ERROR) {
            statusCode = PenRequestBatchStudentStatusCodes.ERROR;
        } else {
            statusCode = PenRequestBatchStudentStatusCodes.FIXABLE;
        }
        try {
            final TypeReference<List<PenRequestValidationIssue>> responseType = new TypeReference<>() {
            };
            final var validationResults = new ObjectMapper().readValue(event.getEventPayload(), responseType);
            if (!validationResults.isEmpty()) {
                final var mappedEntities = validationResults.stream().map(issueMapper::toModel).collect(Collectors.toList());
                this.getPenRequestBatchStudentOrchestratorService().saveDemogValidationResultsAndUpdateStudentStatus(mappedEntities, statusCode, sagaData.getPenRequestBatchStudentID());
            }
        } catch (final JsonProcessingException ex) {
            log.error("json exception for :: {} {}", event.getSagaId().toString(), ex);
        }
    }
}
Also used : PenRequestBatchStudentStatusCodes(ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes) List(java.util.List) TypeReference(com.fasterxml.jackson.core.type.TypeReference) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with PenRequestBatchStudentStatusCodes

use of ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes in project EDUC-PEN-REG-BATCH-API by bcgov.

the class PenRequestBatchAPIControllerTest method testFindAllPenRequestIDs_HasMatchedResultsWithAllSearchCriteria_ShouldReturnStatusOk.

@Test
public void testFindAllPenRequestIDs_HasMatchedResultsWithAllSearchCriteria_ShouldReturnStatusOk() throws Exception {
    final String batchIDs = this.createBatchStudentRecords(2);
    final Map<String, String> searchCriteria = new HashMap<>();
    searchCriteria.put("mincode", "66510518");
    searchCriteria.put("localID", "1488645");
    searchCriteria.put("submittedPen", "123456789");
    searchCriteria.put("legalSurname", "JOHNSTON");
    searchCriteria.put("legalGivenName", "ANGEL");
    searchCriteria.put("legalMiddleNames", "MARIA LYNN");
    searchCriteria.put("usualSurname", "JEB");
    searchCriteria.put("usualGivenName", "JEB");
    searchCriteria.put("usualMiddleNames", "JEB");
    searchCriteria.put("dob", "20060628");
    searchCriteria.put("gender", "F");
    searchCriteria.put("grade", "02");
    searchCriteria.put("postalCode", "Y1A4V1");
    searchCriteria.put("bestMatchPEN", "123456789");
    searchCriteria.put("submissionNumber", "T-428469");
    final ObjectMapper objectMapper = new ObjectMapper();
    final String criteriaJSON = objectMapper.writeValueAsString(searchCriteria);
    this.mockMvc.perform(get("/api/v1/pen-request-batch/pen-request-batch-ids").with(jwt().jwt((jwt) -> jwt.claim("scope", "READ_PEN_REQUEST_BATCH"))).param("penRequestBatchIDs", batchIDs).param("penRequestBatchStudentStatusCodes", PenRequestBatchStudentStatusCodes.SYS_NEW_PEN.getCode() + "," + PenRequestBatchStudentStatusCodes.LOADED.getCode()).param("searchCriteria", criteriaJSON).contentType(APPLICATION_JSON)).andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$", hasSize(1)));
}
Also used : BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) ArgumentMatchers(org.mockito.ArgumentMatchers) MockMvcResultMatchers.jsonPath(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath) PenRequestBatchStudentValidationIssueEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentValidationIssueEntity) Autowired(org.springframework.beans.factory.annotation.Autowired) PenRequestBatchTestUtils(ca.bc.gov.educ.penreg.api.support.PenRequestBatchTestUtils) PenRequestBatchMapper(ca.bc.gov.educ.penreg.api.mappers.v1.PenRequestBatchMapper) JsonUtil(ca.bc.gov.educ.penreg.api.util.JsonUtil) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) PenRequestBatchEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity) PenRequestBatchStudentEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentEntity) MockitoAnnotations(org.mockito.MockitoAnnotations) PENWebBlobEntity(ca.bc.gov.educ.penreg.api.model.v1.PENWebBlobEntity) PenMatchRecord(ca.bc.gov.educ.penreg.api.struct.PenMatchRecord) OR(ca.bc.gov.educ.penreg.api.struct.v1.Condition.OR) TypeReference(com.fasterxml.jackson.core.type.TypeReference) RestUtils(ca.bc.gov.educ.penreg.api.rest.RestUtils) ValueType(ca.bc.gov.educ.penreg.api.struct.v1.ValueType) MockMvcResultHandlers.print(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print) EventOutcome(ca.bc.gov.educ.penreg.api.constants.EventOutcome) PenRequestBatchSubmission(ca.bc.gov.educ.penreg.api.struct.v1.external.PenRequestBatchSubmission) Collectors(java.util.stream.Collectors) Search(ca.bc.gov.educ.penreg.api.struct.v1.Search) java.util(java.util) PenRequestBatchStudentMapper(ca.bc.gov.educ.penreg.api.mappers.v1.PenRequestBatchStudentMapper) LocalDateTime(java.time.LocalDateTime) AND(ca.bc.gov.educ.penreg.api.struct.v1.Condition.AND) MockMvc(org.springframework.test.web.servlet.MockMvc) PenMatchResult(ca.bc.gov.educ.penreg.api.struct.PenMatchResult) PenRequestBatch(ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatch) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) MvcResult(org.springframework.test.web.servlet.MvcResult) APPLICATION_JSON(org.springframework.http.MediaType.APPLICATION_JSON) SchoolGroupCodes(ca.bc.gov.educ.penreg.api.constants.SchoolGroupCodes) Before(org.junit.Before) SecurityMockMvcRequestPostProcessors.jwt(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.jwt) FilterOperation(ca.bc.gov.educ.penreg.api.filter.FilterOperation) PenRequestBatchStudentStatusCodes(ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) lombok.val(lombok.val) PEN_REQUEST_BATCH_USER_MATCH_PROCESSING_SAGA(ca.bc.gov.educ.penreg.api.constants.SagaEnum.PEN_REQUEST_BATCH_USER_MATCH_PROCESSING_SAGA) SagaService(ca.bc.gov.educ.penreg.api.service.SagaService) SearchCriteria(ca.bc.gov.educ.penreg.api.struct.v1.SearchCriteria) Matchers(org.hamcrest.Matchers) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) IOException(java.io.IOException) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) File(java.io.File) Event(ca.bc.gov.educ.penreg.api.struct.Event) Mockito(org.mockito.Mockito) Collectors.toList(java.util.stream.Collectors.toList) Student(ca.bc.gov.educ.penreg.api.struct.Student) ca.bc.gov.educ.penreg.api.repository(ca.bc.gov.educ.penreg.api.repository) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) Test(org.junit.Test)

Example 3 with PenRequestBatchStudentStatusCodes

use of ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes in project EDUC-PEN-REG-BATCH-API by bcgov.

the class PenRequestBatchAPIController method findAllPenRequestIDs.

/**
 * Find all pen request i ds response entity.
 *
 * @param penRequestBatchIDs                the pen request batch i ds
 * @param penRequestBatchStudentStatusCodes the pen request batch student status codes
 * @param searchCriteriaListJson            the search criteria list json
 * @return the response entity
 * @throws JsonProcessingException the json processing exception
 */
@Override
public ResponseEntity<List<PenRequestIDs>> findAllPenRequestIDs(final List<UUID> penRequestBatchIDs, final List<String> penRequestBatchStudentStatusCodes, final String searchCriteriaListJson) throws JsonProcessingException {
    val errorCode = penRequestBatchStudentStatusCodes.stream().filter(statusCode -> PenRequestBatchStudentStatusCodes.valueOfCode(statusCode) == null).findFirst();
    if (errorCode.isPresent()) {
        log.error("Invalid pen request batch student status code provided :: " + errorCode);
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
    }
    Map<String, String> searchCriteria = null;
    if (StringUtils.isNotBlank(searchCriteriaListJson)) {
        searchCriteria = JsonUtil.mapper.readValue(searchCriteriaListJson, new TypeReference<>() {
        });
    }
    return ResponseEntity.ok(this.getService().findAllPenRequestIDs(penRequestBatchIDs, penRequestBatchStudentStatusCodes, searchCriteria));
}
Also used : lombok.val(lombok.val) PenRegBatchStudentFilterSpecs(ca.bc.gov.educ.penreg.api.filter.PenRegBatchStudentFilterSpecs) PenRequestResult(ca.bc.gov.educ.penreg.api.struct.v1.external.PenRequestResult) Autowired(org.springframework.beans.factory.annotation.Autowired) PenRequestBatchAPIEndpoint(ca.bc.gov.educ.penreg.api.endpoint.v1.PenRequestBatchAPIEndpoint) PenRequestBatchMapper(ca.bc.gov.educ.penreg.api.mappers.v1.PenRequestBatchMapper) JsonUtil(ca.bc.gov.educ.penreg.api.util.JsonUtil) StringUtils(org.apache.commons.lang3.StringUtils) PenRequestBatchEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity) PenRequestBatchStudentEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentEntity) PENWebBlobEntity(ca.bc.gov.educ.penreg.api.model.v1.PENWebBlobEntity) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) PenRequestBatchStats(ca.bc.gov.educ.penreg.api.struct.PenRequestBatchStats) Sort(org.springframework.data.domain.Sort) TypeReference(com.fasterxml.jackson.core.type.TypeReference) PenRequestBatchStatusCodes(ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStatusCodes) InvalidPayloadException(ca.bc.gov.educ.penreg.api.exception.InvalidPayloadException) EntityNotFoundException(ca.bc.gov.educ.penreg.api.exception.EntityNotFoundException) Associations(ca.bc.gov.educ.penreg.api.filter.Associations) BAD_REQUEST(org.springframework.http.HttpStatus.BAD_REQUEST) Page(org.springframework.data.domain.Page) PenRequestBatchSubmission(ca.bc.gov.educ.penreg.api.struct.v1.external.PenRequestBatchSubmission) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) PenRequestBatchProcessTypeCodes(ca.bc.gov.educ.penreg.api.constants.PenRequestBatchProcessTypeCodes) PenRegBatchHelper(ca.bc.gov.educ.penreg.api.helpers.PenRegBatchHelper) PenRegBatchFilterSpecs(ca.bc.gov.educ.penreg.api.filter.PenRegBatchFilterSpecs) PenRequestBatchResultDataMapper(ca.bc.gov.educ.penreg.api.mappers.v1.external.PenRequestBatchResultDataMapper) Slf4j(lombok.extern.slf4j.Slf4j) PenRequest(ca.bc.gov.educ.penreg.api.struct.v1.external.PenRequest) Specification(org.springframework.data.jpa.domain.Specification) SagaStatusEnum(ca.bc.gov.educ.penreg.api.constants.SagaStatusEnum) PenRequestBatchService(ca.bc.gov.educ.penreg.api.service.PenRequestBatchService) PRIVATE(lombok.AccessLevel.PRIVATE) ApiError(ca.bc.gov.educ.penreg.api.exception.errors.ApiError) java.util(java.util) PenRequestBatchStudentMapper(ca.bc.gov.educ.penreg.api.mappers.v1.PenRequestBatchStudentMapper) StudentStatusCodeMapper(ca.bc.gov.educ.penreg.api.mappers.v1.StudentStatusCodeMapper) PenRequestBatchStudentService(ca.bc.gov.educ.penreg.api.service.PenRequestBatchStudentService) Getter(lombok.Getter) InvalidParameterException(ca.bc.gov.educ.penreg.api.exception.InvalidParameterException) PenRequestBatchStudentValidationIssueService(ca.bc.gov.educ.penreg.api.service.PenRequestBatchStudentValidationIssueService) LocalDateTime(java.time.LocalDateTime) CompletableFuture(java.util.concurrent.CompletableFuture) ca.bc.gov.educ.penreg.api.struct.v1(ca.bc.gov.educ.penreg.api.struct.v1) PenRequestBatchStudentStatusCodes(ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes) lombok.val(lombok.val) SagaService(ca.bc.gov.educ.penreg.api.service.SagaService) PenRequestBatchStudentValidationIssueMapper(ca.bc.gov.educ.penreg.api.mappers.PenRequestBatchStudentValidationIssueMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) PenWebBlobMapper(ca.bc.gov.educ.penreg.api.mappers.v1.PenWebBlobMapper) HttpStatus(org.springframework.http.HttpStatus) PenRequestBatchSubmissionResult(ca.bc.gov.educ.penreg.api.struct.v1.external.PenRequestBatchSubmissionResult) ResponseEntity(org.springframework.http.ResponseEntity) PenRegAPIRuntimeException(ca.bc.gov.educ.penreg.api.exception.PenRegAPIRuntimeException) TypeReference(com.fasterxml.jackson.core.type.TypeReference)

Aggregations

PenRequestBatchStudentStatusCodes (ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)3 PenRequestBatchMapper (ca.bc.gov.educ.penreg.api.mappers.v1.PenRequestBatchMapper)2 PenRequestBatchStudentMapper (ca.bc.gov.educ.penreg.api.mappers.v1.PenRequestBatchStudentMapper)2 PENWebBlobEntity (ca.bc.gov.educ.penreg.api.model.v1.PENWebBlobEntity)2 PenRequestBatchEntity (ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity)2 PenRequestBatchStudentEntity (ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentEntity)2 SagaService (ca.bc.gov.educ.penreg.api.service.SagaService)2 PenRequestBatchSubmission (ca.bc.gov.educ.penreg.api.struct.v1.external.PenRequestBatchSubmission)2 JsonUtil (ca.bc.gov.educ.penreg.api.util.JsonUtil)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 LocalDateTime (java.time.LocalDateTime)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 BasePenRegAPITest (ca.bc.gov.educ.penreg.api.BasePenRegAPITest)1 EventOutcome (ca.bc.gov.educ.penreg.api.constants.EventOutcome)1 PenRequestBatchProcessTypeCodes (ca.bc.gov.educ.penreg.api.constants.PenRequestBatchProcessTypeCodes)1 PenRequestBatchStatusCodes (ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStatusCodes)1 PEN_REQUEST_BATCH_USER_MATCH_PROCESSING_SAGA (ca.bc.gov.educ.penreg.api.constants.SagaEnum.PEN_REQUEST_BATCH_USER_MATCH_PROCESSING_SAGA)1