use of org.openforis.idm.model.expression.InvalidExpressionException in project collect by openforis.
the class XPathDataQueryEvaluator method evaluate.
@Override
public List<Node<?>> evaluate(CollectRecord record) {
List<Node<?>> result = new ArrayList<Node<?>>();
String condition = query.getConditions();
AttributeDefinition attrDef = query.getAttributeDefinition();
SurveyContext surveyContext = record.getSurveyContext();
ExpressionEvaluator expressionEvaluator = surveyContext.getExpressionEvaluator();
List<Node<?>> nodes = record.findNodesByPath(attrDef.getPath());
for (Node<?> node : nodes) {
try {
if (expressionEvaluator.evaluateBoolean(node.getParent(), node, condition)) {
result.add(node);
}
} catch (InvalidExpressionException e) {
throw new RuntimeException(e);
}
}
return result;
}
use of org.openforis.idm.model.expression.InvalidExpressionException 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.InvalidExpressionException 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.InvalidExpressionException 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.InvalidExpressionException in project collect by openforis.
the class RecordUpdater method recalculateValue.
private Value recalculateValue(Attribute<?, ?> attribute) {
try {
AttributeDefinition defn = attribute.getDefinition();
List<AttributeDefault> attributeDefaults = defn.getAttributeDefaults();
for (AttributeDefault attributeDefault : attributeDefaults) {
if (attributeDefault.evaluateCondition(attribute)) {
Value value = attributeDefault.evaluate(attribute);
return value;
}
}
return null;
} catch (InvalidExpressionException e) {
throw new IllegalStateException(String.format("Invalid expression for calculated attribute %s", attribute.getPath()));
}
}
Aggregations