← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19815: Event analytics, allowing for in-line aggregation operator in program indicators

 

------------------------------------------------------------
revno: 19815
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-08-21 08:47:08 -0400
message:
  Event analytics, allowing for in-line aggregation operator in program indicators
modified:
  dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/ExpressionUtils.java
  dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ExpressionUtilsTest.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addProgramIndicator.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateProgramIndicator.vm


--
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-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/ExpressionUtils.java'
--- dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/ExpressionUtils.java	2015-07-19 16:36:56 +0000
+++ dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/ExpressionUtils.java	2015-08-21 12:47:08 +0000
@@ -33,6 +33,7 @@
 import org.apache.commons.jexl2.JexlEngine;
 import org.apache.commons.jexl2.JexlException;
 import org.apache.commons.jexl2.MapContext;
+import org.apache.commons.lang3.StringUtils;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -48,6 +49,8 @@
     private static final JexlEngine JEXL = new JexlEngine();
     
     private static final Map<String, String> EL_SQL_MAP = new HashMap<>();
+    private static final String IGNORED_KEYWORDS_REGEX = 
+        "SUM|sum|AVERAGE|average|COUNT|count|STDDEV|stddev|VARIANCE|variance|MIN|min|MAX|max|NONE|none";
 
     private static final Pattern NUMERIC_PATTERN = Pattern.compile( "^(-?0|-?[1-9]\\d*)(\\.\\d+)?(E(-)?\\d+)?$" );
     
@@ -78,6 +81,8 @@
      */
     public static Object evaluate( String expression, Map<String, Object> vars )
     {
+        expression = expression.replaceAll( IGNORED_KEYWORDS_REGEX, StringUtils.EMPTY );
+        
         Expression exp = JEXL.createExpression( expression );
         
         JexlContext context = vars != null ? new MapContext( vars ) : new MapContext();

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ExpressionUtilsTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ExpressionUtilsTest.java	2015-07-19 16:36:56 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ExpressionUtilsTest.java	2015-08-21 12:47:08 +0000
@@ -157,10 +157,13 @@
         assertTrue( ExpressionUtils.isValid( "d2:zing(1)", null ) );
         assertTrue( ExpressionUtils.isValid( "(d2:zing(1)+d2:zing(1))*50/1", null ) );
         assertTrue( ExpressionUtils.isValid( "1/(1/100)", null ) );
+        assertTrue( ExpressionUtils.isValid( "SUM(1)", null ) );
+        assertTrue( ExpressionUtils.isValid( "average(2+1)", null ) );
         
         assertFalse( ExpressionUtils.isValid( "2 a 3", null ) );
         assertFalse( ExpressionUtils.isValid( "v2 + 3", vars ) );
         assertFalse( ExpressionUtils.isValid( "4 + abc", vars ) );
         assertFalse( ExpressionUtils.isValid( "'goat' == goat", null ) );
+        assertFalse( ExpressionUtils.isValid( "aver(2+1)", null ) );
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addProgramIndicator.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addProgramIndicator.vm	2015-08-21 02:55:35 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/addProgramIndicator.vm	2015-08-21 12:47:08 +0000
@@ -73,7 +73,7 @@
 	                <option value="VARIANCE">$i18n.getString( "variance" )</option>
 	                <option value="MIN">$i18n.getString( "min" )</option>
 	                <option value="MAX">$i18n.getString( "max" )</option>
-	                <option value="MAX">$i18n.getString( "custom" )</option>
+	                <option value="CUSTOM">$i18n.getString( "custom" )</option>
 	            </select>
 	        </td>
 	    </tr>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateProgramIndicator.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateProgramIndicator.vm	2015-08-21 02:55:35 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateProgramIndicator.vm	2015-08-21 12:47:08 +0000
@@ -73,6 +73,7 @@
                 <option value="VARIANCE"#if( $programIndicator.aggregationType == 'VARIANCE' ) selected="selected"#end>$i18n.getString( "variance" )</option>
                 <option value="MIN"#if( $programIndicator.aggregationType == 'MIN' ) selected="selected"#end>$i18n.getString( "min" )</option>
                 <option value="MAX"#if( $programIndicator.aggregationType == 'MAX' ) selected="selected"#end>$i18n.getString( "max" )</option>
+	            <option value="CUSTOM"#if( $programIndicator.aggregationType == 'CUSTOM' ) selected="selected"#end>$i18n.getString( "custom" )</option>
             </select>
         </td>
     </tr>