How to retrieve the input name and the typename of a condition within a decision

Hi All,

I created an inputstream an engine and loaded the decision:

    InputStream inputStream = DmnApp.class.getResourceAsStream("dinnerDecisions.dmn");
    DmnEngine dmnEngine = DmnEngineConfiguration.createDefaultDmnEngineConfiguration().buildEngine();
    DmnDecision decision = dmnEngine.parseDecision("beverages", inputStream);

This works fine.

My two questions are:
Is it possbile to retrieve the number of conditions used in the decision?
is it possible to retrieve the ‘input names’ and the ‘typedefinitions’ of the conditions in a structured manner?

The statements:
decision.getRequiredDecisions(); and decision.getDecisionLogic(); provide amongst other the right info but in an unstructered way.

Kind regards,

Shooting from the hip here, and if you don’t mind a little “brute force” parsing, you can retrieve the entire decision definition, which would have all of the elements you need to answer your questions. Then, using something like XPath, you can iteratively apply the responses to the resulting XML.

Make a REST call like this:

http://localhost:8080/engine-rest/engine/default/decision-definition/key/myTestDmn/xml

It will return a JSON string like this:

{
"id": "myTestDmn:4:2510fbaf-215b-11e7-b00e-da7420524153",
"dmnXml": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<definitions xmlns=\"http://www.omg.org/spec/DMN/20151101/dmn.xsd\" xmlns:camunda=\"http://camunda.org/schema/1.0/dmn\" id=\"definitions_0a4ktwq\" name=\"definitions\" namespace=\"http://camunda.org/schema/1.0/dmn\">\n  <decision id=\"myTestDmn\" name=\"myTestDmn\">\n    <decisionTable id=\"decisionTable\" hitPolicy=\"COLLECT\">\n      <input id=\"input1\" label=\"myInput\" camunda:inputVariable=\"\">\n        <inputExpression id=\"inputExpression1\" typeRef=\"string\">        <text>myInput</text>\n</inputExpression>\n      </input>\n      <output id=\"output1\" label=\"myOutput\" name=\"myOutput\" typeRef=\"string\" />\n      <rule id=\"row-753205492-6\">\n        <inputEntry id=\"UnaryTests_0a6e6x4\">        <text><![CDATA[\"input_1\"]]></text>\n</inputEntry>\n        <outputEntry id=\"LiteralExpression_10hmylo\">        <text><![CDATA[\"output_1\"]]></text>\n</outputEntry>\n      </rule>\n      <rule id=\"row-753205492-7\">\n        <inputEntry id=\"UnaryTests_0n7w1b6\">        <text><![CDATA[\"input_1\"]]></text>\n</inputEntry>\n        <outputEntry id=\"LiteralExpression_03k8cnn\">        <text><![CDATA[\"output_1a\"]]></text>\n</outputEntry>\n      </rule>\n      <rule id=\"row-753205492-8\">\n        <inputEntry id=\"UnaryTests_09dw1g6\">        <text><![CDATA[\"input_2\"]]></text>\n</inputEntry>\n        <outputEntry id=\"LiteralExpression_1hp7i5x\">        <text><![CDATA[\"output_2\"]]></text>\n</outputEntry>\n      </rule>\n    </decisionTable>\n  </decision>\n</definitions>\n"

}

If you then extract the value of variable “dmnXml”, you’ll have to original XML that made up the table.

Posting an evaluation request to URL (http://localhost:8080/engine-rest/engine/default/decision-definition/key/myTestDmn/evaluate) with the following payload:

{
  "variables" : {
    "myInput" : { "value" : "input_1", "type" : "String" }
  }
}

The response would be something like this:

[
    {
        "myOutput": {
            "type": "String",
            "value": "output_1",
            "valueInfo": {}
        }
    },
    {
        "myOutput": {
            "type": "String",
            "value": "output_1a",
            "valueInfo": {}
        }
    }
]

Each condition matched would return a response (assuming you’re using the COLLECT hit policy), therefore the number of conditions = the number of returned outputs, in this case 2. The ‘input name’ would typically match the object name in the original request. In this example, “myInput”, though I’m a bit unclear on the difference between the “name” and the “label”.

You would then need to use the input value (e.g. “input_1”) and a response output value (e.g. “output_1a”) and use them to traverse the XML until you found the “rule” node, wherein you would find any information you wanted. You would have to use XPath (which I’m not really familiar with) or some other structured text parser.

This is probably a very circuitous way of doing this and I’ll probably be embarrassed to read the much simpler answer of someone who knows this stuff better (and spending 30 minutes creating the response (obsessiveness is a harsh mistress)), but there it is.

Michael