← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2283: Centralized method

 

------------------------------------------------------------
revno: 2283
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2010-12-04 02:31:11 +0100
message:
  Centralized method
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/compulsory/SaveCompulsoryDataElementsAction.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/dataelement/DataElementOperand.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java	2010-12-03 23:12:42 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java	2010-12-04 01:31:11 +0000
@@ -181,8 +181,10 @@
      * @param formula the formula.
      * @return a DataElementOperand.
      */
-    public static DataElementOperand generateOperand( String formula )
+    public static DataElementOperand getOperand( String formula )
     {
+        formula = formula.replaceAll( "[\\[\\]]", "" ); //TODO fix
+        
         final int dataElementId = Integer.parseInt( formula.substring( 0, formula.indexOf( SEPARATOR ) ) );
         final int categoryOptionComboId = Integer.parseInt( formula.substring( formula.indexOf( SEPARATOR ) + 1,
             formula.length() ) );

=== 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	2010-12-04 00:03:38 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java	2010-12-04 01:31:11 +0000
@@ -55,6 +55,11 @@
 import org.springframework.transaction.annotation.Transactional;
 
 /**
+ * The expression is a string describing a formula containing data element ids and
+ * category option combo ids. The formula can potentially contain references to
+ * category totals (also called sub-totals) and data element totals (also called
+ * totals).
+ * 
  * @author Margrethe Store
  * @author Lars Helge Overland
  * @version $Id: DefaultExpressionService.java 6463 2008-11-24 12:05:46Z larshelg $
@@ -66,9 +71,10 @@
     private static final Log log = LogFactory.getLog( DefaultExpressionService.class );
     
     private static final String NULL_REPLACEMENT = "0";
+    private static final String SPACE = " ";
+    
     private static final String FORMULA_EXPRESSION = "(\\[\\d+\\" + SEPARATOR + "\\d+\\])";
     private static final String DESCRIPTION_EXPRESSION = "\\[.+?\\" + SEPARATOR + ".+?\\]";
-    private static final String SPACE = " ";
     
     private final Pattern FORMULA_PATTERN = Pattern.compile( FORMULA_EXPRESSION );
     private final Pattern DESCRIPTION_PATTERN = Pattern.compile( DESCRIPTION_EXPRESSION );
@@ -164,7 +170,7 @@
             
             while ( matcher.find() )
             {
-                final DataElement dataElement = dataElementService.getDataElement( getOperand( matcher.group() ).getDataElementId() );
+                final DataElement dataElement = dataElementService.getDataElement( DataElementOperand.getOperand( matcher.group() ).getDataElementId() );
 
                 if ( dataElement != null )
                 {
@@ -188,7 +194,7 @@
             {
                 String match = matcher.group();
 
-                final DataElementOperand operand = getOperand( match );
+                final DataElementOperand operand = DataElementOperand.getOperand( match );
                 
                 final Integer mappedDataElementId = dataElementMapping.get( operand.getDataElementId() );
                 final Integer mappedCategoryOptionComboId = categoryOptionComboMapping.get( operand.getOptionComboId() );
@@ -231,7 +237,7 @@
 
             while ( matcher.find() )
             {
-                operandsInExpression.add( getOperand( matcher.group() ) );
+                operandsInExpression.add( DataElementOperand.getOperand( matcher.group() ) );
             }
         }
 
@@ -321,7 +327,7 @@
             {
                 String replaceString = matcher.group();
                 
-                final DataElementOperand operand = getOperand( replaceString );
+                final DataElementOperand operand = DataElementOperand.getOperand( replaceString );
                 
                 final DataElement dataElement = dataElementService.getDataElement( operand.getDataElementId() );
                 final DataElementCategoryOptionCombo categoryOptionCombo = 
@@ -414,7 +420,7 @@
             {
                 String replaceString = matcher.group();
 
-                final DataElementOperand operand = getOperand( replaceString );
+                final DataElementOperand operand = DataElementOperand.getOperand( replaceString );
                 
                 String value = null;
               
@@ -444,19 +450,4 @@
 
         return buffer != null ? buffer.toString() : null;
     }
-    
-    // -------------------------------------------------------------------------
-    // Supportive methods
-    // -------------------------------------------------------------------------
-    
-    private DataElementOperand getOperand( String formula )
-    {
-        formula = formula.replaceAll( "[\\[\\]]", "" );
-        
-        final int dataElementId = Integer.parseInt( formula.substring( 0, formula.indexOf( SEPARATOR ) ) );
-        final int categoryOptionComboId = Integer.parseInt( formula.substring( formula.indexOf( SEPARATOR ) + 1, formula.length() ) );
-        
-        return new DataElementOperand( dataElementId, categoryOptionComboId ); 
-    }
-
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/compulsory/SaveCompulsoryDataElementsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/compulsory/SaveCompulsoryDataElementsAction.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/compulsory/SaveCompulsoryDataElementsAction.java	2010-12-04 01:31:11 +0000
@@ -98,8 +98,8 @@
         dataSet.getCompulsoryDataElementOperands().clear();
         
         for ( String id : selectedOperands )
-        {        
-            DataElementOperand temp = DataElementOperand.generateOperand( id );
+        {
+            DataElementOperand temp = DataElementOperand.getOperand( id );
             
             DataElementOperand operand = new DataElementOperand( 
                 dataElementService.getDataElement( temp.getDataElementId() ),