use of org.hisp.dhis.parser.expression.CommonExpressionVisitor in project dhis2-core by dhis2.
the class DefaultExpressionService method getExpressionValue.
// -------------------------------------------------------------------------
// Compute the value of the expression
// -------------------------------------------------------------------------
@Override
public Object getExpressionValue(ExpressionParams params) {
if (isEmpty(params.getExpression())) {
return null;
}
CommonExpressionVisitor visitor = newVisitor(ITEM_EVALUATE, params);
Object value = visit(params.getExpression(), params.getDataType(), visitor, true);
ExpressionState state = visitor.getState();
int itemsFound = state.getItemsFound();
int itemValuesFound = state.getItemValuesFound();
if (state.isUnprotectedNullDateFound()) {
return null;
}
switch(params.getMissingValueStrategy()) {
case SKIP_IF_ANY_VALUE_MISSING:
if (itemValuesFound < itemsFound) {
return null;
}
case SKIP_IF_ALL_VALUES_MISSING:
if (itemsFound != 0 && itemValuesFound == 0) {
return null;
}
case NEVER_SKIP:
if (value == null) {
switch(params.getDataType()) {
case NUMERIC:
return 0d;
case BOOLEAN:
return FALSE;
case TEXT:
return "";
}
}
}
return value;
}
use of org.hisp.dhis.parser.expression.CommonExpressionVisitor in project dhis2-core by dhis2.
the class DefaultProgramIndicatorService method validate.
@Override
@Transactional(readOnly = true)
public void validate(String expression, Class<?> clazz, Map<String, String> itemDescriptions) {
CommonExpressionVisitor visitor = newVisitor(ITEM_GET_DESCRIPTIONS, null);
castClass(clazz, Parser.visit(expression, visitor));
itemDescriptions.putAll(visitor.getItemDescriptions());
}
Aggregations