Soheil Babadi
Soheil Babadi

Reputation: 679

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.

Upvotes: 1

Views: 697

Answers (2)

Soheil Babadi
Soheil Babadi

Reputation: 679

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": ""
        }

Upvotes: 1

Abhijit Humbe
Abhijit Humbe

Reputation: 1631

To get new object you have to use 'kieSession.getObject' after 'fireAllRules' command, like as:

kieSession.fireAllRules()
kieSession.getObject(factHandle)

Upvotes: 1

Related Questions