add facts in afterEvaluate method of RuleListener

pull/81/head
Mahmoud Ben Hassine 8 years ago
parent bf4b4020af
commit bee726af87

@ -43,15 +43,16 @@ public interface RuleListener {
* Triggered after the evaluation of a rule.
*
* @param rule that has been evaluated
* @param facts known after evaluating the rule
* @param evaluationResult true if the rule evaluated to true, false otherwise
*/
void afterEvaluate(Rule rule, boolean evaluationResult);
void afterEvaluate(Rule rule, Facts facts, boolean evaluationResult);
/**
* Triggered before the execution of a rule.
*
* @param rule the current rule
* @param rule known before executing the rule
* @param facts known facts before executing the rule
*/
void beforeExecute(Rule rule, Facts facts);
@ -59,7 +60,7 @@ public interface RuleListener {
* Triggered after a rule has been executed successfully.
*
* @param rule the current rule
* @param facts known after executing the rule
* @param facts known facts after executing the rule
*/
void onSuccess(Rule rule, Facts facts);
@ -67,9 +68,9 @@ public interface RuleListener {
* Triggered after a rule has failed.
*
* @param rule the current rule
* @param facts known facts after executing the rule
* @param exception the exception thrown when attempting to execute the rule
* @param facts known after executing the rule
*/
void onFailure(Rule rule, Exception exception, Facts facts);
void onFailure(Rule rule, Facts facts, Exception exception);
}

@ -127,7 +127,7 @@ public final class DefaultRulesEngine implements RulesEngine {
}
if (rule.evaluate(facts)) {
LOGGER.log(Level.INFO, "Rule ''{0}'' triggered", name);
triggerListenersAfterEvaluate(rule, true);
triggerListenersAfterEvaluate(rule, facts, true);
try {
triggerListenersBeforeExecute(rule, facts);
rule.execute(facts);
@ -148,7 +148,7 @@ public final class DefaultRulesEngine implements RulesEngine {
}
} else {
LOGGER.log(Level.INFO, "Rule ''{0}'' has been evaluated to false, it has not been executed", name);
triggerListenersAfterEvaluate(rule, false);
triggerListenersAfterEvaluate(rule, facts, false);
if (parameters.isSkipOnFirstNonTriggeredRule()) {
LOGGER.info("Next rules will be skipped since parameter skipOnFirstNonTriggeredRule is set");
break;
@ -161,7 +161,7 @@ public final class DefaultRulesEngine implements RulesEngine {
private void triggerListenersOnFailure(final Rule rule, final Exception exception, Facts facts) {
for (RuleListener ruleListener : ruleListeners) {
ruleListener.onFailure(rule, exception, facts);
ruleListener.onFailure(rule, facts, exception);
}
}
@ -186,9 +186,9 @@ public final class DefaultRulesEngine implements RulesEngine {
return true;
}
private void triggerListenersAfterEvaluate(Rule rule, boolean evaluationResult) {
private void triggerListenersAfterEvaluate(Rule rule, Facts facts, boolean evaluationResult) {
for (RuleListener ruleListener : ruleListeners) {
ruleListener.afterEvaluate(rule, evaluationResult);
ruleListener.afterEvaluate(rule, facts, evaluationResult);
}
}

@ -82,8 +82,8 @@ public class RuleListenerTest extends AbstractTest {
InOrder inOrder = inOrder(rule1, fact1, fact2, ruleListener1, ruleListener2);
inOrder.verify(ruleListener1).beforeExecute(rule1, facts);
inOrder.verify(ruleListener2).beforeExecute(rule1, facts);
inOrder.verify(ruleListener1).onFailure(rule1, exception, facts);
inOrder.verify(ruleListener2).onFailure(rule1, exception, facts);
inOrder.verify(ruleListener1).onFailure(rule1, facts, exception);
inOrder.verify(ruleListener2).onFailure(rule1, facts, exception);
}
@ -135,7 +135,7 @@ public class RuleListenerTest extends AbstractTest {
rulesEngine.fire(rules, facts);
// Then
verify(ruleListener1).afterEvaluate(rule1, true);
verify(ruleListener1).afterEvaluate(rule1, facts, true);
}
@Test
@ -152,7 +152,7 @@ public class RuleListenerTest extends AbstractTest {
rulesEngine.fire(rules, facts);
// Then
verify(ruleListener1).afterEvaluate(rule1, false);
verify(ruleListener1).afterEvaluate(rule1, facts, false);
}
}

Loading…
Cancel
Save