← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9638: Analytics, one can now omit any dimension options for a dimension in order to use all options

 

------------------------------------------------------------
revno: 9638
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-01-28 12:55:48 +0200
message:
  Analytics, one can now omit any dimension options for a dimension in order to use all options
modified:
  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/Dimension.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.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/DataQueryParams.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java	2013-01-27 21:03:02 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java	2013-01-28 10:55:48 +0000
@@ -446,19 +446,41 @@
     // Static methods
     // -------------------------------------------------------------------------
 
+    /**
+     * Retrieves the dimension name from the given string. Returns the part of
+     * the string preceding the dimension name separator, or the whole string if
+     * the separator is not present.
+     */
     public static String getDimensionFromParam( String param )
     {
-        return param != null && param.split( DIMENSION_NAME_SEP ).length > 0 ? param.split( DIMENSION_NAME_SEP )[0] : null;
+        if ( param == null )
+        {
+            return null;
+        }
+        
+        return param.split( DIMENSION_NAME_SEP ).length > 0 ? param.split( DIMENSION_NAME_SEP )[0] : param;
     }
     
+    /**
+     * Retrieves the dimension options from the given string. Looks for the part
+     * succeeding the dimension name separator, if exists, splits the string part
+     * on the option separator and returns the resulting values. If the dimension
+     * name separator does not exist an empty list is returned, indicating that
+     * all dimension options should be used.
+     */
     public static List<String> getDimensionOptionsFromParam( String param )
     {
-        if ( param != null && param.split( DIMENSION_NAME_SEP ).length > 0 )
+        if ( param == null )
+        {
+            return null;
+        }
+        
+        if ( param.split( DIMENSION_NAME_SEP ).length > 1 )
         {
             return Arrays.asList( param.split( DIMENSION_NAME_SEP )[1].split( OPTION_SEP ) );
         }
         
-        return null;
+        return new ArrayList<String>();
     }
     
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/Dimension.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/Dimension.java	2013-01-22 07:59:25 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/Dimension.java	2013-01-28 10:55:48 +0000
@@ -41,6 +41,10 @@
     private String dimensionName;
 
     private List<IdentifiableObject> options = new ArrayList<IdentifiableObject>();
+
+    // -------------------------------------------------------------------------
+    // Constructors
+    // -------------------------------------------------------------------------
     
     public Dimension( String dimension )
     {
@@ -53,6 +57,23 @@
         this.type = type;
         this.options = options;
     }
+
+    // -------------------------------------------------------------------------
+    // Logic
+    // -------------------------------------------------------------------------
+    
+    /**
+     * Indicates whether this dimension should use all dimension options. All
+     * dimension options is represented as an option list of zero elements.
+     */
+    public boolean isAllOptions()
+    {
+        return options != null && options.isEmpty();
+    }
+    
+    // -------------------------------------------------------------------------
+    // Get and set methods
+    // -------------------------------------------------------------------------
     
     public String getDimension()
     {
@@ -94,6 +115,10 @@
         this.options = options;
     }
 
+    // -------------------------------------------------------------------------
+    // hashCode, equals, toString
+    // -------------------------------------------------------------------------
+    
     @Override
     public int hashCode()
     {

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java	2013-01-27 14:43:24 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java	2013-01-28 10:55:48 +0000
@@ -121,12 +121,18 @@
         
         for ( Dimension dim : queryDimensions )
         {
-            sql += sqlHelper.whereAnd() + " " + dim.getDimensionName() + " in (" + getQuotedCommaDelimitedString( getUids( dim.getOptions() ) ) + " ) ";
+            if ( !dim.isAllOptions() )
+            {
+                sql += sqlHelper.whereAnd() + " " + dim.getDimensionName() + " in (" + getQuotedCommaDelimitedString( getUids( dim.getOptions() ) ) + " ) ";
+            }
         }
 
         for ( Dimension filter : params.getFilters() )
         {
-            sql += sqlHelper.whereAnd() + " " + filter.getDimensionName() + " in (" + getQuotedCommaDelimitedString( getUids( filter.getOptions() ) ) + " ) ";
+            if ( !filter.isAllOptions() )
+            {
+                sql += sqlHelper.whereAnd() + " " + filter.getDimensionName() + " in (" + getQuotedCommaDelimitedString( getUids( filter.getOptions() ) ) + " ) ";
+            }
         }
         
         sql += "group by " + getCommaDelimitedString( selectDimensions );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java	2013-01-27 21:03:02 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java	2013-01-28 10:55:48 +0000
@@ -183,12 +183,6 @@
             return false;
         }
         
-        if ( params.getEmptyDimension() != null )
-        {
-            ContextUtils.conflictResponse( response, "Dimensions or filters must have at least one option: " + params.getEmptyDimension() );
-            return false;
-        }
-        
         return true;        
     }
 }