dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #36885
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18864: Analytics, made getPermutationOrgUnitGroupCountMap static
------------------------------------------------------------
revno: 18864
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-04-09 21:55:52 +0200
message:
Analytics, made getPermutationOrgUnitGroupCountMap static
modified:
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/data/DefaultAnalyticsService.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== 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<String, Map<String, Integer>> getPermutationOrgUnitGroupCountMap( Map<String, Double> orgUnitCountMap )
- {
- MapMap<String, String, Integer> countMap = new MapMap<>();
-
- for ( String key : orgUnitCountMap.keySet() )
- {
- List<String> 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<String, Map<String, Integer>> getPermutationOrgUnitGroupCountMap( Map<String, Double> orgUnitCountMap )
+ {
+ MapMap<String, String, Integer> countMap = new MapMap<>();
+
+ for ( String key : orgUnitCountMap.keySet() )
+ {
+ List<String> 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<String, Double> aggregatedDataMap = getAggregatedDataValueMap( dataSourceParams );
@@ -644,7 +644,7 @@
Map<String, Double> 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<Indicator> indicators = asTypedList( params.getIndicators() );
+ DataQueryParams dataSourceParams = params.instance();
+ dataSourceParams.removeDimension( DATAELEMENT_DIM_ID );
+ dataSourceParams.removeDimension( DATASET_DIM_ID );
+
+ List<Indicator> indicators = asTypedList( dataSourceParams.getIndicators() );
List<NameableObject> 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;
}
/**