← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11749: Event analytics, paging

 

------------------------------------------------------------
revno: 11749
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-08-22 17:05:17 +0200
message:
  Event analytics, paging
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-08-22 07:53:43 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventAnalyticsService.java	2013-08-22 15:05:17 +0000
@@ -38,5 +38,5 @@
 {
     Grid getEvents( EventQueryParams params );
 
-    EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate, String ou, Set<String> item );
+    EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate, String ou, Set<String> item, 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-08-21 18:09:08 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java	2013-08-22 15:05:17 +0000
@@ -53,6 +53,10 @@
     private List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>();
     
     private String tableName;
+    
+    private Integer page;
+    
+    private Integer pageSize;
 
     // -------------------------------------------------------------------------
     // Constructors
@@ -71,6 +75,8 @@
         this.items = new ArrayList<QueryItem>( params.getItems() );
         this.organisationUnits = new ArrayList<OrganisationUnit>( params.getOrganisationUnits() );
         this.tableName = params.getTableName();
+        this.page = params.getPage();
+        this.pageSize = params.getPageSize();
     }
 
     // -------------------------------------------------------------------------
@@ -82,6 +88,16 @@
         return organisationUnits != null && !organisationUnits.isEmpty();
     }
     
+    public int getPageSizeWithDefault()
+    {
+        return pageSize != null && page > 0 ? pageSize : 50;
+    }
+    
+    public int getOffset()
+    {
+        return page != null && page > 0 ? ( ( page - 1 ) * getPageSizeWithDefault() ) : 0;
+    }
+    
     // -------------------------------------------------------------------------
     // Getters and setters
     // -------------------------------------------------------------------------
@@ -155,4 +171,24 @@
     {
         this.tableName = tableName;
     }
+
+    public Integer getPage()
+    {
+        return page;
+    }
+
+    public void setPage( Integer page )
+    {
+        this.page = page;
+    }
+
+    public Integer getPageSize()
+    {
+        return pageSize;
+    }
+
+    public void setPageSize( Integer pageSize )
+    {
+        this.pageSize = pageSize;
+    }
 }

=== 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-08-22 14:33:21 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java	2013-08-22 15:05:17 +0000
@@ -118,7 +118,7 @@
         return grid;
     }
     
-    public EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate, String ou, Set<String> item )
+    public EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate, String ou, Set<String> item, Integer page, Integer pageSize )
     {
         EventQueryParams params = new EventQueryParams();
         
@@ -196,10 +196,26 @@
             }
         }
         
+        if ( page != null && page <= 0 )
+        {
+            throw new IllegalQueryException( "Page must be positive: " + page );
+        }
+        
+        if ( pageSize != null && pageSize < 0 )
+        {
+            throw new IllegalQueryException( "Page size must be zero or positive: " + pageSize );
+        }
+        
         params.setProgram( pr );
         params.setProgramStage( ps );
         params.setStartDate( start );
         params.setEndDate( end );
+        params.setPage( page );
+        
+        if ( pageSize != null )
+        {
+            params.setPageSize( pageSize );
+        }
         
         return params;
     }

=== 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-08-22 12:09:00 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java	2013-08-22 15:05:17 +0000
@@ -58,7 +58,11 @@
     public Grid getEvents( EventQueryParams params, Grid grid )
     {
         String sql = "select psi,ps,executiondate,ou,";
-        
+
+        // ---------------------------------------------------------------------
+        // Items
+        // ---------------------------------------------------------------------
+
         for ( QueryItem queryItem : params.getItems() )
         {
             IdentifiableObject item = queryItem.getItem();
@@ -81,7 +85,11 @@
         {
             sql += "and ps = '" + params.getProgramStage().getUid() + "' ";
         }
-        
+
+        // ---------------------------------------------------------------------
+        // Filters
+        // ---------------------------------------------------------------------
+
         for ( QueryItem filter : params.getItems() )
         {
             if ( filter.hasFilter() )
@@ -90,6 +98,23 @@
             }
         }
 
+        // ---------------------------------------------------------------------
+        // Paging
+        // ---------------------------------------------------------------------
+
+        if ( params.getPage() != null )
+        {
+            sql += "limit " + params.getPageSizeWithDefault() + " offset " + params.getOffset();
+        }
+        else if ( params.getPageSize() != null )
+        {
+            sql += "limit " + params.getPageSizeWithDefault();
+        }
+
+        // ---------------------------------------------------------------------
+        // Grid
+        // ---------------------------------------------------------------------
+
         int rowLength = grid.getHeaders().size();
 
         Timer t = new Timer().start();

=== 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-08-22 14:33:21 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/EventAnalyticsController.java	2013-08-22 15:05:17 +0000
@@ -69,10 +69,12 @@
         @RequestParam String endDate,
         @RequestParam(required=false) String ou,
         @RequestParam Set<String> item,
+        @RequestParam(required=false) Integer page,
+        @RequestParam(required=false) Integer pageSize,
         Model model,
         HttpServletResponse response ) throws Exception
     {
-        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, ou, item );
+        EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, ou, item, page, pageSize );
         
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.RESPECT_SYSTEM_SETTING );
         Grid grid = analyticsService.getEvents( params );