← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14927: Event analytics, validation

 

------------------------------------------------------------
revno: 14927
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-04-21 16:52:46 +0200
message:
  Event analytics, validation
modified:
  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/DefaultEventQueryPlanner.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.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/EventQueryParams.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java	2014-04-20 20:56:55 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java	2014-04-21 14:52:46 +0000
@@ -40,7 +40,6 @@
 import org.hisp.dhis.analytics.Partitions;
 import org.hisp.dhis.analytics.SortOrder;
 import org.hisp.dhis.common.DimensionalObject;
-import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.common.NameableObject;
 import org.hisp.dhis.common.NameableObjectUtils;
 import org.hisp.dhis.common.QueryItem;
@@ -135,25 +134,6 @@
     // -------------------------------------------------------------------------
     // Logic
     // -------------------------------------------------------------------------
-
-    /**
-     * Returns a list of query items with distinct items / identifiable objects.
-     */
-    public List<QueryItem> getUniqueItems()
-    {
-        Set<IdentifiableObject> existingObjects = new HashSet<IdentifiableObject>();        
-        List<QueryItem> uniqueItems = new ArrayList<QueryItem>();
-        
-        for ( QueryItem item : items )
-        {
-            if ( existingObjects.add( item.getItem() ) )
-            {
-                uniqueItems.add( item );
-            }
-        }
-        
-        return uniqueItems;
-    }
     
     /**
      * Replaces periods with start and end dates, using the earliest start date
@@ -182,6 +162,25 @@
         
         removeDimensionOrFilter( PERIOD_DIM_ID );
     }
+
+    /**
+     * Returns a list of query items which occur more than once.
+     */
+    public List<QueryItem> getDuplicateQueryItems()
+    {
+        Set<QueryItem> dims = new HashSet<QueryItem>();
+        List<QueryItem> duplicates = new ArrayList<QueryItem>();
+        
+        for ( QueryItem dim : items )
+        {
+            if ( !dims.add( dim ) )
+            {
+                duplicates.add( dim );
+            }
+        }
+        
+        return duplicates;
+    }
     
     public boolean isOrganisationUnitMode( String mode )
     {

=== 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-04-21 11:05:22 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java	2014-04-21 14:52:46 +0000
@@ -147,7 +147,7 @@
             grid.addHeader( new GridHeader( dimension.getDimension(), dimension.getDisplayName(), String.class.getName(), false, true ) );
         }
 
-        for ( QueryItem item : params.getUniqueItems() )
+        for ( QueryItem item : params.getItems() )
         {
             grid.addHeader( new GridHeader( item.getItem().getUid(), item.getItem().getName(), item.getTypeAsString(), false, true ) );
         }
@@ -223,7 +223,7 @@
             grid.addHeader( new GridHeader( dimension.getDimension(), dimension.getDisplayName(), String.class.getName(), false, true ) );
         }
 
-        for ( QueryItem item : params.getUniqueItems() )
+        for ( QueryItem item : params.getItems() )
         {
             grid.addHeader( new GridHeader( item.getItem().getUid(), item.getItem().getName(), item.getTypeAsString() ) );
         }
@@ -403,7 +403,7 @@
         params.setPage( page );
         params.setPageSize( pageSize );
         params.setAggregate( false );
-
+        
         return params;
     }
 

=== 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	2014-04-19 10:55:51 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java	2014-04-21 14:52:46 +0000
@@ -91,6 +91,16 @@
         {
             violation = "At least one organisation unit must be specified";
         }
+
+        if ( !params.getDuplicateDimensions().isEmpty() )
+        {
+            violation = "Dimensions cannot be specified more than once: " + params.getDuplicateDimensions();
+        }
+        
+        if ( !params.getDuplicateQueryItems().isEmpty() )
+        {
+            violation = "Query items cannot be specified more than once: " + params.getDuplicateQueryItems();
+        }
         
         if ( !params.hasPeriods() && ( params.getStartDate() == null || params.getEndDate() == null ) )
         {

=== 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-04-21 11:05:22 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java	2014-04-21 14:52:46 +0000
@@ -163,7 +163,7 @@
                 grid.addValue( dimensionValue );
             }
             
-            for ( QueryItem queryItem : params.getUniqueItems() )
+            for ( QueryItem queryItem : params.getItems() )
             {
                 String itemValue = rowSet.getString( queryItem.getItem().getUid() );                
                 grid.addValue( itemValue );
@@ -313,7 +313,7 @@
             sql += statementBuilder.columnQuote( dimension.getDimensionName() ) + ",";
         }
                 
-        for ( QueryItem queryItem : params.getUniqueItems() )
+        for ( QueryItem queryItem : params.getItems() )
         {
             IdentifiableObject item = queryItem.getItem();