javajbossdroolsjbpm

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

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