Integrate 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:
- EAExample Model | Model Simulation | BPSim Models
- Perspective | 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 type - select the Decision element, open the Properties window, for the property 'variableType' select from the 'Value' field
- Decision Table Input/Output clauses - on the Decision Table Input/Output clause, right-click to display the context menu and choose the type
- Boxed Context variables - refer to the Boxed Context Help topic
DMN Code Generation In Java
After using validation to fix any variable type issues, we can proceed to the 'Generate Module' page in the DMN Simulation window.
- Select DecisionService1 in the top toolbar data entry field; 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 DecisionService element
- For Java, the 'Module Path' value 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 the() on the toolbar. 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
- Progress messages are 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 the button on 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 button (2nd to the right on the toolbar of the 'Generate Module' tab) to open the 'Test Module' tab
- Click the on the toolbar to select the input BPMN DataObject elements
- Select the available outputs from the 'Decision' combo box, such as Get_Routing(), and click on the 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 the BPMN DataObjects) 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 Simulation 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 Simulation Artifact.
These Help topics provide two examples of using these methods. See:
- Example: Integrate DMN Decision Service into BPSim Data Object and Property Parameter
- Example: Integrate DMN Business Knowledge Model into BPSim Property Parameter