Search in sources :

Example 1 with OgnlCommand

use of com.peterphi.rules.types.OgnlCommand in project stdlib by petergeneric.

the class RulesEngineImpl method validateSyntax.

@Override
public Map<String, String> validateSyntax(final Rules rules) {
    Map<String, String> results = new HashMap<>();
    Set<String> knownIds = new HashSet<>();
    for (RuleSet ruleSet : rules.ruleSets) {
        if (knownIds.contains(ruleSet.id)) {
            throw new IllegalArgumentException("Duplicate id " + ruleSet.id);
        }
        for (OgnlCommand command : ruleSet.input.commands) {
            validate(ruleSet.id + " - input", command, results);
        }
        for (Rule rule : ruleSet.rules) {
            if (StringUtils.isEmpty(rule.id)) {
                throw new IllegalArgumentException("Rule with condition " + rule.condition + " has no id!");
            }
            if (knownIds.contains(rule.id)) {
                throw new IllegalArgumentException("Duplicate id " + rule.id);
            }
            validate(rule.id + " condition", rule.condition, results);
            for (OgnlCommand command : rule.commands) {
                validate(rule.id, command, results);
            }
        }
    }
    return results;
}
Also used : RuleSet(com.peterphi.rules.types.RuleSet) OgnlCommand(com.peterphi.rules.types.OgnlCommand) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Rule(com.peterphi.rules.types.Rule) HashSet(java.util.HashSet)

Aggregations

OgnlCommand (com.peterphi.rules.types.OgnlCommand)1 Rule (com.peterphi.rules.types.Rule)1 RuleSet (com.peterphi.rules.types.RuleSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1