use of org.hisp.dhis.webapi.controller.event.webrequest.OrderCriteria in project dhis2-core by dhis2.
the class DimensionFilteringAndPagingService method sortedAndPagedStream.
private Stream<DimensionResponse> sortedAndPagedStream(Stream<DimensionResponse> dimensions, DimensionsCriteria pagingAndSortingCriteria) {
if (Objects.nonNull(pagingAndSortingCriteria.getOrder()) && !pagingAndSortingCriteria.getOrder().isEmpty()) {
OrderCriteria orderCriteria = pagingAndSortingCriteria.getOrder().get(0);
Comparator<DimensionResponse> comparator = ORDERING_MAP.keySet().stream().filter(key -> key.equalsIgnoreCase(orderCriteria.getField())).map(ORDERING_MAP::get).findFirst().orElse(DEFAULT_COMPARATOR);
if (Objects.nonNull(orderCriteria.getDirection()) && !orderCriteria.getDirection().isAscending()) {
dimensions = dimensions.sorted(comparator.reversed());
} else {
dimensions = dimensions.sorted(comparator);
}
} else {
dimensions = dimensions.sorted(DEFAULT_COMPARATOR);
}
if (pagingAndSortingCriteria.isPaging()) {
dimensions = dimensions.skip(pagingAndSortingCriteria.getFirstResult()).limit(pagingAndSortingCriteria.getPageSize());
}
return dimensions;
}
Aggregations