dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #25163
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12409: Analytics. Including parent graph map for organisation units in response. Added query parameter h...
------------------------------------------------------------
revno: 12409
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-10-03 10:22:21 +0200
message:
Analytics. Including parent graph map for organisation units in response. Added query parameter hierarchyMeta for adding names of org units in hierarhcy in response.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsService.java
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
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/MockAnalyticsService.java
dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.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-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java 2013-09-04 08:34:55 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java 2013-10-03 08:22:21 +0000
@@ -32,9 +32,11 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
+import java.util.Map;
/**
* @author Lars Helge Overland
@@ -258,4 +260,23 @@
return integers;
}
+
+ /**
+ * Returns a mapping between the uid and the name of the given identifiable
+ * objects.
+ *
+ * @param objects the identifiable objects.
+ * @return mapping between the uid and the name of the given objects.
+ */
+ public static Map<String, String> getUidNameMap( Collection<? extends IdentifiableObject> objects )
+ {
+ Map<String, String> map = new HashMap<String, String>();
+
+ for ( IdentifiableObject object : objects )
+ {
+ map.put( object.getUid(), object.getDisplayName() );
+ }
+
+ return map;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsService.java 2013-09-28 15:06:20 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsService.java 2013-10-03 08:22:21 +0000
@@ -147,12 +147,14 @@
* @param aggregationType the aggregation type.
* @param measureCriteria the measure criteria.
* @param skipMeta whether to skip the meta data part of the response.
+ * @param hierarchyMeta whether to include meta data about the org units
+ * in the hierarchy.
* @param ignoreLimit whether to ignore the max number of cells limit.
* @param format the i18n format.
* @return a data query parameter object created based on the given URL info.
*/
DataQueryParams getFromUrl( Set<String> dimensionParams, Set<String> filterParams,
- AggregationType aggregationType, String measureCriteria, boolean skipMeta, boolean ignoreLimit, I18nFormat format );
+ AggregationType aggregationType, String measureCriteria, boolean skipMeta, boolean hierarchyMeta, boolean ignoreLimit, I18nFormat format );
/**
* Creates a data query parameter object from the given BaseAnalyticalObject.
=== 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 2013-09-29 21:05:46 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java 2013-10-03 08:22:21 +0000
@@ -112,6 +112,8 @@
private Map<MeasureFilter, Double> measureCriteria = new HashMap<MeasureFilter, Double>();
private boolean skipMeta;
+
+ private boolean hierarchyMeta;
private boolean ignoreLimit;
@@ -144,6 +146,7 @@
params.aggregationType = this.aggregationType;
params.measureCriteria = this.measureCriteria;
params.skipMeta = this.skipMeta;
+ params.hierarchyMeta = this.hierarchyMeta;
params.ignoreLimit = this.ignoreLimit;
params.partitions = this.partitions;
@@ -1030,6 +1033,16 @@
this.skipMeta = skipMeta;
}
+ public boolean isHierarchyMeta()
+ {
+ return hierarchyMeta;
+ }
+
+ public void setHierarchyMeta( boolean hierarchyMeta )
+ {
+ this.hierarchyMeta = hierarchyMeta;
+ }
+
public boolean isIgnoreLimit()
{
return ignoreLimit;
=== 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 2013-09-30 13:56:22 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2013-10-03 08:22:21 +0000
@@ -386,12 +386,13 @@
Map<String, String> uidNameMap = getUidNameMap( params );
Map<String, String> cocNameMap = getCocNameMap( grid, cocIndex );
+ Map<String, String> ouParentGraphMap = getParentGrapMap( asTypedList( params.getDimensionOrFilter( ORGUNIT_DIM_ID ), OrganisationUnit.class ) );
uidNameMap.putAll( cocNameMap );
metaData.put( NAMES_META_KEY, uidNameMap );
metaData.put( PERIOD_DIM_ID, getUids( params.getDimensionOrFilter( PERIOD_DIM_ID ) ) );
- metaData.put( ORGUNIT_DIM_ID, getUids( params.getDimensionOrFilter( ORGUNIT_DIM_ID ) ) );
+ metaData.put( ORGUNIT_DIM_ID, ouParentGraphMap );
if ( cocIndex != null )
{
@@ -403,7 +404,7 @@
return grid;
}
-
+
@Override
public Grid getAggregatedDataValues( DataQueryParams params, boolean tableLayout, List<String> columns, List<String> rows )
{
@@ -491,7 +492,7 @@
return getAggregatedDataValueMapping( params );
}
-
+
/**
* Generates aggregated values for the given query. Creates a mapping between
* a dimension key and the aggregated value. The dimension key is a
@@ -584,7 +585,7 @@
@Override
public DataQueryParams getFromUrl( Set<String> dimensionParams, Set<String> filterParams,
- AggregationType aggregationType, String measureCriteria, boolean skipMeta, boolean ignoreLimit, I18nFormat format )
+ AggregationType aggregationType, String measureCriteria, boolean skipMeta, boolean hierarchyMeta, boolean ignoreLimit, I18nFormat format )
{
DataQueryParams params = new DataQueryParams();
@@ -625,6 +626,7 @@
}
params.setSkipMeta( skipMeta );
+ params.setHierarchyMeta( hierarchyMeta );
return params;
}
@@ -915,17 +917,37 @@
return params;
}
+ /**
+ * Returns a mapping between the uid and the name of all dimension and filter
+ * items for the given params.
+ */
private Map<String, String> getUidNameMap( DataQueryParams params )
{
Map<String, String> map = new HashMap<String, String>();
- map.putAll( getUidNameMap( params.getDimensions() ) );
- map.putAll( getUidNameMap( params.getFilters() ) );
+ map.putAll( getUidNameMap( params.getDimensions(), params.isHierarchyMeta() ) );
+ map.putAll( getUidNameMap( params.getFilters(), params.isHierarchyMeta() ) );
map.put( DATA_X_DIM_ID, DISPLAY_NAME_DATA_X );
return map;
}
-
- private Map<String, String> getUidNameMap( List<DimensionalObject> dimensions )
+
+ /**
+ * Returns a mapping between the uid and the uid parent graph of the given
+ * organisation units.
+ */
+ private Map<String, String> getParentGrapMap( List<OrganisationUnit> organisationUnits )
+ {
+ Map<String, String> map = new HashMap<String, String>();
+
+ for ( OrganisationUnit unit : organisationUnits )
+ {
+ map.put( unit.getUid(), unit.getParentGraph() );
+ }
+
+ return map;
+ }
+
+ private Map<String, String> getUidNameMap( List<DimensionalObject> dimensions, boolean hierarchyMeta )
{
Map<String, String> map = new HashMap<String, String>();
@@ -933,6 +955,8 @@
{
List<NameableObject> options = new ArrayList<NameableObject>( dimension.getItems() );
+ boolean hierarchy = hierarchyMeta && DimensionType.ORGANISATIONUNIT.equals( dimension.getType() );
+
// -----------------------------------------------------------------
// If dimension is not fixed and has no options, insert all options
// -----------------------------------------------------------------
@@ -960,6 +984,13 @@
for ( IdentifiableObject idObject : options )
{
map.put( idObject.getUid(), idObject.getDisplayName() );
+
+ if ( hierarchy )
+ {
+ OrganisationUnit unit = (OrganisationUnit) idObject;
+
+ map.putAll( IdentifiableObjectUtils.getUidNameMap( unit.getAncestors() ) );
+ }
}
if ( dimension.getDisplayName() != null )
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/MockAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/MockAnalyticsService.java 2013-09-28 15:06:20 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/MockAnalyticsService.java 2013-10-03 08:22:21 +0000
@@ -81,7 +81,7 @@
@Override
public DataQueryParams getFromUrl( Set<String> dimensionParams, Set<String> filterParams,
- AggregationType aggregationType, String measureCriteria, boolean skipMeta, boolean ignoreLimit, I18nFormat format )
+ AggregationType aggregationType, String measureCriteria, boolean skipMeta, boolean hierarchyMeta, boolean ignoreLimit, I18nFormat format )
{
throw new NotImplementedException();
}
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java 2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java 2013-10-03 08:22:21 +0000
@@ -164,7 +164,7 @@
Set<String> filterParams = new HashSet<String>();
filterParams.add( "ou:" + ouA.getUid() + ";" + ouB.getUid() + ";" + ouC.getUid() + ";" + ouD.getUid() + ";" + ouE.getUid() );
- DataQueryParams params = analyticsService.getFromUrl( dimensionParams, filterParams, null, null, false, false, null );
+ DataQueryParams params = analyticsService.getFromUrl( dimensionParams, filterParams, null, null, false, false, false, null );
assertEquals( 4, params.getDataElements().size() );
assertEquals( 3, params.getPeriods().size() );
@@ -181,7 +181,7 @@
Set<String> filterParams = new HashSet<String>();
filterParams.add( "ou:" + ouA.getUid() );
- DataQueryParams params = analyticsService.getFromUrl( dimensionParams, filterParams, null, null, false, false, null );
+ DataQueryParams params = analyticsService.getFromUrl( dimensionParams, filterParams, null, null, false, false, false, null );
assertEquals( 4, params.getDataElements().size() );
assertEquals( 1, params.getFilterOrganisationUnits().size() );
@@ -197,7 +197,7 @@
Set<String> filterParams = new HashSet<String>();
filterParams.add( "ou:" + ouA.getUid() + ";" + ouB.getUid() );
- DataQueryParams params = analyticsService.getFromUrl( dimensionParams, filterParams, null, null, false, false, null );
+ DataQueryParams params = analyticsService.getFromUrl( dimensionParams, filterParams, null, null, false, false, false, null );
assertEquals( 4, params.getDataElements().size() );
assertEquals( 12, params.getPeriods().size() );
@@ -212,7 +212,7 @@
dimensionParams.add( "dx:" + deA.getUid() + ";" + deB.getUid() );
dimensionParams.add( "pe:2011;2012" );
- DataQueryParams params = analyticsService.getFromUrl( dimensionParams, null, null, null, false, false, null );
+ DataQueryParams params = analyticsService.getFromUrl( dimensionParams, null, null, null, false, false, false, null );
assertEquals( 1, params.getOrganisationUnits().size() );
assertEquals( 2, params.getDataElements().size() );
@@ -227,7 +227,7 @@
dimensionParams.add( "dx:" + deA.getUid() + ";" + deB.getUid() );
dimensionParams.add( "pe:2011;2012" );
- DataQueryParams params = analyticsService.getFromUrl( dimensionParams, null, null, null, false, false, null );
+ DataQueryParams params = analyticsService.getFromUrl( dimensionParams, null, null, null, false, false, false, null );
assertEquals( 2, params.getOrganisationUnits().size() );
assertEquals( 2, params.getDataElements().size() );
@@ -241,7 +241,7 @@
dimensionParams.add( "dx" );
dimensionParams.add( "pe:2012,2012S1,2012S2" );
- analyticsService.getFromUrl( dimensionParams, null, null, null, false, false, null );
+ analyticsService.getFromUrl( dimensionParams, null, null, null, false, false, false, null );
}
@Test( expected = IllegalQueryException.class )
@@ -251,7 +251,7 @@
dimensionParams.add( "dx:" + BASE_UID + "A;" + BASE_UID + "B;" + BASE_UID + "C;" + BASE_UID + "D" );
dimensionParams.add( "pe" );
- analyticsService.getFromUrl( dimensionParams, null, null, null, false, false, null );
+ analyticsService.getFromUrl( dimensionParams, null, null, null, false, false, false, null );
}
@Test( expected = IllegalQueryException.class )
@@ -261,7 +261,7 @@
dimensionParams.add( "dx:" + BASE_UID + "A;" + BASE_UID + "B;" + BASE_UID + "C;" + BASE_UID + "D" );
dimensionParams.add( "ou" );
- analyticsService.getFromUrl( dimensionParams, null, null, null, false, false, null );
+ analyticsService.getFromUrl( dimensionParams, null, null, null, false, false, false, null );
}
@Test( expected = IllegalQueryException.class )
@@ -271,7 +271,7 @@
dimensionParams.add( "dx:" + BASE_UID + "A;" + BASE_UID + "B;" + BASE_UID + "C;" + BASE_UID + "D" );
dimensionParams.add( "yebo:2012,2012S1,2012S2" );
- analyticsService.getFromUrl( dimensionParams, null, null, null, false, false, null );
+ analyticsService.getFromUrl( dimensionParams, null, null, null, false, false, false, null );
}
@Test
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java 2013-09-20 10:32:06 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java 2013-10-03 08:22:21 +0000
@@ -81,6 +81,7 @@
@RequestParam(required = false) AggregationType aggregationType,
@RequestParam(required = false) String measureCriteria,
@RequestParam(required = false) boolean skipMeta,
+ @RequestParam(required = false) boolean hierarchyMeta,
@RequestParam(required = false) boolean ignoreLimit,
@RequestParam(required = false) boolean tableLayout,
@RequestParam(required = false) String columns,
@@ -88,7 +89,7 @@
Model model,
HttpServletResponse response ) throws Exception
{
- DataQueryParams params = analyticsService.getFromUrl( dimension, filter, aggregationType, measureCriteria, skipMeta, ignoreLimit, i18nManager.getI18nFormat() );
+ DataQueryParams params = analyticsService.getFromUrl( dimension, filter, aggregationType, measureCriteria, skipMeta, hierarchyMeta, ignoreLimit, i18nManager.getI18nFormat() );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.RESPECT_SYSTEM_SETTING );
Grid grid = analyticsService.getAggregatedDataValues( params, tableLayout, getDimensionsFromParam( columns ), getDimensionsFromParam( rows ) );
@@ -104,6 +105,7 @@
@RequestParam(required = false) AggregationType aggregationType,
@RequestParam(required = false) String measureCriteria,
@RequestParam(required = false) boolean skipMeta,
+ @RequestParam(required = false) boolean hierarchyMeta,
@RequestParam(required = false) boolean ignoreLimit,
@RequestParam(required = false) boolean tableLayout,
@RequestParam(required = false) String columns,
@@ -111,7 +113,7 @@
Model model,
HttpServletResponse response ) throws Exception
{
- DataQueryParams params = analyticsService.getFromUrl( dimension, filter, aggregationType, measureCriteria, skipMeta, ignoreLimit, i18nManager.getI18nFormat() );
+ DataQueryParams params = analyticsService.getFromUrl( dimension, filter, aggregationType, measureCriteria, skipMeta, hierarchyMeta, ignoreLimit, i18nManager.getI18nFormat() );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.RESPECT_SYSTEM_SETTING );
Grid grid = analyticsService.getAggregatedDataValues( params, tableLayout, getDimensionsFromParam( columns ), getDimensionsFromParam( rows ) );
@@ -125,6 +127,7 @@
@RequestParam(required = false) AggregationType aggregationType,
@RequestParam(required = false) String measureCriteria,
@RequestParam(required = false) boolean skipMeta,
+ @RequestParam(required = false) boolean hierarchyMeta,
@RequestParam(required = false) boolean ignoreLimit,
@RequestParam(required = false) boolean tableLayout,
@RequestParam(required = false) String columns,
@@ -132,7 +135,7 @@
Model model,
HttpServletResponse response ) throws Exception
{
- DataQueryParams params = analyticsService.getFromUrl( dimension, filter, aggregationType, measureCriteria, skipMeta, ignoreLimit, i18nManager.getI18nFormat() );
+ DataQueryParams params = analyticsService.getFromUrl( dimension, filter, aggregationType, measureCriteria, skipMeta, hierarchyMeta, ignoreLimit, i18nManager.getI18nFormat() );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_HTML, CacheStrategy.RESPECT_SYSTEM_SETTING );
Grid grid = analyticsService.getAggregatedDataValues( params, tableLayout, getDimensionsFromParam( columns ), getDimensionsFromParam( rows ) );
@@ -146,6 +149,7 @@
@RequestParam(required = false) AggregationType aggregationType,
@RequestParam(required = false) String measureCriteria,
@RequestParam(required = false) boolean skipMeta,
+ @RequestParam(required = false) boolean hierarchyMeta,
@RequestParam(required = false) boolean ignoreLimit,
@RequestParam(required = false) boolean tableLayout,
@RequestParam(required = false) String columns,
@@ -153,7 +157,7 @@
Model model,
HttpServletResponse response ) throws Exception
{
- DataQueryParams params = analyticsService.getFromUrl( dimension, filter, aggregationType, measureCriteria, skipMeta, ignoreLimit, i18nManager.getI18nFormat() );
+ DataQueryParams params = analyticsService.getFromUrl( dimension, filter, aggregationType, measureCriteria, skipMeta, hierarchyMeta, ignoreLimit, i18nManager.getI18nFormat() );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_CSV, CacheStrategy.RESPECT_SYSTEM_SETTING, "data.csv", true );
Grid grid = analyticsService.getAggregatedDataValues( params, tableLayout, getDimensionsFromParam( columns ), getDimensionsFromParam( rows ) );
@@ -167,6 +171,7 @@
@RequestParam(required = false) AggregationType aggregationType,
@RequestParam(required = false) String measureCriteria,
@RequestParam(required = false) boolean skipMeta,
+ @RequestParam(required = false) boolean hierarchyMeta,
@RequestParam(required = false) boolean ignoreLimit,
@RequestParam(required = false) boolean tableLayout,
@RequestParam(required = false) String columns,
@@ -174,7 +179,7 @@
Model model,
HttpServletResponse response ) throws Exception
{
- DataQueryParams params = analyticsService.getFromUrl( dimension, filter, aggregationType, measureCriteria, skipMeta, ignoreLimit, i18nManager.getI18nFormat() );
+ DataQueryParams params = analyticsService.getFromUrl( dimension, filter, aggregationType, measureCriteria, skipMeta, hierarchyMeta, ignoreLimit, i18nManager.getI18nFormat() );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_EXCEL, CacheStrategy.RESPECT_SYSTEM_SETTING, "data.xls", true );
Grid grid = analyticsService.getAggregatedDataValues( params, tableLayout, getDimensionsFromParam( columns ), getDimensionsFromParam( rows ) );
@@ -188,6 +193,7 @@
@RequestParam(required = false) AggregationType aggregationType,
@RequestParam(required = false) String measureCriteria,
@RequestParam(required = false) boolean skipMeta,
+ @RequestParam(required = false) boolean hierarchyMeta,
@RequestParam(required = false) boolean ignoreLimit,
@RequestParam(required = false) boolean tableLayout,
@RequestParam(required = false) String columns,
@@ -195,7 +201,7 @@
Model model,
HttpServletResponse response ) throws Exception
{
- DataQueryParams params = analyticsService.getFromUrl( dimension, filter, null, null, true, ignoreLimit, i18nManager.getI18nFormat() );
+ DataQueryParams params = analyticsService.getFromUrl( dimension, filter, null, null, true, false, ignoreLimit, i18nManager.getI18nFormat() );
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.RESPECT_SYSTEM_SETTING, "data.jrxml", false );
Grid grid = analyticsService.getAggregatedDataValues( params );