DFC DfOperations Classes – Part 6

The delete operation is one of my favorites. Perhaps because I use it so often, or that I find people like to write this one themselves (me included). It must be the allure of writing a recursive method call to do deep deletes that entices people to write it. Or maybe it is an old habit held over from the days before the operations classes when we had to implement all of this functionality ourselves. Anyway, whatever the reason, I encourage you to use the DfDeleteOperation class instead.

Delete Operation

The delete operation does everything you expect it to: it destroys objects in the Docbase, and if the object is a folder, virtual document, or XML document, it will destroy all of its substructures as well.


private static void doDeleteOp(ArrayList objList ) {
  try {

    // #1 - manufacture an operation
    IDfDeleteOperation deleteOpObj = cx.getDeleteOperation();

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

    // #3 - set op parameters
    deleteOpObj.enableDeepDeleteFolderChildren(true);
    deleteOpObj.enableDeepDeleteVirtualDocumentsInFolders(true);
    deleteOpObj.setDeepFolders(true);

    // #4 - execute the operation
    System.out.println("\tdeleting... ");
    boolean result = deleteOpObj.execute();

    // #5 - check for errors
    if (!result) {
      IDfList errors = deleteOpObj.getErrors();
      for (int i=0; i<errors.getCount(); i++) {  
        IDfOperationError err = (IDfOperationError) errors.get(i);
        System.out.println("Error in Delete operation: " + err.getErrorCode() + " - " + err.getMessage());
      }
    } else {
      IDfList deletedObjs = deleteOpObj.getObjects();
      for (int i=0; i<deletedObjs.getCount(); i++) {
         IDfSysObject sObj = (IDfSysObject) deletedObjs.get(i);
         System.out.println("\tdeleted object " + sObj.getObjectId().toString());
      }
    }

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

There is not much remarkable about this code. The most interesting bits take place at #3 where the operation parameters are set. All of these parameters are true by default, but I set them just to highlight their existence. See the DFC Javadocs for specifics on what each parameter does.

The DfDeleteOperation is by far the best and most robust delete operation I have seen. Beyond the operation parameters, you can customize each node (DfDeleteNode) added to the operation’s node tree at #2 to behave differently, such as delete certain versions. I showed you an example of using these operation-specific nodes last week with the Move operation.

In the next post I will present the Import and Export operations.

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.

2 Responses to DFC DfOperations Classes – Part 6

  1. Tapendu says:

    Hi,
    thanks for the code snippet, it was very useful. I have a doubt. I want to delete multiple objects, and i add them to the operation object and then execute and a few fail to get deleted. Now the error message (e.getMessage()) gives me the names of the objects. How do i get it to print the failed object id? I do not want to run a separate query for that, as i want to know the reason of failure too.

    thanks,
    Tapendu

    Like

    • Scott says:

      I don’t have access to a Documentum system to test this at the moment, but off the top of my head you can do the following: In the if(!result) section of the code (#5), you can obtain the IDfOperationNode from the IDfOperationError object. From the IDfOperationNode, you can obtain the Id of the object that caused the error. Once you have the object’s Id (i.e., r_object_id), you can do whatever is necessary with the failed document.

      Looking at your question again, you are referencing the e.getMessage() method, which is only found in the catch() block of the code. Therefore, some other kind of error is occuring in your code. Try copying the error handling code from the if(!result) block I mentioned above and pasting it in the catch() block and see if you can get what you need.

      Hope that helps.

      Like

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: