← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12303: Event analytics, impl support for filters

 

------------------------------------------------------------
revno: 12303
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2013-09-29 19:43:01 +0200
message:
  Event analytics, impl support for filters
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/EventQueryParams.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-web/dhis-web-api/src/main/java/org/hisp/dhis/api/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	2013-09-28 15:06:20 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventAnalyticsService.java	2013-09-29 17:43:01 +0000
@@ -42,8 +42,8 @@
     Grid getEvents( EventQueryParams params );
 
     EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate, 
-        Set<String> dimension, String ouMode );
+        Set<String> dimension, Set<String> filter, String ouMode );
     
     EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate, 
-        Set<String> dimension, String ouMode, Set<String> asc, Set<String> desc, Integer page, Integer pageSize );
+        Set<String> dimension, Set<String> filter, String ouMode, Set<String> asc, Set<String> desc, Integer page, Integer pageSize );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java	2013-09-29 16:17:08 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java	2013-09-29 17:43:01 +0000
@@ -60,6 +60,8 @@
     private Date endDate;
     
     private List<QueryItem> items = new ArrayList<QueryItem>();
+    
+    private List<QueryItem> itemFilters = new ArrayList<QueryItem>();
 
     private List<String> asc = new ArrayList<String>();
     
@@ -104,6 +106,7 @@
         params.startDate = this.startDate;
         params.endDate = this.endDate;
         params.items = new ArrayList<QueryItem>( this.items );
+        params.itemFilters = new ArrayList<QueryItem>( this.itemFilters );
         params.asc = new ArrayList<String>( this.asc );
         params.desc = new ArrayList<String>( this.desc );
         params.organisationUnitMode = this.organisationUnitMode;
@@ -175,6 +178,7 @@
             "Start date: " + startDate + ", " +
             "End date: " + endDate + ", " +
             "Items " + items + ", " +
+            "Item filters: " + itemFilters + ", " +
             "Dimensions " + dimensions + "]";
     }
     
@@ -232,6 +236,16 @@
         this.items = items;
     }
 
+    public List<QueryItem> getItemFilters()
+    {
+        return itemFilters;
+    }
+
+    public void setItemFilters( List<QueryItem> itemFilters )
+    {
+        this.itemFilters = itemFilters;
+    }
+
     public List<String> getAsc()
     {
         return asc;

=== 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	2013-09-29 16:17:08 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java	2013-09-29 17:43:01 +0000
@@ -32,6 +32,7 @@
 import static org.hisp.dhis.common.DimensionalObject.ORGUNIT_DIM_ID;
 import static org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID;
 
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -118,7 +119,6 @@
 
     //TODO order the event analytics tables up front to avoid default sorting in queries
     //TODO filter items support
-    //TODO relative and fixed periods support
     
     public Grid getAggregatedEventData( EventQueryParams params )
     {
@@ -233,13 +233,13 @@
     }
 
     public EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate, 
-        Set<String> dimension, String ouMode )
+        Set<String> dimension, Set<String> filter, String ouMode )
     {
-        return getFromUrl( program, stage, startDate, endDate, dimension, ouMode, null, null, null, null );
+        return getFromUrl( program, stage, startDate, endDate, dimension, filter, ouMode, null, null, null, null );
     }
     
     public EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate, 
-        Set<String> dimension, String ouMode, Set<String> asc, Set<String> desc, Integer page, Integer pageSize )
+        Set<String> dimension, Set<String> filter, String ouMode, Set<String> asc, Set<String> desc, Integer page, Integer pageSize )
     {
         EventQueryParams params = new EventQueryParams();
         
@@ -273,29 +273,39 @@
             }
         }
         
-        for ( String it : dimension )
-        {
-            String dim = DataQueryParams.getDimensionFromParam( it );
-            
-            if ( ORGUNIT_DIM_ID.equals( dim ) || PERIOD_DIM_ID.equals( dim ) )
-            {
-                List<String> items = DataQueryParams.getDimensionItemsFromParam( it );
-                params.getDimensions().addAll( analyticsService.getDimension( dim, items, null, null ) );
-            }
-            else if ( !it.contains( DIMENSION_NAME_SEP ) )
-            {
-                params.getItems().add( getItem( pr, it, null, null ) );
-            }
-            else // Filter
-            {
-                String[] split = it.split( DIMENSION_NAME_SEP );
-                
-                if ( split == null || split.length != 3 )
-                {
-                    throw new IllegalQueryException( "Item filter has invalid format: " + it );
-                }
-                
-                params.getItems().add( getItem( pr, split[0], split[1], split[2] ) );
+        if ( dimension != null )
+        {
+            for ( String dim : dimension )
+            {
+                String dimensionId = DataQueryParams.getDimensionFromParam( dim );
+                
+                if ( ORGUNIT_DIM_ID.equals( dimensionId ) || PERIOD_DIM_ID.equals( dimensionId ) )
+                {
+                    List<String> items = DataQueryParams.getDimensionItemsFromParam( dim );
+                    params.getDimensions().addAll( analyticsService.getDimension( dimensionId, items, null, null ) );
+                }
+                else
+                {
+                    params.getItems().addAll( getQueryItems( dim, pr ) );
+                }
+            }
+        }
+        
+        if ( filter != null )
+        {
+            for ( String dim : filter )
+            {
+                String dimensionId = DataQueryParams.getDimensionFromParam( dim );
+                
+                if ( ORGUNIT_DIM_ID.equals( dimensionId ) || PERIOD_DIM_ID.equals( dimensionId ) )
+                {
+                    List<String> items = DataQueryParams.getDimensionItemsFromParam( dim );
+                    params.getFilters().addAll( analyticsService.getDimension( dimensionId, items, null, null ) );
+                }
+                else
+                {
+                    params.getItemFilters().addAll( getQueryItems( dim, pr ) );
+                }            
             }
         }
         
@@ -355,6 +365,29 @@
     // Supportive methods
     // -------------------------------------------------------------------------
     
+    private List<QueryItem> getQueryItems( String dimension, Program program )
+    {
+        List<QueryItem> items = new ArrayList<QueryItem>();
+        
+        if ( !dimension.contains( DIMENSION_NAME_SEP ) )
+        {
+            items.add( getItem( program, dimension, null, null ) );
+        }
+        else // Filter
+        {
+            String[] split = dimension.split( DIMENSION_NAME_SEP );
+            
+            if ( split == null || split.length != 3 )
+            {
+                throw new IllegalQueryException( "Item filter has invalid format: " + dimension );
+            }
+            
+            items.add( getItem( program, split[0], split[1], split[2] ) );
+        }
+        
+        return items;
+    }
+    
     private Map<String, String> getUidNameMap( EventQueryParams params )
     {
         Map<String, String> map = new HashMap<String, String>();

=== 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	2013-09-29 16:17:08 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java	2013-09-29 17:43:01 +0000
@@ -273,6 +273,14 @@
                 sql += "and lower(" + filter.getItem().getUid() + ") " + filter.getSqlOperator() + " " + getSqlFilter( filter ) + " ";
             }
         }
+        
+        for ( QueryItem filter : params.getItemFilters() )
+        {
+            if ( filter.hasFilter() )
+            {                
+                sql += "and lower(" + filter.getItem().getUid() + ") " + filter.getSqlOperator() + " " + getSqlFilter( filter ) + " ";
+            }
+        }
 
         return sql;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/EventAnalyticsController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/EventAnalyticsController.java	2013-09-28 16:27:09 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/EventAnalyticsController.java	2013-09-29 17:43:01 +0000
@@ -73,11 +73,12 @@
         @RequestParam(required=false) String startDate,
         @RequestParam(required=false) String endDate,
         @RequestParam Set<String> dimension,
+        @RequestParam(required=false) Set<String> filter,
         @RequestParam(required=false) String ouMode,
         Model model,
         HttpServletResponse response ) throws Exception
     {
-        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, ouMode );
+        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, ouMode );
         
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.RESPECT_SYSTEM_SETTING );
         Grid grid = analyticsService.getAggregatedEventData( params );
@@ -93,11 +94,12 @@
         @RequestParam(required=false) String startDate,
         @RequestParam(required=false) String endDate,
         @RequestParam Set<String> dimension,
+        @RequestParam(required=false) Set<String> filter,
         @RequestParam(required=false) String ouMode,
         Model model,
         HttpServletResponse response ) throws Exception
     {
-        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, ouMode );
+        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, ouMode );
         
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_EXCEL, CacheStrategy.RESPECT_SYSTEM_SETTING, "events.xls", true );
         Grid grid = analyticsService.getAggregatedEventData( params );
@@ -115,6 +117,7 @@
         @RequestParam(required=false) String startDate,
         @RequestParam(required=false) String endDate,
         @RequestParam Set<String> dimension,
+        @RequestParam(required=false) Set<String> filter,
         @RequestParam(required=false) String ouMode,
         @RequestParam(required=false) Set<String> asc,
         @RequestParam(required=false) Set<String> desc,
@@ -123,7 +126,7 @@
         Model model,
         HttpServletResponse response ) throws Exception
     {
-        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, ouMode, asc, desc, page, pageSize );
+        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, ouMode, asc, desc, page, pageSize );
         
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.RESPECT_SYSTEM_SETTING );
         Grid grid = analyticsService.getEvents( params );
@@ -139,6 +142,7 @@
         @RequestParam(required=false) String startDate,
         @RequestParam(required=false) String endDate,
         @RequestParam Set<String> dimension,
+        @RequestParam(required=false) Set<String> filter,
         @RequestParam(required=false) String ouMode,
         @RequestParam(required=false) Set<String> asc,
         @RequestParam(required=false) Set<String> desc,
@@ -147,7 +151,7 @@
         Model model,
         HttpServletResponse response ) throws Exception
     {
-        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, ouMode, asc, desc, page, pageSize );
+        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter, ouMode, asc, desc, page, pageSize );
         
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_EXCEL, CacheStrategy.RESPECT_SYSTEM_SETTING, "events.xls", true );
         Grid grid = analyticsService.getEvents( params );