I am new to drools and the kie-server. I got problem about how to insert new facts in working memory by fired rule RHS(then action) then activate other rules by these dynamic-insered facts.
What I expect is when BaseFeature insert into Working memory from outside and activate RuleOne, inside the RuleOne "then" it will insert the new fact RuleResult, and expected to activate the RuleTwo, but it doesn't activate RuleTwo, just RuleOne was activated, is that something I doing it wrong?
Here I have two rules and a set of facts:
FACTS definition:
public class AppResult implements java.io.Serializable
{
static final long serialVersionUID = 1L;
private java.lang.String key;
private java.lang.String value;
//getters and setters ...
}
public class BaseFeature implements java.io.Serializable
{
static final long serialVersionUID = 1L;
private int age;
//getters and setters ...
}
public class RuleResult implements java.io.Serializable
{
static final long serialVersionUID = 1L;
private java.lang.String ruleName;
private java.lang.Long score;
private boolean state;
//getters and setters ...
}
Rule definition:
rule "RuleOne"
dialect "mvel"
salience 100
no-loop true
lock-on-active true
when
$b : BaseFeature( age < 22 || age > 40 )
then
RuleResult $r = new RuleResult();
$r.setRuleName( "RuleOne" );
$r.setState( false );
insertLogical( $r );
end
rule "RuleTwo"
dialect "mvel"
no-loop false
lock-on-active true
salience 10
when
$r : RuleResult( ruleName == "RuleOne" , state == false )
$a : AppResult( )
then
$a.setKey( "PASS" );
$a.setValue( "false" );
end
how to achieve fired-rules insert new fact and fired other rules dynamic? thank in advance!
I am using kie-server(6.5 Final) to test, and the POST and Reponse as below:
POST:
{
"lookup": "RuleChainTestStateless",
"commands": [
{
"insert": {
"return-object": false,
"object": {
"com.qf.rulechaintest.BaseFeature": {
"age": "10"
}
}
}
},
{
"insert": {
"return-object": true,
"out-identifier": "AppResult",
"object": {
"com.qf.rulechaintest.AppResult": {
}
}
}
},
{
"fire-all-rules": ""
},
{
"get-objects":{
"out-identifier":"allFactsInWrokingMemory"
}
}
]
}
REPONSE:
{
"type": "SUCCESS",
"msg": "Container RuleChainTest1.1 successfully called.",
"result": {
"execution-results": {
"results": [
{
"key": "",
"value": 1
},
{
"key": "AppResult",
"value": {
"com.qf.rulechaintest.AppResult": {
"key": null,
"value": null
}
}
},
{
"key": "allFactsInWrokingMemory",
"value": [
{
"com.qf.rulechaintest.BaseFeature": {
"age": 10
}
},
{
"com.qf.rulechaintest.AppResult": {
"key": null,
"value": null
}
},
{
"com.qf.rulechaintest.RuleResult": {
"ruleName": "RuleOne",
"score": null,
"state": false
}
}
]
}
],
"facts": [
{
"key": "AppResult",
"value": {
"org.drools.core.common.DefaultFactHandle": {
"external-form": "0:2:1542374590:1542374590:2:DEFAULT:NON_TRAIT:com.qf.rulechaintest.AppResult"
}
}
}
]
}
}
}
Notice that the reponse:
"com.qf.rulechaintest.AppResult": {
"key": null,
"value": null
}
what it expected to be:
"com.qf.rulechaintest.AppResult": {
"key": "PASS",
"value": "false"
}