Thursday, October 19, 2017

Skip fields during duplication

This article describes how to skip the user-defined fields during duplication of a record.
To skip the user-defined fields during duplication of a record, complete the following steps:
  • Extend the existing MBO class, for example XYAsset.java

  • Define a static HashSet that contains the names of the fields whose values need not be copied from the source MBO to the target MBO. This HashSet is loaded in the loadXYSkipFieldCopyHashSet.
·         
private static HashSet<String> skipXYFieldCopy = new HashSet<String> ();

  • Define private boolean variable to check whether the HashSet has already been loaded. The HashSet is loaded only once since it is static. The same hashSet can be used by all duplicate methods after it has been loaded.
·         
private static boolean isXYHashSetLoaded = false;


  • Define method loadXYSkipFieldCopyHashSet() that loads the static HashSet with the names of the fields whose values need not be copied from the source Mbo to the target Mbo when a duplicate operation is performed.

private static void loadXYSkipFieldCopyHashSet() throws MXException,RemoteException

{

     isXYHashSetLoaded = true;

     skipXYFieldCopy.add("fieldname");

}
Override the skipCopyField() in the MBO. While this MBO is being copied, this method checks if each attribute needs to be copied by using the data from the static HashSet skipXYFieldCopy.

boolean skipCopyField(MboValueInfo mvi) throws RemoteException, MXException
{
      if(super.skipCopyField(mvi))
     {
         return true;
     }

      if(skipXYFieldCopy.contains(mvi.getName()))
          {
         return true;
      }
     return false;
}
Override duplicate method in the MBO to skip any user defined fields.
MboRemote duplicate() throws MXException, RemoteException
{
      if(!isXYHashSetLoaded)
        {
         loadXYSkipFieldCopyHashSet ();
        }
           MboRemote dup = super.duplicate();

            return dup;
}

No comments:

Post a Comment

JMS Messaging - High availability, scalability and Maximo Integration Framework using a single Service Integration Bus

T he first is configuring the JMS resources for scalability and the second is configuring the messaging engines for highly availability. For...