Thursday, June 10, 2010

IBM MDM Composite Transactions

As per the IBM MDM developers guide there are 2 ways for implementing Composite Transactions.

1)Using custom business proxies.
2)Using composite xml transactions.
Here we will discuss the first approach.
The steps to be followed are in creating a Business Proxy(BP) are

1. Create a  Java project and your BP class extending the DWLTXnBP
2. Override the execute method.
3. Entry in DWLCommon_extension.properties.
4. Register the transaction name in CDBUSINESSTXTP & COMPONENTTYPE table.
5.Given dependency to the BP java project in  MDM.EAR.
6.Associate jars to the build path of the Java project we created.
7.Add reference in Manifest of DWLCommonServiceEJB.
8. Stop,Clean build,publish and run the transaction through XML Tester.

Step 1: Create a  Java project and your BP class extending the DWLTXnBP
Create a Java project Eg:BasicCompositeTransactionProject
My Class I named it like CreateCustomerBP.java

Step 2:Override the execute method.
public Object execute(Object arg0) throws BusinessProxyException{
//Give a Sysout for testing.
}

Step 3:Entry in DWLCommon_extension.properties.
Add the following entry in DWLCommon_extension.properties
BusinessProxy.tcrm.myXXXTranasactionName = com.XXXXX.mdm.MyCustomBP

Eg:
BusinessProxy.tcrm.createCustomerComposite=com.XXXX.mdm.CreateCustomerBP


Step 4:Register the transaction name in CDBUSINESSTXTP table .
insert into DB2ADMIN.CDBUSINESSTXTP (business_tx_tp_cd, name, tx_log_ind, last_update_dt, tx_object_tp)
 values (900201, 'createCustomerComposite', 'Y', current timestamp, 'P');

INSERT INTO DB2ADMIN.COMPONENTTYPE (COMPONENT_TYPE_ID, DWL_PROD_TP_CD, COMPON_TYPE_VALUE, COMPON_LONG_DESC, LAST_UPDATE_DT)
VALUES (900201, 1, 'CreateCustomerBP', 'DWLSampleCreateCustomerBP Composite Transaction Business Proxy', CURRENT TIMESTAMP);

Step 5:Given dependency to the BP java project in  MDM.EAR
Inside MDM project ->META-INF->application.xml ->Module tab ->Project Utility jars->Add BasicCompositeTransactionProject.jar




Step 6.Associate jars to the build path of the Java project we created.

CoreUtilities.jar ManagementCommon.jar CommonUtilities.jar Logging.jar ConfigurationRepository.jar ConfigurationClient.jar DWLCommonServices.jar icu4j.jar BTM.jar Services.jar Base.jar




Step 7.Add reference in Manifest of DWLCommonServiceEJB .
Go to DWLCommonServicesEJB ->MET-INF->Manifest.mf -> Dependencies->Check BasicCompositeTransactionProject.jar


8. Stop,Clean build,publish and run the transaction through XML Tester.
Try Add/Remove the MDM by right clicking the server.

One normal error that we see in the course of  development is

BTM ITxRxException occurred in Request and Response Framework.
<Throwable>com.dwl.base.exception.DWLBaseException: com.mypack.compositetxns.CreateCustomerBP</Throwable>

The main reason is not following the step 7.Add reference in Manifest of DWLCommonServiceEJB properly.

Sample Code:

import com.dwl.base.DWLCommon;
import com.dwl.base.DWLControl;
import com.dwl.base.requestHandler.DWLTransactionPersistent;
import com.dwl.base.requestHandler.DWLTxnBP;
import com.dwl.tcrm.common.TCRMCommon;
import com.dwl.tcrm.common.TCRMResponse;
import com.dwl.tcrm.financial.component.TCRMContractBObj;
import com.dwl.unifi.tx.exception.BusinessProxyException;
import com.XXX.app.tscd.extension.component.XContractBObjExt;





public class CreateCustomerBP  extends DWLTxnBP{
      DWLControl objDWLControl = null;
    @Override
   
    public Object execute(Object arg0) throws BusinessProxyException{
        // TODO Auto-generated method stub
       
           Object objResponse = null;
       
        try{
        System.err.println("Inside execute...");
        DWLTransactionPersistent objDWLTransactionPersistent = (DWLTransactionPersistent) arg0;
        objDWLControl = objDWLTransactionPersistent.getTxnControl();
        objResponse = processBusinessObject(objDWLTransactionPersistent);
       
        System.err.println("Reached..here..");
        }
       
        catch (Exception objException) {
             objException.printStackTrace();
             
           
         }
        return objResponse;
        //return super.execute(arg0);
    }
   
   
    private Object processBusinessObject(
            DWLTransactionPersistent objDWLTransactionPersistent)
            throws Exception {
        TCRMResponse resAddContract = null;
        DWLCommon objTxnTopLevelObject = (DWLCommon) objDWLTransactionPersistent
        .getTxnTopLevelObject();
        System.err.println("Top Level Object---- "+objTxnTopLevelObject.getClass().toString());
        if ((objTxnTopLevelObject instanceof TCRMContractBObj)) {
       
        System.err.println("Top Level Object instanace of TCRMContractBObj ");
       
        TCRMContractBObj ourTCRMContract=(TCRMContractBObj)objTxnTopLevelObject;
       
       
        XContractBObjExt xContractBobj= (XContractBObjExt)objTxnTopLevelObject;
        System.err.println("Club card Number"+xContractBobj.getXClubCardNbr());
        System.err.println("Line of Business---"+ourTCRMContract.getLineOfBusiness());
        resAddContract=doAddContract(ourTCRMContract);   
        }else{
            System.err.println("Top Level Object NOT instanace of TCRMContractBObj ");
           
           
        }
       
       
       
        return resAddContract;   
    }
   
   
public TCRMResponse doAddContract(TCRMContractBObj ourTCRMContract){
       
   
        System.err.println("In doAddContract()");
        TCRMResponse resAddContract = null;
        //XContractBObjExt xcontract =new XContractBObjExt();
        final String TXN_ADDCONTRACT="addContract";
       
        try {
            resAddContract =  executeAddContract(TXN_ADDCONTRACT,ourTCRMContract);
        } catch (BusinessProxyException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
    /*   
        try{
           
           
            if(ourTCRMContract.getXClubCardId() != null){
                System.out.println("XML :::"+objInputXContractBObjExt_dup.toXML());
                resAddContract =  executeAddContract(TXN_ADDCONTRACT,objInputXContractBObjExt_dup);
            }
        }catch (Exception e) {
            System.out.println("Exception in doAddCOntract");
            e.printStackTrace();
        }*/
        return resAddContract;
    }
   
    public TCRMResponse executeAddContract(final String TXN_ADDCONTRACT, final TCRMCommon topLevelObj) throws BusinessProxyException{
        TCRMResponse resExecuteAddContract = null;
        try{
       
        System.err.println("IN executeAddContract()");
       
       
        DWLTransactionPersistent dtpObj = new DWLTransactionPersistent();
       
        //System.out.println("objDWLControl :::"+objDWLControl.toString());
        dtpObj.setTxnControl(objDWLControl);
        dtpObj.setTxnTopLevelObject(topLevelObj);
        dtpObj.setTxnType(TXN_ADDCONTRACT);
       
        resExecuteAddContract = (TCRMResponse) super.processPersistentObject(dtpObj);
       
        }
        catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        return resExecuteAddContract;
       
    }
   
   
   

}

One thing to remember is to change the  DWLServiceControllerTester class in the XML tester project.

//Composite MDM Service Hashmap
        context.put("TargetApplication", "tcrm");
        context.put("RequestType", "standard");
        context.put("ResponseType", "standard");
        context.put("CompositeTxn", "true");
        context.put("CompositeParser", "DWLService");
        context.put("CompositeConstructor", "DWLService");
        context.put("OperationType", "all");


References:
1)MDM Developer Guide.
2)http://www.ibm.com/developerworks/forums/thread.jspa?threadID=328058&tstart=0