@Override protected Collection<ValidationResult> customValidate(final ValidationContext context) { final List<ValidationResult> reasons = new ArrayList<>(super.customValidate(context)); Criteria criteria = null; try { criteria = CriteriaSerDe.deserialize(context.getAnnotationData()); } catch (IllegalArgumentException iae) { reasons.add( new ValidationResult.Builder() .valid(false) .explanation("Unable to deserialize the update criteria." + iae.getMessage()) .build()); } // if there is criteria, validate it if (criteria != null) { final List<Rule> rules = criteria.getRules(); if (rules == null) { reasons.add( new ValidationResult.Builder() .valid(false) .explanation("Update criteria has been specified by no rules were found.") .build()); } else { // validate the each rule for (final Rule rule : rules) { if (rule.getName() == null || rule.getName().trim().isEmpty()) { reasons.add( new ValidationResult.Builder() .valid(false) .explanation("A rule name was not specified.") .build()); } // validate each condition final Set<Condition> conditions = rule.getConditions(); if (conditions == null) { reasons.add( new ValidationResult.Builder() .valid(false) .explanation( String.format("No conditions for rule '%s' found.", rule.getName())) .build()); } else { for (final Condition condition : conditions) { if (condition.getExpression() == null) { reasons.add( new ValidationResult.Builder() .valid(false) .explanation( String.format( "No expression for a condition in rule '%s' was found.", rule.getName())) .build()); } else { final String expression = condition.getExpression().trim(); reasons.add( StandardValidators.createAttributeExpressionLanguageValidator( AttributeExpression.ResultType.BOOLEAN, false) .validate( String.format("Condition for rule '%s'.", rule.getName()), expression, context)); } } } // validate each action final Set<Action> actions = rule.getActions(); if (actions == null) { reasons.add( new ValidationResult.Builder() .valid(false) .explanation(String.format("No actions for rule '%s' found.", rule.getName())) .build()); } else { for (final Action action : actions) { if (action.getAttribute() == null) { reasons.add( new ValidationResult.Builder() .valid(false) .explanation( String.format( "An action in rule '%s' is missing the attribute name.", rule.getName())) .build()); } else if (action.getValue() == null) { reasons.add( new ValidationResult.Builder() .valid(false) .explanation( String.format( "No value for attribute '%s' in rule '%s' was found.", action.getAttribute(), rule.getName())) .build()); } else { reasons.add( StandardValidators.createAttributeExpressionLanguageValidator( AttributeExpression.ResultType.STRING, true) .validate( String.format("Action for rule '%s'.", rule.getName()), action.getValue(), context)); } } } } } } return reasons; }