Decision tables and decision literal expressions allow specifying different types of expressions.This section describes which types of expressions exist.It lists which expression languages are supported and demonstrates how to change the used expression language for an expression.

Expressions in DMN

As shown in the decision table and decision literal expression reference, four types of expressions are supported:

  • Input Expression: sets the input value for an input columnof the decision table
  • Input Entry: used to determine if a rule of the decisiontable is applicable
  • Output Entry: returns a value which is added to the output of a matched ruleof the decision table
  • Literal Expression: used to determine the value of a decision literal expression
    You can read more on this in the DMN 1.1 reference. Inthe DMN 1.1 XML, expressions can be found in the XMLelements inputExpression, inputEntry, outputEntry and literalExpression:
  1. <definitions xmlns="http://www.omg.org/spec/DMN/20151101/dmn.xsd" id="definitions" name="definitions" namespace="http://camunda.org/schema/1.0/dmn">
  2. <decision id="decision" name="Decision">
  3. <decisionTable>
  4. <input id="input">
  5. <!-- the input expression determines the input value of a column -->
  6. <inputExpression>
  7. <text>age</text>
  8. </inputExpression>
  9. </input>
  10. <output id="output"/>
  11. <rule id="rule1">
  12. <!-- the input entry determines if the rule is applicable -->
  13. <inputEntry>
  14. <text>[18..30]</text>
  15. </inputEntry>
  16. <!-- the output entry determines the rule if it is applicable -->
  17. <outputEntry>
  18. <text>"okay"</text>
  19. </outputEntry>
  20. </rule>
  21. </decisionTable>
  22. </decision>
  23. <decision id="decision2 name="Decision 2">
  24. <!-- the literal expression determines the value of this decision -->
  25. <literalExpression>
  26. <text>a + b</text>
  27. </literalExpression>
  28. </decision>
  29. </definitions>

Supported Expression Languages

The Camunda DMN engine supports two expression languages out of the box:

  • JUEL: An implementation of the Java Unified Expression Language
  • FEEL: The Friendly Enough Expression Language of the DMN 1.1 standard.Note: FEEL is only supported for Input Entries in the Camunda DMNengine. See the reference for more information.
    Depending on the JDK you use, there may also be a Javascript implementationavailable like Rhino or Nashhorn.

You can also use every other script language which provides a JSR-223implementation. This includes groovy, python and ruby. To use theselanguages you have to add the corresponding dependency to your project.

For example, to use groovy as language for expressions add this dependencyto your project pom.xml:

  1. <dependency>
  2. <groupId>org.codehaus.groovy</groupId>
  3. <artifactId>groovy-all</artifactId>
  4. <!-- please update this version if needed -->
  5. <version>2.4.5</version>
  6. </dependency>

Default Expression Languages

The default expression languages of the different expression types in theDMN engine are as follows:

  • Input Expression: JUEL
  • Input Entry: FEEL
  • Output Entry: JUEL
  • Literal Expression: JUEL
    The default language can be changed by setting it directly in the DMN 1.1 XML as global expression language with the expressionLanguage attribute ofthe definitions element:
  1. <!-- this sets the default expression language for all expressions -->
  2. <!-- in this file to javascript -->
  3. <definitions xmlns="http://www.omg.org/spec/DMN/20151101/dmn.xsd" id="definitions" name="definitions" namespace="http://camunda.org/schema/1.0/dmn" expressionLanguage="javascript">
  4. <decision id="decision" name="Decision">
  5. <decisionTable>
  6. <!-- ... -->
  7. </decisionTable>
  8. </decision>
  9. </definitions>

Additionally, it is possible to change the default expression language in the default DMN engine configuration as described in the user guide.

Configuring the Expression Language

It is also possible to set the language for each expression individually using the expressionLanguage attribute:

  1. <definitions xmlns="http://www.omg.org/spec/DMN/20151101/dmn.xsd" id="definitions" name="definitions" namespace="http://camunda.org/schema/1.0/dmn">
  2. <decision id="decision" name="Decision">
  3. <decisionTable>
  4. <input id="input">
  5. <!-- use javascript for this input expression -->
  6. <inputExpression expressionLanguage="javascript">
  7. <text>age</text>
  8. </inputExpression>
  9. </input>
  10. <output id="output"/>
  11. <rule id="rule1">
  12. <!-- use juel for this input entry -->
  13. <inputEntry expressionLanguage="juel">
  14. <text><![CDATA[cellInput >= 18 && cellInput <= 30]]></text>
  15. </inputEntry>
  16. <!-- use javascript for this output entry -->
  17. <outputEntry expressionLanguage="javascript">
  18. <text>"okay"</text>
  19. </outputEntry>
  20. </rule>
  21. </decisionTable>
  22. </decision>
  23. <decision id="decision2" name="Decision 2">
  24. <!-- use groovy for this literal expression -->
  25. <literalExpression expressionLanguage="groovy">
  26. <text>a + b</text>
  27. </literalExpression>
  28. </decision>
  29. </definitions>

If you want to use another Java Unified Expression Language or FEELimplementation, you can replace the default implementations in theDMN engine configuration. This way you can also changethe JSR-223 script engine resolving, for example if you want to configurethe script engine before using it.

原文: https://docs.camunda.org/manual/7.9/user-guide/dmn-engine/expressions-and-scripts/