Search in sources :

Example 11 with ExpressionEvaluator

use of org.openforis.idm.model.expression.ExpressionEvaluator 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 12 with ExpressionEvaluator

use of org.openforis.idm.model.expression.ExpressionEvaluator 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;
    }
}
Also used : CoordinateOperations(org.openforis.idm.geospatial.CoordinateOperations) InvalidExpressionException(org.openforis.idm.model.expression.InvalidExpressionException) ExpressionEvaluator(org.openforis.idm.model.expression.ExpressionEvaluator)

Example 13 with ExpressionEvaluator

use of org.openforis.idm.model.expression.ExpressionEvaluator 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;
    }
}
Also used : InvalidExpressionException(org.openforis.idm.model.expression.InvalidExpressionException) ExpressionEvaluator(org.openforis.idm.model.expression.ExpressionEvaluator)

Example 14 with ExpressionEvaluator

use of org.openforis.idm.model.expression.ExpressionEvaluator 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)

Aggregations

ExpressionEvaluator (org.openforis.idm.model.expression.ExpressionEvaluator)14 InvalidExpressionException (org.openforis.idm.model.expression.InvalidExpressionException)10 SurveyContext (org.openforis.idm.metamodel.SurveyContext)9 IdmInterpretationError (org.openforis.idm.metamodel.IdmInterpretationError)5 Node (org.openforis.idm.model.Node)3 Record (org.openforis.idm.model.Record)3 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)2 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)2 Survey (org.openforis.idm.metamodel.Survey)2 Entity (org.openforis.idm.model.Entity)2 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 CodeListImportException (org.openforis.collect.io.exception.CodeListImportException)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 CoordinateOperations (org.openforis.idm.geospatial.CoordinateOperations)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1 Schema (org.openforis.idm.metamodel.Schema)1 IdmlParseException (org.openforis.idm.metamodel.xml.IdmlParseException)1 Attribute (org.openforis.idm.model.Attribute)1 CodeAttribute (org.openforis.idm.model.CodeAttribute)1