← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18753: Event analytics. Added support for showHierarchy query param.

 

------------------------------------------------------------
revno: 18753
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-03-30 17:14:47 +0200
message:
  Event analytics. Added support for showHierarchy query param.
modified:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventAnalyticsService.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java
  dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/EventAnalyticsController.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/event/EventAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventAnalyticsService.java	2015-03-05 15:38:58 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventAnalyticsService.java	2015-03-30 15:14:47 +0000
@@ -64,6 +64,7 @@
      * @param skipMeta whether to skip meta-data in response.
      * @param skipRounding whether to skip rounding of values in response.
      * @param hierarchyMeta whether to include hierarchy meta-data in the response.
+     * @param showHierarchy whether to include hierarchy meta-data names in the response.
      * @param sortOrder the sort order of the aggregate values.
      * @param limit the max limit of records to return.
      * @param outputType the event output type.
@@ -73,7 +74,7 @@
      */
     EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate, 
         Set<String> dimension, Set<String> filter, String value, AggregationType aggregationType, 
-        boolean skipMeta, boolean skipRounding, boolean hierarchyMeta, SortOrder sortOrder, Integer limit, 
+        boolean skipMeta, boolean skipRounding, boolean hierarchyMeta, boolean showHierarchy, SortOrder sortOrder, Integer limit, 
         EventOutputType outputType, boolean collapseDataDimensions, DisplayProperty displayProperty, I18nFormat format );
 
     /**

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java	2015-03-26 08:36:46 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java	2015-03-30 15:14:47 +0000
@@ -30,6 +30,7 @@
 
 import static org.hisp.dhis.analytics.AnalyticsService.NAMES_META_KEY;
 import static org.hisp.dhis.analytics.AnalyticsService.OU_HIERARCHY_KEY;
+import static org.hisp.dhis.analytics.AnalyticsService.OU_NAME_HIERARCHY_KEY;
 import static org.hisp.dhis.common.DimensionalObject.ORGUNIT_DIM_ID;
 import static org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID;
 import static org.hisp.dhis.common.DimensionalObjectUtils.DIMENSION_NAME_SEP;
@@ -40,6 +41,7 @@
 import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
 import static org.hisp.dhis.common.NameableObjectUtils.asTypedList;
 import static org.hisp.dhis.organisationunit.OrganisationUnit.getParentGraphMap;
+import static org.hisp.dhis.organisationunit.OrganisationUnit.getParentNameGraphMap;
 
 import java.util.Arrays;
 import java.util.Collection;
@@ -248,13 +250,18 @@
             metaData.put( ORGUNIT_DIM_ID, getUids( params.getDimensionOrFilter( ORGUNIT_DIM_ID ) ) );
 
             User user = currentUserService.getCurrentUser();
-            
+
+            List<OrganisationUnit> organisationUnits = asTypedList( params.getDimensionOrFilter( ORGUNIT_DIM_ID ), OrganisationUnit.class );
             Collection<OrganisationUnit> roots = user != null ? user.getOrganisationUnits() : null;
             
             if ( params.isHierarchyMeta() )
             {
-                metaData.put( OU_HIERARCHY_KEY, getParentGraphMap( asTypedList( 
-                    params.getDimensionOrFilter( ORGUNIT_DIM_ID ), OrganisationUnit.class ), roots ) );
+                metaData.put( OU_HIERARCHY_KEY, getParentGraphMap( organisationUnits, roots ) );
+            }
+
+            if ( params.isShowHierarchy() )
+            {
+                metaData.put( OU_NAME_HIERARCHY_KEY, getParentNameGraphMap( organisationUnits, roots, true, params.getDisplayProperty() ) );
             }
 
             grid.setMetaData( metaData );
@@ -362,7 +369,7 @@
     @Override
     public EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate,
         Set<String> dimension, Set<String> filter, String value, AggregationType aggregationType, boolean skipMeta, boolean skipRounding, boolean hierarchyMeta, 
-        SortOrder sortOrder, Integer limit, EventOutputType outputType, boolean collapseDataDimensions, DisplayProperty displayProperty, I18nFormat format )
+        boolean showHierarchy, SortOrder sortOrder, Integer limit, EventOutputType outputType, boolean collapseDataDimensions, DisplayProperty displayProperty, I18nFormat format )
     {
         EventQueryParams params = getFromUrl( program, stage, startDate, endDate, dimension, filter, null, null, null,
             skipMeta, hierarchyMeta, false, displayProperty, null, null, format );
@@ -370,6 +377,7 @@
         params.setValue( getValueDimension( value ) );
         params.setAggregationType( aggregationType );
         params.setSkipRounding( skipRounding );
+        params.setShowHierarchy( showHierarchy );
         params.setSortOrder( sortOrder );
         params.setLimit( limit );
         params.setOutputType( MoreObjects.firstNonNull( outputType, EventOutputType.EVENT ) );

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java	2015-03-27 14:15:16 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java	2015-03-30 15:14:47 +0000
@@ -181,7 +181,7 @@
         filterParams.add( "pe:201401;201402" );
         
         EventQueryParams params = analyticsService.getFromUrl( prA.getUid(), null, 
-            null, null, dimensionParams, filterParams, null, null, false, false, false, null, null, null, false, null, null );
+            null, null, dimensionParams, filterParams, null, null, false, false, false, false, null, null, null, false, null, null );
         
         assertEquals( prA, params.getProgram() );
         assertEquals( 1, params.getOrganisationUnits().size() );
@@ -200,7 +200,7 @@
         filterParams.add( "pe:201401" );
         
         EventQueryParams params = analyticsService.getFromUrl( prA.getUid(), null, 
-            null, null, dimensionParams, filterParams, deA.getUid(), AggregationType.AVERAGE, false, false, false, null, null, null, false, null, null );
+            null, null, dimensionParams, filterParams, deA.getUid(), AggregationType.AVERAGE, false, false, false, false, null, null, null, false, null, null );
         
         assertEquals( prA, params.getProgram() );
         assertEquals( 1, params.getOrganisationUnits().size() );
@@ -334,7 +334,7 @@
         filterParams.add( atA.getUid() + ":LE:5" );
         
         EventQueryParams params = analyticsService.getFromUrl( prA.getUid(), null, 
-            null, null, dimensionParams, filterParams, null, null, false, false, false, null, null, null, false, null, null );
+            null, null, dimensionParams, filterParams, null, null, false, false, false, false, null, null, null, false, null, null );
         
         assertEquals( prA, params.getProgram() );
         assertEquals( 1, params.getItems().size() );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/EventAnalyticsController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/EventAnalyticsController.java	2015-03-05 15:38:58 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/EventAnalyticsController.java	2015-03-30 15:14:47 +0000
@@ -90,6 +90,7 @@
         @RequestParam( required = false ) boolean skipMeta,
         @RequestParam( required = false ) boolean skipRounding,
         @RequestParam( required = false ) boolean hierarchyMeta,
+        @RequestParam( required = false ) boolean showHierarchy,
         @RequestParam( required = false ) Integer limit,
         @RequestParam( required = false ) EventOutputType outputType,
         @RequestParam( required = false ) boolean collapseDataDimensions,
@@ -99,7 +100,7 @@
         HttpServletResponse response ) throws Exception
     {
         EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter,
-            value, aggregationType, skipMeta, skipRounding, hierarchyMeta, sortOrder, limit, outputType, collapseDataDimensions, displayProperty, i18nManager.getI18nFormat() );
+            value, aggregationType, skipMeta, skipRounding, hierarchyMeta, showHierarchy, sortOrder, limit, outputType, collapseDataDimensions, displayProperty, i18nManager.getI18nFormat() );
 
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.RESPECT_SYSTEM_SETTING );
         Grid grid = analyticsService.getAggregatedEventData( params );
@@ -121,6 +122,7 @@
         @RequestParam( required = false ) boolean skipMeta,
         @RequestParam( required = false ) boolean skipRounding,
         @RequestParam( required = false ) boolean hierarchyMeta,
+        @RequestParam( required = false ) boolean showHierarchy,
         @RequestParam( required = false ) Integer limit,
         @RequestParam( required = false ) EventOutputType outputType,
         @RequestParam( required = false ) boolean collapseDataDimensions,
@@ -130,7 +132,7 @@
         HttpServletResponse response ) throws Exception
     {
         EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter,
-            value, aggregationType, skipMeta, skipRounding, hierarchyMeta, sortOrder, limit, outputType, collapseDataDimensions, displayProperty, i18nManager.getI18nFormat() );
+            value, aggregationType, skipMeta, skipRounding, hierarchyMeta, showHierarchy, sortOrder, limit, outputType, collapseDataDimensions, displayProperty, i18nManager.getI18nFormat() );
 
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.RESPECT_SYSTEM_SETTING, "events.xml", false );
         Grid grid = analyticsService.getAggregatedEventData( params );
@@ -150,6 +152,7 @@
         @RequestParam( required = false ) boolean skipMeta,
         @RequestParam( required = false ) boolean skipRounding,
         @RequestParam( required = false ) boolean hierarchyMeta,
+        @RequestParam( required = false ) boolean showHierarchy,
         @RequestParam( required = false ) Integer limit,
         @RequestParam( required = false ) EventOutputType outputType,
         @RequestParam( required = false ) boolean collapseDataDimensions,
@@ -159,7 +162,7 @@
         HttpServletResponse response ) throws Exception
     {
         EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter,
-            value, aggregationType, skipMeta, skipRounding, hierarchyMeta, sortOrder, limit, outputType, collapseDataDimensions, displayProperty, i18nManager.getI18nFormat() );
+            value, aggregationType, skipMeta, skipRounding, hierarchyMeta, showHierarchy, sortOrder, limit, outputType, collapseDataDimensions, displayProperty, i18nManager.getI18nFormat() );
 
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_EXCEL, CacheStrategy.RESPECT_SYSTEM_SETTING, "events.xls", true );
         Grid grid = analyticsService.getAggregatedEventData( params );
@@ -179,6 +182,7 @@
         @RequestParam( required = false ) boolean skipMeta,
         @RequestParam( required = false ) boolean skipRounding,
         @RequestParam( required = false ) boolean hierarchyMeta,
+        @RequestParam( required = false ) boolean showHierarchy,
         @RequestParam( required = false ) Integer limit,
         @RequestParam( required = false ) EventOutputType outputType,
         @RequestParam( required = false ) boolean collapseDataDimensions,
@@ -188,7 +192,7 @@
         HttpServletResponse response ) throws Exception
     {
         EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter,
-            value, aggregationType, skipMeta, skipRounding, hierarchyMeta, sortOrder, limit, outputType, collapseDataDimensions, displayProperty, i18nManager.getI18nFormat() );
+            value, aggregationType, skipMeta, skipRounding, hierarchyMeta, showHierarchy, sortOrder, limit, outputType, collapseDataDimensions, displayProperty, i18nManager.getI18nFormat() );
 
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_CSV, CacheStrategy.RESPECT_SYSTEM_SETTING, "events.csv", true );
         Grid grid = analyticsService.getAggregatedEventData( params );
@@ -208,6 +212,7 @@
         @RequestParam( required = false ) boolean skipMeta,
         @RequestParam( required = false ) boolean skipRounding,
         @RequestParam( required = false ) boolean hierarchyMeta,
+        @RequestParam( required = false ) boolean showHierarchy,
         @RequestParam( required = false ) Integer limit,
         @RequestParam( required = false ) EventOutputType outputType,
         @RequestParam( required = false ) boolean collapseDataDimensions,
@@ -217,7 +222,7 @@
         HttpServletResponse response ) throws Exception
     {
         EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter,
-            value, aggregationType, skipMeta, skipRounding, hierarchyMeta, sortOrder, limit, outputType, collapseDataDimensions, displayProperty, i18nManager.getI18nFormat() );
+            value, aggregationType, skipMeta, skipRounding, hierarchyMeta, showHierarchy, sortOrder, limit, outputType, collapseDataDimensions, displayProperty, i18nManager.getI18nFormat() );
 
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_HTML, CacheStrategy.RESPECT_SYSTEM_SETTING, "events.html", false );
         Grid grid = analyticsService.getAggregatedEventData( params );