Search in sources :

Example 1 with Associations

use of ca.bc.gov.educ.penreg.api.filter.Associations 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 2 with Associations

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

the class PaginatedController method getSortCriteria.

/**
 * Gets sort criteria.
 *
 * @param sortCriteriaJson the sort criteria json
 * @param objectMapper     the object mapper
 * @param sorts            the sorts
 * @return the association names
 * @throws JsonProcessingException the json processing exception
 */
public Associations getSortCriteria(final String sortCriteriaJson, final ObjectMapper objectMapper, final List<Sort.Order> sorts) throws JsonProcessingException {
    final Associations associationNames = new Associations();
    if (StringUtils.isNotBlank(sortCriteriaJson)) {
        final Map<String, String> sortMap = objectMapper.readValue(sortCriteriaJson, new TypeReference<>() {
        });
        sortMap.forEach((k, v) -> {
            final var names = k.split("\\.");
            if (names.length > 1) {
                associationNames.getSortAssociations().add(names[0]);
            }
            if ("ASC".equalsIgnoreCase(v)) {
                sorts.add(new Sort.Order(Sort.Direction.ASC, k));
            } else {
                sorts.add(new Sort.Order(Sort.Direction.DESC, k));
            }
        });
    }
    return associationNames;
}
Also used : Sort(org.springframework.data.domain.Sort) Associations(ca.bc.gov.educ.penreg.api.filter.Associations)

Example 3 with Associations

use of ca.bc.gov.educ.penreg.api.filter.Associations 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

Associations (ca.bc.gov.educ.penreg.api.filter.Associations)3 InvalidParameterException (ca.bc.gov.educ.penreg.api.exception.InvalidParameterException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Sort (org.springframework.data.domain.Sort)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 SagaStatusEnum (ca.bc.gov.educ.penreg.api.constants.SagaStatusEnum)1 PenRequestBatchAPIEndpoint (ca.bc.gov.educ.penreg.api.endpoint.v1.PenRequestBatchAPIEndpoint)1 PenRequestBatchHistoryAPIEndpoint (ca.bc.gov.educ.penreg.api.endpoint.v1.PenRequestBatchHistoryAPIEndpoint)1 EntityNotFoundException (ca.bc.gov.educ.penreg.api.exception.EntityNotFoundException)1 InvalidPayloadException (ca.bc.gov.educ.penreg.api.exception.InvalidPayloadException)1 PenRegAPIRuntimeException (ca.bc.gov.educ.penreg.api.exception.PenRegAPIRuntimeException)1 ApiError (ca.bc.gov.educ.penreg.api.exception.errors.ApiError)1 PenRegBatchFilterSpecs (ca.bc.gov.educ.penreg.api.filter.PenRegBatchFilterSpecs)1 PenRegBatchStudentFilterSpecs (ca.bc.gov.educ.penreg.api.filter.PenRegBatchStudentFilterSpecs)1 PenRegBatchHelper (ca.bc.gov.educ.penreg.api.helpers.PenRegBatchHelper)1 PenRequestBatchStudentValidationIssueMapper (ca.bc.gov.educ.penreg.api.mappers.PenRequestBatchStudentValidationIssueMapper)1 PenRequestBatchMapper (ca.bc.gov.educ.penreg.api.mappers.v1.PenRequestBatchMapper)1 PenRequestBatchStudentMapper (ca.bc.gov.educ.penreg.api.mappers.v1.PenRequestBatchStudentMapper)1