Maven Coordinates

The Camunda DMN engine is released to Maven Central.

Start by importing the to ensure correct dependency management.

Next, include the camunda-engine-dmnartifact in the dependencies section.

Building a DMN Engine

To build a new DMN engine, create a DMN engine configuration.Configure it as needed and then build a new DMN engine from it.

Configuration of the DMN Engine

The DMN engine configuration allows you add a custom decision table . A decision table evaluation listener isnotified after a decision table has been evaluated. It receives an evaluation eventwhich contains the result of the evaluation. You can decide if thelistener should be notified before or after the default listeners.

  1. // create default DMN engine configuration
  2. DmnEngineConfiguration configuration = DmnEngineConfiguration
  3. .createDefaultDmnEngineConfiguration();
  4. // instantiate the listener
  5. DmnDecisionTableEvaluationListener myListener = ...;
  6. // notify before default listeners
  7. configuration.getCustomPreDecisionTableEvaluationListeners()
  8. .add(myListener);
  9. // notify after default listeners
  10. configuration.getCustomPostDecisionTableEvaluationListeners()
  11. .add(myListener);

A specialized evaluation listener is the metric collector, which records the number of executed decisionelements. This metric can be used to monitor the workload of a decision engine.

  1. // create default DMN engine configuration
  2. DmnEngineConfiguration configuration = DmnEngineConfiguration
  3. .createDefaultDmnEngineConfiguration();
  4. // create your metric collector
  5. DmnEngineMetricCollector metricCollector = ...;
  6. // set the metric collector
  7. configuration.setEngineMetricCollector(metricCollector);

The DMN engine configuration allows you add a custom . A decision evaluation listener isnotified after a decision with all the required decisions has been evaluated. It receives an evaluation eventwhich contains the result of the evaluation. You can decide if thelistener should be notified before or after the default listeners.

  1. // create default DMN engine configuration
  2. DmnEngineConfiguration configuration = DmnEngineConfiguration
  3. .createDefaultDmnEngineConfiguration();
  4. // instantiate the listener
  5. // notify before default listeners
  6. configuration.getCustomPreDecisionEvaluationListeners()
  7. .add(myListener);
  8. // notify after default listeners
  9. configuration.getCustomPostDecisionEvaluationListeners()
  10. .add(myListener);

Customizing and Extending the DMN Engine

Please be aware that these APIs are not part of the public API and may change in later releases.

The has further customization andextension points.

It is possible to customize the transformation of DMN by providing a DMN transformer or configuring the .

  1. // with a default DMN engine configuration
  2. .createDefaultDmnEngineConfiguration();
  3. // instantiate transform listener
  4. DmnTransformListener myTransformListener = ... ;
  5. // add the transform listener
  6. configuration.getTransformer()
  7. .getTransformListeners()
  8. .add(myTransformListener);

While the transform listener allows modifying of the transformed objects, it does not support instantiating custom subclasses.This can be achieved using a custom transform handler.

A transform handler is registered for a given type like a DecisionTable.

First, implement a transform handler which can transform a decision table.

Then, register an instance of the handler in the default DMN transformer element handler registry.

  1. // with a default DMN engine configuration
  2. DefaultDmnEngineConfiguration configuration = (DefaultDmnEngineConfiguration) DmnEngineConfiguration
  3. .createDefaultDmnEngineConfiguration();
  4. // add the handler
  5. configuration.getTransformer()
  6. .getElementTransformHandlerRegistry()
  7. .addHandler(DecisionTable.class, new MyDecisionTableHandler());

The DMN engine supports a set of built-in . It is possible to override existing types with new types.

Assume you want to support a local date format type.To achieve this, override the existing date transformer by implementing a custom transformer:

  1. public class GermanDateDataTypeTransformer extends DateDataTypeTransformer {
  2. protected SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
  3. protected Date transformString(String value) {
  4. try {
  5. return format.parse(value);
  6. }
  7. catch (ParseException e) {
  8. throw new IllegalArgumentException(e);
  9. }
  10. }
  11. }

Then, register an instance of the handler in the default DMN transformer element handler registry:

  1. // with a default DMN engine configuration
  2. DefaultDmnEngineConfiguration configuration = (DefaultDmnEngineConfiguration) DmnEngineConfiguration
  3. // add the data type transformer,
  4. // overriding the existing type "date":
  5. configuration
  6. .getTransformer()
  7. .getDataTypeTransformerRegistry()
  8. .addTransformer("date", new GermanDateDataTypeTransformer());

It is also possible to add a new data type by implementing a new transformer and registering it for a non-existing type name:

  1. DefaultDmnEngineConfiguration configuration = (DefaultDmnEngineConfiguration) DmnEngineConfiguration
  2. .createDefaultDmnEngineConfiguration();
  3. // add the data type transformer for custom type "currency"
  4. configuration
  5. .getTransformer()
  6. .getDataTypeTransformerRegistry()
  7. .addTransformer("currency", new currencyTypeTransformer());

The DMN engine supports a subset of the DMN 1.1 hit policies. It is possible to implement new hit policies oroverride an existing hit policy implementation.

A has multiple expressions which are evaluated when the table is executed.The default expression language for every expression type can be configured.The following expression types exist:

  • Input Expression: Used to specify the input of a column in a decisiontable. The default language for input expressions in the DMN engine isJUEL.
  • Input Entry: Used to specify the condition of a rule in a decisiontable. The default language for input entries in the DMN engine isFEEL.
  • Output Entry: Used to specify the output of a rule in a decisiontable. The default language for output entries in the DMN engine isJUEL.
    The default expression language of a DMN decision literal expression can also be configured, the default in the DMN engine is JUEL.

It is possible to change the default expression language on the DMN engine configuration:

  1. DefaultDmnEngineConfiguration configuration = (DefaultDmnEngineConfiguration) DmnEngineConfiguration
  2. .createDefaultDmnEngineConfiguration();
  3. configuration
  4. .setDefaultInputExpressionExpressionLanguage("javascript");

Please note that the chosen language must be available in the classpath. Bydefault JUEL and FEEL are available. The default FEEL implementationis only supported for input entries.

If the JDK includes a JavaScriptimplementation like Rhino or Nashorn, then javascript is available as well.

It is also possible to use other script languages like groovy, python or ruby.Just make sure that the corresponding libraries are available on the classpath at runtime.

The default DMN engine resolves the supported expression and script languagesusing different providers.

To evaluate JUEL expressions, the DMN engine uses the configured in theDMN engine configuration. To use another implementation of the Unified Expression Language, replace this implementation.

  1. // with a default DMN engine configuration
  2. DefaultDmnEngineConfiguration configuration = (DefaultDmnEngineConfiguration) DmnEngineConfiguration
  3. .createDefaultDmnEngineConfiguration();
  4. // set a custom el provider
  5. configuration.setElProvider(new MyElProvider());

To configure the FEEL engine used you can provide a custom FeelEngineFactory.

  1. // with a default DMN engine configuration
  2. DefaultDmnEngineConfiguration configuration = (DefaultDmnEngineConfiguration) DmnEngineConfiguration
  3. .createDefaultDmnEngineConfiguration();
  4. // set a custom feel engine factory
  5. configuration.setFeelEngineFactory(new MyFeelEngineFactory());

Script languages are resolved by the . To customize the script engine resolving, provide an own implementation.

  1. // with a default DMN engine configuration
  2. DefaultDmnEngineConfiguration configuration = (DefaultDmnEngineConfiguration) DmnEngineConfiguration
  3. .createDefaultDmnEngineConfiguration();
  4. // set custom script engine resolver
  5. configuration.setScriptEngineResolver(new MyScriptEngineResolver());

Logging

The DMN engine uses SLF4J as logging API. The artifactdoes not have a dependency to any of the existing backends. This means thatyou can choose which backend you want to use. One example would be LOGBack, orif you want to use Java util logging, you could use the slf4j-jdk14 artifact.For more information on how to configure and use SLF4J, please refer to the.