dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #31841
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16263: Validation, ignoring NaN in expressions instead of reporting as validation errors
------------------------------------------------------------
revno: 16263
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-07-27 18:58:03 +0200
message:
Validation, ignoring NaN in expressions instead of reporting as validation errors
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/ValidatorThread.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.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/ValidatorThread.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/ValidatorThread.java 2014-07-16 15:29:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/ValidatorThread.java 2014-07-27 16:58:03 +0000
@@ -56,6 +56,7 @@
import org.hisp.dhis.period.CalendarPeriodType;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.system.util.MathUtils;
/**
* Runs a validation task on a thread within a multi-threaded validation run.
@@ -133,16 +134,16 @@
attributeOptionCombos.addAll( rightSideValues.keySet() );
}
- for ( int combo : attributeOptionCombos )
+ for ( int optionCombo : attributeOptionCombos )
{
- Double leftSide = leftSideValues.get ( combo );
- Double rightSide = rightSideValues.get ( combo );
+ Double leftSide = leftSideValues.get ( optionCombo );
+ Double rightSide = rightSideValues.get ( optionCombo );
boolean violation = false;
if ( Operator.compulsory_pair.equals( rule.getOperator() ) )
{
- violation = (leftSide != null && rightSide == null)
- || (leftSide == null && rightSide != null);
+ violation = ( leftSide != null && rightSide == null )
+ || ( leftSide == null && rightSide != null );
}
else if ( leftSide != null && rightSide != null )
{
@@ -153,13 +154,13 @@
{
context.getValidationResults().add( new ValidationResult(
period, sourceX.getSource(),
- context.getDataElementCategoryService().getDataElementCategoryOptionCombo( combo ), rule,
+ context.getDataElementCategoryService().getDataElementCategoryOptionCombo( optionCombo ), rule,
roundSignificant( zeroIfNull( leftSide ) ),
roundSignificant( zeroIfNull( rightSide ) ) ) );
}
log.trace( "Evaluated " + rule.getName()
- + ", combo id " + combo + ": "
+ + ", combo id " + optionCombo + ": "
+ (violation ? "violation" : "OK") + " " + ( leftSide == null ? "(null)" : leftSide.toString() )
+ " " + rule.getOperator() + " " + ( rightSide == null ? "(null)" : rightSide.toString() )
+ " (" + context.getValidationResults().size() + " results)" );
@@ -464,10 +465,14 @@
for ( Map.Entry<Integer, Map<DataElementOperand, Double>> entry : valueMap.entrySet() )
{
- expressionValueMap.put( entry.getKey(),
- context.getExpressionService().getExpressionValue( expression,
+ Double value = context.getExpressionService().getExpressionValue( expression,
entry.getValue(), context.getConstantMap(), null, null,
- incompleteValuesMap.getSet( entry.getKey() ) ) );
+ incompleteValuesMap.getSet( entry.getKey() ) );
+
+ if ( MathUtils.isValidDouble( value ) )
+ {
+ expressionValueMap.put( entry.getKey(), value );
+ }
}
return expressionValueMap;
=== 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 2014-07-21 09:45:25 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java 2014-07-27 16:58:03 +0000
@@ -43,7 +43,6 @@
*/
public class MathUtils
{
- public static final double INVALID = -1.0;
public static final Double ZERO = new Double( 0 );
private static final double TOLERANCE = 0.01;
@@ -88,9 +87,19 @@
final JEP parser = getJep();
parser.parseExpression( expression );
- double result = parser.getValue();
-
- return ( result == Double.NEGATIVE_INFINITY || result == Double.POSITIVE_INFINITY ) ? INVALID : result;
+ return parser.getValue();
+ }
+
+ /**
+ * Indicates whether the given double valid, implying it is not null, not
+ * infinite and not NaN.
+ *
+ * @param d the double.
+ * @return true if the given double is valid.
+ */
+ public static boolean isValidDouble( Double d )
+ {
+ return d != null && !Double.isInfinite( d ) && !Double.isNaN( d );
}
/**