=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java' --- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java 2015-04-09 19:08:39 +0000 +++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java 2015-04-09 19:55:52 +0000 @@ -713,37 +713,6 @@ } /** - * Returns a mapping of permutations keys (org unit id or null) and mappings - * of org unit group and counts, based on the given mapping of dimension option - * keys and counts. - */ - public Map> getPermutationOrgUnitGroupCountMap( Map orgUnitCountMap ) - { - MapMap countMap = new MapMap<>(); - - for ( String key : orgUnitCountMap.keySet() ) - { - List keys = new ArrayList<>( Arrays.asList( key.split( DIMENSION_SEP ) ) ); - - // Org unit group always at last index, org unit potentially at first - - int ougInx = keys.size() - 1; - - String oug = keys.get( ougInx ); - - ListUtils.removeAll( keys, ougInx ); - - String permKey = StringUtils.trimToNull( StringUtils.join( keys, DIMENSION_SEP ) ); - - Integer count = orgUnitCountMap.get( key ).intValue(); - - countMap.putEntry( permKey, oug, count ); - } - - return countMap; - } - - /** * Retrieves the options for the given dimension identifier. Returns null if * the dimension is not present. */ @@ -988,6 +957,37 @@ } /** + * Returns a mapping of permutations keys (org unit id or null) and mappings + * of org unit group and counts, based on the given mapping of dimension option + * keys and counts. + */ + public static Map> getPermutationOrgUnitGroupCountMap( Map orgUnitCountMap ) + { + MapMap countMap = new MapMap<>(); + + for ( String key : orgUnitCountMap.keySet() ) + { + List keys = new ArrayList<>( Arrays.asList( key.split( DIMENSION_SEP ) ) ); + + // Org unit group always at last index, org unit potentially at first + + int ougInx = keys.size() - 1; + + String oug = keys.get( ougInx ); + + ListUtils.removeAll( keys, ougInx ); + + String permKey = StringUtils.trimToNull( StringUtils.join( keys, DIMENSION_SEP ) ); + + Integer count = orgUnitCountMap.get( key ).intValue(); + + countMap.putEntry( permKey, oug, count ); + } + + return countMap; + } + + /** * Retrieves the measure criteria from the given string. Criteria are separated * by the option separator, while the criterion filter and value are separated * with the dimension name separator. === modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java' --- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2015-04-09 19:08:39 +0000 +++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2015-04-09 19:55:52 +0000 @@ -297,7 +297,7 @@ dataSourceParams.removeDimension( DATAELEMENT_DIM_ID ); dataSourceParams.removeDimension( DATASET_DIM_ID ); - dataSourceParams = replaceIndicatorsWithDataElements( dataSourceParams, indicatorIndex ); + dataSourceParams = getQueryIndicatorsReplacedByDataElements( dataSourceParams, indicatorIndex ); Map aggregatedDataMap = getAggregatedDataValueMap( dataSourceParams ); @@ -644,7 +644,7 @@ Map orgUnitCountMap = getAggregatedOrganisationUnitTargetMap( orgUnitTargetParams ); - return orgUnitTargetParams.getPermutationOrgUnitGroupCountMap( orgUnitCountMap ); + return DataQueryParams.getPermutationOrgUnitGroupCountMap( orgUnitCountMap ); } /** @@ -1226,22 +1226,26 @@ // ------------------------------------------------------------------------- /** - * Replaces the indicator dimension including items with the data elements - * part of the indicator expressions. + * Returns a new instance of the given query where indicators are replaced + * with the data elements part of the indicator expressions. * * @param params the data query parameters. * @param indicatorIndex the index of the indicator dimension in the given query. * @return the data query parameters. */ - private DataQueryParams replaceIndicatorsWithDataElements( DataQueryParams params, int indicatorIndex ) + private DataQueryParams getQueryIndicatorsReplacedByDataElements( DataQueryParams params, int indicatorIndex ) { - List indicators = asTypedList( params.getIndicators() ); + DataQueryParams dataSourceParams = params.instance(); + dataSourceParams.removeDimension( DATAELEMENT_DIM_ID ); + dataSourceParams.removeDimension( DATASET_DIM_ID ); + + List indicators = asTypedList( dataSourceParams.getIndicators() ); List dataElements = asList( expressionService.getDataElementsInIndicators( indicators ) ); - params.getDimensions().set( indicatorIndex, new BaseDimensionalObject( DATAELEMENT_DIM_ID, DimensionType.DATAELEMENT, dataElements ) ); - params.enableCategoryOptionCombos(); + dataSourceParams.getDimensions().set( indicatorIndex, new BaseDimensionalObject( DATAELEMENT_DIM_ID, DimensionType.DATAELEMENT, dataElements ) ); + dataSourceParams.enableCategoryOptionCombos(); - return params; + return dataSourceParams; } /**