Creating custom data validation levels

When values are mapped from one business object to another based on transformation code, incorrect data can result. The data validation feature checks each operation in a map and logs an error when data in the incoming business object cannot be transformed to data in the outgoing business object according to certain rules.

Example: Suppose that a map transforms a string value in the source business object to an integer value in the destination business object. This type conversion works properly when an incoming string value represents an integer (for example, "1234" represents the integer 1234). However, the conversion does not work properly if the string value does not represent an integer (for example, "ABCD" might indicate invalid data).

This section provides the following information about using data validation levels in a map:

Coding a data validation level

The map development system defines data validation levels 0 and 1; levels 2 and greater are available for you to define. Table 62 summarizes the data validation levels:

Table 62. Data Validation Levels
Level Description
0 Default; no data validation
1 IBM-defined data type checks
2 and greater User-defined validation checks

To create a custom validation level, double-click an attribute to display its code in the Activity Editor window. Note the following if statement, which introduces the code that throws an exception when invalid data is encountered:

if (dataValidationLevel >= 1) 

Add your own if statement to specify the action that you want to associate with the data validation level. The data validation rules that you associate with a level can be whatever is appropriate and needed for your business logic and applications. For example, a level 2 rule for a particular attribute might check for a certain value and, if it is not present, set the attribute to a default.

Example: The following example code uses data validation level 2 to check that a credit card number is valid:

/*
** At data validation level 2, check credit card numbers resulting 
** from data entry errors, etc.
*/
if (dataValidationLevel >= 2)
   {
   if (!CustUtility.validateCreditCard(ObjPurchaseReq.getString
         ("creditCardNumber")))    
      {
      logWarning("Invalid credit card number sent through.");
      if (failOnInvalidData)
         {
         throw new MapFailureException(
            "Invalid credit card number.");
         }
      }
   }

Steps for testing the data validation level

In a test run of the map, you can set the data validation level to see that it is working properly. Perform the following steps to test the data validation level for a map instance:

  1. Display the Map Properties dialog, as follows:

    From the Edit menu, select Map Properties. For information on other ways to display the Map Properties dialog, see Specifying map property information.

    Result: The General tab of the Map Properties dialog appears.

    Figure 92. General tab of Map Properties dialog
  2. Set the data validation level you want to test. Optionally, set the map to fail if the data is invalid.
  3. Stop and restart the map for the new data validation level to take effect.
Note:
You can also set the data validation level and whether it fails if invalid data is present from the Map Properties window and the server component management view.

Copyright IBM Corp. 2004, 2005