← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12301: Event analytics, reusing method

 

------------------------------------------------------------
revno: 12301
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2013-09-29 18:26:26 +0200
message:
  Event analytics, reusing method
modified:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/QueryPlanner.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.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/QueryPlanner.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/QueryPlanner.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/QueryPlanner.java	2013-09-29 16:26:26 +0000
@@ -83,4 +83,13 @@
      */
     DataQueryGroups planQuery( DataQueryParams params, int optimalQueries, String tableName )
         throws IllegalQueryException;
+
+    /**
+     * If organisation units appear as dimensions; groups the given query into 
+     * sub queries based on the level of the organisation units. Sets the organisation 
+     * unit level on each query. If organisation units appear as filter; replaces
+     * the organisation unit filter with one filter for each level. Sets the dimension
+     * names and filter names respectively.
+     */
+    List<DataQueryParams> groupByOrgUnitLevel( DataQueryParams params );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java	2013-09-29 15:24:12 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java	2013-09-29 16:26:26 +0000
@@ -434,14 +434,7 @@
         return queries;        
     }
     
-    /**
-     * If organisation units appear as dimensions; groups the given query into 
-     * sub queries based on the level of the organisation units. Sets the organisation 
-     * unit level on each query. If organisation units appear as filter; replaces
-     * the organisation unit filter with one filter for each level. Sets the dimension
-     * names and filter names respectively.
-     */
-    private List<DataQueryParams> groupByOrgUnitLevel( DataQueryParams params )
+    public List<DataQueryParams> groupByOrgUnitLevel( DataQueryParams params )
     {
         List<DataQueryParams> queries = new ArrayList<DataQueryParams>();
 

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java	2013-09-29 16:17:08 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java	2013-09-29 16:26:26 +0000
@@ -34,13 +34,11 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.analytics.DataQueryParams;
 import org.hisp.dhis.analytics.IllegalQueryException;
 import org.hisp.dhis.analytics.QueryPlanner;
 import org.hisp.dhis.analytics.event.EventQueryParams;
 import org.hisp.dhis.analytics.event.EventQueryPlanner;
-import org.hisp.dhis.common.ListMap;
-import org.hisp.dhis.common.NameableObject;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Cal;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.program.Program;
@@ -103,7 +101,7 @@
         
         for ( EventQueryParams byPartition : groupedByPartition )
         {
-            queries.addAll( groupByOrgUnitLevel( byPartition ) );
+            queries.addAll( convert( queryPlanner.groupByOrgUnitLevel( byPartition ) ) );
         }
         
         return queries;
@@ -157,28 +155,6 @@
         return list;
     }
     
-    private List<EventQueryParams> groupByOrgUnitLevel( EventQueryParams params )
-    {
-        ListMap<Integer, OrganisationUnit> levelOrgUnitMap = new ListMap<Integer, OrganisationUnit>();
-        
-        for ( NameableObject object : params.getOrganisationUnits() )
-        {
-            OrganisationUnit unit = (OrganisationUnit) object;
-            levelOrgUnitMap.putValue( unit.getLevel(), unit );
-        }
-        
-        List<EventQueryParams> queries = new ArrayList<EventQueryParams>();
-        
-        for ( Integer level : levelOrgUnitMap.keySet() )
-        {
-            EventQueryParams query = params.instance();
-            query.setOrganisationUnits( levelOrgUnitMap.get( level ) );
-            queries.add( query );
-        }
-        
-        return queries;
-    }
-    
     private static EventQueryParams getQuery( EventQueryParams params, Date startDate, Date endDate, Program program )
     {
         EventQueryParams query = params.instance();
@@ -197,4 +173,16 @@
     {
         return new Cal( year( date ), 12, 31 ).time();
     }
+
+    private static List<EventQueryParams> convert( List<DataQueryParams> params )
+    {
+        List<EventQueryParams> eventParams = new ArrayList<EventQueryParams>();
+        
+        for ( DataQueryParams param : params )
+        {
+            eventParams.add( (EventQueryParams) param );
+        }
+        
+        return eventParams;
+    }    
 }