Jython with DFC Code

669 views Asked by At

I am trying to work with IDfSysObjects in Documentum via jython, but I can't figure out how to call the methods appropriately from the interperter. The code below illustrates what I'd like to call with jython.

String docId= getDocId();
IDfSysObject doc = (IDfSysObject)session.getObject(new DfId(docId));
ByteArrayInputStream stream = doc.getContent();

from this post:

DFC reading a file

I don't know how to reconcile an IDfSysObject with the session. I have tried calling

session.getObject([r_object_id])

but I get

TypeError: 1st arg can't be coerced to com.documentum.fc.common.IDfId

My primary question is, does anyone know how to convert the following line of code into jython?

IDfSysObject doc = (IDfSysObject)session.getObject(new DfId(docId));
2

There are 2 answers

1
KarolBe On BEST ANSWER

Try this code, it does what you want:

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

import array 

class DFCExample:
 def connectToDocbase(docbase, user, password):
   client = DfClient.getLocalClient()
   li = common.DfLoginInfo()        
   li.setUser(user)
   li.setPassword(password)
   sess = client.newSession(docbase, li)
   return sess

 def example(sess, docId):  
   id = common.DfId(docId)
   sysObj = sess.getObject(id)
   print array.array('b', iter(sysObj.getContent().read, -1)).tostring()

 session = connectToDocbase("docbaseDev", "dmadmin", "dmadmin")
 example(session, "0900323e80071339")
 sess.disconnect()  
0
ionalchemist On

I wanted to add an answer here in relevance to my original question and a secondary operation in case someone else may find the information useful. After successfully getting the object, I also wanted to perform an export operation on it, which was not as straightforward as I would have liked. I found that certain operations are not available via the typical DfClient and that I had to instantiate the session with DfClientX, but note the difference in establishing the session:

import com.documentum.com.DfClientX as DfClientX
import com.documentum.fc.common as common

class DFCExample:
    def connectToDocbase(docbase, user, password):
        clientx = DfClientX() #extra step
        clx = clientx.getLocalClient()
        li = common.DfLoginInfo()        
        li.setUser(user)
        li.setPassword(password)
        sess = clx.newSession(docbase, li)
        return sess, clientx

    def exportDoc(sess, docId, clientx):
        id = common.DfId(docId)
        sysObj = sess.getObject(id)
        exp = clientx.getExportOperation()
        node = exp.add(sysObj)
        exp.setDestinationDirectory(exp.getDefaultDestinationDirectory())
        exp.execute()

    sess, clientx = connectToDocbase("mydocBase", username, password)
    exportDoc(sess, "0900aaa28023215i", clientx)
    sess.disconnect()

While I realize that this addition may not belong as an answer to my original question, figuring this out was something that helped me with regard to the topic at hand. So I just wanted to share in case this helps someone else. Thanks!