Search in sources :

Example 1 with SortField

use of org.folio.dao.util.SortField in project mod-source-record-manager by folio-org.

the class MetadataProviderImpl method mapSortQueryToSortFields.

private List<SortField> mapSortQueryToSortFields(List<String> sortQuery) {
    ArrayList<SortField> fields = new ArrayList<>();
    for (String sortFieldQuery : sortQuery) {
        String sortField = StringUtils.substringBefore(sortFieldQuery, ",");
        String sortOrder = StringUtils.substringAfter(sortFieldQuery, ",");
        if (!JOB_EXECUTION_SORTABLE_FIELDS.contains(sortField) || !SORT_ORDER_VALUES.contains(sortOrder)) {
            throw new BadRequestException(format(INVALID_SORT_PARAMS_MSG, sortFieldQuery, JOB_EXECUTION_SORTABLE_FIELDS));
        }
        fields.add(new SortField(sortField, sortOrder));
    }
    return fields;
}
Also used : ArrayList(java.util.ArrayList) BadRequestException(javax.ws.rs.BadRequestException) SortField(org.folio.dao.util.SortField)

Example 2 with SortField

use of org.folio.dao.util.SortField in project mod-source-record-manager by folio-org.

the class MetadataProviderImpl method getMetadataProviderJobExecutions.

@Override
public void getMetadataProviderJobExecutions(List<String> statusAny, List<String> profileIdNotAny, String statusNot, List<String> uiStatusAny, String hrId, String fileName, List<String> profileIdAny, String userId, Date completedAfter, Date completedBefore, List<String> sortBy, int offset, int limit, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
    vertxContext.runOnContext(v -> {
        try {
            List<SortField> sortFields = mapSortQueryToSortFields(sortBy);
            JobExecutionFilter filter = buildJobExecutionFilter(statusAny, profileIdNotAny, statusNot, uiStatusAny, hrId, fileName, profileIdAny, userId, completedAfter, completedBefore);
            jobExecutionsCache.get(tenantId, filter, sortFields, offset, limit).map(GetMetadataProviderJobExecutionsResponse::respond200WithApplicationJson).map(Response.class::cast).otherwise(ExceptionHelper::mapExceptionToResponse).onComplete(asyncResultHandler);
        } catch (Exception e) {
            asyncResultHandler.handle(Future.succeededFuture(ExceptionHelper.mapExceptionToResponse(e)));
        }
    });
}
Also used : Response(javax.ws.rs.core.Response) JobExecutionFilter(org.folio.dao.JobExecutionFilter) SortField(org.folio.dao.util.SortField) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(javax.ws.rs.NotFoundException)

Aggregations

BadRequestException (javax.ws.rs.BadRequestException)2 SortField (org.folio.dao.util.SortField)2 ArrayList (java.util.ArrayList)1 NotFoundException (javax.ws.rs.NotFoundException)1 Response (javax.ws.rs.core.Response)1 JobExecutionFilter (org.folio.dao.JobExecutionFilter)1