I am building a rule Engine in which I want to group rules in such a way that for a particular fact drools will not check for all the rules instead it will check for the rule in a specific group.
Is it possible to implement?
Yes. It is possible to implement, you have to implement a process with the rules you want to apply to the specific group, then you can implement a rule like this:
rule "start process if ..."
when
// Fact in specific group?
then
kcontext.getKieRuntime().startProcess("ProcessName");
end
I would recommend you to follow the official drools tutorial, specially the lesson 4: https://nheron.gitbooks.io/droolsonboarding/content/gettingStarted/lesson_4__ruleflow.html
They teach you how to do this step by step.
Related
I have written a Drool rule as shown below:
rule "first and second"
activation-group "first"
activation-group "second"
when
// conditions
then
// actions
end
However, when compiling, I get this error:
Duplicate attribute definition: activation-group in rule first and second
I want to know if it is possible to include multiple activation-groups in a rule. If this is possible, how can you do it?
Thanks in advance.
It's not possible to use multiple activation groups in a single rule. If you feel the need to do this then you should restructure your rules to be a little smarter with your conditions so you can get it to a state that would work with single activation groups (per rule).
I'm new to the IBM Rule Designer (8.8.1) and my team has inherited a project that contains numerous rule flows, subflows, rule/action tasks, etc. I'm attempting to document at the task (ie. rule flow node) level, but there are instances where 100+ rules are included in a rule task. Is there a way to query a rule task to quickly find the number of rules that are associated with a specific rule task? I couldn't find any query condition phrases or objects that appeared to say something like Find all business rules such that each business rule [is contained within <a rule task>].
Any ideas on how to accomplish that? Is there a way to turn the results from a list of rules into an integer count of rules?
Thanks for your help; please let me know if clarification is needed.
Short Answer: I don't think there is an easy way, but there is a way.
Using queries, I think the closest you can come is to find all rules in a rule package. It is common (and good) practice for the rule tasks to line up with rule packages, so that is often useful or good enough. If the rule selection specifies individual rules, queries probably won't help.
It is easy to go the other way -- to find which rule task(s) a rule appears in. Just right-click on a rule, either in the Rule Explorer view or the Rule Editor view, select 'Find Rule Dependencies' then select 'Ruleflows which may select this rule'. Not what you asked for, but often helpful.
Note: When you run a query or do any other search, the results appear in the Search view and the number of matches is included at the top. Be aware that this count may include the same rule more than once if it appears in multiple rule tasks.
What I would do to count the rules of a rule task that are specified individually is look at the source code for the rule flow. Open the ruleflow in the Ruleflow Editor and select the *.rfl tab. Scroll down or search to find the tag that you are interested in. You can turn on line numbering (right-click, Preferences, Show line numbers) and do the math yourself. Or you can select the tags from the , copy it to the clipboard, and paste it into another program that counts lines. You could use Excel, which automatically counts the number of items selected, or another editor, or even create empty file in Eclipse with line numbering on.
How to Fire all the rules in drools regardless of which group it belongs to,
I have two Rule-flow groups i.e., "rules1" "rules2", How to fire all the rules without mentioning rule-flow group name? I want to apply all the rules.
This is not possible. If a rule is in a group, the group has to receive the focus - otherwise the rules won't fire.
However, it isn't difficult at all to add a rule that will set the focus to another group.
Also, you can write a very simple loop setting the focus to group after group and to fire all rules.
If you don't need the grouping, remove the rule attribute.
In my project i want Drools ( version 5.5.0.final) to execute specific rule flow group.
Is there a way to do this?
Use ruleflow. I tried it with Java AgendaFilters but the API is limited. Create a flow diagram that has your ruleflow-group node and start as process.
I need to execute some rule as the last rule. Any one knows how to do this ?
Also can a rule change behavior of other rules ? For example can a rule be used to execute certain rule package ?
Thanks in Advance.
yes you can use the rule attribute salience to give your rules priority.
You can insert a fact in the Right Hand Side of the rule to make another rules match.
You can also read the documentation for Agenda Groups to select different groups of rules that will be executed at different times.
Hope it helps!