Custom Validation

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.

  1. Identify an existing converter plug-in class that you want to customize. It will most likely be the converter that is already configured for the domain in question or inherited by it from an ancestor domain.
  2. Create a new sub-class of the relevant converter plug-in and override the validate method.
  3. In the implementation of the method, invoke the super-class's method of the same name to perform any existing validations (if that is appropriate).
  4. Complete the implementation by performing your validations and throwing an exception if any validation fails.
  5. Configure your new plug-in for the relevant domains.

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.

Figure 1. Custom Validation for Odd Numbers
/**
 * 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:

Figure 2. Custom Validation Failure Message
-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:

Figure 3. Configuration for Custom Validation
<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>