Comments (10)
Hi, and thanks for the fast response :)
I had already started implementing it storing stuff in the "facts", and it's working correctly. Auditing would be great, if it comes I will probably change the way I run my rules.
Thanks again, and kudos for the great lib :)
from rulebook.
Your concern is actually addressed in Issue #38.
But to answer your question... No, 'else' is not available for a rule. The decision not to allow for rules firing on 'else' was intentional. The idea being that each rule is an independent action that executes given some specific state. There was also a concern that building out if/then/else logic could lead to nesting rules and basically creating the exact kind of conditional branching chain complexity that rules are intended to address.
Still, there are some approaches you 'could' use.
-
Change your way of thinking [slightly]. Make every rule simply an action that executes based on some required or expected state. I think you'll find thinking this way about rules greatly simplifies the organization and maintenance of rules.
-
Use a Fact to store stuff that doesn't make it to the 'then' logic. It's not elegant, but you can do this, even in the 'when' statement.
-
Have a rule that fires on negative logic. Again, this is not elegant. But it is one way to achieve what you are trying to do.
Auditing is coming that should address your need - allow you to determine which rules fired and which ones didn't. But there are some other things on deck before it - I've got to put a bow on thread safety for POJO rules and my time commitments at work have increased a bit, which takes some time away from RuleBook.
from rulebook.
@LvelezH auditing is currently available in 0.9-SNAPSHOT. Auditing will allow you to determine which rules were run, and which rules were not run. Here's a link that explains how you can use the snapshot repository in your project: https://github.com/rulebook-rules/rulebook/wiki/Download-and-Install.
from rulebook.
The plan is to have 0.9 released to Maven central within the next week or two. For an explanation on how to enable and use auditing, check out the README in this branch: https://github.com/rulebook-rules/rulebook/tree/Issue38_RulesAudit
from rulebook.
The current snapshot 0.9-SNAPSHOT is released to the sonatype snapshot repo. Assuming no issues, this snapshot release will become the 0.9 release in Maven Central shortly. It will contain rules auditing.
from rulebook.
After further consideration, I think adding "orElse" to the DSL might be a good idea. The "orElse" could create a rule action based on the negative condition. This would still make each rule an independent assertion.
As far as POJO Rules are concerned, I don't think an orElse is either needed, nor would it be a good idea - it would just make things more complicated and messy, IMO.
from rulebook.
@Clayton7510
Any example for OrElse in DSL? I am planning to create child of GoldenRule Class and have custom ELSE method which will be called when the condition returns true. I am not sure if that will be better approach. As you are pretty familiar with the code, can you suggest?
Thanks
from rulebook.
I think first, have it work in the Rules - add it to the interface and put the functionality in GoldenRule so that when the "when" condition was not true, an OrElse action would fire. Then, the DSL could be modified to streamline building the OrElse action. Finally, an @orElse annotation should be added for POJO rules.
I also think that OrElse should only support a single action, whereas Then supports multiple actions that are chained together.
from rulebook.
Else is coming to Rules. v0.11 is targeted for Else rules at the moment.
from rulebook.
Actually, it's looking more like v0.12
from rulebook.
Related Issues (20)
- rule book runner incorrectly eats exceptions so buggy code is not caught. HOT 2
- Why withDefaultResult is mandatory? HOT 4
- How can i write dynamic rules to execute rather than writing in java program .like rules defined in JSON or Yaml? HOT 4
- Q: Rule as a singleton bean HOT 3
- Add the Supplier function to avoid the passage by reference for the default result HOT 2
- Should I fork? HOT 2
- using codegen to improving performance of rule execution HOT 1
- Rule name is dropping when build Rule withFactType. HOT 1
- How to write Unit Tests for a RuleBean? HOT 1
- Switch CI to GitHub Actions HOT 2
- Deprecated classes/methods and non-compiling examples in README.md HOT 1
- Auditor not set on rules when RuleBookBuilder.create(Class) is used HOT 2
- Futures/CompletionStage/Async HOT 2
- Fact checking before evaluating rules HOT 2
- Rulebook in Spring Boot - stop execution
- Project status HOT 2
- Lambdas stack error
- RuleBuilder doesn't create a Rule with action type RuleChainActionType.ERROR_ON_FAILURE HOT 2
- RuleBookRunner4PojoClasses does not run rules according to the order property
- Would need an update on how frequently this project is developed and actively supported HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rulebook.