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;
}
Aggregations