Search in sources :

Example 21 with SurveyContext

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;
}
Also used : InvalidExpressionException(org.openforis.idm.model.expression.InvalidExpressionException) Node(org.openforis.idm.model.Node) ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) ExpressionEvaluator(org.openforis.idm.model.expression.ExpressionEvaluator) SurveyContext(org.openforis.idm.metamodel.SurveyContext)

Example 22 with SurveyContext

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;
}
Also used : Record(org.openforis.idm.model.Record) ExpressionEvaluator(org.openforis.idm.model.expression.ExpressionEvaluator) SurveyContext(org.openforis.idm.metamodel.SurveyContext)

Example 23 with SurveyContext

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);
    }
}
Also used : IdmInterpretationError(org.openforis.idm.metamodel.IdmInterpretationError) InvalidExpressionException(org.openforis.idm.model.expression.InvalidExpressionException) Record(org.openforis.idm.model.Record) ExpressionEvaluator(org.openforis.idm.model.expression.ExpressionEvaluator) SurveyContext(org.openforis.idm.metamodel.SurveyContext)

Example 24 with SurveyContext

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;
    }
}
Also used : Survey(org.openforis.idm.metamodel.Survey) CollectSurvey(org.openforis.collect.model.CollectSurvey) CodeAttribute(org.openforis.idm.model.CodeAttribute) ExpressionEvaluator(org.openforis.idm.model.expression.ExpressionEvaluator) SurveyContext(org.openforis.idm.metamodel.SurveyContext) CodeListImportException(org.openforis.collect.io.exception.CodeListImportException) IdmlParseException(org.openforis.idm.metamodel.xml.IdmlParseException) FileNotFoundException(java.io.FileNotFoundException)

Example 25 with SurveyContext

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;
}
Also used : Survey(org.openforis.idm.metamodel.Survey) InputStream(java.io.InputStream) TestSurveyContext(org.openforis.idm.model.TestSurveyContext) SurveyIdmlBinder(org.openforis.idm.metamodel.xml.SurveyIdmlBinder) SurveyContext(org.openforis.idm.metamodel.SurveyContext) TestSurveyContext(org.openforis.idm.model.TestSurveyContext)

Aggregations

SurveyContext (org.openforis.idm.metamodel.SurveyContext)26 ExpressionEvaluator (org.openforis.idm.model.expression.ExpressionEvaluator)9 Survey (org.openforis.idm.metamodel.Survey)8 CodeListService (org.openforis.idm.metamodel.CodeListService)6 InvalidExpressionException (org.openforis.idm.model.expression.InvalidExpressionException)6 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)5 CollectSurvey (org.openforis.collect.model.CollectSurvey)4 IdmInterpretationError (org.openforis.idm.metamodel.IdmInterpretationError)4 Schema (org.openforis.idm.metamodel.Schema)4 Record (org.openforis.idm.model.Record)4 ArrayList (java.util.ArrayList)3 SurveyIdmlBinder (org.openforis.idm.metamodel.xml.SurveyIdmlBinder)3 Node (org.openforis.idm.model.Node)3 InputStream (java.io.InputStream)2 AttributeDefault (org.openforis.idm.metamodel.AttributeDefault)2 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)2 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)2 CodeListItem (org.openforis.idm.metamodel.CodeListItem)2 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)2 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)2