Creating Dynamic Domains from an Excel file
A very common requirement in a Rule development project is to manage some data objects with dynamic domains. But wait, what are domains? A Domain places a restriction for your BOM members, this includes attributes, method arguments and classes. For more information about domains click here.
There are many ways to use Domains, the easiest way is to use Static References to define the possible values. But what if we want to have an external source to manage and update our values frecuently? Well, that’s when Dynamic Domains come in handy. In this tutorial we will focus on creating dynamic domains from an excel file.
The IBM knowledge center provides an article about this topic but without some key details that can make you spend more time than neccesary.
Steps:
-
- Creating the Domains Values Excel File
-
- The Excel file must have the structure defined by the Excel Domain Provider:
- Value column
- Label column
- BOM to XOM column
- Documentation and additonal labels/documentation for other locales (Optional)
- You can have multiple sheets, each one representing a Domain. Example: Countries, Cities, Streets, etc.
- Each row represents a value for that particular Domain, you cannot have merged cells.
- Here is an example of how your excel file should look like:
- Tip: If you want to have the option to send a blank value use “None” or “NA” in the Values and Label columns and return “”; in the BOM to XOM column. Check the example above.
- Save the Excel file in the resources folder or your BOM rule project.
- The Excel file must have the structure defined by the Excel Domain Provider:
-
- Creating the Dynamic Domains from the Domains Excel File
-
- It is recommended to have the Domain values in a separate BOM model, or at least in a separate package from your original objects. Here is a simple example:
- Create a class in your new BOM model for each Domain you have. In this example “CountryValues”.
- Open the new class and expand the BOM to XOM Mapping section. In the Execution name field you need to specify the type for your Domain values, for example java.lang.String:
- Now you are ready to create your dynamic domains, locate the Domain section and click Create.
- Select the Excel option under Dynamic Domains, click Next and then select your excel file.
- Select the correct sheet for the Domain you are working on and check the “Table with Header” option to see the column header values. Now map the columns to the appropiate field, here is how your final mapping should look like:
- The values should appear in the Domain section:
- You can update the values by modifying the Excel file and clicking “Synchronize” or at the BOM Entry level, clicking “Update”:
-
- Creating the virtual attribute
-
- Our first intention would be to change the type our attribute to our new virtual class but this would create a duplicate of the original member and a BOM to XOM conflict error. That is why we need to create a virtual member for each attribute that is going to use Domains.
- Create a new member in your Class editor and in the type field select the virtual class with the Domains. In this example we are going to create “countryVirtualName”:
- Verbalize the member accordingly. You will need to change Edit the subject to elaborate correct sentences for Action and Navigation fields. Remember to delete the original member verbalization.
- Check the “Ignore for DVS” option to avoid having the virtual value being added when testing with DVS Excel testsuites.
- And the last but most important step is to finish the BOM to XOM mapping. In Getter return the original member and in Setter assign the value to the original member. Example:
-
- Creating the Domains Values Excel File
Results:
Now you are ready to use Dinamyc Domains for your BOM members like in the Decision Table sample below:
Please feel free to contact me with any queries or feedback about this article. Thank you!
- Published in Domains, Rule Authoring, Rule Designer