We saw a very simple example to establish a session with the Docbase. Once the Docbase session has been created, you can perform a host of operations in the Docbase. In this example, we will see how to create a document object in the Docbase, associate it with a text file, and link this object to a cabinet in the Docbase via DFC methods.
Create a simple Java file LinkingFileDFC.java
as shown below:
import com.documentum.fc.client.*; import com.documentum.fc.common.*; import java.io.IOException; public class LinkingFileDFC{ //Main method public static void main(String args[]){ IDfSession session = null; IDfSessionManager sMgr = null; try { String strDocbaseName = "dev_doc"; //Connecting to DocBase IDfClient client = new DfClient().getLocalClient(); sMgr = client.newSessionManager(); IDfLoginInfo loginInfo = new DfLoginInfo(); loginInfo.setUser( "documentum" ); loginInfo.setPassword( "solutions" ); sMgr.setIdentity(strDocbaseName, loginInfo ); session = sMgr.getSession(strDocbaseName); System.out.println("Connected to DocBase.."); //Linking a text document to a DocBase cabinet IDfDocument document = null; document = (IDfDocument)session.newObject( "dm_document" ); document.setObjectName( "testing_link_file" ); document.setContentType( "crtext" ); document.setFile( "C:\test\DummyLinkedFile.txt" ); document.link("/Custom_Cabinet/Custom_Fld"); document.save(); System.out.println("Object saved and linked!!"); }catch(DfException dfe){ System.out.println("DfException caught in main: " + dfe.getMessage()); }catch(Exception e){ System.out.println("main::Exception is " + e.getMessage()); } finally { sMgr.release( session ); } }// end of Main } // end of class
The anatomy of the DFC code follows:
IDfClient client = new DfClient().getLocalClient(); sMgr = client.newSessionManager(); IDfLoginInfo loginInfo = new DfLoginInfo(); loginInfo.setUser( "documentum" ); loginInfo.setPassword( "solutions" ); sMgr.setIdentity(strDocbaseName, loginInfo ); session = sMgr.getSession(strDocbaseName);
A session is established with the Docbase.
document = (IDfDocument)session.newObject( "dm_document" );
The newObject()
method of IDfSession
is invoked to create a new persistent object in the Docbase of the type specified as a parameter (dm_document
). The returned object is cast to the required interface (IDfDocument
).
It is worth mentioning that Documentum does not commit this object to the Docbase until and unless an explicit save()
call is made via DFC (see line 36).
document.setObjectName( "testing_link_file" );
Here we set the name of the document object by passing the name as a parameter to the setObjectName()
method of IDfDocument
.
document.setContentType( "crtext" );
Here we set the file format of the document's content by calling the setContentType()
method of IDfSysObject
object. (Remember that IDfSysObject
is a superinterface of IDfDocument.)
Pass the Documentum format name (of the type dm_format)
as a parameter to the method. In our case we have passed crtext
as the format name to the setContentType()
method since we need to link a Windows text file with the document object.
Note that for UNIX, the format name for a text document is text
while it is mactext
for Mac OS.
document.setFile( "C:\test\DummyLinkedFile.txt" );
This line creates a sample .txt
file on your machine by providing the complete path to this file in the setFile()
method of the IDfSysObject
object.
This method sets the content file for the newly created document object in Docbase.
document.link("/Custom_Cabinet/Custom_Fld");
The document object is associated with a folder existing in the Docbase by calling the link()
method. We have provided the folder path (Custom_Fld
folder within Custom_Cabinet
cabinet) where the document object needs to be linked in the Docbase.
Note that you can also provide the object ID of the folder instead of its cabinet path in the link()
method.
When you compile and execute the LinkingFileDFC.java
code, the following messages are printed on your console:
Connected to DocBase. followed by Object saved and linked!!.
You can log in to Web Publisher and browse to the Custom_Fld folder within Custom_Cabinet cabinet in the Docbase. You will notice a text file object with the name testing_link_file created and linked via DFC as shown in figure 23.2.
18.224.52.212