← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8461: Improved ValidationRule.mergeWith

 

------------------------------------------------------------
revno: 8461
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-10-10 14:49:27 +0200
message:
  Improved ValidationRule.mergeWith
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/Expression.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRule.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/Expression.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/Expression.java	2012-09-23 07:25:57 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/Expression.java	2012-10-10 12:49:27 +0000
@@ -33,6 +33,8 @@
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+
+import org.apache.commons.lang.Validate;
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.common.Dxf2Namespace;
 import org.hisp.dhis.common.annotation.Scanned;
@@ -293,4 +295,17 @@
     {
         this.nullIfBlank = nullIfBlank;
     }
+    
+    public void mergeWith( Expression other )
+    {
+        Validate.notNull( other );
+        
+        expression = other.getExpression() == null ? expression : other.getExpression();
+        description = other.getDescription() == null ? description : other.getDescription();
+        nullIfBlank = other.isNullIfBlank();
+        dataElementsInExpression = other.getDataElementsInExpression() == null ?
+            dataElementsInExpression : new HashSet<DataElement>( other.getDataElementsInExpression() );
+        optionCombosInExpression = other.getOptionCombosInExpression() == null ? 
+            optionCombosInExpression : new HashSet<DataElementCategoryOptionCombo>( other.getOptionCombosInExpression() );        
+    }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRule.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRule.java	2012-05-21 13:28:46 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRule.java	2012-10-10 12:49:27 +0000
@@ -260,10 +260,18 @@
             description = validationRule.getDescription() == null ? description : validationRule.getDescription();
             type = validationRule.getType() == null ? type : validationRule.getType();
             operator = validationRule.getOperator() == null ? operator : validationRule.getOperator();
-            leftSide = validationRule.getLeftSide() == null ? leftSide : validationRule.getLeftSide();
-            rightSide = validationRule.getRightSide() == null ? rightSide : validationRule.getRightSide();
             periodType = validationRule.getPeriodType() == null ? periodType : validationRule.getPeriodType();
 
+            if ( leftSide != null && validationRule.getLeftSide() != null )
+            {
+                leftSide.mergeWith( validationRule.getLeftSide() );
+            }
+            
+            if ( rightSide != null && validationRule.getRightSide() != null )
+            {
+                rightSide.mergeWith( validationRule.getRightSide() );
+            }
+
             groups.clear();
         }
     }