← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11042: Analytics, removing category based dimensions when indicators/data set are present in query, not ...

 

------------------------------------------------------------
revno: 11042
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-05-28 11:19:19 +0200
message:
  Analytics, removing category based dimensions when indicators/data set are present in query, not allowed
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/CombinationGenerator.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.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-api/src/main/java/org/hisp/dhis/common/CombinationGenerator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/CombinationGenerator.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/CombinationGenerator.java	2013-05-28 09:19:19 +0000
@@ -118,7 +118,9 @@
         
         for ( int i = 0; i < no; i++ )
         {
-            current.add( objects[i][indexes[i]] );
+            int index = indexes[i];
+            
+            current.add( objects[i][index] );
         }
         
         return current;

=== 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	2013-05-27 19:46:30 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java	2013-05-28 09:19:19 +0000
@@ -49,6 +49,7 @@
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Map;
@@ -150,8 +151,8 @@
     
     /**
      * Ensures conformity for this query. The category option combo dimension
-     * can only be present if the data element dimension exists and the indicator
-     * and data set dimensions do not exist.
+     * and any category dimensions can only be present if the data element 
+     * dimension exists and the indicator and data set dimensions do not exist.
      */
     public DataQueryParams conform()
     {
@@ -160,6 +161,7 @@
             dimensions.contains( new BaseDimensionalObject( DATASET_DIM_ID ) ) )
         {
             removeDimension( CATEGORYOPTIONCOMBO_DIM_ID );
+            removeDimensions( DimensionType.CATEGORY );
         }
         
         return this;
@@ -318,6 +320,24 @@
         
         return this;
     }
+    
+    /**
+     * Removes dimensions of the given type.
+     */
+    public void removeDimensions( DimensionType type )
+    {
+        Iterator<DimensionalObject> iterator = dimensions.iterator();
+        
+        while ( iterator.hasNext() )
+        {
+            DimensionalObject dimension = iterator.next();
+            
+            if ( DimensionType.CATEGORY.equals( dimension.getType() ) )
+            {
+                iterator.remove();
+            }
+        }
+    }
 
     /**
      * Removes the filter with the given identifier.
@@ -542,7 +562,7 @@
                 dimensionOptions.add( options.toArray( DIM_OPT_ARR ) );
             }
         }
-                
+        
         CombinationGenerator<DimensionItem> generator = new CombinationGenerator<DimensionItem>( dimensionOptions.toArray( DIM_OPT_2D_ARR ) );
         
         List<List<DimensionItem>> permutations = generator.getCombinations();