Advanced Customization > Services and Infrastructure Customization > Enumerated Types > External Enumerated Value Lists
  
External Enumerated Value Lists
You can define an enumeration constraint on an attribute that is not a simple static list of values. The values come from some external source and may change over time. The Type and Attribute Management utility lets you define static enumeration constraints on attributes. These enumerations must be maintained manually through the UI. However, there are some cases where you might want to retrieve the enumeration from an external source rather than maintaining the static list manually.
Scope/Applicability/Assumptions
This capability applies to string attributes defined in the Type and Attribute Management utility.
Intended Outcome
With this solution, you can constrain an attribute to an enumerated list of values that comes from an external source. You can control the following:
Localization of the values
Sort order of the values
Selectability of the values
Any trigger condition to ensure the enumeration is always up to date
Solution
Implement an EnumerationInfoProvider to supply the enumerated list and configure a constraint in the Type and Attribute Management utility to use your EnumerationInfoProvider.
Prerequisite Knowledge
To achieve this objective, you need to have an understanding of the following:
Adding constraints to an attribute in the Type and Attribute Management utility.
How to extract the required enumeration values from your external source.
Solution Elements
Element
Type
Description
EnumerationInfoProvider
java
The interface defines how to implement a custom dynamic enumeration provider. Instances of this are instantiated through reflection. Therefore a public no-arg constructor is required. Any exceptions thrown from the methods in this interface result in an empty enumeration.
EnumerationInfoManager
java
This interface defines the method that enumeration info providers can use to reset their cached enumerations.
EnumerationInfo
java
This class represents an enumeration. It contains both the properties of the enumeration as well as it's entries. This class is not thread safe and should not be modified after handing it off to other code.
EnumerationEntryInfo
java
This class represents an enumeration entry. It contains the properties of the enumeration entry. There is a unique name for each enumeration entry.
Procedure – Implementing an EnumerationInfoProvider
Provide an implementation of the EnumerationInfoProvider interface.
The initialize method is called once, before the first time the enumeration is retrieved by the system. The usage of the parameter field is optional. If your implementation does not require any inputs, then the parameter can be ignored. The syntax of the parameter field is entirely up to you, with the only restriction being that it should not contain white space or the ‘~’ character. The parameter is not used by the system for any purpose. The EnumerationInfoProvider.initialize() method is also invoked after EnumerationInfomanager.resetEnumeration(<provider>) call is made.
The getEnumerationInfo method is called after the initialization, and the results of that call is cached by the system automatically. The getEnumerationInfo method is called again only on the next request for the enumeration after an EnumerationInfomanager.resetEnumeration(<provider>) call is made. Otherwise, the cached information is returned. You can use any logic appropriate to your use case to determine when to make the resetEnumeration call. If you never call it, then the enumeration is effectively static (unless the system caches flush for another reason.) You could call it periodically, or in response to a trigger. For best performance, only call this method after changes to the external information have been made which need to be reflected in the enumeration.
The getEnumerationInfo() method is where you return an instance of the EnumerationInfo data structure. The EnumerationInfo supports two non-localizable properties that you can use to customize the behavior of your enumeration.
Sample
public EnumerationInfo getEnumerationInfo() {
EnumerationInfo enumerationInfo = new EnumerationInfo();

enumerationInfo.setNonLocalizableProperty(EnumerationInfo.AUTO_SORT,
Boolean.TRUE);
enumerationInfo.setNonLocalizableProperty(EnumerationInfo.DEFAULT_LOCALE,
Locale.EN_US);

Set<EnumerationEntryInfo> enumEntryInfos = getEntries();
enumerationInfo.addEnumerationEntryInfos(enumEntryInfos);

return enumerationInfo;
}
An EnumerationInfo contains a collection of EnumerationEntryInfo data structures. The EnumerationEntryInfo data structure supports two non-localizable and one localizable property that you can use to customize the behavior of your enumeration. Localizable properties can have distinct values set of any number of different locales.
Sample
Set<EnumerationEntryInfo> enumEntryInfos =
new LinkedHashSet<EnumerationEntryInfo>(12);
loop (…) {
String name = …;
EnumerationEntryInfo enumEntryInfo = new EnumerationEntryInfo(name);

int sortOrder = …;
Boolean selectable = …;

enumEntryInfo.setNonLocalizableProperty(EnumerationEntryInfo.SORT_ORDER,
sortOrder);
enumEntryInfo.setNonLocalizableProperty(EnumerationEntryInfo.SELECTABLE,
selectable);

Locale locale = …;
String displayName = …;
enumEntryInfo.setLocalizableProperty(EnumerationEntryInfo.DISPLAY_NAME,
locale, displayName); }
Procedure – Configuring an External Enumerated Value List Constraint in the Type Manager and Attribute Management Utility
When you add an External Enumerated Value List constraint to an attribute in the Type and Attribute Management utility, you must specify two fields.
Specify the fully qualified classname of your EnumerationInfoProvider implementation.
Optionally specify a parameter String which should be passed to your EnumerationInfoProvider implementation’s initialize method.
Customization Points
Customization Points - EnumerationInfo
Property
Default Value
Possible Values
Required?
Description
EnumerationInfo.AUTO_SORT
Boolean.FALSE
Boolean.FALSE
Boolean.TRUE
no
If the EnumerationInfo.AUTO_SORT property is set to true, then the system automatically sorts the enumeration based on the localized display names of the entries. If it is set to false, then the system sorts the enumeration based on the relative sort order you assign to the entries. If two or more entries are given the same sort order, those entries are sorted relative to each other based on their display names. Entries without a sort order defined are sorted after all entries with a sort order defined.
EnumerationInfo.DEFAULT_LOCALE
System Locale
Any Locale
no
Indicates the locale which should be used as the fallback if the client requests the localized display information for an enumeration entry for a locale for which localizations are not available.
Customization Points - EnumerationEntryInfo
Property
Default Value
Possible Values
Required?
Description
EnumerationEntryInfo.SORT_ORDER
null
Any Integer
no
If the EnumerationInfo.AUTO_SORT property is set to false, the system sorts the enumeration based on the relative sort order you assign to the entries. If two or more entries are given the same sort order, those entries are sorted relative to each other based on their display names. Entries without a sort order defined are sorted after all entries with a sort order defined.
EnumerationEntryInfo.SELECTABLE
Boolean.TRUE
Boolean.TRUE
Boolean.FALSE
no
Indicates whether the entry should be selectable by the end user during edit operations.
EnumerationEntryInfo.DISPLAY_NAME
null
Any String
no
The display name for the enumeration entry for the indicated locale.