How to Compute and get value of Formula defined inside rules in Drools? - jboss

I have drools UI created for my application, in the UI I have created some rules i.e(Fire rules if Quantity < 100), the rule i have created directly using literals(100) where drools directly compare the quantity with literal.
In Drools UI there is an option where we can create our own formulas or expressions for the rules i.e(Fire Rule if Quantity < MarkPrice * 5),now here the drools have to do the calculation and comparison before firing the rule.
My requirement is:
How is drools comparing the value of Quantity and MarkPrice*5 to
fire or unfire the rule?
How can i get the value of MarkPrice*5 at runtime?
The image is of the rule created at drools UI

Related

Drools/ Kogito Dynamic runtime flow/ process

I'm new to drools (I can consider Kogito as well) we have a requirements where the rules with orders are stored in a decision table and it should be executed based on the order given by the users the rules order could change at anytime. Please keep in mind that the response(output) from any rules is the input for the next one. is there anyway to achieve this?
example:
Rules
rank
rule 1
1
rule 2
2
order might change to:
Rules
rank
rule 1
2
rule 2
1

Drools Guided Decision table :How to reference fact in action column?

I am trying to use the Guided decision table in Drools Workbench 7.8.0.Final. I am binding a fact pattern for the condition column. Like so:
I then add a condition for one of the fields.
I now add an action column.
I bind it to a different fact. I want a field of this fact to be same as person.age.
How can I do this in the decision table?
It seems to allow only constants
p.age is taken to be a string constant. Not what I want.

How to dynamically select drools rules for execution at business rule task level?

I've few drools rules that I want to use in different rule flows. Since, Drools rule supports only one ruleflow-group name at a time and rule flow business rule task also can be mapped with single ruleflow-group, I'm not able to use same rule in different rule flows. Is there any other way that I can use to filter the rules? like using tags or and metadata?
You could create your own rule groups. You create a class OwnRuleGroup with String group in it as a field. Then when you fire rules you create an instance of your own rule grup:
OwnRuleGroup myGroup = new OwnRuleGroup();
myGroup.group = "foo";
and insert it into session with other facts. In every rule you could specify which of the groups you want to fire.
rule "This will fire for groups foo,bar"
when
OwnRuleGroup(group in ["foo", "bar"])

Kie Server Guided Descision table rules not fired from REST API

I have a small project created on drools workbench deployed on a KIE server. Using the rest API I am able to insert facts, with rules appropriately fired. However the rules included in guided decision tables do not fire. Here is an example of a request I would send to the KIE server:
<batch-execution lookup="defaultKieSession">
<insert out-identifier="applicant" return-object="true" entry-point="DEFAULT">
<models.Applicant>
<timeEmployed>35</timeEmployed>
<employmentStatus>Contract</employmentStatus>
<violations>[]</violations>
</models.Applicant>
</insert>
<fire-all-rules/>
</batch-execution>
All rules that this data should trigger are fired, except for those included in the Decision table.
When I run a test scenario with the same data, all rules, including the decision table's rules, are fired correctly:
The problem seems to be related to the use of the REST API. Any ideas as to what I am doing wrong?
Here is the Table in question:
Violation simply calls a method that appends an error to the violations array.
Inside kmodule.xml I have.
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
Clarification
Just to be clear my requests fire rules from Guided DRLs, my issue is only with the rules in guided rules table. For example:
Given the rule:
If I send this request:
1994-04-15 11:03:44-0000
1970-01-13 16:19:41-0024
Contract
35
[]
This is a fragment of the response:
This data should also match the rule in the gdst however it is not fired.
While we can't see the condition operators in the table, my guess is the criteria doesn't meet any of the decision table rows/rules.
Mapping the input data to the decision table, we can see that:
Employment Status is Contract, so that matches row 1. In rows 3-11 it is ignored, so depends on the matching of the remaining columns.
Employment Duration is probably timeEmployed, and it does not match equality of any row. If the column operator is >, it matches rows 2-11. If it is <, then it matches row 1.
Job Category is ignored for rows 1 and 2, and has no apparent matching value in the input so rows 3-11 do not match.
Based on those:
3 says only rows 1 and 2 could match
1 says only row 1 could match of rows 1 and 2
2 is indeterminate based on what we see
My guess is row 1 is close but #2 doesn't match.

Firing particular rule by rule name in drools without using Agenda Filters

I read the rule file and add them into my knowledgeBase then I want to fire a particular rule in that knowledgeBase. Is this task possible in current drools version?
If you have a rule base where rules should be made active dynamically according to some criterion you have several choices.
Agenda filter. You say you don't want this, but why?
Put the alternative rules into agenda groups. Select the agenda group "group_3" prior to inserting the fact by a call to
kieSession.getAgenda().getAgendaGroup( "group_3" ).setFocus();
Write your rules to include a "selection" fact, e.g.
rule rule_3
when
Select( rule == "rule_3" )
Person( ... )
then ... end
The Select fact can be inserted along with the data fact but must be retracted after firing the rule.