A Documentum Job Base Class

For those of you that downloaded and examined the PDFCompress job code, you probably noticed that the job class extended a custom base class named dmJobBaseClass.  The purpose of this base class is to take the drudgery out of writing a job for the Content Server, and free you to focus on implementing the logic of the job.  In particular, the dmJobBaseClass base class provides these features:

  • parses and collects both default and custom arguments passed to the job;
  • takes care of session management, and pre- and post-job “plumbing”;
  • creates a log file and attaches it to the job object;
  • updates all of the job statistics associated with the job object; and
  • provides a debug mode to output key job parameters.

The dmJobBaseClassclass implements a single, abstract method that must be overridden in your implementation code:

public abstract int run(Map params, PrintWriter log) throws Exception;

The params Map contains a Map of the job’s arguments — both the default server arguments as well as any custom arguments passed by the job definition.  This Map is automatically created by the base class. The log PrintWriter points to the log file opened in the base class.

The Content Server will invoke the execute(Map params, PrintWriter pw) method of the base class (because it implements the IDfMethod interface), which in turn will call your run(Map params, PrintWriter log).  Before and after the call to run(Map params, PrintWriter log), the base class will take care of all of the plumbing necessary to make the job run and record its results.

The public dmJobBaseClass methods are:

  • ArrayList<String> getJobPropertyKeys() — returns an array that contains all of the names of the properties passed to the job
  • void setJobPropery(String key, String value) — sets a job property value
  • Properties getJobProperties() — returns the property object
  • String getJobProperty(String key) — returns a specific property value
  • String getCurrentStatus() — returns the job’s current status (dm_job.a_current_status)
  • String getLastInvocation() — returns the job’s last invocation date/time (dm_job.a_last_invocation)
  • String getIterations() — returns the number of times the job has previously run (dm_job.a_iterations)
  • String getLastCompletion() — returns the date/time the job last completed (dm_job.a_last_completion)
  • String getLastReturnCode() — returns the last return code for the job (dm_job.a_last_return_code)
  • String getLastDocId() — returns the r_object_id for the last report/log attached to the job (dm_job.a_last_document_id)
  • String getJobName() — returns the name of the job object
  • String getLogFilePath() — returns the local path to the log file
  • String dumpJobParams() — formats all of the job’s arguments for printing
  • IDfSession getSession() — returns the job’s session object

Here is a simple example of a job that uses the dmJobBaseClass method.

public class SimpleJob extends dmJobBaseClass  {
  @Override
  public int run(Map params, PrintWriter log) throws Exception {

    // write log file intro
    log.println(super.getJobName() + " -- " + Calendar.getInstance().getTime().toString());
    log.println("==============================================");
    log.println();

    // print job parameters for this run
    log.println("Job Parameters:");
    log.println("---------------");
    log.println(super.dumpJobParams());
    log.println();

    return 0;
  }
}

Writing a base class like this is nothing new to Documentum; in fact, this is the third iteration of this particular base class I have written.  If you search the Internet or EDN you will find more — you probably have some of your own.  Any way, in the spirit of sharing, I offer mine here .  If you have any suggestions for improvement to the class I’d love to hear them.

This iteration of the dmJobBaseClass class is based partly on information and code found 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.

9 Responses to A Documentum Job Base Class

    • Scott says:

      Thanks for the link. Like I said, there are plenty of these classes laying around. I was not aware of this one, but it looks very thorough.

      Like

  1. Do you have a git repository or somewhere the source is stored? I’m looking at Paniflov’s as well and I’m hoping to find some time savings over doing my own but I already have a lot of code that will need to be refactored and that might take longer than just writing my own since at least then I’ll understand it better. I generally shy away from using someone else’s code, even when it is well written because I like to understand how my code works at a very detailed level and I find I can’t easily get that when using someone else’s code, but at least it is worth a look, if only for inspiration.

    Like

  2. Also, the javadoc doesn’t seem to be included, just empty folders.

    Like

  3. Pingback: Links to All of My Source Code | dm_misc: Miscellaneous Documentum Information

  4. Kyle Jackson says:

    Would you mind sharing the source code?

    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: