'A dedicated object in response to a rule in DROOLS
In the drool engine, how can a new object be filled in as a response in the THEN section?
Instead of LiabilityRequestDto, I want to return the answer with another dedicated object.
rule "validate Date"
salience 100
when
$req : LiabilityRequestDto(expireAt before issueAt || issueAt before getNow())
then
$req.setResultMessage("\\n"+" invalid date");
$req.setIsValid(false);
end;
I use Drools Workbench, so I have no access to kieSession directly.
Solution 1:[1]
To get new object you have to use 'kieSession.getObject' after 'fireAllRules' command, like as:
kieSession.fireAllRules()
kieSession.getObject(factHandle)
Solution 2:[2]
I found the solution and I hope it will be useful for others We define an object and that is our output model
rule "min Policy Duration"
when
$response:ResponseModel();
$model:LifeModel(duration<5 )
then
$response.addMessage("Error message");
$response.setValid(false);
end;
Now we write the name of the output model in the request and in this way the model can be obtained.
{
"commands": [
{
"insert": {
"out-identifier": "PhysiciansLiability_1.0.0-SNAPSHOT",
"return-object": "true",
"object": {
"ResponseModel": {
"expireAt": "2019-04-23",
"issueAt": "2022-04-23",
},
{
"fire-all-rules": ""
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Abhijit Humbe |
| Solution 2 | Soheil Babadi |
