← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8193: Validation rule, requiring that all data elements in a validation rule must be present for it to ...

 

------------------------------------------------------------
revno: 8193
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-09-22 17:04:26 +0200
message:
  Validation rule, requiring that all data elements in a validation rule must be present for it to be relevant. Improved validation performance.
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.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-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java	2012-07-26 11:14:41 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java	2012-09-22 15:04:26 +0000
@@ -409,23 +409,21 @@
      * @return all validation rules which have data elements assigned to it
      *         which are members of the given data set.
      */
-    private Collection<ValidationRule> getRelevantValidationRules( Collection<DataElement> dataElements )
+    private Collection<ValidationRule> getRelevantValidationRules( Set<DataElement> dataElements )
     {
-        final Set<ValidationRule> relevantValidationRules = new HashSet<ValidationRule>();
-
+        Set<ValidationRule> relevantValidationRules = new HashSet<ValidationRule>();
+        
+        Set<DataElement> validationRuleElements = new HashSet<DataElement>();
+        
         for ( ValidationRule validationRule : getAllValidationRules() )
         {
-            for ( DataElement dataElement : dataElements )
+            validationRuleElements.clear();
+            validationRuleElements.addAll( validationRule.getLeftSide().getDataElementsInExpression() );
+            validationRuleElements.addAll( validationRule.getRightSide().getDataElementsInExpression() );
+            
+            if ( dataElements.containsAll( validationRuleElements ) )
             {
-                if ( validationRule.getPeriodType() != null && dataElement.getPeriodType() != null
-                    && validationRule.getPeriodType().equals( dataElement.getPeriodType() ) )
-                {
-                    if ( validationRule.getLeftSide().getDataElementsInExpression().contains( dataElement )
-                        || validationRule.getRightSide().getDataElementsInExpression().contains( dataElement ) )
-                    {
-                        relevantValidationRules.add( validationRule );
-                    }
-                }
+                relevantValidationRules.add( validationRule );
             }
         }