use of org.openforis.idm.metamodel.IdmInterpretationError 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.metamodel.IdmInterpretationError 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.metamodel.IdmInterpretationError in project collect by openforis.
the class Check method getMessageWithEvaluatedExpressions.
public String getMessageWithEvaluatedExpressions(Attribute<?, ?> context, String preferredLanguage) {
Survey survey = context.getSurvey();
String message;
if (preferredLanguage == null || survey.isDefaultLanguage(preferredLanguage)) {
message = getMessage(survey.getDefaultLanguage());
} else {
message = getMessageInPreferredLanguage(survey, preferredLanguage);
}
if (StringUtils.isBlank(message)) {
return null;
} else {
try {
StringBuffer sb = new StringBuffer();
Matcher matcher = MESSAGE_NESTED_EXPRESSION_PATTERN.matcher(message);
while (matcher.find()) {
String expr = matcher.group(1);
Object val = getExpressionEvaluator(context).evaluateValue(context.getParent(), context, expr);
String replacement = val == null ? "" : val.toString();
matcher.appendReplacement(sb, replacement);
}
matcher.appendTail(sb);
return sb.toString();
} catch (InvalidExpressionException e) {
throw new IdmInterpretationError("Unable to evaluate condition " + condition, e);
}
}
}
use of org.openforis.idm.metamodel.IdmInterpretationError 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);
}
}
use of org.openforis.idm.metamodel.IdmInterpretationError in project collect by openforis.
the class RecordUpdater method calculateMinCount.
private int calculateMinCount(Entity entity, NodeDefinition defn) {
String expression = defn.getMinCountExpression();
if (!entity.isRelevant(defn) || StringUtils.isBlank(expression)) {
return 0;
}
if (defn.getFixedMinCount() != null) {
return defn.getFixedMinCount();
}
try {
SurveyContext surveyContext = defn.getSurvey().getContext();
ExpressionEvaluator expressionEvaluator = surveyContext.getExpressionEvaluator();
Number value = expressionEvaluator.evaluateNumericValue(entity, null, expression);
return value == null ? 0 : value.intValue();
} catch (InvalidExpressionException e) {
throw new IdmInterpretationError("Error evaluating required expression", e);
}
}
Aggregations