Integrate a DMN Module Into BPSim for Simulation
The strength of DMN is its ability to describe business requirements through the Decision Requirement diagram and to encapsulate the complicated logic in versatile expressions such as the Decision Table and Boxed Context.
Equally, the strength of BPMN is its ability to describe business processes with a Sequence Flow of tasks and events, or to describe collaborations of processes with Message Flows.
The Decision Requirements diagram forms a bridge between business process models and decision logic models:
- Business process models define tasks within business processes, where decision-making is required
- Decision Requirements diagrams define the decisions to be made in those tasks, their interrelationships, and their requirements for decision logic
- Decision logic defines the required decisions in sufficient detail to allow validation and/or automation
DMN provides a complete decision model that complements a business process model by specifying in detail the decision-making carried out in process tasks.
The two examples demonstrated in this topic can be accessed from:
- EA Example Model | Model Simulation | BPSim Models
- Perspectives | Business Modeling | BPSim | BPSim Case Studies
There are two ways in which BPSim expressions use a DMN model:
- DMN's Decision Service - demonstrated by the Loan Application Process
- DMN's BusinessKnowledgeModel - demonstrated by the Delivery Cost Calculation
The process of integrating a DMN model with a BPSim model includes:
- DMN Model Validation, Simulation, Code Generation and Testing on the generated module
- Set up a usage dependency from the BPSim Artifact to the DMN Artifact
- Generate or update the BPMN DataObject from the DMN DataSet
- Create Property Parameters in BPSim to be used on tasks and Sequence Flows out going from Gateways
- Bind the DMN interface to BPSim Property Parameters
DMN Model Validation for Compiled languages such as Java
However, for languages such as C++, C# and Java, the compiler will report an error that a variable does not have a type.
For generation to these languages you must run validation on the model and use the results to find variables that need their type set. For example:
- Business Knowledge Model parameter - select the BKM element to view in the DMN Expression window, click on the second button to open the 'Parameter' dialog, specify a type for the parameter
- Decision's type - select the Decision element, open the Properties window, for the property 'variableType' select from the value combobox
- Decision Table's Input/Output clauses: On the Decision Table's Input/Output clause, right-click to display the context menu and choose the type
- Boxed Context's variables: Refer to this page: Boxed Context
DMN Code Generation In Java
After using validation to fix any variable type issues, we can proceed on to the 'Generate Module' page in the DMN Simulation window.
- Select DecisionService1 in the top combo box; all the elements involved in DecisionService1 will now be included in the list
- Item Definition and Business Knowledge Model are global elements
- Input Data and Decisions are encapsulated in the Decision Service element
- For Java, the Module Path must match the Package structure; in this example, the DMNModule.java must be generated to a directory to form a file path that ends with "\com\sparxsystems\dmn\DMNModule.java" - you have to manually create the directory structures for now
Click on theon the toolbar (next to the 'Language' combo box). This example will use Java; however, C++ and C# are the same. These actions are performed:
- The .java file is generated to the path specified
- An Analyzer Script (Build script) for this Artifact is created
- The Build Script for this Analyzer Script is executed
- The message is reported in the System Output window
If the model is valid, this process will return the message:
If there are compiling errors, you can open the generated .java file by clicking the button next to theon the toolbar, manually fix the issue, and compile with the generated script until you are successful.
One common reason for a compile failure is that languages can have different grammars for an expression. You might need to provide a value for a language to overwrite the default (right-click on a DMN Literal Expression | Edit Expression).
Testing DMN Modules before external Use
Having generated the model to java code and successfully compiled it we now want to:
- Test this module's correctness
- Provide it with inputs
- Get the output decision values
Generate BPMN DataObject
The data carried by the selected data set will be generated to the BPMN DataObject's 'Notes' field.
- Click the Test (2nd to the right on the toolbar of the 'Generate Module' page) to open the 'Test Module' page
- Click the first button on the toolbar to select the inputs - BPMN DataObject elements
- Select the available outputs from the 'Decision' combo box, such as Get_Routing(), and click on the Run button on the toolbar
The execution result will be displayed in the Debug window. You can also open the test module file, set a breakpoint on the line and debug in the DMN Module to do line-level-debugging.
We highly recommend you test your DMN Module with this window to guarantee that the DMN Module is functional with the given inputs (from BPMN DataObject) and that it will successfully compute the result of the output.
Note: The DMN Module path is saved in the DMNSimConfiguration Artifact's 'Filepath' property.
Now, it is time to integrate the DMN module with the BPSim model.
The first step is to set up the usage dependency between the BPSim Artifact and the DMN Artifact.
Note: A BPSim Artifact can use multiple DMN modules if necessary. This is supported by simply putting all DMN Artifacts on this diagram and drawing a Dependency connector from the BPSim Artifact to each DMN Artifact.
These Help topics provide two examples of using the above methods. See:
- Example: Integrate DMN Decision Service into BPSim Data Object and Property Parameter
- Example: Integrate DMN Business Knowledge Model into BPSim Property Parameter