How to execute dmn files - imona/tutorial GitHub Wiki
DMN(Decision Model and Notation) tables can be executed with Camunda Engine API's. The project will be a dynamic web project with Maven depnedencies. Maven archetype should be type of maven-archetype-webapp. The maven dependency management for Camunda BPM is:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.camunda.bpm</groupId>
<artifactId>camunda-bom</artifactId>
<version>7.5.0</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
For Camunda engine there are 3 dependencies
<dependency>
<groupId>org.camunda.bpm.dmn</groupId>
<artifactId>camunda-engine-dmn-bom</artifactId>
<version>7.5.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.camunda.bpm.dmn</groupId>
<artifactId>camunda-engine-dmn</artifactId>
</dependency>
<dependency>
<groupId>org.camunda.bpm</groupId>
<artifactId>camunda-engine</artifactId>
<scope>provided</scope>
</dependency>
The dependency for java servlet is
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
By default, there is no java directory. The source code should be in the directory src/main/java created by developer .
A DMN engine object is created with a configuration. The DMNEngineConfiguration is the type for the configuration in which one can configure as needed.
DmnEngineConfiguration configuration = DmnEngineConfiguration.createDefaultDmnEngineConfiguration();
The expression languages(JUEL, FEEL) can be set in DMN file or one can create a Spring XML file named processEngineConfiguration. Detailed information about engine configuration can be found here. DmnEngine dmnEngine = configuration.buildEngine();
The DMN file can be read with inputStream or readModelFromFile library of Camunda. DmnModelInstance dmnModelInstance = Dmn.readModelFromFile(dmnFile); The DMN model instance is parsed by DMN engine and put in the DMNDesicion list. List<DmnDecision> decisions = dmnEngine.parseDecisions(dmnModelInstance); This means we can have more than one decision table in an XML(DMN) file, however only the first one is displayed by Camunda DMN modeler. A decision is picked from decisionlist DmnDecision decision = decisions.get(0); and evaluated by the engine with given variables . Camunda API has Variables and VariableMap classes. The variable mapping is created with Variables class' createVariables() method which returns a VariableMap type. The DMN engine's evaluateDecisionTable method returns a DmnDecisionTableResult which contains the list of all results that matched our input variables. DmnDecisionTableResult result = dmnEngine.evaluateDecisionTable(decision, variables);
List<Map<String, Object>> results;
results = result.getResultList();
The DMN engine uses SLF4J as logging API. The camunda-dmn-engine artifact does not have a dependency to any of the existing SLF4J backends. This means that you can choose which backend you want to use. One example would be LOGBack, or if 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 user manual.
Detailed information can be found in Camunda Documentation and GitHub.