Search in sources :

Example 1 with InvalidParameterException

use of ca.bc.gov.educ.penreg.api.exception.InvalidParameterException 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());
    }
}
Also used : ApiError(ca.bc.gov.educ.penreg.api.exception.errors.ApiError) PenRequestBatchUnmatchSagaData(ca.bc.gov.educ.penreg.api.struct.PenRequestBatchUnmatchSagaData) java.util(java.util) Getter(lombok.Getter) PenRequestBatchSagaEndpoint(ca.bc.gov.educ.penreg.api.endpoint.v1.PenRequestBatchSagaEndpoint) InvalidParameterException(ca.bc.gov.educ.penreg.api.exception.InvalidParameterException) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) CompletableFuture(java.util.concurrent.CompletableFuture) JsonUtil(ca.bc.gov.educ.penreg.api.util.JsonUtil) StringUtils(org.apache.commons.lang3.StringUtils) SagaMapper(ca.bc.gov.educ.penreg.api.mappers.v1.SagaMapper) SagaEnum(ca.bc.gov.educ.penreg.api.constants.SagaEnum) ca.bc.gov.educ.penreg.api.struct.v1(ca.bc.gov.educ.penreg.api.struct.v1) Pair(org.springframework.data.util.Pair) Orchestrator(ca.bc.gov.educ.penreg.api.orchestrator.base.Orchestrator) Sort(org.springframework.data.domain.Sort) TypeReference(com.fasterxml.jackson.core.type.TypeReference) InvalidPayloadException(ca.bc.gov.educ.penreg.api.exception.InvalidPayloadException) BAD_REQUEST(org.springframework.http.HttpStatus.BAD_REQUEST) PenRequestBatchUserActionsSagaData(ca.bc.gov.educ.penreg.api.struct.PenRequestBatchUserActionsSagaData) BasePenRequestBatchStudentSagaData(ca.bc.gov.educ.penreg.api.struct.BasePenRequestBatchStudentSagaData) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) lombok.val(lombok.val) SagaService(ca.bc.gov.educ.penreg.api.service.SagaService) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) SagaFilterSpecs(ca.bc.gov.educ.penreg.api.filter.SagaFilterSpecs) Page(org.springframework.data.domain.Page) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) SagaRuntimeException(ca.bc.gov.educ.penreg.api.exception.SagaRuntimeException) HttpStatus(org.springframework.http.HttpStatus) Slf4j(lombok.extern.slf4j.Slf4j) Specification(org.springframework.data.jpa.domain.Specification) ArchiveAndReturnSagaResponseMapper(ca.bc.gov.educ.penreg.api.mappers.v1.ArchiveAndReturnSagaResponseMapper) ResponseEntity(org.springframework.http.ResponseEntity) SagaStatusEnum(ca.bc.gov.educ.penreg.api.constants.SagaStatusEnum) Transactional(org.springframework.transaction.annotation.Transactional) PRIVATE(lombok.AccessLevel.PRIVATE) lombok.val(lombok.val) InvalidParameterException(ca.bc.gov.educ.penreg.api.exception.InvalidParameterException) SagaRuntimeException(ca.bc.gov.educ.penreg.api.exception.SagaRuntimeException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) InvalidParameterException(ca.bc.gov.educ.penreg.api.exception.InvalidParameterException) InvalidPayloadException(ca.bc.gov.educ.penreg.api.exception.InvalidPayloadException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) SagaRuntimeException(ca.bc.gov.educ.penreg.api.exception.SagaRuntimeException)

Example 2 with InvalidParameterException

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

the class PenRequestBatchAPIController method findAllStudents.

/**
 * Find all students completable future.
 *
 * @param pageNumber             the page number
 * @param pageSize               the page size
 * @param sortCriteriaJson       the sort criteria json
 * @param searchCriteriaListJson the search criteria list json
 * @return the completable future
 */
@Override
public CompletableFuture<Page<PenRequestBatchStudent>> findAllStudents(final Integer pageNumber, final Integer pageSize, final String sortCriteriaJson, final String searchCriteriaListJson) {
    final List<Sort.Order> sorts = new ArrayList<>();
    Specification<PenRequestBatchStudentEntity> penRequestBatchStudentEntitySpecification = null;
    try {
        final var associationNames = this.getSortCriteria(sortCriteriaJson, JsonUtil.mapper, sorts);
        if (StringUtils.isNotBlank(searchCriteriaListJson)) {
            final List<Search> searches = JsonUtil.mapper.readValue(searchCriteriaListJson, new TypeReference<>() {
            });
            this.getAssociationNamesFromSearchCriterias(associationNames, searches);
            int i = 0;
            for (final var search : searches) {
                penRequestBatchStudentEntitySpecification = this.getSpecifications(penRequestBatchStudentEntitySpecification, i, search, associationNames, this.penRegBatchStudentFilterSpecs);
                i++;
            }
        }
    } catch (final JsonProcessingException e) {
        throw new InvalidParameterException(e.getMessage());
    }
    return this.getStudentService().findAll(penRequestBatchStudentEntitySpecification, pageNumber, pageSize, sorts).thenApplyAsync(penRegBatchEntities -> penRegBatchEntities.map(studentMapper::toStructure));
}
Also used : InvalidParameterException(ca.bc.gov.educ.penreg.api.exception.InvalidParameterException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) PenRequestBatchAPIEndpoint(ca.bc.gov.educ.penreg.api.endpoint.v1.PenRequestBatchAPIEndpoint) PenRequestBatchStudentEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentEntity)

Example 3 with InvalidParameterException

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

the class PenRequestBatchHistoryAPIController method findAll.

/**
 * Find all completable future.
 *
 * @param pageNumber       the page number
 * @param pageSize         the page size
 * @param sortCriteriaJson the sort criteria json
 * @param searchList       the search list
 * @return the completable future
 */
@Override
public CompletableFuture<Page<PenRequestBatchHistorySearch>> findAll(final Integer pageNumber, final Integer pageSize, final String sortCriteriaJson, final String searchList) {
    final ObjectMapper objectMapper = new ObjectMapper();
    final List<Sort.Order> sorts = new ArrayList<>();
    Specification<PenRequestBatchHistoryEntity> penRegBatchSpecs = null;
    final Associations associationNames;
    try {
        associationNames = this.getSortCriteria(sortCriteriaJson, objectMapper, sorts);
        if (StringUtils.isNotBlank(searchList)) {
            final List<Search> searches = objectMapper.readValue(searchList, new TypeReference<>() {
            });
            this.getAssociationNamesFromSearchCriterias(associationNames, searches);
            int i = 0;
            for (final var search : searches) {
                penRegBatchSpecs = this.getSpecifications(penRegBatchSpecs, i, search, associationNames, this.getPenRegBatchFilterSpecs());
                i++;
            }
        }
    } catch (final JsonProcessingException e) {
        throw new InvalidParameterException(e.getMessage());
    }
    return this.getService().findAll(penRegBatchSpecs, pageNumber, pageSize, sorts).thenApplyAsync(page -> page.map(mapper::toSearchStructure));
}
Also used : PenRequestBatchHistoryEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchHistoryEntity) ArrayList(java.util.ArrayList) Associations(ca.bc.gov.educ.penreg.api.filter.Associations) PenRequestBatchHistoryAPIEndpoint(ca.bc.gov.educ.penreg.api.endpoint.v1.PenRequestBatchHistoryAPIEndpoint) InvalidParameterException(ca.bc.gov.educ.penreg.api.exception.InvalidParameterException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with InvalidParameterException

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

the class PaginatedController method getEntitySpecification.

/**
 * Gets entity specification.
 *
 * @param criteriaList the criteria list
 * @return the entity specification
 */
private <T> Specification<T> getEntitySpecification(final List<SearchCriteria> criteriaList, final Associations associationNames, BaseFilterSpecs<T> filterSpecs) {
    Specification<T> entitySpecification = null;
    if (!criteriaList.isEmpty()) {
        int i = 0;
        for (final SearchCriteria criteria : criteriaList) {
            if (criteria.getKey() != null && criteria.getOperation() != null && criteria.getValueType() != null) {
                final Specification<T> typeSpecification = this.getTypeSpecification(criteria.getKey(), criteria.getOperation(), criteria.getValue(), criteria.getValueType(), associationNames, filterSpecs);
                entitySpecification = this.getSpecificationPerGroup(entitySpecification, i, criteria, typeSpecification);
                i++;
            } else {
                throw new InvalidParameterException("Search Criteria can not contain null values for", criteria.getKey(), criteria.getOperation().toString(), criteria.getValueType().toString());
            }
        }
    }
    return entitySpecification;
}
Also used : InvalidParameterException(ca.bc.gov.educ.penreg.api.exception.InvalidParameterException) SearchCriteria(ca.bc.gov.educ.penreg.api.struct.v1.SearchCriteria)

Example 5 with InvalidParameterException

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

the class PenRequestBatchAPIController method findAll.

/**
 * Find all completable future.
 *
 * @param pageNumber       the page number
 * @param pageSize         the page size
 * @param sortCriteriaJson the sort criteria json
 * @param searchList       the search list
 * @return the completable future
 */
@Override
public CompletableFuture<Page<PenRequestBatchSearch>> findAll(final Integer pageNumber, final Integer pageSize, final String sortCriteriaJson, final String searchList) {
    final List<Sort.Order> sorts = new ArrayList<>();
    Specification<PenRequestBatchEntity> penRegBatchSpecs = null;
    final Associations associationNames;
    try {
        associationNames = this.getSortCriteria(sortCriteriaJson, JsonUtil.mapper, sorts);
        if (StringUtils.isNotBlank(searchList)) {
            final List<Search> searches = JsonUtil.mapper.readValue(searchList, new TypeReference<>() {
            });
            this.getAssociationNamesFromSearchCriterias(associationNames, searches);
            int i = 0;
            for (final var search : searches) {
                penRegBatchSpecs = this.getSpecifications(penRegBatchSpecs, i, search, associationNames, this.getPenRegBatchFilterSpecs());
                i++;
            }
        }
    } catch (final JsonProcessingException e) {
        throw new InvalidParameterException(e.getMessage());
    }
    if (associationNames.hasSearchAssociations()) {
        return this.getService().findAllByPenRequestBatchStudent(penRegBatchSpecs, pageNumber, pageSize, sorts).thenApplyAsync(page -> page.map(pair -> {
            final var batch = mapper.toSearchStructure(pair.getFirst());
            batch.setSearchedCount(pair.getSecond());
            return batch;
        }));
    } else {
        return this.getService().findAll(penRegBatchSpecs, pageNumber, pageSize, sorts).thenApplyAsync(page -> page.map(mapper::toSearchStructure));
    }
}
Also used : 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) PenRequestBatchEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity) Associations(ca.bc.gov.educ.penreg.api.filter.Associations) PenRequestBatchAPIEndpoint(ca.bc.gov.educ.penreg.api.endpoint.v1.PenRequestBatchAPIEndpoint) InvalidParameterException(ca.bc.gov.educ.penreg.api.exception.InvalidParameterException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

InvalidParameterException (ca.bc.gov.educ.penreg.api.exception.InvalidParameterException)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 SagaStatusEnum (ca.bc.gov.educ.penreg.api.constants.SagaStatusEnum)2 PenRequestBatchAPIEndpoint (ca.bc.gov.educ.penreg.api.endpoint.v1.PenRequestBatchAPIEndpoint)2 PenRequestBatchSagaEndpoint (ca.bc.gov.educ.penreg.api.endpoint.v1.PenRequestBatchSagaEndpoint)2 InvalidPayloadException (ca.bc.gov.educ.penreg.api.exception.InvalidPayloadException)2 ApiError (ca.bc.gov.educ.penreg.api.exception.errors.ApiError)2 Associations (ca.bc.gov.educ.penreg.api.filter.Associations)2 PenRequestBatchStudentEntity (ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentEntity)2 SagaService (ca.bc.gov.educ.penreg.api.service.SagaService)2 ca.bc.gov.educ.penreg.api.struct.v1 (ca.bc.gov.educ.penreg.api.struct.v1)2 JsonUtil (ca.bc.gov.educ.penreg.api.util.JsonUtil)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 LocalDateTime (java.time.LocalDateTime)2 PenRequestBatchProcessTypeCodes (ca.bc.gov.educ.penreg.api.constants.PenRequestBatchProcessTypeCodes)1 PenRequestBatchStatusCodes (ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStatusCodes)1 PenRequestBatchStudentStatusCodes (ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes)1 SagaEnum (ca.bc.gov.educ.penreg.api.constants.SagaEnum)1 PenRequestBatchHistoryAPIEndpoint (ca.bc.gov.educ.penreg.api.endpoint.v1.PenRequestBatchHistoryAPIEndpoint)1