Saturday, January 7, 2012

Disabling MDM validations for OOTB business objects

Problem:
Consider a scenario where we need to provide the following fields in the request object
1)AdminContractId,AdminSystemType
2)Phone number/Email -Contact Method
3) Attach Privacy Preferene type/reason ,value etc to the contact methods listed above
The object that will come to our mind are
1)TCRMAdminNativeKeyBObj
2)TCRMContactMethodBObj
3)TCRMPartyContactMethodPrivPrefBObj
Yes you are correct on that.
All these objects can be included in TCRMContractBObj. I decided to create a custom MDM txn(say addMyPreferenceTxn)- (I am using MDM8.5) with TCRMContractBObj as the request object.The response objects doesn't matter for this scenario.
I generated the code,and wrote my logic in the component class which got generated.
When I am about to test the code, it throwed the following errors at my face .

Currency type,ContractStatusType ,Role Type are mandatory. There are a few OOTB external/internal validation on the TCRMContractBObj which makes it mandatory. But for my custom addMyPreferenceTxn I dont want the consumer of the service to provide any dummy values for these 3 fields.

Soultion:
When you genrate the code you will get an EJB project which contains the following class.
 yourmoduleprojectNameTxnBean.
Open that class ,there will be a method  public DWLResponse addMyPreferenceTxn(TCRMContractBObj theBObj) throws DWLBaseException

Here is where you are going to put the extra piece of code to bypass the validation logic.
This piece will be executed after the validations happens but before it enters your component.

I am providing the  code outline for the  addMyPreferenceTxn method.

DWLTransaction txObj = new DWLTransactionPersistent("addMyPreferenceTxn", theBObj, theBObj.getControl());
        DWLResponse retObj = null;
        retObj = executeTx(txObj);
       
        Vector vector = retObj.getStatus().getDwlErrorGroup();
        //Create an iterator for the vector ,iterator through it.


                 DWLError error = vector.get(); 
                //The component ids for currncy typ,role type,status type etc..
                if(error.getComponentType() == 2000 || error.getComponentType() == 2001 || error.getComponentType() == 2002) {

                    //Remove from the iterator.       
           
        }   
     
        //It will be zero if all the validations where success.If it failed for eg:PrivPrefType is empty ,the
        //vector still contains data and that will be returned back.
        if(vector.size() == 0 ) {               
            retObj.setData(theBObj);
            DWLStatus status = new DWLStatus();
            status.setStatus(DWLStatus.SUCCESS);
            retObj.setStatus(status);
           
            try {
                retObj = handleAddMyPreferenceTxn(theBObj);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
       
        return retObj;



 Hope that helps!.