Prev | Next |
Example - Loan Installment Calculation
The Business Knowledge Model (BKM) Installment calculation is implemented as Boxed Context.
- The BKM defines four parameters: Product Type, Rate, Term and Amount
- The Boxed Context defines two variable-expression pair entries, these variables serve as 'local variables' that can be used in later expressions
- Return value: The expression can use the value of 'local variables'
- Any expressions in a Boxed Context can use built-in functions, which are defined in the customizable Template — DMN Library; for example, functions PMT(...) and decimal(...) are used in this example
Specify Type to Context Entry Variable
In general, the expression and variables do not have to specify a type, which is inferred from the value provided. This feature is supported generically by JavaScript, which is used for Enterprise Architect's DMN Simulation.
However, if you want to generate code from a DMN model to compiled languages such as Java, C++ or C#, you will have to specify the type for each Context Entry Variable. Otherwise, if you validate the model, you will see warnings such as:
Right-click on the Context Entry Variable (Monthly Fee, Monthly Repayment) in this model.
Select the 'Show Variable Type' option.
Now type in the variable type, appending it to the variable name, separated by a colon (see the field above Monthly Fee).
Then click on the
on the toolbar to save the expression, and click on the (seventh from the left in the toolbar) to validate the model again.Expression Editor and Intelli-sense Support
The parameter and Context Entry's variable name can contain spaces, according to the FEEL language specification. This feature makes the expression easy to read. In order to help you edit the expressions with less typing and making fewer mistakes, Enterprise Architect provides Intelli-sense support for editing expressions:
Right-click on the Expression | Edit Expressions... the 'Expression' dialog displays
Press
to show the Intelli-sense menu:- All the Context Entry Variables earlier than the current one will be included (the context entries later than the current one are excluded)
- For BKM, all the parameters will be included
- For Decision, all the required Decisions will be included
The DMN model can be generated as source code for JavaScript, Java, C# and C++. Since some languages might have different syntax for some expressions, Enterprise Architect provides language override pages for each language. If no override code is specified for a language, the expression defined for the FEEL language will be used.
In the generated code, the space inside a variable name will be replaced by an underscore.
Test Harness for Business Knowledge Model
Select the 'Input Parameter Values for Simulation' tab and complete the fields.
Click on the
on the toolbar; the test result will be presented in the Boxed Context.
- The runtime parameter value will be displayed; for example, 'Rate = 0.00375'
- The 'Context Entry' variable's runtime value will be displayed; for example, 'Monthly Repayment = 1520.05'
- The BKM's result will be evaluated by the last entry and the values displayed on the declaration line; for example, 'return = 1540.06'
You can use this functionality to unit test a BusinessKnowledgeModel without knowing the context and later on invoked by a Decision or other BusinessKnowledgeModel.
Menu options are available for this tool bar button. For more information, see the Business Knowledge Model and Test Harness Help topic.