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