← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21393: Dimensional item object in expressions.

 

------------------------------------------------------------
revno: 21393
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-12-09 18:24:33 +0100
message:
  Dimensional item object in expressions.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionValidationOutcome.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/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties
  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/DataElementOperand.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java	2015-12-06 23:17:32 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java	2015-12-09 17:24:33 +0000
@@ -198,7 +198,7 @@
             name = dataElement.getName();
         }
 
-        if ( categoryOptionCombo != null )
+        if ( categoryOptionCombo != null && !categoryOptionCombo.isDefault() )
         {
             name += SPACE + categoryOptionCombo.getName();
         }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionValidationOutcome.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionValidationOutcome.java	2015-12-08 21:44:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionValidationOutcome.java	2015-12-09 17:24:33 +0000
@@ -35,9 +35,7 @@
 {
     VALID( "expression_is_empty" ), 
     EXPRESSION_IS_EMPTY( "data_element_does_not_exist"),
-    DIMENSIONA_ITEM_OBJECT_DOES_NOT_EXIST( "dimensional_item_object_does_not_exist" ),
-    DATAELEMENT_DOES_NOT_EXIST( "data_element_does_not_exist" ),
-    CATEGORYOPTIONCOMBO_DOES_NOT_EXIST( "category_option_combo_does_not_exist"),
+    DIMENSIONAL_ITEM_OBJECT_DOES_NOT_EXIST( "dimensional_item_object_does_not_exist" ),
     CONSTANT_DOES_NOT_EXIST( "constant_does_not_exist"),
     ORG_UNIT_GROUP_DOES_NOT_EXIST( "org_unit_group_does_not_exist"),
     EXPRESSION_IS_NOT_WELL_FORMED( "expression_is_not_well_formed");

=== 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-12-08 22:12:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java	2015-12-09 17:24:33 +0000
@@ -51,6 +51,7 @@
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.common.DimensionService;
 import org.hisp.dhis.common.DimensionalItemObject;
 import org.hisp.dhis.common.GenericStore;
 import org.hisp.dhis.common.ListMap;
@@ -126,6 +127,13 @@
     {
         this.organisationUnitGroupService = organisationUnitGroupService;
     }
+    
+    private DimensionService dimensionService;
+
+    public void setDimensionService( DimensionService dimensionService )
+    {
+        this.dimensionService = dimensionService;
+    }
 
     // -------------------------------------------------------------------------
     // Expression CRUD operations
@@ -491,23 +499,17 @@
         // ---------------------------------------------------------------------
         
         StringBuffer sb = new StringBuffer();
-        Matcher matcher = OPERAND_PATTERN.matcher( expression );
+        Matcher matcher = VARIABLE_PATTERN.matcher( expression );
 
         while ( matcher.find() )
         {
-            String de = matcher.group( 1 );
-            String coc = matcher.group( 2 );
+            String dimensionItem = matcher.group( 2 );
             
-            if ( dataElementService.getDataElement( de ) == null )
-            {
-                return ExpressionValidationOutcome.DATAELEMENT_DOES_NOT_EXIST;
-            }
-
-            if ( !operandIsTotal( matcher ) && categoryService.getDataElementCategoryOptionCombo( coc ) == null )
-            {
-                return ExpressionValidationOutcome.CATEGORYOPTIONCOMBO_DOES_NOT_EXIST;
-            }
-                    
+            if ( dimensionService.getDataDimensionalItemObject( dimensionItem ) == null )
+            {
+                return ExpressionValidationOutcome.DIMENSIONAL_ITEM_OBJECT_DOES_NOT_EXIST;
+            }
+                                
             matcher.appendReplacement( sb, "1.1" );
         }
         
@@ -587,27 +589,20 @@
         // ---------------------------------------------------------------------
         
         StringBuffer sb = new StringBuffer();
-        Matcher matcher = OPERAND_PATTERN.matcher( expression );
+        Matcher matcher = VARIABLE_PATTERN.matcher( expression );
         
         while ( matcher.find() )
         {
-            String de = matcher.group( 1 );
-            String coc = matcher.group( 2 );
-            
-            DataElement dataElement = dataElementService.getDataElement( de );
-            DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDataElementCategoryOptionCombo( coc );
-            
-            if ( dataElement == null )
-            {
-                throw new InvalidIdentifierReferenceException( "Identifier does not reference a data element: " + de );
-            }
-
-            if ( !operandIsTotal( matcher ) && categoryOptionCombo == null )
-            {
-                throw new InvalidIdentifierReferenceException( "Identifier does not reference a category option combo: " + coc );
-            }
-            
-            matcher.appendReplacement( sb, Matcher.quoteReplacement( DataElementOperand.getPrettyName( dataElement, categoryOptionCombo ) ) );
+            String dimensionItem = matcher.group( 2 );
+            
+            DimensionalItemObject dimensionItemObject = dimensionService.getDataDimensionalItemObject( dimensionItem );
+            
+            if ( dimensionItemObject == null )
+            {
+                throw new InvalidIdentifierReferenceException( "Identifier does not reference a dimensional item object: " + dimensionItem );
+            }
+            
+            matcher.appendReplacement( sb, Matcher.quoteReplacement( dimensionItemObject.getDisplayName() ) );
         }
         
         expression = TextUtils.appendTail( matcher, sb );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2015-12-08 22:12:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2015-12-09 17:24:33 +0000
@@ -740,6 +740,7 @@
     <property name="constantService" ref="org.hisp.dhis.constant.ConstantService" />
     <property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
     <property name="organisationUnitGroupService" ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService" />
+    <property name="dimensionService" ref="org.hisp.dhis.dimension.DimensionService" />
   </bean>
 
   <bean id="org.hisp.dhis.validation.ValidationRuleService" class="org.hisp.dhis.validation.DefaultValidationRuleService">

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties	2015-12-08 21:44:36 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties	2015-12-09 17:24:33 +0000
@@ -754,6 +754,7 @@
 data_element_does_not_exist=Data element does not exist
 constant_does_not_exist=Constant does not exist
 org_unit_group_does_not_exist=Organisation unit group does not exist
+dimensional_item_object_does_not_exist=Object does not exist
 id_not_numeric=Identifier is not numeric
 expression_is_not_well_formed=Expression is not well-formed
 valid=Valid

=== 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-12-08 21:44:36 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java	2015-12-09 17:24:33 +0000
@@ -384,11 +384,11 @@
 
         expressionA = "#{nonExisting" + SEPARATOR + categoryOptionCombo.getUid() + "} + 12";
 
-        assertEquals( ExpressionValidationOutcome.DATAELEMENT_DOES_NOT_EXIST, expressionService.expressionIsValid( expressionA ) );
+        assertEquals( ExpressionValidationOutcome.DIMENSIONAL_ITEM_OBJECT_DOES_NOT_EXIST, expressionService.expressionIsValid( expressionA ) );
 
         expressionA = "#{" + dataElementA.getUid() + SEPARATOR + 999 + "} + 12";
 
-        assertEquals( ExpressionValidationOutcome.CATEGORYOPTIONCOMBO_DOES_NOT_EXIST, expressionService
+        assertEquals( ExpressionValidationOutcome.DIMENSIONAL_ITEM_OBJECT_DOES_NOT_EXIST, expressionService
             .expressionIsValid( expressionA ) );
 
         expressionA = "#{" + dataElementA.getUid() + SEPARATOR + categoryOptionCombo.getUid() + "} + ( 12";