Red Hat Decision Manager V7 implements DMN v1.1 (Compliance Level 3).
Red Hat Process Automation Manager V7 makes possible to leverage DMN in the context of a BPMN process.
For a first introduction to the DMN here some resources:
- Capture your decisions with DMN
- Standards in Business Rules Space: Decision Model and Notation (DMN) and Other Standards
- Building Business Applications with DMN and BPMN
<!-- Required for the DMN runtime API -->
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-dmn-core</artifactId>
<version>${drools.version}</version>
</dependency>
<!-- Required if not using classpath KIE container -->
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-ci</artifactId>
<version>${drools.version}</version>
</dependency>
Basic data types: string, Boolean, Number, date, time and duration
You can express complex data types in DMN or importing XSD definitions.
E.g.
<itemDefinition label="tBid" name="tBid">
<itemComponent id="..." name="id">
<typeRef>feel:string</typeRef>
</itemComponent>
<itemComponent id="..." name="quotation">
<typeRef>feel:number</typeRef>
</itemComponent>
<itemComponent id="..." name="deliveryTime">
<typeRef>feel:number</typeRef>
</itemComponent>
</itemDefinition>
<itemDefinition isCollection="true" label="tBids" name="tBids">
<typeRef>tBid</typeRef>
</itemDefinition>
<inputData id="..." name="Suppliers bids">
<variable id="..." name="Suppliers bids" typeRef="tBids"/>
</inputData>
In the previous example there are:
-
tBid
type definition:- id - string
- quotation - number
- deliveryTime - number
-
tBids
is a collection oftBid
-
Suppliers bids
is a variable defined astBids
To help the DMN engine to map the Java fields in the FEEL properties:
@FEELProperty("initial rating")
public double getInitialRating() {
return initialRating;
}
FEEL is able to query data in a sophisticated way with constructs that recall closely XPATH 2.0.
As many other languages the dot (".") is used to access to the nested data structure (JavaScript, Python).
E.g.
Let's consider the following variable Bid which type was described before:
<variable id="..." name="Bid" typeRef="tBid"/>
Bid.id
retrieve the id
But if the type is a collection, the result is a collection with all the ids.
Example of Suppliers Bids:
id | quotation | deliveryTime |
---|---|---|
1 | 100 | 2 |
2 | 120 | 1 |
3 | 80 | 4 |
In this case the expression Suppliers Bids.id
retrieve a list of values:
id |
---|
1 |
2 |
3 |
Suppliers bids[ quotation = lower quotation].id
This functions applies to lists.
There are functions that summarize the data: count, min, max, sum, mean, and, or, list contains
.
E.g.
min(Suppliers bids.quotation)
Other list function manipulate the list.
Name(parameters) | Parameter Domain | Description | Example |
---|---|---|---|
count(list) | list | return size of list | count([1,2,3]) = 3 |
list contains(list, element) | list, any element of the semantic domain including null | does the list contain the element? | list contains([1,2,3], 2) = true |
min(list) min(c1 ,..., cN ), N>1 max(list) max(c1 ,..., cN ), N>1 |
(list of) comparable items | return minimum(maximum) item | min([1,2,3]) = 1 min(1,2,3) = 1 max([1,2,3]) = 3 max(1,2,3) = 3 |
A Boxed Function Definition is the way to define function in DMN. In the Trisotech editor, it is "Function (Expression)".
There are 3 possible implementations (kinds): FEEL, PMML and Java.
This is the way to define a Java function:
In a decision table cell, it's possible to write a complex FEEL expression and use the special character "?" (placeholder) to reference the column value.
E.g.
list contains(?, "A")
FEEL extension to evaluate time:
-
now()
: Returns the current local date and time. -
today()
: Returns the current local date.
Warning Using this functions in different point of a decision could give different results base on the real evaluation execution time.
Subtracting two dates gives a duration:
date1 - date2
Duration operations:
days, hours, minutes, seconds
Example: days between two dates
(date1 - date2).days
In order to initialize the context in a straightforward way, leverage the helper factories: prototype
and entry
.
-
Dependency
<!-- DMN test--> <dependency> <groupId>org.kie</groupId> <artifactId>kie-dmn-core</artifactId> <type>test-jar</type> <scope>compile</scope> </dependency>
-
Code example:
import static org.kie.dmn.core.util.DynamicTypeUtils.entry; import static org.kie.dmn.core.util.DynamicTypeUtils.prototype; Map<String, Object> transaction1 = prototype ( entry("balance", 2200), entry("amount", -500), entry("value date", LocalDateTime.now()), entry("category", "shopping") );
It's possible to add event listeners: DMNRuntimeEventListener
Programmatically, add it to DMNRuntime:
dmnRuntime.addListener( new DMNRuntimeEventListener() {
@Override
public void afterEvaluateBKM(AfterEvaluateBKMEvent event) {
System.out.println(">>> " + event.getResult().getContext());
}
});
Add listeners to the kie server using the property via kmodule.xml or system property: org.kie.dmn.runtime.listeners.$NAME
.
Details described here: https://issues.redhat.com/browse/DROOLS-4488
logs (tipo org.kie=DEBUG)