DFC DfOperations Classes – Part 7

In this post we will examine the Import and Export operations. These functions tend to be very common in practice. The respective DfOperations for these functions are similar to those previously discussed with a few exceptions noted below.

Import Operation

The Import operation performs a complete import. It creates necessary objects, cleans up, and patches links to XML files if necessary.


private void doImportOp(ArrayList fileList, IDfId importFolderId) {

  try {

    // #1 - manufacture an operation
    IDfImportOperation importOpObj = cx.getImportOperation();

    // #2 - add objects to the operation for processing
    for (String file : fileList) {
    IDfImportNode node = (IDfImportNode) importOpObj.add(file);
      node.setDocbaseObjectType("dm_document");
      node.setFormat("crtext");
    }

    // #3 - set operation params
    // interesting no ACL specified
    importOpObj.setSession(session);
    importOpObj.setDestinationFolderId(importFolderId);
    importOpObj.setKeepLocalFile(true);

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

    // #5 - check for errors
    if (!result) {
      IDfList errors = importOpObj.getErrors();
      for (int i=0; i<errors.getCount(); i++) { 
         IDfOperationError err = (IDfOperationError) errors.get(i);
         System.out.println("Error in Import operation: " + err.getErrorCode() + " - " + err.getMessage());
      }
    } else {

      // #6 - get new obj ids
      IDfList newObjs = importOpObj.getNewObjects();
      for (int i=0; i<newObjs.getCount(); i++) { 
         IDfSysObject sObj = (IDfSysObject) newObjs.get(i);
         System.out.println("\timported " + sObj.getObjectId().toString());
        // set ACL here?
      }
    }

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

}

  • #2 – instead of adding sysobjects to the operation’s node tree, for Import, we add strings that represent the files (complete paths) to import.  The add() method creates IDfImportNodes which we must further update to include the object type and format for each file being imported.
  • #3 – the Import operation is the only DfOperation that requires you to explicitly set the session.  The other operation parameters set here are obvious
  • #6 – I find it interesting that there is no accommodation for setting the ACL on the DfImportNode.  I guess after the import is completed ACLs, lifecycles, etc. can be set here. 

Export Operation

The export operation does a reasonable job of exporting content from the Docbase.  For virtual documents and XML documents it will export all of the referenced children of the parent document.  The most obvious drawback to the Export operation is that it does not perform a deep export of a folder tree.  You can add dm_folder objects to the operation’s node tree for export and it will export them, but none of their contents.  It would be nice to extend this DfOperation class to perform deep exports but there are limitations there too.


private void doExportOp(ArrayList objList, String dir) {

  try {

    // #1 - manufacture an operation
    IDfExportOperation exportOpObj = cx.getExportOperation();

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

    // #3 - set operation params
    exportOpObj.setDestinationDirectory(dir);

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

    // #5 - check for errors
    if (!result) {
    IDfList errors = exportOpObj.getErrors();
      for (int i=0; i<errors.getCount(); i++) {
        IDfOperationError err = (IDfOperationError) errors.get(i);
        System.out.println("Error in Export operation: " + err.getErrorCode() + " - " + err.getMessage());
      }
    } else {

      // #6 - get new obj ids
      IDfList newObjs = exportOpObj.getObjects();
      for (int i=0; i<newObjs.getCount(); i++) {
        IDfSysObject sObj = (IDfSysObject) newObjs.get(i);
          System.out.println("\texported " + sObj.getObjectId().toString());
      }
    }

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

}

Really, other than the caveats mentioned above, the Export operation is pretty straighforward. In the next post, I will briefly touch on some advanced topics and wrap up this series on the DfOperations classes.

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.

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: