An open API service indexing awesome lists of open source software.

https://github.com/materna-se/jdec

🤔 Java library that offers a unified interface to DMN and Java decisions
https://github.com/materna-se/jdec

java

Last synced: over 1 year ago
JSON representation

🤔 Java library that offers a unified interface to DMN and Java decisions

Awesome Lists containing this project

README

          

# jDEC






jDEC is a Java library designed to provide a unified interface for executing decisions. The decisions can be modeled with [DMN](https://www.omg.org/spec/DMN) (Decision Model and Notation) or with Java.

## Download

jDEC is published to the Maven Central Repository. To get the release versions, you can add the following dependency to your your build management tool. In addition, snapshot versions are published at more regular intervals to the Maven Snapshot Repository. All available versions are also tagged and can be seen at https://github.com/materna-se/jdec/releases.

### Maven
```xml

com.github.materna-se
jdec
VERSION

```
If you want to download the snapshot versions, the following repository must also be added:
```xml

sonatype-snapshot-repository
http://oss.sonatype.org/content/repositories/snapshots

false


true

```

### Gradle
```gradle
compile group: 'com.github.materna-se', name: 'jdec', version: 'VERSION'
```

## Documentation

Decisions can be modeled with DMN with applications like the [Trisotech Decision Modeler](https://www.trisotech.com/digital-modeling-suite), the [ACTICO Platform](https://www.actico.com/platform/dmn-decision-model-notation) or the [Red Hat Decision Manager](https://www.redhat.com/de/technologies/jboss-middleware/decision-manager). After the decisions are modeled, they can be exported as XML:
```xml


string

"UNEMPLOYED","EMPLOYED","SELF-EMPLOYED","STUDENT"








"You are " + Employment Status




```

In addition to DMN, the decisions can be modeled with Java by extending the abstract class `DecisionModel`:
```java
package de.materna.jdec.java.test;

import de.materna.jdec.java.DecisionModel;
import de.materna.jdec.model.ComplexInputStructure;
import de.materna.jdec.model.ExecutionResult;
import de.materna.jdec.model.InputStructure;

import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

public class EmploymentStatusDecision extends DecisionModel {
@Override
public ComplexInputStructure getInputStructure() {
Map inputs = new LinkedHashMap<>();

InputStructure inputStructure = new InputStructure("string", Arrays.asList("UNEMPLOYED", "EMPLOYED", "SELF-EMPLOYED", "STUDENT"));
inputs.put("Employment Status", inputStructure);

return new ComplexInputStructure("object", inputs);
}

@Override
public Map executeDecision(Map inputs) {
Map output = new HashMap<>();
output.put("Employment Status Statement", "You are " + inputs.get("Employment Status"));
return output;
}
}
```

Once the decisions are modeled, they can be used with jDEC. For this purpose, a DecisionSession can be created with three different modes to choose from:
- `DMNDecisionSession`: Accepts only DMN decisions, components to execute Java decisions are not imported.
- `JavaDecisionSession`: Accepts only Java decisions, components to execute DMN decisions are not imported.
- `HybridDecisionSession`: Accepts DMN and Java decisions, even referencing a decision of one language in a decision of another language during execution is possible.

If `DMNDecisionSession` or `HybridDecisionSession` is used, DMN decisions can be imported and executed like this:
```java
DecisionSession decisionSession = new DMNDecisionSession();
decisionSession.importModel("https://github.com/agilepro/dmn-tck", "0003-input-data-string-allowed-values", /* Decision Source */);

Map inputs = new HashMap<>();
inputs.put("Employment Status", "UNEMPLOYED");

Map outputs = decisionSession.executeModel("https://github.com/agilepro/dmn-tck", "0003-input-data-string-allowed-values", inputs);
System.out.println("executeHashMap(): " + outputs);

Assertions.assertTrue(outputs.containsKey("Employment Status Statement"));
Assertions.assertEquals("You are UNEMPLOYED", outputs.get("Employment Status Statement"));
```

If `JavaDecisionSession` or `HybridDecisionSession` is used, Java decisions can be imported and executed like this:
```java
DecisionSession decisionSession = new JavaDecisionSession();
decisionSession.importModel("de.materna.jdec.java.test", "EmploymentStatusDecision", /* Decision Source */);

Map inputs = new HashMap<>();
inputs.put("Employment Status", "UNEMPLOYED");

Map outputs = decisionSession.executeModel("de.materna.jdec.java.test", "EmploymentStatusDecision", inputs);
System.out.println("executeHashMap(): " + outputs);

Assertions.assertTrue(outputs.containsKey("Employment Status Statement"));
Assertions.assertEquals("You are UNEMPLOYED", outputs.get("Employment Status Statement"));
```