DFC DfOperations Classes – Part 5

In this post I will show you two related functions: copy and move.

Copy Operation

The copy operation copies a folder, document, virtual document or XML document from its current location, to the location specified. If a folder, virtual document or XML document is added to the operation’s node list, the copy is by default “deep”, meaning it will copy sub-folders and children along with the parent object.


private void doCopyOp(ArrayList objList, IDfFolder toFolder ) {

  try {

    // #1 - manufacture an operation
    IDfCopyOperation copyOpObj = cx.getCopyOperation();

    // #2 - add objects to the operation for processing
    for (IDfSysObject sObj : objList) {
      copyOpObj.add(sObj);
    }

    // #3 - set copy params
    copyOpObj.setCopyPreference(DfCopyOperation.COPY_COPY);
    copyOpObj.setDestinationFolderId(toFolder.getObjectId());

    // #4 - execute the operation
    boolean result = copyOpObj.execute();

    // #5 - check for errors
    if (!result) {
      IDfList errors = copyOpObj.getErrors();
        for (int i=0; i<errors.getCount(); i++) {
          IDfOperationError err = (IDfOperationError) errors.get(i);
          System.out.println("Error in Copy operation: " + err.getErrorCode() + " - " + err.getMessage());
        }
    } else {
      // #6 - get new obj ids
      IDfList newObjs = copyOpObj.getNewObjects();
      for (int i=0; i<newObjs.getCount(); i++) {
        IDfSysObject sObj = (IDfSysObject) newObjs.get(i);
        System.out.println("\tnew object is " + sObj.getObjectId().toString());
        newSysObjs.add(sObj);
      }
    }

  } catch(Exception e) {
    System.out.println("Exception in Copy operation: " + e.getMessage());
    e.printStackTrace();
  }

}

Again, the only thing of real note here is the use of the operation-specific parameters at #3.

  • setCopyPreference takes an integer constant defined in the DfCopyOperation class.  This parameter dictates the kind of copy to perform (make copies of children objects, or reference existing children objects)
  • setDestinationFolderId, which indicates where the copies should be made.  Note this parameter is an IDfId object.

Move Operation

The move operation will move objects from one location to another in the repository.  It performs all necessary linking and unlinking of objects.  If the object to be moved is a virtual document or a folder, all of the object’s substructures will be moved also.


private void doMoveOp(ArrayList objList, IDfFolder fromFolder, IDfFolder toFolder ) {

  try {

    // #1 - manufacture an operation
    IDfMoveOperation moveOpObj = cx.getMoveOperation();

    // #2 - add objects to the operation for processing
    for (IDfSysObject sObj : objList) {
      moveOpObj.add(sObj);
    }

    // #3 - set the source and target folder
    moveOpObj.setDestinationFolderId(toFolder.getObjectId());
    moveOpObj.setSourceFolderId(fromFolder.getObjectId());

    // #4 - execute the operation
    boolean result = moveOpObj.execute();

    // #5 - check for errors
    if (!result) {
      IDfList errors = moveOpObj.getErrors();
      for (int i=0; i<errors.getCount(); i++) {
        IDfOperationError err = (IDfOperationError) errors.get(i);
        System.out.println("Error in Move operation: " + err.getErrorCode() + " - " + err.getMessage());
      }
    } else {
      // #6 - get new obj ids
      IDfList newObjs = moveOpObj.getObjects();
        for (int i=0; i<newObjs.getCount(); i++) {
          IDfSysObject sObj = (IDfSysObject) newObjs.get(i);
          System.out.println("\tmoved object " + sObj.getObjectId().toString());
        }
    }

  } catch(Exception e) {
    System.out.println("Exception in Move operation: " + e.getMessage());
    e.printStackTrace();
  }

}

Note with the move operation you must provide the object id for the source folder of the object you are moving, in addition to the destination. This is necessary for the unlink to occur. If you add objects to the operation’s node tree that are in different folders you will need to indicate the source folder for each object as it is added to the tree. In this case, you would not set the setSourceFolderId parameter and change the code that adds objects to the operation’s node tree (#2) to look like this:


// #3 - add objects to the operation for processing
  for (IDfSysObject sObj : objList) {
  IDfMoveNode node = (IDfMoveNode) moveOpObj.add(sObj);
    node.setDestinationFolderId(toFolder.getObjectId());
    node.setSourceFolderId(sObj.getFolderId(0));
  }

This format for adding objects to the operation is actually valid for all of the operation classes. So, if you need more control over the objects you are adding to an operation, it can be achieved like this.

In the next post I’ll show you the delete operation.

Advertisements

About Scott
I have been implementing Documentum solutions since 1997. In 2005, I published a book about developing Documentum solutions for the Documentum Desktop Client (ISBN 0595339689). In 2010, I began this blog as a record of interesting and (hopefully) helpful bits of information related to Documentum, and as a creative outlet.

One Response to DFC DfOperations Classes – Part 5

  1. Pingback: DFC DfOperations Classes – Part 6 « dm_misc: Miscellaneous Documentum Tidbits and Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: