A decision table allows to specify the types of inputs and outputs. When theDMN engine evaluates an input or an output, it checks if the type of thevalue matches the specified type. If the types do not match, the enginetries to transform the value into the specified type or throws an exception.
The DMN engine supports basic types which can be extended by custom types.
Supported Data Types
The following types are supported by the DMN engine:
Data Type | Can transform from | Produce values of type |
---|---|---|
string | java.lang.Object | StringValue |
boolean | java.lang.Boolean, java.lang.String | BooleanValue |
integer | java.lang.Number, java.lang.String | IntegerValue |
long | java.lang.Number, java.lang.String | LongValue |
double | java.lang.Number, java.lang.String | DoubleValue |
date | java.util.Date, java.lang.String | DateValue |
Each data type transformer produces a typed value which contains the value andadditional type informations.
If the given type does not match one of the above types then the value istransformed into an untyped value by default.
Working with Dates
The DMN engine supports a date
type which is a combination of date and time.By default, the data type transformer accept objects of the typejava.util.Date
and Strings having the format yyyy-MM-dd'T'HHss
.
If you prefer another format or different representation of a date,implement a custom type and replace the default transformer.
Setting the Data Type of an Input
The type of a decision table input is specified by the typeRef
attribute on theinputExpression
element.
<decision>
<decisionTable>
<input id="orderSum" label="Order sum">
<inputExpression typeRef="double">
<text>sum</text>
</inputExpression>
</input>
<!-- ... -->
</decisionTable>
</decision>
Setting the Data Type of an Output
The type of a decision table output is specified by the typeRef
attribute on the output
element.
<decision>
<decisionTable>
<!-- ... -->
<output id="result" label="Check Result" name="result" typeRef="string" />
<!-- ... -->
</decisionTable>
</decision>
Setting the Data Type of a Variable
The type of a decision literal expression result is specified by the typeRef
attribute on the variable
element.
<decision>
<variable name="result" typeRef="string" />
<!-- ... -->
</decision>
Implement a Custom Data Type
Use of Internal API
Please be aware that these APIs are not part of the public API and may change in later releases.
The default data types of the DMN engine can be extended or replaced by customtypes. For example, you can add a new type for time or change thetransformation to support a different date format or localized booleanconstants.
To do this, implement a new DmnDataTypeTransformer. The transformation is processed in thetransform()
method and returns a typed value. If it cannot successfully transform a value,it must throw an IllegalArgumentException
.
public class CustomDataTypeTransformer implements DmnDataTypeTransformer {
public TypedValue transform(Object value) throws IllegalArgumentException {
// transform the value into a typed value
return typedValue;
}
}
To use this data type transformer in the DMN engine, add it to theDMN engine configuration.
原文: https://docs.camunda.org/manual/7.9/user-guide/dmn-engine/data-types/