Evaluate Existing DMN Table in Java

I would like to evaluate a variable in an existing (deployed) DMN table using a Java delegate. I’ve read the documentation on this and it seems that you have to create a DMN engine instance and then read the DMN table itself into that instance. That would be very time consuming.

Is there way to simply evaluate the decision in the same manner that you would through the REST interface? Something like this:

  VariableMap variables = Variables.createVariables().putValue("myVar1", "myValue1");

  DmnDecisionResult decisionResult = dmnEngine.evaluateDecisionTable("dmnTable1", variables);

  decisionResult.getSingleEntry();

I’m trying to do this with as little code as possible or through the creation of a simple method that would not require a REST call or instantiation of DMN engine object.

Thanks.

Michael

Hi @mppfor_manu,

in the Java delegate, you could use the decision service to evaluate the deployed decision.

Why don’t you use a business rule task instead?

Best regards,
Philipp

The primary answer is that I have a lot of these to do and don’t want a diagram that is unmanageable.

The second reason is, we built a library for extraction, transformation, validation, and loading of process variables based upon an annotation framework. It allows us to both extract values from existing variables or JSON objects, transform them (e.g. make it all upper case), validate them against a range of constraints, and then create a process variable. As part of this POJO, I want to perform other functions on the variables in a separate method.

As you didn’t provide an example or reference to an example, I’m thinking that I could use something like this:

execution.setVariable("myVar1", rfpDataBean.myVar1);
DmnDecisionTableResult myResult = evaluateDecisionTableByKey("myDmnTable1");

However, the compiler doesn’t recognize the “evaluateDecisionTableByKey” method, so I’ll have to figure out how to make that work.

Now that I’ve considered it, without the Business Rule Task, I won’t be able to define the mapDecisionResult value or other parameters that a Business Rule Task allows. So, I think you’re right, I’ll use a Business Rule Task and split up the process.

Thanks, Philip.

Hi @mppfor_manu,

thank you for the insides.

Here is the example how you can use the decision service within a Java delegate:

DecisionService decisionService = execution.getProcessEngineServices().getDecisionService();
DmnDecisionResult decisionResult = decisionService.evaluateDecisionByKey("myDmnTable1").variables(execution.getVariables()).evaluate();
2 Likes