TBOs – Part 4

In the last post, I showed you how to override the doSave() method in order to inherit metadata from the case_folder to the case_document. In this post, I will show you how to override the doDelete() method log each case_document that is deleted.

Logging the date, time and person deleting an object is pretty straight forward, as seen in the code below.

/*
* Case Document TBO
* (C) 2010 M. Scott Roth / dm_misc
*
*/
	protected void doDestroy(boolean force, Object[] extendedArgs) throws DfException {

		DfLogger.info(this, "ENTER: doDestroy method for obj id {0}, obj name {1}",
                                  new String [] {this.getObjectId().toString(),
                                  this.getObjectName() },
                                  null);

		// get user and current time to use in log statements
		IDfUser user = this.getSession().getUser("");
		IDfTime now = new DfTime();

		// get the object id and name to use in log statements
		String object_name = this.getObjectName();
		String object_id = this.getObjectId().toString();

                DfLogger.info(this, "*** doDestroy: {0} ({1}) destroyed by {2} on {3} ***",
                                  new String [] {object_name,
                                  object_id,
                                  user.getUserName(),
                                  now.asString(DfTime.DF_TIME_PATTERN17)},
                                  null);

		// call destroy
		super.doDestroy(force, extendedArgs);

		DfLogger.info(this, "EXIT: doDestroy method for obj id {0}, obj name {1}",
                                  new String [] {object_id,
                                  object_name },
                                  null);
	}

A more interesting implementation might be to log the delete, but not really delete the case_document until a supervisor can review it. In this case, the doDelete() method should not call the super.doDelete() method, instead it should move the case_document to a “Trash” cabinet. However, these objects do need to eventually be deleted, so I added a conditional statement in the doDelete() method that checks the user’s capabilities and chooses which delete action to take.

/*
* Case Document TBO
* (C) 2010 M. Scott Roth / dm_misc
*
*/

	protected void doDestroy(boolean force, Object[] extendedArgs) throws DfException {

               DfLogger.info(this, "ENTER: doDestroy method for obj id {0}, obj name {1}",
                                 new String [] {this.getObjectId().toString(),
                                 this.getObjectName() },
                                 null);

		// get user and current time to use in log statements
		IDfUser user = this.getSession().getUser("");
		IDfTime now = new DfTime();

		// get the object id and name to use in log statements
		String object_name = this.getObjectName();
		String object_id = this.getObjectId().toString();

		// #1 if user is super user, destroy object
		if (user.isSuperUser()) {

			DfLogger.info(this, "*** doDestroy: {0} ({1}) destroyed by {2} on {3} ***",
                                          new String [] {object_name,
                                          object_id,
                                          user.getUserName(),
                                          now.asString(DfTime.DF_TIME_PATTERN17)},
                                          null);

			// #2 call destroy
			super.doDestroy(force, extendedArgs);

		// #3 if user is not superuser, move the object to the Trash
		} else {
			DfLogger.info(this, "*** doDestroy: {0} ({1}) moved to trash {2} on {3} ***",
                                          new String [] {object_name,
                                          object_id,
                                          user.getUserName(),
                                          now.asString(DfTime.DF_TIME_PATTERN17)},
                                          null);

			// move object to trash
			moveToTrash(this);
		}

		DfLogger.info(this, "EXIT: doDestroy method for obj id {0}, obj name {1}",
                                  new String [] {object_id,
                                  object_name },
                                  null);
	}

	private void moveToTrash(IDfSysObject sObj) throws DfException {

		// #4 get the trash folder
		IDfFolder trash = (IDfFolder) sObj.getSession().getObjectByQualification("dm_cabinet where object_name = 'Trash'");

		if (trash != null) {

			//#5  link to trash and unlink from current folder
			sObj.link(trash.getObjectId().toString());
			sObj.unlink(sObj.getFolderId(0).toString());
			sObj.save();

		} else {
			DfLogger.error(sObj,"Could not find Trash cabinet.",null,null);
		}
	}
  1. If the user is a superuser, log the deletion and do the delete.
  2. Call the super class’ destroy method.
  3. If the user is NOT a superuser then log the “deletion” and move the object to the Trash cabinet.
  4. This is the short method that moves the object to the Trash. First, find the Trash cabinet (in this example I assume one already exists).
  5. Simply link and unlink the object to the Trash cabinet. Notice that the sObj.save() will fire the onSave() method discussed in the last post. Because the onSave() method prevents case_documents from being saved anywhere except in a case_folder, you will get an error when this line is called. Either make an exception in the onSave() method for the Trash cabinet or don’t throw the Exception.

A snippet from the log4j file shows that the TBO is working.

22:57:52,088  INFO [http-8080-2] com.dm_misc.tbo.CaseDocumentTBO - ENTER: doDestroy method for obj id 090000018000d139, obj name case doc 14
22:57:52,088  INFO [http-8080-2] com.dm_misc.tbo.CaseDocumentTBO - *** doDestroy: case doc 14 (090000018000d139) destroyed by dmadmin on 28/09/10 22:57:52 ***
22:57:52,354  INFO [http-8080-2] com.dm_misc.tbo.CaseDocumentTBO - EXIT: doDestroy method for obj id 090000018000d139, obj name case doc 14
...
22:57:22,869  INFO [http-8080-2] com.dm_misc.tbo.CaseDocumentTBO - ENTER: doDestroy method for obj id 090000018000d140, obj name case doc 14-1
22:57:22,869  INFO [http-8080-2] com.dm_misc.tbo.CaseDocumentTBO - *** doDestroy: case doc 14-1 (090000018000d140) moved to trash case_worker_1 on 28/09/10 22:57:22 ***
22:57:22,885  INFO [http-8080-2] com.dm_misc.tbo.CaseDocumentTBO - ENTER: doSave method for obj id 090000018000d140, obj name case doc 14-1
22:57:22,885 ERROR [http-8080-2] com.dm_misc.tbo.CaseDocumentTBO - doSave: Could not find containing case folder for case doc 14-1
22:57:22,948  INFO [http-8080-2] com.dm_misc.tbo.CaseDocumentTBO - EXIT: doSave method for obj id 090000018000d140, obj name case doc 14-1
22:57:22,948  INFO [http-8080-2] com.dm_misc.tbo.CaseDocumentTBO - EXIT: doDestroy method for obj id 090000018000d140, obj name case doc 14-1

In this post I showed you some interesting things you can do with the doDelete() method and how overridden methods do not always have to call their super class equivalents. In the next post I will give you tips on creating TBOs in Composer.

Note:  all of the code discussed in this series can be downloaded here.

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 TBOs – Part 4

  1. Pingback: TBOs – Part 3 « 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: