← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8196: Impl method for exploding totals in validation rule expressions

 

------------------------------------------------------------
revno: 8196
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-09-22 19:46:17 +0200
message:
  Impl method for exploding totals in validation rule expressions
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/Expression.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.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/expression/Expression.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/Expression.java	2012-07-26 11:14:41 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/Expression.java	2012-09-22 17:46:17 +0000
@@ -111,6 +111,15 @@
     private Set<DataElementCategoryOptionCombo> optionCombosInExpression = new HashSet<DataElementCategoryOptionCombo>();
 
     // -------------------------------------------------------------------------
+    // Transient properties
+    // -------------------------------------------------------------------------
+
+    /**
+     * Set on-the-fly with exploded data element totals.
+     */
+    private transient String explodedExpression;
+    
+    // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------
 
@@ -293,4 +302,14 @@
     {
         this.nullIfBlank = nullIfBlank;
     }
+
+    public String getExplodedExpression()
+    {
+        return explodedExpression;
+    }
+
+    public void setExplodedExpression( String explodedExpression )
+    {
+        this.explodedExpression = explodedExpression;
+    }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java	2012-07-26 11:14:41 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java	2012-09-22 17:46:17 +0000
@@ -35,6 +35,7 @@
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.dataelement.DataElementOperand;
 import org.hisp.dhis.indicator.Indicator;
+import org.hisp.dhis.validation.ValidationRule;
 
 /**
  * Interface for ExpressionService. Defines service functionality for
@@ -202,6 +203,14 @@
     void explodeAndSubstituteExpressions( Collection<Indicator> indicators, Integer days );
     
     /**
+     * Populates the explodedExpression property on the Expression objects of all
+     * ValidationRules in the given collection.
+     * 
+     * @param validationRules the collection of ValidationRules.
+     */
+    void explodeExpressions( Collection<ValidationRule> validationRules );
+    
+    /**
      * Replaces references to data element totals with references to all
      * category option combos in the category combo for that data element.
      * 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java	2012-07-26 11:14:41 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java	2012-09-22 17:46:17 +0000
@@ -55,6 +55,7 @@
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.system.util.MathUtils;
+import org.hisp.dhis.validation.ValidationRule;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -453,7 +454,19 @@
             }     
         }
     }
-
+    
+    public void explodeExpressions( Collection<ValidationRule> validationRules )
+    {
+        if ( validationRules != null && !validationRules.isEmpty() )
+        {
+            for ( ValidationRule rule : validationRules )
+            {
+                rule.getLeftSide().setExplodedExpression( explodeExpression( rule.getLeftSide().getExpression() ) );
+                rule.getRightSide().setExplodedExpression( explodeExpression( rule.getRightSide().getExpression() ) );
+            }
+        }
+    }
+    
     private String explodeExpression( String expression, Map<Integer, Set<Integer>> dataElementMap )
     {
         StringBuffer buffer = null;