use of org.openforis.idm.model.expression.ExpressionEvaluator in project collect by openforis.
the class CustomCheck method evaluate.
@Override
public ValidationResultFlag evaluate(Attribute<?, ?> node) {
try {
ExpressionEvaluator expressionEvaluator = node.getSurvey().getContext().getExpressionEvaluator();
boolean valid = expressionEvaluator.evaluateBoolean(node.getParent(), node, getExpression());
return ValidationResultFlag.valueOf(valid, this.getFlag());
} catch (InvalidExpressionException e) {
throw new IdmInterpretationError("Error evaluating custom check", e);
}
}
use of org.openforis.idm.model.expression.ExpressionEvaluator in project collect by openforis.
the class DistanceCheck method evaluateAttributeValueExpression.
private <T extends Object> T evaluateAttributeValueExpression(String expression, CoordinateAttribute thisNode) {
if (expression == null) {
return null;
}
try {
ExpressionEvaluator expressionEvaluator = getExpressionEvaluator(thisNode);
T result = expressionEvaluator.evaluateAttributeValue(thisNode.getParent(), thisNode, thisNode.getDefinition(), 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 UniquenessCheck method evaluate.
@Override
public ValidationResultFlag evaluate(final Attribute<?, ?> attribute) {
try {
SurveyContext recordContext = attribute.getRecord().getSurveyContext();
ExpressionEvaluator expressionEvaluator = recordContext.getExpressionEvaluator();
Node<?> duplicateNode = expressionEvaluator.findNode(attribute.getParent(), attribute, expression, new Predicate<Node<?>>() {
public boolean evaluate(Node<?> node) {
if (node instanceof Attribute && node != attribute) {
Value value = ((Attribute<?, ?>) node).getValue();
if (value != null && value.equals(attribute.getValue())) {
return true;
}
}
return false;
}
});
boolean unique = duplicateNode == null;
return ValidationResultFlag.valueOf(unique, this.getFlag());
} catch (InvalidExpressionException e) {
throw new IdmInterpretationError("Error evaluating uniqueness check", e);
}
}
use of org.openforis.idm.model.expression.ExpressionEvaluator in project collect by openforis.
the class AttributeDefault method evaluateExpression.
private <V extends Value> V evaluateExpression(Attribute<?, V> attrib) throws InvalidExpressionException {
ExpressionEvaluator expressionEvaluator = getExpressionEvaluator(attrib);
V val = expressionEvaluator.evaluateAttributeValue(attrib.getParent(), attrib, attrib.getDefinition(), expression);
return val;
}
use of org.openforis.idm.model.expression.ExpressionEvaluator in project collect by openforis.
the class RecordUpdater method calculateMaxCount.
private int calculateMaxCount(Entity entity, NodeDefinition defn) {
String expression = defn.getMaxCountExpression();
if (!entity.isRelevant(defn) || StringUtils.isBlank(expression)) {
return defn.isMultiple() ? Integer.MAX_VALUE : 1;
}
if (defn.getFixedMaxCount() != null) {
return defn.getFixedMaxCount();
}
try {
SurveyContext surveyContext = defn.getSurvey().getContext();
ExpressionEvaluator expressionEvaluator = surveyContext.getExpressionEvaluator();
Number value = expressionEvaluator.evaluateNumericValue(entity, null, expression);
return value == null ? Integer.MAX_VALUE : value.intValue();
} catch (InvalidExpressionException e) {
throw new IdmInterpretationError("Error evaluating required expression", e);
}
}
Aggregations