EMC Developer Network
 

EMC Developer Network - Using Jython to connect to Documentum Docbases via DFC

Using Jython to connect to Documentum Docbases via DFC

January 2008
Contributed by - Manish Pandit, Burntsand Inc.

Abstract

The tip below demonstrates how to use Jython to connect to a Documentum docbase using DFC and get Docbase session information. Also demonstrated is how to query for a document and display attribute values. With this tip I try to explore a new approach to programming DFC, which in my view has a strong potential.

What is Jython?

Jython is a hybrid programming language, an implementation of Python scripting language written in Java that runs under any compliant Java Virtual Machine. In other words, Jython combines the beauty of Python with OO design of Java. Using Jython, you can write Python programs that interact with any Java code. Jython is an interpreted language and there are no pre-compile steps as in Java and C++. Every time a Jython script is run, it is interpreted afresh. Jython is designed to be object-oriented (unlike other scripting languages) and supports a sophisticated packaging scheme. Features like these make Jython a strong candidate for Rapid application development. (Note: Some points in this section are taken from an O’Reilly publication book named “Jython Essentials”)


Why Jython, and where do I get it?

According to some empirical estimates, one may need 50% less lines of code in Jython/Python than in Java programming language in order to achieve similar results.


You can get Jython at http://www.jython.org. The site also has detailed instructions to install this snake on your machine. For the tip below, Jython version 2.2.1 is used and it is assumed that JRE 1.4.2 or higher is also installed.


Setting up Jython and importing DFC library

Download and install Jython. For the sake of this example, I’ve downloaded and installed Jython 2.2.1. The directory where Jython is installed will be referred to as Jython home in this tip. Run Jython in interactive mode by opening a command prompt and typing a command jython. Jython will be run in interactive mode as shown below:


Type in the following command at Jython interactive prompt:
> > > import sys


Import the DFC library using command (it is assumed here that the DFC jar file is installed in the directory C:\Program Files\Documentum\Shared. Also, the DFC version used in this tip is DFC 5.3 SP2
sys.path.append(r'C:\Program Files\Documentum\Shared\dfc.jar')


Jython DFC Sample

In the listing below, I’ve demonstrated a simple Jython script that connects to a Documentum docbase and displays docbase session information. It then asks a user for a document name and queries the attributes r_object_id, title and keywords and displays this information. It should be noted that indentation in the code is important and has to be kept as-is for it to be interpreted correctly by Jython interpreter


After saving this script in a *.py file, it can be executed from Jython home as under:
jython <<location of saved script>>



import com.documentum.fc.client.DfQuery as DfQuery
import com.documentum.fc.client.DfCollection as DfCollection
import com.documentum.fc.client.DfClient as DfClient
import com.documentum.fc.common as common

class DFCTest:
  def connectToDocbase():
    client = DfClient.getLocalClient()
    docbase = raw_input("Enter Docbase Name: ")
    li = common.DfLoginInfo()		
    li.setUser(raw_input("Enter User Name: "))
    li.setPassword(raw_input("Enter Password: "))	
    print "Attempting to connect to Docbase: ",docbase
    sess = client.newSession(docbase, li)
    return sess

  def displaySessionInfo(sess):
    print ""
    print "***Displaying Session Information***"
    print "Docbase Name      : ", sess.getDocbaseName()
    print "Server Version    : ", sess.getServerVersion()
    print "DBMS Name         : ", sess.getDBMSName()
    print "Docbase Owner Name: ", sess.getDocbaseOwnerName()
    print "Session Id        : ", sess.getSessionId()
    print "DMCL Session Id   : ", sess.getDMCLSessionId()
    print "Docbase Id        : ", sess.getDocbaseId()
    print "Docbase Scope     : ", sess.getDocbaseScope()
    print "Current User      : ", sess.getLoginUserName()	
    print "Security Mode     : ", sess.getSecurityMode()
    print "***End Session Information***"
    print ""

  def queryDocbase(sess):	
    print "Now lets play with Objects!"
    print ""
    object = raw_input("Enter Document Name: ")
    query = "select r_object_id,title,keywords from dm_document where object_name = '" + object + "'"
    DQL = DfQuery()
    DQL.setDQL(query)	
    col = DQL.execute(sess, DfQuery.DF_READ_QUERY)
    while (col.next()):
      print "Object Id: ",col.getString("r_object_id")
      print "Document Title: ",col.getString("title")
      print "Document Keywords: ",col.getString("keywords")
		
  def disconnectFromDocbase(sess):
    if sess.isConnected() == 1:	
      print ""
      print "Disconnecting from docbase..."
      sess.disconnect()	
    if sess.isConnected() == 0:
      print "Successfully disconnected..."

  session = connectToDocbase()
  displaySessionInfo(session)
  queryDocbase(session)
  disconnectFromDocbase(session)
  

For more information

Jython/Python is a vast subject in itself, a subject of which we’ve only scratched the surface in the above tip. Following resources are useful to learn python:


About the Author

Manish Pandit works as Senior Consultant with Burntsand Inc and has direct experience with several Pharmaceuticals/Biotech clients. Manish has more than 5 years of experience on EMC Documentum Platform and has been involved in implementation and customization of the EMC Documentum suite of products along with EMC Documentum partner products. He can be reached at mpandit@burntsand.com.


Discuss

Click here to discuss this article