3.7. Data Enumerations
3.7.1. Data Enumerations Drop Down List Configuration Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Data enumerations are an optional type of asset that can be configured to provide drop-down lists for the guided editor. They are stored and edited just like any other asset and only apply to the package they are created in.
The contents of an enumeration configuration are the mapping of a
fact.field
to a list of values. These values are used to populate the drop-down menu. The list can either be literal or use a utility class (which must be added to the classpath) to load the strings. The strings contain either a value to be shown in the drop-down menu or a mapping from the code value (which is what is used in the rule) and a display value, e.g., M=Mini.
Example 3.3. An Example Enumeration Configuration
'Board.type' : [ 'Short', 'Long', 'M=Mini', 'Boogie'] 'Person.age' : [ '20', '25', '30', '35' ]
'Board.type' : [ 'Short', 'Long', 'M=Mini', 'Boogie']
'Person.age' : [ '20', '25', '30', '35' ]
3.7.2. Advanced Enumeration Concepts Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Drop-down lists are dependent on field values. With enumerations it is possible to define multiple options based on other field values.
A fact model for insurance policies could have a class called Insurance, consisting of the fields,
policyType
and coverage
. The choices for policyType
could be Home
or Car
. The type of insurance policy will determine the type of coverage that will be available. A home insurance policy could include property
or liability
. A car insurance policy could include collision
or fullCoverage
.
The field value policyType determines which options will be presented for coverage, and it is expressed as follows:
'Insurance.policyType' : ['Home', 'Car'] 'Insurance.coverage[policyType=Home]' : ['property', 'liability'] 'Insurance.coverage[policyType=Car]' : ['collision', 'fullCoverage']
'Insurance.policyType' : ['Home', 'Car']
'Insurance.coverage[policyType=Home]' : ['property', 'liability']
'Insurance.coverage[policyType=Car]' : ['collision', 'fullCoverage']
3.7.3. Obtaining Data Lists from External Sources Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
A list of Strings from an external source can be retrieved and used in an enumeration menu. This is achieved by adding code to the classpath that returns a
java.util.List
(of strings). Instead of specifying a list of values in the user interface, the code can return the list of strings. (As normal, you can use the "=" sign inside the strings if you want to use a different display value to the rule value.) For example, you could use the following:
'Person.age' : ['20','25', '30', '35']
'Person.age' : ['20','25', '30', '35']
To:
'Person.age' : (new com.yourco.DataHelper()).getListOfAges()
'Person.age' : (new com.yourco.DataHelper()).getListOfAges()
This assumes you have a class called
DataHelper
which has a method getListOfAges()
which returns a list of strings. The data enumerations are loaded the first time the guided editor is used in a session. To check the enumeration has loaded, go to the package configuration screen. You can "save and validate" the package; this will check it and provide feedback about any errors.