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-dmn
artifact 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.
// create default DMN engine configuration
DmnEngineConfiguration configuration = DmnEngineConfiguration
.createDefaultDmnEngineConfiguration();
// instantiate the listener
DmnDecisionTableEvaluationListener myListener = ...;
// notify before default listeners
configuration.getCustomPreDecisionTableEvaluationListeners()
.add(myListener);
// notify after default listeners
configuration.getCustomPostDecisionTableEvaluationListeners()
.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.
// create default DMN engine configuration
DmnEngineConfiguration configuration = DmnEngineConfiguration
.createDefaultDmnEngineConfiguration();
// create your metric collector
DmnEngineMetricCollector metricCollector = ...;
// set the metric collector
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.
// create default DMN engine configuration
DmnEngineConfiguration configuration = DmnEngineConfiguration
.createDefaultDmnEngineConfiguration();
// instantiate the listener
// notify before default listeners
configuration.getCustomPreDecisionEvaluationListeners()
.add(myListener);
// notify after default listeners
configuration.getCustomPostDecisionEvaluationListeners()
.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 .
// with a default DMN engine configuration
.createDefaultDmnEngineConfiguration();
// instantiate transform listener
DmnTransformListener myTransformListener = ... ;
// add the transform listener
configuration.getTransformer()
.getTransformListeners()
.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.
// with a default DMN engine configuration
DefaultDmnEngineConfiguration configuration = (DefaultDmnEngineConfiguration) DmnEngineConfiguration
.createDefaultDmnEngineConfiguration();
// add the handler
configuration.getTransformer()
.getElementTransformHandlerRegistry()
.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:
public class GermanDateDataTypeTransformer extends DateDataTypeTransformer {
protected SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
protected Date transformString(String value) {
try {
return format.parse(value);
}
catch (ParseException e) {
throw new IllegalArgumentException(e);
}
}
}
Then, register an instance of the handler in the default DMN transformer element handler registry:
// with a default DMN engine configuration
DefaultDmnEngineConfiguration configuration = (DefaultDmnEngineConfiguration) DmnEngineConfiguration
// add the data type transformer,
// overriding the existing type "date":
configuration
.getTransformer()
.getDataTypeTransformerRegistry()
.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:
DefaultDmnEngineConfiguration configuration = (DefaultDmnEngineConfiguration) DmnEngineConfiguration
.createDefaultDmnEngineConfiguration();
// add the data type transformer for custom type "currency"
configuration
.getTransformer()
.getDataTypeTransformerRegistry()
.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 isJUEL
.
It is possible to change the default expression language on the DMN engine configuration:
DefaultDmnEngineConfiguration configuration = (DefaultDmnEngineConfiguration) DmnEngineConfiguration
.createDefaultDmnEngineConfiguration();
configuration
.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.
// with a default DMN engine configuration
DefaultDmnEngineConfiguration configuration = (DefaultDmnEngineConfiguration) DmnEngineConfiguration
.createDefaultDmnEngineConfiguration();
// set a custom el provider
configuration.setElProvider(new MyElProvider());
To configure the FEEL
engine used you can provide a custom FeelEngineFactory.
// with a default DMN engine configuration
DefaultDmnEngineConfiguration configuration = (DefaultDmnEngineConfiguration) DmnEngineConfiguration
.createDefaultDmnEngineConfiguration();
// set a custom feel engine factory
configuration.setFeelEngineFactory(new MyFeelEngineFactory());
Script languages are resolved by the . To customize the script engine resolving, provide an own implementation.
// with a default DMN engine configuration
DefaultDmnEngineConfiguration configuration = (DefaultDmnEngineConfiguration) DmnEngineConfiguration
.createDefaultDmnEngineConfiguration();
// set custom script engine resolver
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.