1

MyProblem: Based on TrainData I want to set the value of TrainStatus via postman call but I am not getting expected response.

How i can achieve this ?

I have created two data objects-

TrainData-

Column A Column B
trainID integer
area String

TrainStatus-

Column A Column B
TrainStatus String
DriverName String

Drl file-

rule "set Train status"

when
    TDobj : TrainData(trainID==111 && area=="South")
    TSobj : TrainStatus()
then
    TSobj.setTrainStatus("running");
end

Request:

  • Endpoint: http://localhost:8080/kie-server/services/rest/server/containers/instances/demo_1.0.0-SNAPSHOT
{ 
     "lookup": null,
     "commands": [ 
                {"insert": { "object":{ "TrainData":{  "trainID":112 , "area":"South"}},
               
                "out-identifier": "TrainData", 
                "return-object":true
                } }, 

                {"insert": { "object":{ "TrainStatus":{ }},
               
                "out-identifier": "TrainStatus", 
                "return-object":true
                } }, 

                { "fire-all-rules": {}}                              
        ] 
}

Response:

{
    "type": "SUCCESS",
    "msg": "Container demo_1.0.0-SNAPSHOT successfully called.",
    "result": {
        "execution-results": {
            "results": [
                {
                    "value": {
                        "com.dummyspace.demo.TrainData": {
                            "trainID": 112,
                            "area": "South",
                            "trainType": null
                        }
                    },
                    "key": "TrainData"
                },
                {
                    "value": {
                        "com.dummyspace.demo.TrainStatus": {
                            "trainStatus": "Running",
                            "auditInterval": null,
                            "hpbufferAllowance": null
                        }
                    },
                    "key": "TrainStatus"
                }
            ],
            "facts": [
                {
                    "value": {
                        "org.drools.core.common.DefaultFactHandle": {
                            "external-form": "0:5:2011994629:2011994629:5:DEFAULT:NON_TRAIT:com.dummyspace.demo.TrainData"
                        }
                    },
                    "key": "TrainData"
                },
                {
                    "value": {
                        "org.drools.core.common.DefaultFactHandle": {
                            "external-form": "0:6:1902014052:1902014052:6:DEFAULT:NON_TRAIT:com.dummyspace.demo.TrainStatus"
                        }
                    },
                    "key": "TrainStatus"
                }
            ]
        }
    }
}

My rule is if TrainData==111 and area=="south" then set TrainStatus to "Running". but in body if I am entering different train data/area irrespective of condition I am getting TrainStatus = Running.

I am not getting response based on the condition.

Shalini
  • 11
  • 3
  • `i am not getting expected response` -- well what _are_ you getting? And what are you sending as your request? Also I hope those curly quotes/"smart" quotes in your DRL are just copy-paste artifacts and not actually in your code. – Roddy of the Frozen Peas Apr 24 '23 at 22:42
  • Also you have what looks like a typo in your "then": `TSobj:setTrainStatus(“running”);` should be `TSobj.setTrainStatus("running");` (`.` not `:`). I'm presuming this is a typo since the rule as written won't even compile. – Roddy of the Frozen Peas Apr 24 '23 at 22:43
  • I have edited my question and added API Body and Response – Shalini Apr 25 '23 at 09:34
  • Can you edit your question and put the actual DRL? as mentioned in previous comment the current looks like some kind of copy-paste error and won't even compile. – Roddy of the Frozen Peas Apr 25 '23 at 14:22
  • 1
    Yes, I forgot to remove ( : ) from TSobj.setTrainStatus("running"); – Shalini Apr 26 '23 at 08:55

1 Answers1

0

In your question, you are reporting that allegedly the TrainStatus is not correctly valorized.

In your description, you say:

My rule is if TrainData==111 and area=="south" then set TrainStatus to "Running". but in body if I am entering different train data/area irrespective of condition I am getting TrainStatus = Running.

In your snippet response, you have:

"trainStatus": "Running",

but on request to provide the actual DRL file, you provide:

rule "set Train status"

when
    TDobj : TrainData(trainID==111 && area=="South")
    TSobj : TrainStatus()
then
    TSobj.setTrainStatus("running");
end

which clearly is A. not the actual DRL, B. not the only rule in the rule base, since the setter is valorizing with "running" (lowercase R) which is inconsistent from the alleged reported issue/question.

Based on the information provided, it's difficult to investigate further, and just by the current available information I would suspect there is something else going on based on this inconsistency; consider providing a full reproducer (e.g. the KJAR project shared on github for example).

tarilabs
  • 2,178
  • 2
  • 15
  • 23