← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15933: Impl support for organisation unit group sets in event analytics

 

------------------------------------------------------------
revno: 15933
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-07-02 13:08:10 +0200
message:
  Impl support for organisation unit group sets in event analytics
modified:
  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/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/JdbcEventAnalyticsManager.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/jdbc/AnalyticsDataSetReportStore.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/AnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsService.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsService.java	2014-07-02 11:08:10 +0000
@@ -185,8 +185,10 @@
      * @param dimension the dimension identifier.
      * @param items the dimension items.
      * @param relativePeriodDate the date to use for generating relative periods, can be null.
-     * @parma format the I18nFormat, can be null.
+     * @param format the I18nFormat, can be null.
+     * @param allowNull return null if no dimension was found.
+     * @throws IllegalQueryException if no dimensions was found.
      * @return list of DimensionalObjects.
      */
-    List<DimensionalObject> getDimension( String dimension, List<String> items, Date relativePeriodDate, I18nFormat format );
+    List<DimensionalObject> getDimension( String dimension, List<String> items, Date relativePeriodDate, I18nFormat format, boolean allowNull );
 }

=== 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	2014-05-18 00:49:40 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java	2014-07-02 11:08:10 +0000
@@ -255,8 +255,8 @@
     }
         
     /**
-     * Creates a mapping between dimension identifiers and filter dimensions. Filters 
-     * are guaranteed not to be null.
+     * Creates a mapping between filter dimension identifiers and filter dimensions. 
+     * Filters are guaranteed not to be null.
      */
     public ListMap<String, DimensionalObject> getDimensionFilterMap()
     {
@@ -871,6 +871,38 @@
     }
     
     /**
+     * Returns a list of dimensions and filters in the mentioned, preserved order.
+     */
+    public List<DimensionalObject> getDimensionsAndFilters()
+    {
+        List<DimensionalObject> list = new ArrayList<DimensionalObject>();
+        list.addAll( dimensions );
+        list.addAll( filters );
+        return list;
+    }
+    
+    /**
+     * Returns a list of dimensions and filters of the given dimension type.
+     */
+    public List<DimensionalObject> getDimensionsAndFilters( DimensionType dimensionType )
+    {
+        List<DimensionalObject> list = new ArrayList<DimensionalObject>();
+        
+        if ( dimensionType != null )
+        {
+            for ( DimensionalObject dimension : getDimensionsAndFilters() )
+            {
+                if ( dimension.getDimensionType().equals( dimensionType ) )
+                {
+                    list.add( dimension );
+                }
+            }
+        }
+        
+        return list;
+    }
+    
+    /**
      * Indicates whether this params specifies data approval levels.
      */
     public boolean isDataApproval()

=== 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	2014-06-24 08:47:50 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2014-07-02 11:08:10 +0000
@@ -709,7 +709,7 @@
                 
                 if ( dimension != null && options != null )
                 {
-                    params.getDimensions().addAll( getDimension( dimension, options, null, format ) );
+                    params.getDimensions().addAll( getDimension( dimension, options, null, format, false ) );
                 }
             }
         }
@@ -723,7 +723,7 @@
                 
                 if ( dimension != null && options != null )
                 {
-                    params.getFilters().addAll( getDimension( dimension, options, null, format ) );
+                    params.getFilters().addAll( getDimension( dimension, options, null, format, false ) );
                 }
             }
         }
@@ -755,17 +755,17 @@
             
             for ( DimensionalObject column : object.getColumns() )
             {
-                params.getDimensions().addAll( getDimension( toDimension( column.getDimension() ), getUids( column.getItems() ), date, format ) );
+                params.getDimensions().addAll( getDimension( toDimension( column.getDimension() ), getUids( column.getItems() ), date, format, false ) );
             }
             
             for ( DimensionalObject row : object.getRows() )
             {
-                params.getDimensions().addAll( getDimension( toDimension( row.getDimension() ), getUids( row.getItems() ), date, format ) );
+                params.getDimensions().addAll( getDimension( toDimension( row.getDimension() ), getUids( row.getItems() ), date, format, false ) );
             }
             
             for ( DimensionalObject filter : object.getFilters() )
             {
-                params.getFilters().addAll( getDimension( toDimension( filter.getDimension() ), getUids( filter.getItems() ), date, format ) );
+                params.getFilters().addAll( getDimension( toDimension( filter.getDimension() ), getUids( filter.getItems() ), date, format, false ) );
             }
         }
         
@@ -774,7 +774,7 @@
     
     // TODO verify that current user can read each dimension and dimension item
     
-    public List<DimensionalObject> getDimension( String dimension, List<String> items, Date relativePeriodDate, I18nFormat format )
+    public List<DimensionalObject> getDimension( String dimension, List<String> items, Date relativePeriodDate, I18nFormat format, boolean allowNull )
     {        
         if ( DATA_X_DIM_ID.equals( dimension ) )
         {
@@ -1037,6 +1037,11 @@
             return ListUtils.getList( object );
         }
         
+        if ( allowNull )
+        {
+            return null;
+        }
+        
         throw new IllegalQueryException( "Dimension identifier does not reference any dimension: " + dimension );
     }
 

=== 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	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/MockAnalyticsService.java	2014-07-02 11:08:10 +0000
@@ -94,7 +94,7 @@
 
     @Override
     public List<DimensionalObject> getDimension( String dimension, List<String> items, Date relativePeriodDate,
-        I18nFormat format )
+        I18nFormat format, boolean allowNull )
     {
         throw new NotImplementedException();
     }

=== 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	2014-06-27 10:12:09 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java	2014-07-02 11:08:10 +0000
@@ -352,11 +352,12 @@
             for ( String dim : dimension )
             {
                 String dimensionId = DimensionalObjectUtils.getDimensionFromParam( dim );
-
-                if ( ORGUNIT_DIM_ID.equals( dimensionId ) || PERIOD_DIM_ID.equals( dimensionId ) )
+                List<String> items = DimensionalObjectUtils.getDimensionItemsFromParam( dim );                
+                List<DimensionalObject> dimObj = analyticsService.getDimension( dimensionId, items, date, format, true );
+                
+                if ( dimObj != null )
                 {
-                    List<String> items = DimensionalObjectUtils.getDimensionItemsFromParam( dim );
-                    params.getDimensions().addAll( analyticsService.getDimension( dimensionId, items, date, format ) );
+                    params.getDimensions().addAll( dimObj );
                 }
                 else
                 {
@@ -370,11 +371,12 @@
             for ( String dim : filter )
             {
                 String dimensionId = DimensionalObjectUtils.getDimensionFromParam( dim );
-
-                if ( ORGUNIT_DIM_ID.equals( dimensionId ) || PERIOD_DIM_ID.equals( dimensionId ) )
+                List<String> items = DimensionalObjectUtils.getDimensionItemsFromParam( dim );                
+                List<DimensionalObject> dimObj = analyticsService.getDimension( dimensionId, items, date, format, true );
+                
+                if ( dimObj != null )
                 {
-                    List<String> items = DimensionalObjectUtils.getDimensionItemsFromParam( dim );
-                    params.getFilters().addAll( analyticsService.getDimension( dimensionId, items, date, format ) );
+                    params.getFilters().addAll( dimObj );
                 }
                 else
                 {

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java	2014-05-10 11:18:29 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java	2014-07-02 11:08:10 +0000
@@ -46,6 +46,7 @@
 import org.hisp.dhis.analytics.event.EventAnalyticsManager;
 import org.hisp.dhis.analytics.event.EventAnalyticsService;
 import org.hisp.dhis.analytics.event.EventQueryParams;
+import org.hisp.dhis.common.DimensionType;
 import org.hisp.dhis.common.DimensionalObject;
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.common.IdentifiableObject;
@@ -304,7 +305,7 @@
         
         return count;
     }
-        
+    
     // -------------------------------------------------------------------------
     // Supportive methods
     // -------------------------------------------------------------------------
@@ -353,7 +354,11 @@
     private String getFromWhereClause( EventQueryParams params, String partition )
     {
         String sql = "from " + partition + " ";
-        
+
+        // ---------------------------------------------------------------------
+        // Periods
+        // ---------------------------------------------------------------------
+
         if ( params.hasStartEndDate() )
         {        
             sql += "where executiondate >= '" + getMediumDateString( params.getStartDate() ) + "' ";
@@ -363,7 +368,11 @@
         {
             sql += "where " + params.getPeriodType() + " in (" + getQuotedCommaDelimitedString( getUids( params.getDimensionOrFilter( PERIOD_DIM_ID ) ) ) + ") ";
         }
-        
+
+        // ---------------------------------------------------------------------
+        // Organisation units
+        // ---------------------------------------------------------------------
+
         if ( params.isOrganisationUnitMode( DimensionalObject.OU_MODE_SELECTED ) )
         {
             sql += "and ou in (" + getQuotedCommaDelimitedString( getUids( params.getDimensionOrFilter( ORGUNIT_DIM_ID ) ) ) + ") ";
@@ -384,12 +393,34 @@
             
             sql = removeLastOr( sql ) + ") ";
         }
-        
+
+        // ---------------------------------------------------------------------
+        // Organisation unit group sets
+        // ---------------------------------------------------------------------
+
+        for ( DimensionalObject dim : params.getDimensionsAndFilters( DimensionType.ORGANISATIONUNIT_GROUPSET ) )
+        {
+            if ( !dim.isAllItems() )
+            {
+                String col = statementBuilder.columnQuote( dim.getDimensionName() );
+                
+                sql += "and " + col + " in (" + getQuotedCommaDelimitedString( getUids( dim.getItems() ) ) + ") ";
+            }
+        }
+
+        // ---------------------------------------------------------------------
+        // Program stage
+        // ---------------------------------------------------------------------
+
         if ( params.getProgramStage() != null )
         {
             sql += "and ps = '" + params.getProgramStage().getUid() + "' ";
         }
 
+        // ---------------------------------------------------------------------
+        // Query items and filters
+        // ---------------------------------------------------------------------
+
         for ( QueryItem item : params.getItems() )
         {
             if ( item.hasFilter() )

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/jdbc/AnalyticsDataSetReportStore.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/jdbc/AnalyticsDataSetReportStore.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/jdbc/AnalyticsDataSetReportStore.java	2014-07-02 11:08:10 +0000
@@ -90,7 +90,7 @@
         {
             for ( String dim : dimensions.keySet() )
             {
-                params.setFilters( analyticsService.getDimension( dim, getList( dimensions.get( dim ) ), null, null ) );
+                params.setFilters( analyticsService.getDimension( dim, getList( dimensions.get( dim ) ), null, null, false ) );
             }
         }
         
@@ -142,7 +142,7 @@
                 {
                     for ( String dim : dimensions.keySet() )
                     {
-                        params.setFilters( analyticsService.getDimension( dim, getList( dimensions.get( dim ) ), null, null ) );
+                        params.setFilters( analyticsService.getDimension( dim, getList( dimensions.get( dim ) ), null, null, false ) );
                     }
                 }
                 
@@ -181,7 +181,7 @@
         {
             for ( String dim : dimensions.keySet() )
             {
-                params.setFilters( analyticsService.getDimension( dim, getList( dimensions.get( dim ) ), null, null ) );
+                params.setFilters( analyticsService.getDimension( dim, getList( dimensions.get( dim ) ), null, null, false ) );
             }
         }
         
@@ -218,7 +218,7 @@
         {
             for ( String dim : dimensions.keySet() )
             {
-                params.setFilters( analyticsService.getDimension( dim, getList( dimensions.get( dim ) ), null, null ) );
+                params.setFilters( analyticsService.getDimension( dim, getList( dimensions.get( dim ) ), null, null, false ) );
             }
         }