Search in sources :

Example 1 with ExpressionValidator

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

the class PatternCheckFormValidator method validateExpression.

private boolean validateExpression(ValidationContext ctx) {
    if (!validateRequired(ctx, REGULAR_EXPRESSION_FIELD)) {
        return false;
    }
    ExpressionValidator expressionValidator = getExpressionValidator(ctx);
    String expression = getValue(ctx, REGULAR_EXPRESSION_FIELD);
    ExpressionValidationResult result = expressionValidator.validateRegularExpression(expression);
    if (result.isError()) {
        String message = Strings.firstNotBlank(result.getDetailedMessage(), result.getMessage());
        addInvalidMessage(ctx, REGULAR_EXPRESSION_FIELD, getMessage(INVALID_EXPRESSION_MESSAGE_KEY, message));
        return false;
    }
    return true;
}
Also used : ExpressionValidator(org.openforis.idm.metamodel.expression.ExpressionValidator) ExpressionValidationResult(org.openforis.idm.metamodel.expression.ExpressionValidator.ExpressionValidationResult)

Example 2 with ExpressionValidator

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

the class UniquenessCheckFormValidator method validateExpression.

private boolean validateExpression(ValidationContext ctx) {
    if (validateRequired(ctx, EXPRESSION_FIELD)) {
        ExpressionValidator expressionValidator = getExpressionValidator(ctx);
        NodeDefinition contextNode = getContextNode(ctx);
        String expression = getValue(ctx, EXPRESSION_FIELD);
        ExpressionValidationResult result = expressionValidator.validateUniquenessExpression(contextNode.getParentDefinition(), contextNode, expression);
        if (result.isError()) {
            String message = Strings.firstNotBlank(result.getDetailedMessage(), result.getMessage());
            addInvalidMessage(ctx, EXPRESSION_FIELD, getMessage(INVALID_EXPRESSION_MESSAGE_KEY, message));
            return false;
        }
    }
    return true;
}
Also used : NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) ExpressionValidator(org.openforis.idm.metamodel.expression.ExpressionValidator) ExpressionValidationResult(org.openforis.idm.metamodel.expression.ExpressionValidator.ExpressionValidationResult)

Example 3 with ExpressionValidator

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

Aggregations

ExpressionValidator (org.openforis.idm.metamodel.expression.ExpressionValidator)3 ExpressionValidationResult (org.openforis.idm.metamodel.expression.ExpressionValidator.ExpressionValidationResult)3 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)1