← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12415: Analytics, fixed bug with Days keyword in indicators

 

------------------------------------------------------------
revno: 12415
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-10-03 12:21:15 +0200
message:
  Analytics, fixed bug with Days keyword in indicators
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.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/ExpressionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java	2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java	2013-10-03 10:21:15 +0000
@@ -234,14 +234,23 @@
      * Populates the explodedNumerator and explodedDenominator property on all
      * indicators in the given collection. This method uses
      * explodeExpression( String ) internally to generate the exploded expressions.
-     * This method will perform compared to calling explodeExpression( String )
+     * This method will perform better compared to calling explodeExpression( String )
      * multiple times outside a transactional context as the transactional
      * overhead is avoided.
      * 
      * @param indicators the collection of indicators.
-     * @param 
+     * @param days the number of days in aggregation period.
      */
     void explodeAndSubstituteExpressions( Collection<Indicator> indicators, Integer days );
+
+    /**
+     * Populates the explodedNumerator and explodedDenominator property on all
+     * indicators in the given collection. This method uses
+     * explodeExpression( String ) internally to generate the exploded expressions.
+     * 
+     * @param indicators the collection of indicators.
+     */    
+    void explodeExpressions( Collection<Indicator> indicators );
     
     /**
      * Replaces references to data element totals with references to all

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2013-10-03 08:22:21 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2013-10-03 10:21:15 +0000
@@ -222,7 +222,7 @@
             int indicatorIndex = params.getIndicatorDimensionIndex();
             List<Indicator> indicators = asTypedList( params.getIndicators() );
             
-            expressionService.explodeAndSubstituteExpressions( indicators, null );
+            expressionService.explodeExpressions( indicators );
             
             DataQueryParams dataSourceParams = params.instance();
             dataSourceParams.removeDimension( DATAELEMENT_DIM_ID );

=== 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	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java	2013-10-03 10:21:15 +0000
@@ -490,6 +490,15 @@
                 indicator.setExplodedDenominator( substituteExpression( indicator.getDenominator(), days ) );
             }
 
+            explodeExpressions( indicators );
+        }
+    }
+
+    @Transactional
+    public void explodeExpressions( Collection<Indicator> indicators )
+    {
+        if ( indicators != null && !indicators.isEmpty() )
+        {
             Set<String> dataElementTotals = new HashSet<String>();
             
             for ( Indicator indicator : indicators )
@@ -631,7 +640,7 @@
         {
             return null;
         }
-
+        
         // ---------------------------------------------------------------------
         // Operands
         // ---------------------------------------------------------------------
@@ -683,7 +692,7 @@
         matcher = DAYS_PATTERN.matcher( expression );
         
         while ( matcher.find() )
-        {            
+        {
             String replacement = days != null ? String.valueOf( days ) : NULL_REPLACEMENT;
             
             matcher.appendReplacement( sb, replacement );