=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java 2012-09-22 17:46:17 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java 2012-09-22 21:59:39 +0000 @@ -56,7 +56,6 @@ final String EXPRESSION_NOT_WELL_FORMED = "expression_not_well_formed"; final String CONSTANT_DOES_NOT_EXIST = "constant_does_not_exist"; - final String DAYS_DESCRIPTION = "[Number of days]"; final String NULL_REPLACEMENT = "0"; final String SPACE = " "; @@ -65,6 +64,7 @@ final String OPERAND_EXPRESSION = "\\[\\d+?.*?\\]"; final String DAYS_EXPRESSION = "[days]"; final String CONSTANT_EXPRESSION = "\\[C(\\d+?)\\]"; + final String COMPULSORY_PAIR_EXPRESSION = "[Compulsory]"; /** * Adds a new Expression to the database. === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/Operator.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/Operator.java 2011-12-26 10:07:59 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/Operator.java 2012-09-22 21:59:39 +0000 @@ -34,7 +34,8 @@ greater_than( ">" ), greater_than_or_equal_to( ">=" ), less_than( "<" ), - less_than_or_equal_to( "<=" ); + less_than_or_equal_to( "<=" ), + compulsory_pair( "[Compulsory pair]" ); private final String mathematicalOperator; === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationResult.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationResult.java 2011-11-22 14:38:08 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationResult.java 2012-09-22 21:59:39 +0000 @@ -50,9 +50,9 @@ private ValidationRule validationRule; - private double leftsideValue; + private Double leftsideValue; - private double rightsideValue; + private Double rightsideValue; // ------------------------------------------------------------------------- // Constructors @@ -63,7 +63,7 @@ } public ValidationResult( Period period, OrganisationUnit source, ValidationRule validationRule, - double leftsideValue, double rightsideValue ) + Double leftsideValue, Double rightsideValue ) { this.source = source; this.period = period; @@ -189,22 +189,22 @@ this.validationRule = validationRule; } - public double getLeftsideValue() + public Double getLeftsideValue() { return leftsideValue; } - public void setLeftsideValue( double leftsideValue ) + public void setLeftsideValue( Double leftsideValue ) { this.leftsideValue = leftsideValue; } - public double getRightsideValue() + public Double getRightsideValue() { return rightsideValue; } - public void setRightsideValue( double rightsideValue ) + public void setRightsideValue( Double rightsideValue ) { this.rightsideValue = rightsideValue; } === 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-09-22 18:42:59 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java 2012-09-22 21:59:39 +0000 @@ -33,7 +33,7 @@ import static org.hisp.dhis.i18n.I18nUtils.getObjectsByName; import static org.hisp.dhis.i18n.I18nUtils.i18n; import static org.hisp.dhis.system.util.MathUtils.expressionIsTrue; -import static org.hisp.dhis.system.util.MathUtils.getRounded; +import static org.hisp.dhis.system.util.MathUtils.*; import java.util.Collection; import java.util.Date; @@ -48,6 +48,7 @@ import org.hisp.dhis.dataset.DataSet; import org.hisp.dhis.datavalue.DataValueService; import org.hisp.dhis.expression.ExpressionService; +import org.hisp.dhis.expression.Operator; import org.hisp.dhis.i18n.I18nService; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.period.Period; @@ -256,20 +257,29 @@ if ( validationRule.getPeriodType() != null && validationRule.getPeriodType().equals( period.getPeriodType() ) ) { + Operator operator = validationRule.getOperator(); + leftSide = expressionService.getExpressionValue( validationRule.getLeftSide(), valueMap, constantMap, null ); - if ( leftSide != null ) + if ( leftSide != null || Operator.compulsory_pair.equals( operator ) ) { rightSide = expressionService.getExpressionValue( validationRule.getRightSide(), valueMap, constantMap, null ); - if ( rightSide != null ) + if ( rightSide != null || Operator.compulsory_pair.equals( operator ) ) { - violation = !expressionIsTrue( leftSide, validationRule.getOperator(), rightSide ); - + if ( Operator.compulsory_pair.equals( operator ) ) + { + violation = ( leftSide != null && rightSide == null ) || ( leftSide == null && rightSide != null ); + } + else + { + violation = !expressionIsTrue( leftSide, operator, rightSide ); + } + if ( violation ) { validationViolations.add( new ValidationResult( period, unit, validationRule, - getRounded( leftSide, DECIMALS ), getRounded( rightSide, DECIMALS ) ) ); + getRounded( zeroIfNull( leftSide ), DECIMALS ), getRounded( zeroIfNull( rightSide ), DECIMALS ) ) ); } } } === modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java' --- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java 2012-08-25 11:47:17 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java 2012-09-22 21:59:39 +0000 @@ -234,6 +234,17 @@ } /** + * Returns 0d if the given value is null, the original value otherwise. + * + * @param value the value. + * @return a double. + */ + public static double zeroIfNull( Double value ) + { + return value == null ? 0d : value; + } + + /** * Returns a random int between 0 and 999. */ public static int getRandom() === modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/org/hisp/dhis/validationrule/i18n_module.properties' --- dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/org/hisp/dhis/validationrule/i18n_module.properties 2012-09-22 18:42:59 +0000 +++ dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/org/hisp/dhis/validationrule/i18n_module.properties 2012-09-22 21:59:39 +0000 @@ -124,4 +124,5 @@ specify_dataset=Please specify data sets analysing_please_wait=Analysing data, please wait skip_for_missing_values=Skip for missing values -select_parameters=Select parameters \ No newline at end of file +select_parameters=Select parameters +compulsory_pair=Compulsory pair \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/addValidationRuleForm.vm' --- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/addValidationRuleForm.vm 2012-07-26 11:14:41 +0000 +++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/addValidationRuleForm.vm 2012-09-22 21:59:39 +0000 @@ -34,7 +34,8 @@ - + + === modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/updateValidationRuleForm.vm' --- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/updateValidationRuleForm.vm 2012-07-26 11:30:34 +0000 +++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/updateValidationRuleForm.vm 2012-09-22 21:59:39 +0000 @@ -43,6 +43,7 @@ +