use of org.openforis.idm.metamodel.SurveyContext 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.metamodel.SurveyContext in project collect by openforis.
the class Check method getExpressionEvaluator.
private ExpressionEvaluator getExpressionEvaluator(Attribute<?, ?> context) {
Record record = context.getRecord();
SurveyContext surveyContext = record.getSurveyContext();
ExpressionEvaluator evaluator = surveyContext.getExpressionEvaluator();
return evaluator;
}
use of org.openforis.idm.metamodel.SurveyContext 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.metamodel.SurveyContext 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;
}
}
use of org.openforis.idm.metamodel.SurveyContext in project collect by openforis.
the class AbstractTest method createTestSurvey.
protected static Survey createTestSurvey() throws IdmlParseException {
InputStream is = AbstractTest.class.getClassLoader().getResourceAsStream("test.idm.xml");
SurveyContext surveyContext = new TestSurveyContext();
SurveyIdmlBinder parser = new SurveyIdmlBinder(surveyContext);
Survey survey = parser.unmarshal(is);
return survey;
}
Aggregations