Using Scala DMN Engine

I am experimenting with the scala dmn-engine. I very much appreciate that it appears to be pluggable into Camunda BPMN.

<dependency>
    <groupId>org.camunda.bpm.extension.dmn.scala</groupId>
    <artifactId>dmn-engine</artifactId>
    <version>1.9.0</version>
</dependency>

Questions:

  • The code below allows me to use it from Java 21, however, I don’t see how I can find out which matching rule provided the result. The Audit$DecisionTableEvaluationResult internally has a matchedRules attribute, but it appears to be private.
public class DmnDecision {

    DmnEngine engine = new DmnEngine.Builder().build();

    public Object evaluate(InputStream dmnModel, String decisionId, Map<String, Object> context) {
        Either<DmnEngine.EvalFailure, DmnEngine.EvalResult> either = engine.parse(dmnModel)
                .flatMap(dmn -> engine.eval(dmn, decisionId, context));

        return switch (either) {
            case Right<DmnEngine.EvalFailure, DmnEngine.EvalResult> right when right.value().isNil() ->
                    Map.of(decisionId, null);
            case Right<DmnEngine.EvalFailure, DmnEngine.EvalResult> right -> {
                Audit.AuditLog auditLog = right.value().auditLog();
                Audit.AuditLogEntry entry = auditLog.entries().apply(0);
                // no access to matchedRules here?
                yield Map.of(decisionId, right.value().value());
            }
            case Left<DmnEngine.EvalFailure, DmnEngine.EvalResult> failure 
                    -> Map.of(decisionId, failure.value());
            default -> throw new IllegalStateException("Unexpected value: " + either);
        };
    }
}

Hi @dschulten . :wave:

I’m happy about your interest in the DMN-Scala engine. :rocket:

Currently, the audit API of the DMN engine is written for Scala. It is a bit clunky to access it in Java code.

You can have a look at how it is used in Zeebe.

1 Like