Search in sources :

Example 1 with PAGER

use of org.hisp.dhis.analytics.AnalyticsMetaDataKey.PAGER in project dhis2-core by dhis2.

the class AbstractAnalyticsService method getGrid.

protected Grid getGrid(EventQueryParams params) {
    // ---------------------------------------------------------------------
    // Decide access, add constraints and validate
    // ---------------------------------------------------------------------
    securityManager.decideAccessEventQuery(params);
    params = securityManager.withUserConstraints(params);
    queryValidator.validate(params);
    // keywords as well as their periods are removed in the next step,
    // params object is modified
    List<DimensionItemKeywords.Keyword> periodKeywords = params.getDimensions().stream().map(DimensionalObject::getDimensionItemKeywords).filter(dimensionItemKeywords -> dimensionItemKeywords != null && !dimensionItemKeywords.isEmpty()).flatMap(dk -> dk.getKeywords().stream()).collect(Collectors.toList());
    params = new EventQueryParams.Builder(params).withStartEndDatesForPeriods().build();
    // ---------------------------------------------------------------------
    // Headers
    // ---------------------------------------------------------------------
    Grid grid = createGridWithHeaders(params);
    for (DimensionalObject dimension : params.getDimensions()) {
        grid.addHeader(new GridHeader(dimension.getDimension(), dimension.getDimensionDisplayName(), ValueType.TEXT, false, true));
    }
    for (QueryItem item : params.getItems()) {
        /**
         * Special case: If the request contains an item of Org Unit value
         * type and the item UID is linked to coordinates (coordinateField),
         * then create an Header of ValueType COORDINATE and type "Point"
         */
        if (item.getValueType() == ValueType.ORGANISATION_UNIT && params.getCoordinateField().equals(item.getItem().getUid())) {
            grid.addHeader(new GridHeader(item.getItem().getUid(), item.getItem().getDisplayProperty(params.getDisplayProperty()), COORDINATE, false, true, item.getOptionSet(), item.getLegendSet()));
        } else if (hasNonDefaultRepeatableProgramStageOffset(item)) {
            String column = item.getItem().getDisplayProperty(params.getDisplayProperty());
            RepeatableStageParams repeatableStageParams = item.getRepeatableStageParams();
            String name = repeatableStageParams.getDimension();
            grid.addHeader(new GridHeader(name, column, repeatableStageParams.simpleStageValueExpected() ? item.getValueType() : ValueType.REFERENCE, false, true, item.getOptionSet(), item.getLegendSet(), item.getProgramStage().getUid(), item.getRepeatableStageParams()));
        } else {
            final String uid = getItemUid(item);
            final String column = item.getItem().getDisplayProperty(params.getDisplayProperty());
            grid.addHeader(new GridHeader(uid, column, item.getValueType(), false, true, item.getOptionSet(), item.getLegendSet()));
        }
    }
    // ---------------------------------------------------------------------
    // Data
    // ---------------------------------------------------------------------
    long count = 0;
    if (!params.isSkipData() || params.analyzeOnly()) {
        count = addEventData(grid, params);
    }
    // ---------------------------------------------------------------------
    // Meta-data
    // ---------------------------------------------------------------------
    addMetadata(params, periodKeywords, grid);
    if (params.hasDataIdScheme()) {
        substituteData(grid);
    }
    if (params.isPaging()) {
        Pager pager = new Pager(params.getPageWithDefault(), count, params.getPageSizeWithDefault());
        grid.getMetaData().put(PAGER.getKey(), pager);
    }
    maybeApplyHeaders(params, grid);
    return grid;
}
Also used : DIMENSIONS(org.hisp.dhis.analytics.AnalyticsMetaDataKey.DIMENSIONS) ORGUNIT_DIM_ID(org.hisp.dhis.common.DimensionalObject.ORGUNIT_DIM_ID) Arrays(java.util.Arrays) QueryItem(org.hisp.dhis.common.QueryItem) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ValueType(org.hisp.dhis.common.ValueType) StringUtils.joinWith(org.apache.commons.lang3.StringUtils.joinWith) HashMap(java.util.HashMap) AnalyticsSecurityManager(org.hisp.dhis.analytics.AnalyticsSecurityManager) ArrayList(java.util.ArrayList) RepeatableStageParams(org.hisp.dhis.common.RepeatableStageParams) ORG_UNIT_HIERARCHY(org.hisp.dhis.analytics.AnalyticsMetaDataKey.ORG_UNIT_HIERARCHY) Lists(com.google.common.collect.Lists) Calendar(org.hisp.dhis.calendar.Calendar) GridHeader(org.hisp.dhis.common.GridHeader) Map(java.util.Map) DimensionalObjectUtils.getDimensionalItemIds(org.hisp.dhis.common.DimensionalObjectUtils.getDimensionalItemIds) User(org.hisp.dhis.user.User) ORG_UNIT_NAME_HIERARCHY(org.hisp.dhis.analytics.AnalyticsMetaDataKey.ORG_UNIT_NAME_HIERARCHY) DimensionItemKeywords(org.hisp.dhis.common.DimensionItemKeywords) PAGER(org.hisp.dhis.analytics.AnalyticsMetaDataKey.PAGER) COORDINATE(org.hisp.dhis.common.ValueType.COORDINATE) OrganisationUnit.getParentNameGraphMap(org.hisp.dhis.organisationunit.OrganisationUnit.getParentNameGraphMap) EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) PERIOD_DIM_ID(org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID) Collection(java.util.Collection) EventQueryValidator(org.hisp.dhis.analytics.event.EventQueryValidator) Pager(org.hisp.dhis.common.Pager) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Grid(org.hisp.dhis.common.Grid) Collectors(java.util.stream.Collectors) AnalyticsUtils(org.hisp.dhis.analytics.util.AnalyticsUtils) MetadataItem(org.hisp.dhis.common.MetadataItem) Objects(java.util.Objects) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) OrganisationUnit.getParentGraphMap(org.hisp.dhis.organisationunit.OrganisationUnit.getParentGraphMap) List(java.util.List) Option(org.hisp.dhis.option.Option) IdentifiableObjectUtils.getUids(org.hisp.dhis.common.IdentifiableObjectUtils.getUids) DimensionalObject(org.hisp.dhis.common.DimensionalObject) PeriodType(org.hisp.dhis.period.PeriodType) IdentifiableObjectUtils.getLocalPeriodIdentifiers(org.hisp.dhis.common.IdentifiableObjectUtils.getLocalPeriodIdentifiers) ITEMS(org.hisp.dhis.analytics.AnalyticsMetaDataKey.ITEMS) DimensionalObjectUtils.asTypedList(org.hisp.dhis.common.DimensionalObjectUtils.asTypedList) IdScheme(org.hisp.dhis.common.IdScheme) EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) QueryItem(org.hisp.dhis.common.QueryItem) Grid(org.hisp.dhis.common.Grid) RepeatableStageParams(org.hisp.dhis.common.RepeatableStageParams) DimensionalObject(org.hisp.dhis.common.DimensionalObject) GridHeader(org.hisp.dhis.common.GridHeader) Pager(org.hisp.dhis.common.Pager)

Aggregations

Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Lists (com.google.common.collect.Lists)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 StringUtils.joinWith (org.apache.commons.lang3.StringUtils.joinWith)1 DIMENSIONS (org.hisp.dhis.analytics.AnalyticsMetaDataKey.DIMENSIONS)1 ITEMS (org.hisp.dhis.analytics.AnalyticsMetaDataKey.ITEMS)1 ORG_UNIT_HIERARCHY (org.hisp.dhis.analytics.AnalyticsMetaDataKey.ORG_UNIT_HIERARCHY)1 ORG_UNIT_NAME_HIERARCHY (org.hisp.dhis.analytics.AnalyticsMetaDataKey.ORG_UNIT_NAME_HIERARCHY)1 PAGER (org.hisp.dhis.analytics.AnalyticsMetaDataKey.PAGER)1 AnalyticsSecurityManager (org.hisp.dhis.analytics.AnalyticsSecurityManager)1 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)1 EventQueryValidator (org.hisp.dhis.analytics.event.EventQueryValidator)1 AnalyticsUtils (org.hisp.dhis.analytics.util.AnalyticsUtils)1