Documentum Jobs & Methods(好文章,但仍未涉及如果用代码调用方法,以调用超出当前用户权限的功能)

时间:2022-12-02 20:24:41

http://www.revasolutions.com/ecm-blog/?p=77

 

Documentum Jobs & Methods

October 2nd, 2009 by Praveena Killamsetty

I spent quite some time writing methods in D6.5. Here are some of the pointers I found very useful.

Methods:

A method is an object in the docbase that lets you launch a program on the server without being logged into the server. Methods enable custom code to run on behalf of the Content Server. They allow normal users to execute a command that only a superuser can execute, off load processor-intensive tasks from the client to the server so that they can be run on the background during the off peak time.They are typically implemented in docbasic or Java but can also be written in any other programming language.

Implementation :

The IDmMethod interface is the interface that a method must implement to be invoked via the method server. This interface is located in the method server JAR file (mthdservlet.jar) which is found on the Content Server. The IDmMethod interface has a single method execute which operates very similarly to the main method in traditional Java-based method implementations. The parameters argument is a Map containing the method parameters (Strings) keyed by their names (Strings).


A sample method:

public class DmSampleMethod implements IDmMethod       /*另注,IDfMethod是用于在Bof中使用的,参见http://donr7n.wordpress.com/2008/10/20/methods-as-bof-modules/    */
{

public void execute(Map parameters, OutputStream output) throws Exception
{
// initialize parameters
String docbase = null;
String user = null;
String ticket = null;
IDfSession session = null;

// extract parameter values
Iterator i = parameters.keySet().iterator();
while ( i.hasNext() )
{
String key = (String) i.next();
String[] values = (String[]) parameters.get(key);

if((key == null) || (key.length() == 0) ||(values == null) || (values.length < 1))
{
continue;
}

if (key.equalsIgnoreCase(“docbase_name”))

{
docbase = values[0];
}
else if (key.equalsIgnoreCase(“user_name”))

{
user = values[0];
}
else if (key.equalsIgnoreCase(“ticket”))

{
ticket = values[0];
}
}

// validate parameter values
validateParam( “docbase”, docbase );
validateParam( “user”, user );
validateParam( “ticket”, ticket );

// Connect to docbase with given credentials
IDfClient client = DfClient.getLocalClient();
DfLoginInfo loginInfo = new DfLoginInfo();
loginInfo.setUser(user);
loginInfo.setPassword(ticket);
session = client.newSession(docbase, loginInfo);

// Retrieve the document object
String queryStr = “dm_sysobject where r_object_id = ‘” + id + “‘”;
IDfSysObject sysObj = (IDfSysObject) session.getObjectByQualification(queryStr);

//do the processing with the retrived object

}

//disconnect the session
session.disconnect();
}

private void validateParam(String parameter, String value) throws Exception
{
if((value == null) || (value.length() == 0))

{
throw new Exception(“Non-null value for parameter -” + parameter +” which is required for DmSampleMethod, was not definedinARGUMENTS.”);
}
}

Methods which execute operations on workflows can be written extending ‘com.documentum.bpm.rtutil.WorkflowMethod’.

Deploying method implementations to the Java method server:

To deploy methods to the method server,we need to simply copy the class files or JAR files to the %DOCUMENTUM%\dba\java_methods directory on the Content Server. The method server will include them in its classpath. Jboss is the Java Method Server in D6 .Whenever classes are deployed to the method server, the method server will need to be stopped, the tmp folder in %DOCUMENTUM%\jboss1.4.2\server\DctmServer_MethodServer\tmp and start the server. We can find the jboss logs under %DOCUMENTUM%\dba\jboss1.4.2\DctmServer_MethodServer\log.

Documentum Jobs & Methods(好文章,但仍未涉及如果用代码调用方法,以调用超出当前用户权限的功能)

jboss folder

Jobs:

Typically, methods are executed on demand through Documentum Administrator.Jobs automate method execution.The methods are executed automatically on the schedule specified in the job.Jobs can be created using Documentum Administrator.It is a good practice to pass the standard arguments to the job. The server passes the following 4 standard arguements to the job:(这回知道标准参数传的是什么了)

-docbase_name                         repository_name Identifies the  repository

-user_name                              The user executing  the job

-job_id                                        Object ID of the job

-method_trace_level          Method trace level touse. The default is 0 (no tracing). The value for this argument is taken                                                                 from the method_trace_levelproperty of the job  object.

If the server passes the standard arguments, it does not pass to the method any arguments defined in the job’s method_arguments property. The method must use the job ID passed as a standard argument to obtain the argument values defined in the job’s method_arguments property.A code snippet to get arguments from the job’s method argument property:

IDfId oId = oDfClientX.getId(m_jobId);

IDfSysObject oSysObject = (IDfSysObject)

session.getObject(oId);

for (int iCount = 0; iCount < oSysObject.getValueCount( “method_arguments” ); iCount++)

{

System.out.println(“argument # ” + iCount + ” ” + oSysObject.getRepeatingString(“method_arguments”, iCount));

String argument=oSysObject.getRepeatingString(“method_arguments”, iCount);

if(argument.startsWith(“startDate”))

{

String[] split =argument.split(” “);

m_StartDate=split[1];

}

}

Job Report:

                       To see the job report print the required statements using ‘OutputStream output’.

out.write((“Statment: “‘\n”).getBytes());

Documentum Jobs & Methods(好文章,但仍未涉及如果用代码调用方法,以调用超出当前用户权限的功能)
Documentum Jobs & Methods(好文章,但仍未涉及如果用代码调用方法,以调用超出当前用户权限的功能) Tweet

Tags: Documentum, Documentum Jobs, Documentum Methods, Java Method Server, Reva Technical

3 Responses to “Documentum Jobs & Methods”

  1. Documentum Jobs & Methods(好文章,但仍未涉及如果用代码调用方法,以调用超出当前用户权限的功能)sagrys says:

    Great post for our newbie documentum developers!!

    How would I go about wanting the default arguments to be passed to a custom method, together with an extra custom parameter? I created a method in which I re-use code, thus would create 3 jobs that would call the same method, where the custom parameter would differ.

    Please advise, when I log my mappings from the job, some arguments are not picked up??

    I have checked the option on the job to pass the default arguments, thus just eneterd my additional custom parameter. This did not work, I had to
    still pass the default parameters also, as I found out with endless trial and error.

     
  2. Would it not be better to check for null or zero length key values before you retrieve corresponding values from Map? e.g. Instead of this:
    String key = (String) i.next();
    String[] values = (String[]) parameters.get(key);

    if((key == null) || (key.length() == 0) ||(values == null) || (values.length < 1))
    {
    continue;
    }
    How about this:

    String key = (String) i.next();
    if((key == null) || (key.length() == 0))
    continue;

    String[] values = (String[]) parameters.get(key);

    if((values == null) || (values.length < 1))
    {
    continue;
    }
    Just a passing thought!

     
  3. That would be a good option too. Thanks Sanket.