-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ActivationRuleGroup implementation #122
Comments
Hi, This is indeed an interesting use case. Another user asked for a custom composite rule (see #108). The issue is that I'm not sure these custom implementations should provided out of the box. Not even the current There are a lot of custom use cases for a "composite" rule:
I am not sure we should end up with all of them inside the library. Do you see?
This is related to #107 . I don't exclude adding this feature to easy rules. |
@benas: I agree that CompositeRule has varied use cases and having it in core library limits the users to create their on set of conditions on composite rule. Instead i would suggest to have a RuleGroup feature. Each Rule can belong to one or many RuleGroup. Each RuleGroup can have its own condition to operate upon. By default each Rule belongs to a default group and it executed on firing rules of default group. For example RuleGroup : Avengers RuleGroup Avengers Condition : (BlackPanther||Wasp) && IronMan && Thor && Hulk So each user can form its own set of CompositeRules with different conditions. Let me know what you think about it. |
@benas Thanks for the feedback I have been thinking about this quite extensively since I wrote the question. I've used the current CompositeRule Implementation to create the use case I mentioned, which works pretty well. The only issue I had was that I wanted to know which Rule's actually fired - so I added the names of the Triggered Rule's to a list which I then compared in the evaluate method. (I can provide a code snippet if my explanation is not clear) With regards to a negation rule, wrapping a rule or composite rule in which returns the opposite boolean value is incredibly easy to implement so that is probably unnecessary as well. (Again, I can provide a code snippet need be) As another note - I am using this lib with Kotlin - so creating a wrapper class whereby you pass the rule in as a function makes the change even more simple. |
Well, it is not that limiting, the composite rule is just 4 lines of code for the condition and 4 lines for the action 😄 One can always write another rule with custom behaviour. The point is that since I've added it to the core library, everyone now would like the to add its own variant to the core. If it was outside the library as an example, no one would do it.
good idea, a bit like drools activation group. I might consider adding it to the library but for next major release (not minor ones). |
I think a
Yes, as said in #107, I was not aware some rules engines would provide it (like IBM ODM). Drools on the other hand does not provide an 'else' statement. And I much tend to agree with Drools on this, because production systems are not designed to have an 'else' part.
Oh cool! I'm a kotlin newbie but I would love to see an example. |
Can you provide the implementation of your composite rule with 'any' semantics? May be we can make the current one configurable with the strategy (all/any)? |
Hi All, I think I found a good tradeoff to all your great suggestions! I will create a new module called
The naming I really like how we are brainstorming all these ideas and I would like to thank you upfront. Please let me know what do you think! Kr |
@benas I think the An example class written in Kotlin which allows someone to just define a function could look something like this:
Example Rule Creation
This is obviously very simplistic and you can set the priority, description and name via passing in values as one might need. In order to negate the rule, or rather make the rule execute on false rather than true a simple change could be made by changing Lastly, an example of how I created a 'composite rule' that executes all the rules that fire is as follows (I will just include the
This is also in Kotlin but it would work similarly in Java. |
Cool, I started the work in the easy-rules-support branch:
With this preparatory work, we can move forward and add other subclasses of
With theses planned additions, the |
The
@SeanSWatkins Are you willing to contribute the |
This has been planned for v3.3. I'm releasing v3.2 with the new module + |
I finally managed to get this done in v3.2 which is now released (see here). |
Hey everyone
Currently, composite rules work only if all the rules return true.
Is modifying this behaviour outside of the scope of easy-rules? I'd just like to know, if it is something that would be of interest, I would love to contribute.
My use case is such that I am using the easy-rules for form field validations (which is work beautifully for). The only issue I have is that I would like composite rules to fire is any of the internal rules return true vs all of them.
It might also be an interesting idea to allow the action to be fired on the reverse of a rule fire (i.e. allow a negative return to trigger the action - but perhaps this is for another issue)
The text was updated successfully, but these errors were encountered: