use of org.hisp.dhis.common.DimensionsCriteria in project dhis2-core by dhis2.
the class DimensionFilteringAndPagingServiceTest method testFiltering.
@Test
public void testFiltering() {
DimensionsCriteria criteria = new DimensionsCriteria();
criteria.setFilter(Set.of("name:eq:test"));
AnalyticsDimensionsPagingWrapper<ObjectNode> pagingWrapper = service.pageAndFilter(dimensionResponses, criteria, Collections.singletonList("*"));
assertThat(pagingWrapper.getDimensions().size(), is(5));
}
use of org.hisp.dhis.common.DimensionsCriteria 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;
}
use of org.hisp.dhis.common.DimensionsCriteria in project dhis2-core by dhis2.
the class DimensionFilteringAndPagingServiceTest method testPaging.
@Test
public void testPaging() {
DimensionsCriteria criteria = new DimensionsCriteria();
criteria.setPageSize(5);
AnalyticsDimensionsPagingWrapper<ObjectNode> pagingWrapper = service.pageAndFilter(dimensionResponses, criteria, Collections.singletonList("*"));
assertThat(pagingWrapper.getDimensions().size(), is(5));
}
Aggregations