Custom validation can be performed in two ways: by setting the domain definition options in the UML model, or by implementing a validate operation in a custom converter plug-in. It is also possible to combine both ways to meet your validation requirements.
The domain definition options in the UML model are limited to a small number of validations that are described in the Cúram Modeling Reference Guide and summarized in Converter Plug-ins above. If the domain definition options meet your needs, you should use them in preference to any programmatic alternative. If the options meet only some of your needs, you should use them and also create a custom converter plug-in to complete the validations. If the options are not useful, you should create a custom converter plug-in and implement all the validations there. Some uses for custom validation routines might include the validation of check digits or the imposition of any other arbitrary restrictions on the permitted values.
In this example, a new converter plug-in is created that extends the InternalIDConverter plug-in with a validation that only permits even numbers. The InternalIDConverter is derived from the SvrInt64Converter class that is configured for use by the SVR_INT64 domain. Values in this domain are represented by java.lang.Long objects.
/** * Reports ID numbers as invalid if they are odd. */ public class EvenIDConverter extends InternalIDConverter { public void validate(Object data) throws ConversionException { // Perform any existing validations first. super.validate(data); if (((Long) data).longValue() % 2 != 0) { throw new CustomConversionException(-200010); } } }
The error message entry in the custom message catalog may look like this:
-200010=ERROR: The field '%0s' must be an even number.
If this validation is to be applied to the EVEN_ID and the NOT_ODD_ID domains, then the configuration will look like this:
<dc:domains xmlns:dc="http://www.curamsoftware.com/curam/util/common/domain-config"> <dc:domain name="EVEN_ID"> <dc:plug-in name="converter" class="custom.EvenIDConverter"/> </dc:domain> <dc:domain name="NOT_ODD_ID"> <dc:plug-in name="converter" class="custom.EvenIDConverter"/> </dc:domain> </dc:domains>