dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #40842
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20794: Fixed bug with program indicator expression validation
------------------------------------------------------------
revno: 20794
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-10-20 10:18:49 +0200
message:
Fixed bug with program indicator expression validation
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ValueType.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicator.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicatorService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/org/hisp/dhis/trackedentity/i18n_module.properties
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/programIndicator.js
--
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/common/ValueType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ValueType.java 2015-10-20 07:22:15 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ValueType.java 2015-10-20 08:18:49 +0000
@@ -69,6 +69,9 @@
public static final Set<ValueType> NUMERIC_TYPES = Sets.newHashSet(
INTEGER, INTEGER_POSITIVE, INTEGER_NEGATIVE, INTEGER_ZERO_OR_POSITIVE, NUMBER, UNIT_INTERVAL, PERCENTAGE );
+ public static final Set<ValueType> BOOLEAN_TYPES = Sets.newHashSet(
+ BOOLEAN, TRUE_ONLY );
+
public static final Set<ValueType> TEXT_TYPES = Sets.newHashSet(
TEXT, LONG_TEXT, LETTER, COORDINATE );
@@ -101,6 +104,11 @@
{
return NUMERIC_TYPES.contains( this );
}
+
+ public boolean isBoolean()
+ {
+ return BOOLEAN_TYPES.contains( this );
+ }
public boolean isText()
{
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicator.java 2015-10-04 20:41:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicator.java 2015-10-20 08:18:49 +0000
@@ -87,7 +87,7 @@
public static final Pattern VALUECOUNT_PATTERN = Pattern.compile( "V\\{(" + VAR_VALUE_COUNT + "|" + VAR_ZERO_POS_VALUE_COUNT + ")\\}" );
public static final String VALID = "valid";
- public static final String EXPRESSION_NOT_WELL_FORMED = "expression_not_well_formed";
+ public static final String EXPRESSION_NOT_VALID = "expression_not_valid";
public static final String INVALID_IDENTIFIERS_IN_EXPRESSION = "invalid_identifiers_in_expression";
public static final String FILTER_NOT_EVALUATING_TO_TRUE_OR_FALSE = "filter_not_evaluating_to_true_or_false";
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicatorService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicatorService.java 2015-10-13 13:10:18 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicatorService.java 2015-10-20 08:18:49 +0000
@@ -138,7 +138,7 @@
*
* @param expression An expression string.
* @return the string {@link ProgramIndicator.VALID} if valid, if not any of
- * {@link ProgramIndicator.EXPRESSION_NOT_WELL_FORMED},
+ * {@link ProgramIndicator.EXPRESSION_NOT_VALID},
* {@link ProgramIndicator.INVALID_VARIABLES_IN_EXPRESSION}.
*/
String expressionIsValid( String expression );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java 2015-10-13 13:10:18 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java 2015-10-20 08:18:49 +0000
@@ -53,6 +53,7 @@
import org.hisp.dhis.i18n.I18nService;
import org.hisp.dhis.jdbc.StatementBuilder;
import org.hisp.dhis.system.util.DateUtils;
+import org.hisp.dhis.system.util.ValidationUtils;
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -427,7 +428,7 @@
if ( !ExpressionUtils.isValid( expr, null ) )
{
- return ProgramIndicator.EXPRESSION_NOT_WELL_FORMED;
+ return ProgramIndicator.EXPRESSION_NOT_VALID;
}
return ProgramIndicator.VALID;
@@ -478,7 +479,7 @@
if ( programStage != null && dataElement != null )
{
- String sample = dataElement.isNumericType() ? String.valueOf( 1 ) : dataElement.getValueType().isDate() ? "'2000-01-01'" : "'A'";
+ String sample = ValidationUtils.getSubstitutionValue( dataElement.getValueType() );
matcher.appendReplacement( expr, sample );
}
@@ -493,7 +494,7 @@
if ( attribute != null )
{
- String sample = attribute.isNumericType() ? String.valueOf( 1 ) : attribute.isDateType() ? "'2000-01-01'" : "'A'";
+ String sample = ValidationUtils.getSubstitutionValue( attribute.getValueType() );
matcher.appendReplacement( expr, sample );
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties 2015-10-19 19:21:51 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties 2015-10-20 08:18:49 +0000
@@ -658,6 +658,7 @@
waiting=Please wait
invalid_identifiers_in_expression=Invalid identifiers in expression
filter_not_evaluating_to_true_or_false=Filter is not evaluating to true or false
+expression_not_valid = Expression is not valid
locate_by_code=Locate by code
select_at_level=Select at level
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java 2015-10-19 19:37:11 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java 2015-10-20 08:18:49 +0000
@@ -540,7 +540,7 @@
assertEquals( ProgramIndicator.VALID, programIndicatorService.expressionIsValid( indicatorB.getExpression() ) );
assertEquals( ProgramIndicator.VALID, programIndicatorService.expressionIsValid( indicatorA.getExpression() ) );
- assertEquals( ProgramIndicator.EXPRESSION_NOT_WELL_FORMED, programIndicatorService.expressionIsValid( indicatorD.getExpression() ) );
+ assertEquals( ProgramIndicator.EXPRESSION_NOT_VALID, programIndicatorService.expressionIsValid( indicatorD.getExpression() ) );
}
@Test
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java 2015-10-20 07:16:41 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java 2015-10-20 08:18:49 +0000
@@ -467,9 +467,15 @@
return value != null && HEX_COLOR_PATTERN.matcher( value ).matches();
}
+ /**
+ * Returns a string useful for substitution.
+ *
+ * @param valueType the value type.
+ * @return the string.
+ */
public static String getSubstitutionValue( ValueType valueType )
{
- if ( valueType.isNumeric() )
+ if ( valueType.isNumeric() || valueType.isBoolean() )
{
return "1";
}
@@ -479,7 +485,7 @@
}
else
{
- return "A";
+ return "'A'";
}
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/org/hisp/dhis/trackedentity/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/org/hisp/dhis/trackedentity/i18n_module.properties 2015-10-13 15:48:34 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/org/hisp/dhis/trackedentity/i18n_module.properties 2015-10-20 08:18:49 +0000
@@ -491,7 +491,6 @@
date_diff = Date diff
program_stage_sort_order = Program stage sort order
sort_order = Sort order
-expression_is_not_well_formed = Expression is not well-formed
program_variables = Program variables
custom_standard_interval = Custom standard interval
period_type = Period type
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/programIndicator.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/programIndicator.js 2015-10-20 07:16:41 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/programIndicator.js 2015-10-20 08:18:49 +0000
@@ -80,7 +80,7 @@
for( i in json.dataElements ) {
var de = json.dataElements[i];
- if ( !('expression' == type && de.valueType && !dhis2.pi.aggregatableValueTypes.indexOf(de.valueType))) {
+ if ( !('expression' == type && de.valueType && dhis2.pi.aggregatableValueTypes.indexOf(de.valueType) == -1)) {
dataElements.append("<option value='" + json.dataElements[i].id + "' title='" + json.dataElements[i].name +
"' suggested='" + json.dataElements[i].optionset + "'>" + json.dataElements[i].name + "</option>");
}