Search in sources :

Example 1 with CATEGORYOPTIONCOMBO_DIM_ID

use of org.hisp.dhis.common.DimensionalObject.CATEGORYOPTIONCOMBO_DIM_ID in project dhis2-core by dhis2.

the class MetadataHandler method addMetaData.

/**
 * Adds meta data values to the given grid based on the given data query
 * parameters.
 *
 * @param params the {@link DataQueryParams}.
 * @param grid the grid.
 */
void addMetaData(DataQueryParams params, Grid grid) {
    if (!params.isSkipMeta()) {
        Map<String, Object> metaData = new HashMap<>();
        Map<String, Object> internalMetaData = new HashMap<>();
        // -----------------------------------------------------------------
        // Items / names element
        // -----------------------------------------------------------------
        Map<String, String> cocNameMap = getCocNameMap(params);
        metaData.put(ITEMS.getKey(), getDimensionMetadataItemMap(params));
        // -----------------------------------------------------------------
        // Item order elements
        // -----------------------------------------------------------------
        Map<String, Object> dimensionItems = new HashMap<>();
        Calendar calendar = PeriodType.getCalendar();
        List<String> periodUids = calendar.isIso8601() ? getUids(params.getDimensionOrFilterItems(PERIOD_DIM_ID)) : getLocalPeriodIdentifiers(params.getDimensionOrFilterItems(PERIOD_DIM_ID), calendar);
        dimensionItems.put(PERIOD_DIM_ID, periodUids);
        dimensionItems.put(CATEGORYOPTIONCOMBO_DIM_ID, Sets.newHashSet(cocNameMap.keySet()));
        for (DimensionalObject dim : params.getDimensionsAndFilters()) {
            if (!dimensionItems.containsKey(dim.getDimension())) {
                dimensionItems.put(dim.getDimension(), getDimensionalItemIds(dim.getItems()));
            }
        }
        metaData.put(DIMENSIONS.getKey(), dimensionItems);
        // -----------------------------------------------------------------
        // Organisation unit hierarchy
        // -----------------------------------------------------------------
        List<OrganisationUnit> organisationUnits = asTypedList(params.getDimensionOrFilterItems(ORGUNIT_DIM_ID));
        List<OrganisationUnit> roots = dataQueryService.getUserOrgUnits(params, null);
        if (params.isHierarchyMeta()) {
            metaData.put(ORG_UNIT_HIERARCHY.getKey(), getParentGraphMap(organisationUnits, roots));
        }
        if (params.isShowHierarchy()) {
            Map<Object, List<?>> ancestorMap = organisationUnits.stream().collect(toMap(OrganisationUnit::getUid, ou -> ou.getAncestorNames(roots, true)));
            internalMetaData.put(ORG_UNIT_ANCESTORS.getKey(), ancestorMap);
            metaData.put(ORG_UNIT_NAME_HIERARCHY.getKey(), getParentNameGraphMap(organisationUnits, roots, true));
        }
        grid.setMetaData(copyOf(metaData));
        grid.setInternalMetaData(copyOf(internalMetaData));
    }
}
Also used : DIMENSIONS(org.hisp.dhis.analytics.AnalyticsMetaDataKey.DIMENSIONS) ORGUNIT_DIM_ID(org.hisp.dhis.common.DimensionalObject.ORGUNIT_DIM_ID) DataQueryService(org.hisp.dhis.analytics.DataQueryService) ImmutableMap.copyOf(com.google.common.collect.ImmutableMap.copyOf) HashMap(java.util.HashMap) ORG_UNIT_HIERARCHY(org.hisp.dhis.analytics.AnalyticsMetaDataKey.ORG_UNIT_HIERARCHY) Collectors.toMap(java.util.stream.Collectors.toMap) Calendar(org.hisp.dhis.calendar.Calendar) Map(java.util.Map) DATA_VALUE_SET(org.hisp.dhis.analytics.OutputFormat.DATA_VALUE_SET) DimensionalObjectUtils.getDimensionalItemIds(org.hisp.dhis.common.DimensionalObjectUtils.getDimensionalItemIds) ORG_UNIT_NAME_HIERARCHY(org.hisp.dhis.analytics.AnalyticsMetaDataKey.ORG_UNIT_NAME_HIERARCHY) OrganisationUnit.getParentNameGraphMap(org.hisp.dhis.organisationunit.OrganisationUnit.getParentNameGraphMap) AnalyticsUtils.getDimensionMetadataItemMap(org.hisp.dhis.analytics.util.AnalyticsUtils.getDimensionMetadataItemMap) PERIOD_DIM_ID(org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Grid(org.hisp.dhis.common.Grid) AnalyticsUtils.getCocNameMap(org.hisp.dhis.analytics.util.AnalyticsUtils.getCocNameMap) Sets(com.google.common.collect.Sets) AnalyticsUtils.handleGridForDataValueSet(org.hisp.dhis.analytics.util.AnalyticsUtils.handleGridForDataValueSet) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) OrganisationUnit.getParentGraphMap(org.hisp.dhis.organisationunit.OrganisationUnit.getParentGraphMap) List(java.util.List) Component(org.springframework.stereotype.Component) ORG_UNIT_ANCESTORS(org.hisp.dhis.analytics.AnalyticsMetaDataKey.ORG_UNIT_ANCESTORS) IdentifiableObjectUtils.getUids(org.hisp.dhis.common.IdentifiableObjectUtils.getUids) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) 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) CATEGORYOPTIONCOMBO_DIM_ID(org.hisp.dhis.common.DimensionalObject.CATEGORYOPTIONCOMBO_DIM_ID) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) HashMap(java.util.HashMap) Calendar(org.hisp.dhis.calendar.Calendar) DimensionalObject(org.hisp.dhis.common.DimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) List(java.util.List) DimensionalObjectUtils.asTypedList(org.hisp.dhis.common.DimensionalObjectUtils.asTypedList)

Aggregations

Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableMap.copyOf (com.google.common.collect.ImmutableMap.copyOf)1 Sets (com.google.common.collect.Sets)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 DIMENSIONS (org.hisp.dhis.analytics.AnalyticsMetaDataKey.DIMENSIONS)1 ITEMS (org.hisp.dhis.analytics.AnalyticsMetaDataKey.ITEMS)1 ORG_UNIT_ANCESTORS (org.hisp.dhis.analytics.AnalyticsMetaDataKey.ORG_UNIT_ANCESTORS)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 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)1 DataQueryService (org.hisp.dhis.analytics.DataQueryService)1 DATA_VALUE_SET (org.hisp.dhis.analytics.OutputFormat.DATA_VALUE_SET)1 AnalyticsUtils.getCocNameMap (org.hisp.dhis.analytics.util.AnalyticsUtils.getCocNameMap)1 AnalyticsUtils.getDimensionMetadataItemMap (org.hisp.dhis.analytics.util.AnalyticsUtils.getDimensionMetadataItemMap)1 AnalyticsUtils.handleGridForDataValueSet (org.hisp.dhis.analytics.util.AnalyticsUtils.handleGridForDataValueSet)1 Calendar (org.hisp.dhis.calendar.Calendar)1 DimensionalObject (org.hisp.dhis.common.DimensionalObject)1