Search in sources :

Example 1 with DimensionsCriteria

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));
}
Also used : DimensionsCriteria(org.hisp.dhis.common.DimensionsCriteria) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Test(org.junit.jupiter.api.Test)

Example 2 with DimensionsCriteria

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;
}
Also used : FieldFilterService(org.hisp.dhis.fieldfiltering.FieldFilterService) Comparator.nullsFirst(java.util.Comparator.nullsFirst) Comparator.naturalOrder(java.util.Comparator.naturalOrder) AnalyticsDimensionsPagingWrapper(org.hisp.dhis.analytics.dimensions.AnalyticsDimensionsPagingWrapper) NonNull(lombok.NonNull) Collection(java.util.Collection) Pager(org.hisp.dhis.common.Pager) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Collectors(java.util.stream.Collectors) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Objects(java.util.Objects) List(java.util.List) OrderCriteria(org.hisp.dhis.webapi.controller.event.webrequest.OrderCriteria) Stream(java.util.stream.Stream) FieldFilterParams(org.hisp.dhis.fieldfiltering.FieldFilterParams) Service(org.springframework.stereotype.Service) Map(java.util.Map) Optional(java.util.Optional) DimensionsCriteria(org.hisp.dhis.common.DimensionsCriteria) Comparator.comparing(java.util.Comparator.comparing) Comparator(java.util.Comparator) OrderCriteria(org.hisp.dhis.webapi.controller.event.webrequest.OrderCriteria)

Example 3 with DimensionsCriteria

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));
}
Also used : DimensionsCriteria(org.hisp.dhis.common.DimensionsCriteria) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 DimensionsCriteria (org.hisp.dhis.common.DimensionsCriteria)3 Test (org.junit.jupiter.api.Test)2 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 Comparator.comparing (java.util.Comparator.comparing)1 Comparator.naturalOrder (java.util.Comparator.naturalOrder)1 Comparator.nullsFirst (java.util.Comparator.nullsFirst)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 NonNull (lombok.NonNull)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 AnalyticsDimensionsPagingWrapper (org.hisp.dhis.analytics.dimensions.AnalyticsDimensionsPagingWrapper)1 Pager (org.hisp.dhis.common.Pager)1 FieldFilterParams (org.hisp.dhis.fieldfiltering.FieldFilterParams)1 FieldFilterService (org.hisp.dhis.fieldfiltering.FieldFilterService)1