dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #01399
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 413: Fixed bug #385142
------------------------------------------------------------
revno: 413
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Fri 2009-07-03 12:03:22 +0200
message:
Fixed bug #385142
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.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/java/org/hisp/dhis/validation/DefaultValidationRuleService.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java
dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/CalculateCDEsAction.java
=== 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 2009-06-10 22:25:07 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java 2009-07-03 10:03:22 +0000
@@ -96,11 +96,13 @@
* @param expression The Expression.
* @param source The Source.
* @param period The Period.
+ * @param nullIfNoValues indicates whether null should be returned if no
+ * DataValues are registered for a DataElement in the expression.
* @return The value of the given Expression, or null
* if no values are registered for a given combination of
* DataElement, Source, and Period.
*/
- Double getExpressionValue( Expression expression, Period period, Source source );
+ Double getExpressionValue( Expression expression, Period period, Source source, boolean nullIfNoValues );
/**
*
@@ -184,7 +186,9 @@
* @param expression The expression string.
* @param period The Period.
* @param source The Source.
+ * @param nullIfNoValues indicates whether null should be returned if no
+ * DataValues are registered for a DataElement in the expression.
* @return A numerical expression.
*/
- String generateExpression( String expression, Period period, Source source );
+ String generateExpression( String expression, Period period, Source source, boolean nullIfNoValues );
}
=== 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 2009-07-02 23:13:13 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java 2009-07-03 10:03:22 +0000
@@ -134,12 +134,12 @@
// Business logic
// -------------------------------------------------------------------------
- public Double getExpressionValue( Expression expression, Period period, Source source )
+ public Double getExpressionValue( Expression expression, Period period, Source source, boolean nullIfNoValues )
{
- final String expressionString = generateExpression( expression.getExpression(), period, source );
+ final String expressionString = generateExpression( expression.getExpression(), period, source, nullIfNoValues );
return expressionString != null ? calculateExpression( expressionString ) : null;
- }
+ }
public Set<DataElement> getDataElementsInCalculatedDataElement( int id )
{
@@ -396,7 +396,7 @@
return buffer != null ? buffer.toString() : null;
}
- public String generateExpression( String expression, Period period, Source source )
+ public String generateExpression( String expression, Period period, Source source, boolean nullIfNoValues )
{
StringBuffer buffer = null;
@@ -418,6 +418,11 @@
final DataValue dataValue = dataValueService.getDataValue( source, dataElement, period, categoryOptionCombo );
+ if ( dataValue == null && nullIfNoValues )
+ {
+ return null;
+ }
+
replaceString = ( dataValue == null ) ? NULL_REPLACEMENT : dataValue.getValue();
matcher.appendReplacement( buffer, replaceString );
=== 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 2009-06-30 23:27:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java 2009-07-03 10:03:22 +0000
@@ -190,8 +190,8 @@
for ( final ValidationRule validationRule : validationRules )
{
- leftSide = expressionService.getExpressionValue( validationRule.getLeftSide(), period, source );
- rightSide = expressionService.getExpressionValue( validationRule.getRightSide(), period, source );
+ leftSide = expressionService.getExpressionValue( validationRule.getLeftSide(), period, source, true );
+ rightSide = expressionService.getExpressionValue( validationRule.getRightSide(), period, source, true );
if ( leftSide != null && rightSide != null )
{
=== 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 2009-06-10 22:25:07 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java 2009-07-03 10:03:22 +0000
@@ -158,13 +158,13 @@
{
Expression expression = new Expression( expressionA, descriptionA, dataElements );
- Double value = expressionService.getExpressionValue( expression, period, source );
+ Double value = expressionService.getExpressionValue( expression, period, source, false );
assertEquals( value, 15.0 );
expression = new Expression( expressionB, descriptionB, dataElements );
- value = expressionService.getExpressionValue( expression, period, source );
+ value = expressionService.getExpressionValue( expression, period, source, false );
assertEquals( value, 0.0 );
}
@@ -253,11 +253,11 @@
@Test
public void testGenerateExpression()
{
- String expression = expressionService.generateExpression( expressionA, period, source );
+ String expression = expressionService.generateExpression( expressionA, period, source, false );
assertEquals( expression, "10 + 5" );
- expression = expressionService.generateExpression( expressionB, period, source );
+ expression = expressionService.generateExpression( expressionB, period, source, false );
assertEquals( expression, "0 - 0" );
}
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/CalculateCDEsAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/CalculateCDEsAction.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/CalculateCDEsAction.java 2009-07-03 10:03:22 +0000
@@ -140,7 +140,7 @@
for ( CalculatedDataElement cde : cdes )
{
- value = expressionService.getExpressionValue( cde.getExpression(), period, organisationUnit ).toString();
+ value = expressionService.getExpressionValue( cde.getExpression(), period, organisationUnit, false ).toString();
if ( value == null )
{
--
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.