Information Management IBM InfoSphere Master Data Management, Version 11.3

Example: Using external validations

Business scenario

In this scenario, a product needs to be validated for an add transaction. The product has both variable type data and fixed type data. The fixed type data of Java™ type-product has two fields: Description and ShortDescription. The variable type data has following schema:
<xsd:schema xmlns:product="http://www.ibm.com/xmlns/prod/websphere/mdm/product/schema"
	xmlns:xsd= "http://www.w3.org/2001/XMLSchema"
	targetNamespace="http://www.ibm.com/xmlns/prod/websphere/mdm/product/schema">
	<xsd:complexType name="ProductPrice">
    		<xsd:sequence>
		      <xsd:element name="normal" type="xsd:decimal"/>
		      <xsd:element name="discount" type="xsd:decimal" minOccurs="0"/>
		</xsd:sequence>
	</xsd:element>
	<xsd:element name="Product">
  		<xsd:complexType>
    		     <xsd:sequence>
		           <xsd:element name="GTIN" type="xsd:integer"/>
		           <xsd:element name="description" type="xsd:string" minOccurs="0"/>
		           <xsd:element name="Price" type="product:ProductPrice"/>
		      </xsd:sequence>
  		</xsd:complexType>
	</xsd:element>
</xsd:schema>
An instance of this schema:
<Product>
	<GTIN>1853729163851</GTIN>
	<description>Example</description>
	<Price>
	   <normal>188.00</normal>
	   <discount>94.00</discount>
	</Price>
</Product>
The validation rule requirements are as follows:
  1. Description can have a maximum length of 100. This applies to all transaction types and is of transaction type GENERAL.
  2. The ShortDescription can have a maximum length of 50. This applies to all transaction types and is of transaction type GENERAL.
  3. The Description and ShortDescription fields cannot both be blank; at least one of them must be assigned a value. This applies only to a CREATE transaction type.
  4. The GTIN element for variable data has to match a complex GTIN rule. See http://www.gs1.org/productssolutions/barcodes/support/check_digit_calculator.html#how

    This applies to all transaction types and it is of transaction type GENERAL.

  5. The normal price must be more than the discount price in variable type data. This applies only to a CREATE transaction type.

Solution in external validation

Fixed type validation is used to solve the first three validation requirements. Variable type validation is used to solve the last two validation requirements.
  1. Element Validation
    Target
    • ELEMENT: Description
    • GROUP: Product
    Context
    • APPLICATION: TCRM
    • TRANSACTION_TYPE: GENERAL
    Function
    JAVA_CLASS: com.ibm.mdm.validation.MaxLen
    Condition
    Optional. No condition.
    Parameters
    • PARAM_TYPE: MAXLENGTH

      PARAM: 100

  2. Element Validation
    Target
    • ELEMENT: ShortDescription
    • GROUP: Product
    Context
    • APPLICATION: TCRM
    • TRANSACTION_TYPE: GENERAL
    Function
    JAVA_CLASS: com.ibm.mdm.validation.MaxLen
    Condition
    Optional. No condition.
    Parameters
    • PARAM_TYPE: MAXLENGTH

      PARAM: 50

  3. Group Validation
    Target
    GROUP: Product
    Context
    • APPLICATION: TCRM
    • TRANSACTION_TYPE: CREATE
    Function
    JAVA_CLASS: com.ibm.mdm.validation.DescBlankCheck
    Condition
    Optional. No condition.
    Parameters
    None
  4. Spec Validation
    Target
    TARGET_ID: 12345

    Assuming spec format id is 12345 for the schema

    Context
    • APPLICATION: TCRM
    • TRANSACTION_TYPE: GENERAL
    Function
    JAVA_CLASS: com.ibm.mdm.validation.GTINCheck
    Condition
    Optional. No condition.
    Parameters
    • PARAM_TYPE: PATH

      PARAM: /Product/GTIN

  5. Spec validation
    Target
    TARGET_ID: 12345

    Assuming spec format id is 12345 for the schema

    Context
    • APPLICATION: TCRM
    • TRANSACTION_TYPE: CREATE
    Function
    JAVA_CLASS: com.ibm.mdm.validation.GreaterCheck
    Condition
    Optional. No condition.
    Parameters
    • PARAM_TYPE: BIG

      PARAM: /Product/Price/normal

    • PARAM_TYPE: SMALL

      PARAM: /Product/Price/discount

Sample Java validation function

A Java class that extends ValidatorCommon and contains greater than logic is used as the validation function. The following is the sample code.
public class GreaterCheck extends ValidatorCommon {

    public final static String BIG = "BIG";
    public final static String SMALL = "SMALL";
    public final static String SPECNAME = "SPECNAME";
    public final static String NAMESPACE = "NAMESPACE";
    private String big;
    private String small;
    private String specName;
    private String nameSpace;

    public PriceCheck() {
        super();
    }

    protected void setValidatorParameter(Map param) throws ValidationException 
	 {
        List list = null;

        try {
            list = (List) param.get(BIG);
            big = (String) list.get(0);
            list = (List) param.get(SMALL);
            small= (String) list.get(0);
            list = (List) param.get(SPECNAME);
            specName = (String) list.get(0);
            list = (List) param.get(NAMESPACE);
            nameSpace = (String) list.get(0);
        } catch (Exception e) {
            throw new ValidationException("Set ParamType: " + BIG + " and "+ 
			SMALL + " failed. " + e);
        }
    }

  protected DWLStatus validateObject(Object obj, DWLStatus status, Object env) throws ValidationException{
        try {

	      //cast to dynamic object
	      DynamicEntity dn = (DynamicEntity) obj;
	
	     //get SpecValueBObj
	    SpecValueBObj sv = dn.retrieveSpecValueBObj(specName, nameSpace);
			
	     //get big and small value
	     float aBig = Float.parseFloat(sv.retrieveLeafAttributeText(big));
  	     float aSmall = Float.parseFloat(sv.retrieveLeafAttributeText(small));
	
	     //check value
	     if (aBig <= aSmall)		  {
	                this.setErrorStatus(status);
	     }
        } catch (Exception e) {
            throw new ValidationException(e);
        }

        return status;
  }    
}


Last updated: 27 June 2014