use of org.openforis.idm.model.expression.ExpressionEvaluator in project collect by openforis.
the class ComparisonCheck method evaluate.
@Override
public ValidationResultFlag evaluate(Attribute<?, ?> node) {
Record record = node.getRecord();
SurveyContext recordContext = record.getSurveyContext();
ExpressionEvaluator expressionEvaluator = recordContext.getExpressionEvaluator();
String expr = getExpression();
try {
boolean valid = expressionEvaluator.evaluateBoolean(node.getParent(), node, expr, true);
return ValidationResultFlag.valueOf(valid, this.getFlag());
} catch (InvalidExpressionException e) {
throw new IdmInterpretationError("Error evaluating comparison check", e);
}
}
use of org.openforis.idm.model.expression.ExpressionEvaluator in project collect by openforis.
the class DistanceCheck method evaluate.
@Override
public ValidationResultFlag evaluate(CoordinateAttribute coordinateAttr) {
CoordinateOperations coordinateOperations = getCoordinateOperations(coordinateAttr);
if (coordinateOperations == null) {
return ValidationResultFlag.OK;
}
try {
ExpressionEvaluator expressionEvaluator = getExpressionEvaluator(coordinateAttr);
boolean valid = expressionEvaluator.evaluateBoolean(coordinateAttr.getParent(), coordinateAttr, getExpression());
return ValidationResultFlag.valueOf(valid, this.getFlag());
} catch (InvalidExpressionException e) {
if (LOG.isInfoEnabled()) {
LOG.info("Unable to evaluate distance check ", e);
}
return ValidationResultFlag.OK;
}
}
use of org.openforis.idm.model.expression.ExpressionEvaluator in project collect by openforis.
the class DistanceCheck method evaluateValueExpression.
private <T extends Object> T evaluateValueExpression(String expression, CoordinateAttribute thisNode) {
if (expression == null) {
return null;
}
try {
ExpressionEvaluator expressionEvaluator = getExpressionEvaluator(thisNode);
@SuppressWarnings("unchecked") T result = (T) expressionEvaluator.evaluateValue(thisNode.getParent(), thisNode, expression);
return result;
} catch (InvalidExpressionException e) {
if (LOG.isWarnEnabled()) {
LOG.warn(String.format("[survey %s: coordinate attribute: %s] Unable to evaluate expression %s" + thisNode.getSurvey().getName(), thisNode.getPath(), expression), e);
}
return null;
}
}
use of org.openforis.idm.model.expression.ExpressionEvaluator in project collect by openforis.
the class CodeListManager method getCodeParent.
protected CodeAttribute getCodeParent(Entity context, CodeAttributeDefinition def) {
try {
Survey survey = context.getSurvey();
SurveyContext surveyContext = survey.getContext();
ExpressionEvaluator expressionEvaluator = surveyContext.getExpressionEvaluator();
String parentExpr = def.getParentExpression();
Node<?> parentNode = expressionEvaluator.evaluateNode(context, null, parentExpr);
if (parentNode != null && parentNode instanceof CodeAttribute) {
return (CodeAttribute) parentNode;
} else {
return null;
}
} catch (Exception e) {
return null;
}
}
Aggregations