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));
}
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;
}
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));
}
}
Aggregations