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 require to specify a type, which is inferred from the value provided. This feature is supported generically by JavaScript, which is used for EA's DMN Simulation.
However, if you want to generate code from DMN model to compiled languages like Java, C++, C#, you will have to specify the type for each Context Entry Variables. Otherwise, if you validate the model, you will have warnings like this:
Context menu on the Context Entry Variable on the following model,
Choose "Show Variable Type"
Then type in the variable type, by appending to the variable name, separated by a colon.
Then save the expression, use the validation button on 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.