← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 864: Improved expression description functionality.

 

------------------------------------------------------------
revno: 864
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Thu 2009-10-15 17:59:10 +0200
message:
  Improved expression description functionality.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.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/dataelement/DataElementCategoryOptionCombo.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java	2009-10-13 20:08:57 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java	2009-10-15 15:59:10 +0000
@@ -66,7 +66,7 @@
     }
     
     // -------------------------------------------------------------------------
-    // hashCode and equals
+    // hashCode, equals and toString
     // -------------------------------------------------------------------------
 
     @Override
@@ -150,6 +150,10 @@
         return buffer.append( "]]" ).toString();
     }
 
+    // -------------------------------------------------------------------------
+    // Logic
+    // -------------------------------------------------------------------------
+
     /**
      * Tests whether two objects compare on a name basis. The default equals method
      * becomes unusable in conjunction with persistence frameworks that put proxys
@@ -215,7 +219,16 @@
         
         return null;
     }
-   
+
+    public boolean isDefault()
+    {
+        return categoryCombo != null && categoryCombo.getName().equals( DEFAULT_NAME );
+    }
+    
+    // -------------------------------------------------------------------------
+    // Getters and setters
+    // -------------------------------------------------------------------------
+
     public String getName()
     {
         StringBuffer name = new StringBuffer();
@@ -288,10 +301,6 @@
         throw new UnsupportedOperationException( "Cannot set alternativename on DataElementCategoryOptionCombo: " + alternativeName );
     }
     
-    // -------------------------------------------------------------------------
-    // Getters and setters
-    // -------------------------------------------------------------------------
-
     public DataElementCategoryCombo getCategoryCombo()
     {
         return categoryCombo;

=== 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	2009-10-13 20:08:57 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java	2009-10-15 15:59:10 +0000
@@ -334,11 +334,11 @@
                         + operand.getOptionComboId() );
                 }
 
-                replaceString = dataElement.getName() + SEPARATOR + categoryOptionCombo.getName();
-
-                if ( replaceString.endsWith( SEPARATOR ) )
+                replaceString = dataElement.getName();
+                
+                if ( !categoryOptionCombo.isDefault() )
                 {
-                    replaceString = replaceString.substring( 0, replaceString.length() - 1 );
+                    replaceString += SEPARATOR + categoryOptionCombo.getName();
                 }
 
                 matcher.appendReplacement( buffer, replaceString );

=== 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	2009-09-25 21:45:01 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java	2009-10-15 15:59:10 +0000
@@ -44,6 +44,7 @@
 import org.hisp.dhis.dataelement.DataElementCategoryCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryComboService;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionComboService;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.dataelement.Operand;
 import org.hisp.dhis.datavalue.DataValueService;
@@ -59,11 +60,7 @@
  */
 public class ExpressionServiceTest
     extends DhisTest
-{
-    private ExpressionService expressionService;
-
-    private DataElementCategoryComboService categoryComboService;
-        
+{        
     private SourceStore sourceStore;
     
     private DataElement dataElementA;
@@ -80,8 +77,6 @@
     private int dataElementIdC;    
     private int dataElementIdD;
 
-    private DataElementCategoryCombo categoryCombo;
-    
     private DataElementCategoryOptionCombo categoryOptionCombo;
     
     private int categoryOptionComboId;
@@ -108,6 +103,8 @@
 
         categoryComboService = (DataElementCategoryComboService) getBean( DataElementCategoryComboService.ID );
         
+        categoryOptionComboService = (DataElementCategoryOptionComboService) getBean( DataElementCategoryOptionComboService.ID );
+        
         dataValueService = (DataValueService) getBean( DataValueService.ID );
         
         sourceStore = (SourceStore) getBean( SourceStore.ID );
@@ -122,9 +119,7 @@
         dataElementIdC = dataElementService.addDataElement( dataElementC );
         dataElementIdD = dataElementService.addDataElement( dataElementD );
         
-        categoryCombo = categoryComboService.getDataElementCategoryComboByName( DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME );             
-        
-        categoryOptionCombo = categoryCombo.getOptionCombos().iterator().next();
+        categoryOptionCombo = categoryOptionComboService.getDefaultDataElementCategoryOptionCombo();
         
         categoryOptionComboId = categoryOptionCombo.getId();
         
@@ -172,7 +167,7 @@
 
         value = expressionService.getExpressionValue( expression, period, source, false );
         
-        assertEquals( value, 0.0 );
+        assertEquals( 0.0, value );
     }
 
     @Test
@@ -253,7 +248,7 @@
     {
         String description = expressionService.getExpressionDescription( expressionA );        
         
-        assertEquals( description, "DataElementA + DataElementB" );
+        assertEquals( "DataElementA + DataElementB", description );
     }
 
     @Test
@@ -261,11 +256,11 @@
     {
         String expression = expressionService.generateExpression( expressionA, period, source, false );
         
-        assertEquals( expression, "10 + 5" );
+        assertEquals( "10 + 5", expression );
         
         expression = expressionService.generateExpression( expressionB, period, source, false );
         
-        assertEquals( expression, "0 - 0" );
+        assertEquals( "0 - 0", expression );
     }
     
     // -------------------------------------------------------------------------
@@ -281,9 +276,9 @@
         
         expression = expressionService.getExpression( id );
         
-        assertEquals( expression.getExpression(), expressionA );
-        assertEquals( expression.getDescription(), descriptionA );
-        assertEquals( expression.getDataElementsInExpression(), dataElements );
+        assertEquals( expressionA, expression.getExpression() );
+        assertEquals( descriptionA, expression.getDescription() );
+        assertEquals( dataElements, expression.getDataElementsInExpression() );
     }
 
     @Test
@@ -295,8 +290,8 @@
         
         expression = expressionService.getExpression( id );
         
-        assertEquals( expression.getExpression(), expressionA );
-        assertEquals( expression.getDescription(), descriptionA );
+        assertEquals( expressionA, expression.getExpression() );
+        assertEquals( descriptionA, expression.getDescription() );
         
         expression.setExpression( expressionB );
         expression.setDescription( descriptionB );
@@ -305,8 +300,8 @@
 
         expression = expressionService.getExpression( id );
         
-        assertEquals( expression.getExpression(), expressionB );
-        assertEquals( expression.getDescription(), descriptionB );
+        assertEquals( expressionB, expression.getExpression() );
+        assertEquals( descriptionB, expression.getDescription() );
     }
 
     @Test