Search in sources :

Example 6 with ExpressionValidationResult

use of org.openforis.idm.metamodel.expression.ExpressionValidator.ExpressionValidationResult in project collect by openforis.

the class FormValidator method validateExpression.

protected boolean validateExpression(ValidationContext ctx, ExpressionType type, String field, NodeDefinition contextNodeDef, NodeDefinition thisNodeDef, String epression) {
    if (StringUtils.isNotBlank(epression)) {
        ExpressionValidator expressionValidator = getExpressionValidator(ctx);
        ExpressionValidationResult result = expressionValidator.validateExpression(type, contextNodeDef, thisNodeDef, epression);
        if (result.isError()) {
            addInvalidMessage(ctx, field, generateErrorMessageLabel(result, INVALID_EXPRESSION_MESSAGE_KEY));
            return false;
        }
        ExpressionValidationResult circularReferenceValidationResult = expressionValidator.validateCircularReferenceAbsence(contextNodeDef, thisNodeDef, epression);
        if (circularReferenceValidationResult.isError()) {
            addInvalidMessage(ctx, field, generateErrorMessageLabel(circularReferenceValidationResult, CIRCULAR_REFERENCE_IN_EXPRESSION_MESSAGE_KEY));
            return false;
        }
    }
    return true;
}
Also used : ExpressionValidator(org.openforis.idm.metamodel.expression.ExpressionValidator) ExpressionValidationResult(org.openforis.idm.metamodel.expression.ExpressionValidator.ExpressionValidationResult)

Example 7 with ExpressionValidationResult

use of org.openforis.idm.metamodel.expression.ExpressionValidator.ExpressionValidationResult in project collect by openforis.

the class ModelJXPathCompiledExpression method validateOperations.

private ExpressionValidationResult validateOperations(OperationVaildator operationValidator) {
    Deque<Expression> stack = new LinkedList<Expression>();
    stack.push(getExpression());
    while (!stack.isEmpty()) {
        Expression expression = stack.pop();
        if (expression instanceof Operation) {
            Operation op = (Operation) expression;
            ExpressionValidationResult result = operationValidator.validate(op);
            if (result.isError()) {
                return result;
            } else {
                Expression[] args = op.getArguments();
                if (args != null) {
                    stack.addAll(Arrays.asList(args));
                }
            }
        }
    }
    return new ExpressionValidationResult();
}
Also used : JXPathCompiledExpression(org.apache.commons.jxpath.ri.JXPathCompiledExpression) Expression(org.apache.commons.jxpath.ri.compiler.Expression) Operation(org.apache.commons.jxpath.ri.compiler.Operation) ExpressionValidationResult(org.openforis.idm.metamodel.expression.ExpressionValidator.ExpressionValidationResult) LinkedList(java.util.LinkedList)

Aggregations

ExpressionValidationResult (org.openforis.idm.metamodel.expression.ExpressionValidator.ExpressionValidationResult)7 ExpressionValidator (org.openforis.idm.metamodel.expression.ExpressionValidator)3 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 JXPathCompiledExpression (org.apache.commons.jxpath.ri.JXPathCompiledExpression)1 Expression (org.apache.commons.jxpath.ri.compiler.Expression)1 Operation (org.apache.commons.jxpath.ri.compiler.Operation)1 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)1 ComparisonCheck (org.openforis.idm.metamodel.validation.ComparisonCheck)1 CustomCheck (org.openforis.idm.metamodel.validation.CustomCheck)1 DistanceCheck (org.openforis.idm.metamodel.validation.DistanceCheck)1 PatternCheck (org.openforis.idm.metamodel.validation.PatternCheck)1 UniquenessCheck (org.openforis.idm.metamodel.validation.UniquenessCheck)1