← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18872: Added methods to ExpressionService

 

------------------------------------------------------------
revno: 18872
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-04-10 08:53:15 +0200
message:
  Added methods to ExpressionService
modified:
  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
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.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	2015-04-09 18:08:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java	2015-04-10 06:53:15 +0000
@@ -181,24 +181,6 @@
     Set<DataElement> getDataElementsInExpression( String expression );
 
     /**
-     * Returns all data elements included in the given expression string which
-     * represent data element totals.
-     * 
-     * @param expression the expression string.
-     * @return a set of data elements.
-     */
-    Set<DataElement> getDataElementTotalsInExpression( String expression );
-
-    /**
-     * Returns all data elements included in the given expression string which
-     * represent operands with data elements and category option combinations.
-     * 
-     * @param expression the expression string.
-     * @return a set of data elements.
-     */
-    Set<DataElement> getDataElementsWithOptionCombosInExpression( String expression );
-    
-    /**
      * Returns all OrganisationUnitGroups in the numerator and denominator
      * expressions in the given Indicators.
      * 
@@ -243,6 +225,24 @@
      * @return a set of data elements.
      */
     Set<DataElement> getDataElementsInIndicators( Collection<Indicator> indicators );
+
+    /**
+     * Returns all data elements which are present in the numerator and denominator
+     * of the given indicators which represent totals.
+     * 
+     * @param indicators the collection of indicators.
+     * @return a set of data elements.
+     */
+    Set<DataElement> getDataElementTotalsInIndicators( Collection<Indicator> indicators );
+
+    /**
+     * Returns all data elements which are present in the numerator and denominator
+     * of the given indicators which include category option combinations.
+     * 
+     * @param indicators the collection of indicators.
+     * @return a set of data elements.
+     */
+    Set<DataElement> getDataElementWithOptionCombosInIndicators( Collection<Indicator> indicators );
     
     /**
      * Filters indicators from the given collection where the numerator and /

=== 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	2015-04-09 18:08:56 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java	2015-04-10 06:53:15 +0000
@@ -231,20 +231,6 @@
     {
         return getDataElementsInExpressionInternal( OPERAND_PATTERN, expression );
     }
-
-    @Override
-    @Transactional
-    public Set<DataElement> getDataElementTotalsInExpression( String expression )
-    {
-        return getDataElementsInExpressionInternal( DATA_ELEMENT_TOTAL_PATTERN, expression );
-    }
-
-    @Override
-    @Transactional
-    public Set<DataElement> getDataElementsWithOptionCombosInExpression( String expression )
-    {
-        return getDataElementsInExpressionInternal( OPTION_COMBO_OPERAND_PATTERN, expression );
-    }
     
     private Set<DataElement> getDataElementsInExpressionInternal( Pattern pattern, String expression )
     {
@@ -412,6 +398,56 @@
 
     @Override
     @Transactional
+    public Set<DataElement> getDataElementTotalsInIndicators( Collection<Indicator> indicators )
+    {
+        Set<DataElement> dataElements = new HashSet<>();
+        
+        for ( Indicator indicator : indicators )
+        {
+            Set<DataElement> numerator = getDataElementsInExpressionInternal( DATA_ELEMENT_TOTAL_PATTERN, indicator.getNumerator() );
+            Set<DataElement> denominator = getDataElementsInExpressionInternal( DATA_ELEMENT_TOTAL_PATTERN, indicator.getDenominator() );
+            
+            if ( numerator != null )
+            {
+                dataElements.addAll( numerator );
+            }
+            
+            if ( denominator != null )
+            {
+                dataElements.addAll( denominator );
+            }
+        }
+        
+        return dataElements;
+    }
+
+    @Override
+    @Transactional
+    public Set<DataElement> getDataElementWithOptionCombosInIndicators( Collection<Indicator> indicators )
+    {
+        Set<DataElement> dataElements = new HashSet<>();
+        
+        for ( Indicator indicator : indicators )
+        {
+            Set<DataElement> numerator = getDataElementsInExpressionInternal( OPTION_COMBO_OPERAND_PATTERN, indicator.getNumerator() );
+            Set<DataElement> denominator = getDataElementsInExpressionInternal( OPTION_COMBO_OPERAND_PATTERN, indicator.getDenominator() );
+            
+            if ( numerator != null )
+            {
+                dataElements.addAll( numerator );
+            }
+            
+            if ( denominator != null )
+            {
+                dataElements.addAll( denominator );
+            }
+        }
+        
+        return dataElements;
+    }
+
+    @Override
+    @Transactional
     public void filterInvalidIndicators( Collection<Indicator> indicators )
     {
         if ( indicators != null )

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java	2015-04-09 18:08:56 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java	2015-04-10 06:53:15 +0000
@@ -277,25 +277,6 @@
     }
 
     @Test
-    public void testGetDataElementTotalsInExpression()
-    {
-        Set<DataElement> dataElements = expressionService.getDataElementTotalsInExpression( expressionG );
-
-        assertTrue( dataElements.size() == 2 );
-        assertTrue( dataElements.contains( dataElementB ) );
-        assertTrue( dataElements.contains( dataElementC ) );
-    }
-
-    @Test
-    public void testGetDataElementsWithOptionCombosInExpression()
-    {
-        Set<DataElement> dataElements = expressionService.getDataElementsWithOptionCombosInExpression( expressionG );
-
-        assertTrue( dataElements.size() == 1 );
-        assertTrue( dataElements.contains( dataElementA ) );
-    }
-
-    @Test
     public void testGetDataElementTotalUids()
     {
         Set<String> uids = new HashSet<>();