← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16138: Analytics, moved AggregationType enum to api, using value of enum instead of multiple if tests

 

------------------------------------------------------------
revno: 16138
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-07-15 20:16:29 +0200
message:
  Analytics, moved AggregationType enum to api, using value of enum instead of multiple if tests
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/analytics/
renamed:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AggregationType.java => dhis-2/dhis-api/src/main/java/org/hisp/dhis/analytics/AggregationType.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/analytics/AggregationType.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
=== added directory 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/analytics'
=== renamed file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AggregationType.java' => 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/analytics/AggregationType.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AggregationType.java	2014-03-31 08:21:01 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/analytics/AggregationType.java	2014-07-15 18:16:29 +0000
@@ -33,5 +33,31 @@
  */
 public enum AggregationType
 {
-    SUM, AVERAGE_INT, AVERAGE_INT_DISAGGREGATION, AVERAGE_BOOL, COUNT, STDDEV, VARIANCE
+    SUM( "sum" ), 
+    AVERAGE_INT( "avg_int" ), 
+    AVERAGE_INT_DISAGGREGATION( "avg_int_disaggregation" ), 
+    AVERAGE_BOOL( "avg" ), 
+    COUNT( "count" ), 
+    STDDEV( "stddev" ), 
+    VARIANCE( "variance" );
+
+    private final String value;
+
+    private AggregationType( String value )
+    {
+        this.value = value;
+    }
+
+    public static AggregationType fromValue( String value )
+    {
+        for ( AggregationType type : AggregationType.values() )
+        {
+            if ( type.value.equalsIgnoreCase( value ) )
+            {
+                return type;
+            }
+        }
+
+        return null;
+    }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java	2014-06-30 07:40:07 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java	2014-07-15 18:16:29 +0000
@@ -102,7 +102,7 @@
     public static final String AGGREGATION_OPERATOR_COUNT = "count";
     public static final String AGGREGATION_OPERATOR_STDDEV = "stddev";
     public static final String AGGREGATION_OPERATOR_VARIANCE = "variance";
-
+    
     /**
      * The name to appear in forms.
      */

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java	2014-07-10 10:31:06 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java	2014-07-15 18:16:29 +0000
@@ -32,11 +32,8 @@
 import static org.hisp.dhis.analytics.AggregationType.AVERAGE_INT;
 import static org.hisp.dhis.analytics.AggregationType.AVERAGE_INT_DISAGGREGATION;
 import static org.hisp.dhis.analytics.AggregationType.SUM;
-import static org.hisp.dhis.analytics.AggregationType.COUNT;
-import static org.hisp.dhis.analytics.AggregationType.STDDEV;
-import static org.hisp.dhis.analytics.AggregationType.VARIANCE;
+import static org.hisp.dhis.analytics.DataQueryParams.DEFAULT_MAX_DIM_OPT_PERM;
 import static org.hisp.dhis.analytics.DataQueryParams.LEVEL_PREFIX;
-import static org.hisp.dhis.analytics.DataQueryParams.DEFAULT_MAX_DIM_OPT_PERM;
 import static org.hisp.dhis.common.DimensionalObject.CATEGORYOPTIONCOMBO_DIM_ID;
 import static org.hisp.dhis.common.DimensionalObject.DATAELEMENT_DIM_ID;
 import static org.hisp.dhis.common.DimensionalObject.DATASET_DIM_ID;
@@ -44,10 +41,6 @@
 import static org.hisp.dhis.common.DimensionalObject.ORGUNIT_DIM_ID;
 import static org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID;
 import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_AVERAGE;
-import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_SUM;
-import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_COUNT;
-import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_STDDEV;
-import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_VARIANCE;
 import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_BOOL;
 
 import java.util.ArrayList;
@@ -672,11 +665,7 @@
     {
         AggregationType aggregationType = null;
         
-        if ( AGGREGATION_OPERATOR_SUM.equals( aggregationOperator ) )
-        {
-            aggregationType = SUM;
-        }
-        else if ( AGGREGATION_OPERATOR_AVERAGE.equals( aggregationOperator ) )
+        if ( AGGREGATION_OPERATOR_AVERAGE.equals( aggregationOperator ) )
         {
             if ( VALUE_TYPE_BOOL.equals( valueType ) )
             {
@@ -694,17 +683,9 @@
                 }
             }
         }
-        else if ( AGGREGATION_OPERATOR_COUNT.equals( aggregationOperator ) )
-        {
-            aggregationType = COUNT;
-        }
-        else if ( AGGREGATION_OPERATOR_STDDEV.equals( aggregationOperator ) )
-        {
-            aggregationType = STDDEV;
-        }
-        else if ( AGGREGATION_OPERATOR_VARIANCE.equals( aggregationOperator ) )
-        {
-            aggregationType = VARIANCE;
+        else
+        {
+            aggregationType = AggregationType.fromValue( aggregationOperator );
         }
         
         return aggregationType;