use of ognl.MethodFailedException in project stdlib by petergeneric.
the class RulesEngineImpl method run.
@Override
public void run(final Rules rules, boolean ignoreMethodErrors) throws OgnlException {
Map<String, Object> vars = prepare(rules);
for (RuleSet rs : rules.ruleSets) {
try {
log.debug("Assessing input for ruleset : " + rs.id);
OgnlContext rsContext = createContext(vars);
rs.runInput(rsContext);
for (Rule rule : rs.rules) {
if (StringUtils.isEmpty(rule.id)) {
throw new IllegalArgumentException("Rule with condition " + rule.condition + " has no id!");
}
final RuleProcessTask task = new RuleProcessTask(this, rs, rule, rsContext);
synchronized (activeTasks) {
// if not currently being processed
if (!activeTasks.containsKey(rule.id)) {
try {
activeTasks.put(rule.id, task);
task.submit(executorService);
} catch (Exception e) {
log.error("Error submitting rule for execution ", e);
activeTasks.remove(rule.id);
}
}
}
}
} catch (MethodFailedException mfe) {
if (!ignoreMethodErrors) {
throw mfe;
}
log.warn("Method failed for ruleset " + rs.id, mfe);
}
}
}
use of ognl.MethodFailedException in project stdlib by petergeneric.
the class RulesEngineImpl method matching.
/**
* returns a list of the rules that match from the supplied Rules document
*
* @param rules
*
* @return
*/
@Override
public Map<RuleSet, List<Rule>> matching(Rules rules, Map<String, Object> vars, boolean ignoreMethodErrors) throws OgnlException {
Map<RuleSet, List<Rule>> ret = new HashMap<>();
for (RuleSet ruleSet : rules.ruleSets) {
try {
OgnlContext context = createContext(vars);
List<Rule> matching = match(ruleSet, context);
if (!matching.isEmpty()) {
ret.put(ruleSet, matching);
}
} catch (MethodFailedException mfe) {
if (!ignoreMethodErrors) {
throw mfe;
}
log.warn("Method failed for ruleset " + ruleSet.id, mfe);
}
}
return ret;
}
Aggregations