Search in sources :

Example 6 with OgnlException

use of ognl.OgnlException in project entando-core by entando.

the class OgnlValidationRule method validate.

public AttributeFieldError validate(AttributeInterface attribute, AttributeTracer tracer, ILangManager langManager) {
    AttributeFieldError error = null;
    String expression = this.getExpression();
    if (null == expression || expression.trim().length() == 0) {
        return null;
    }
    if (this.isEvalExpressionOnValuedAttribute() && attribute.getStatus().equals(AttributeInterface.Status.EMPTY)) {
        return null;
    }
    try {
        Object expr = Ognl.parseExpression(expression);
        OgnlContext ctx = this.createContextForExpressionValidation(attribute, tracer, langManager);
        Boolean value = (Boolean) Ognl.getValue(expr, ctx, attribute, Boolean.class);
        if (!value) {
            error = new AttributeFieldError(attribute, AttributeFieldError.OGNL_VALIDATION, tracer);
            error.setMessage(this.getErrorMessage());
            error.setMessageKey(this.getErrorMessageKey());
        }
    } catch (OgnlException oe) {
        _logger.error("Error on evaluation of expression : {}", expression, oe);
    } catch (Throwable t) {
        _logger.error("Generic Error on evaluation Ognl Expression : {}", expression, t);
        throw new RuntimeException("Generic Error on evaluation Ognl Expression", t);
    }
    return error;
}
Also used : OgnlException(ognl.OgnlException) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError) OgnlContext(ognl.OgnlContext)

Aggregations

OgnlException (ognl.OgnlException)6 OgnlContext (ognl.OgnlContext)3 AttributeFieldError (com.agiletec.aps.system.common.entity.model.AttributeFieldError)1 Rule (com.peterphi.rules.types.Rule)1 RuleSet (com.peterphi.rules.types.RuleSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 ArrayPropertyAccessor (ognl.ArrayPropertyAccessor)1 EnumerationPropertyAccessor (ognl.EnumerationPropertyAccessor)1 IteratorPropertyAccessor (ognl.IteratorPropertyAccessor)1 ListPropertyAccessor (ognl.ListPropertyAccessor)1 MapPropertyAccessor (ognl.MapPropertyAccessor)1 MethodFailedException (ognl.MethodFailedException)1 ObjectPropertyAccessor (ognl.ObjectPropertyAccessor)1 PropertyAccessor (ognl.PropertyAccessor)1 SetPropertyAccessor (ognl.SetPropertyAccessor)1 ExpressionEvaluationException (org.apache.camel.ExpressionEvaluationException)1 KettleConfigException (org.pentaho.di.core.exception.KettleConfigException)1 ExpressionCacheKey (org.thymeleaf.cache.ExpressionCacheKey)1 ICacheManager (org.thymeleaf.cache.ICacheManager)1