deliveredtechnologies / rulebook

100% Java, Lambda Enabled, Lightweight Rules Engine with a Simple and Intuitive DSL
http://www.deliveredtechnologies.com
Apache License 2.0
716 stars 124 forks source link

Auditor not set on rules when RuleBookBuilder.create(Class) is used #202

Open danielmustafa opened 3 years ago

danielmustafa commented 3 years ago

Suppose I have a class

public class MyRuleBook extends CoRRuleBook {

    // some named rules here

}

And I want to reference that class in the RuleBookBuilder process:

RuleBookBuilder.create(MyRuleBook.class).asAuditor().build();

When I use the above statement, the rules inside of MyRuleBook do not get the Auditor value injected. So when I try to run the rules set I get an NPE in AuditableRule#invoke (Line 100) because it tries to update the RuleStatus but has no Auditor instance to update.

If I try to build a RuleBook using the RuleBookBuilder and use the addRule chained approach as described in the documentation, it works. Is this Auditor not available when we try to create a rulebook using a specific RuleBook class?

danielmustafa commented 3 years ago

Looking a bit deeper, I believe this is due to the fact that my class rulebook is extending CoRRuleBook, so when the rules are lazily added to the rulebook it is executing the CoRRuleBook#addRule instead of RuleBookAuditor#addRule. However my custom Rulebook does get decorated with RuleBookAuditor like I expect.

rocnwall commented 2 years ago

I have the same problem and I couldn't fix it. Did you find a way to solve it ?