EMC Documentum DFC create cabinet, file,folder and query
From w3cyberlearnings
Contents |
How to create a cabinet using DFC?
- A cabinet is provided storage for files and other document objects.
- Everything that you are going to store is placed in the Cabinet.
code
package w3cyberlearning.framework.test; import com.documentum.fc.client.DfClient; import com.documentum.fc.client.IDfClient; import com.documentum.fc.client.IDfSession; import com.documentum.fc.client.IDfSysObject; import com.documentum.fc.common.DfLoginInfo; import com.documentum.fc.common.IDfLoginInfo; public class CreateCabinet { /** * @param args */ private static final String userName ="Administrator"; private static final String userPassword="dmadmin"; private static final String docbase = "documentum"; private static final String cabinetName ="Dept_Science"; public static void main(String[] args) { // TODO Auto-generated method stub try { IDfClient client = DfClient.getLocalClient(); IDfLoginInfo loginInfo = new DfLoginInfo(); loginInfo.setUser(userName); loginInfo.setPassword(userPassword); loginInfo.setDomain(""); IDfSession docbase_session = client.newSession(docbase,loginInfo); IDfSysObject cabinet = null; cabinet = (IDfSysObject) docbase_session.newObject("dm_cabinet"); cabinet.setObjectName(cabinetName); cabinet.setSubject("My sample cabinet"); cabinet.save(); if(docbase_session != null){ System.out.println("successful create cabinet"); } else { System.out.println("failed to create cabinet"); } } catch(Exception e){ e.printStackTrace(); } } }
code detail
IDfSysObject cabinet = null; cabinet = (IDfSysObject) docbase_session.newObject("dm_cabinet"); cabinet.setObjectName(cabinetName); cabinet.setSubject("My sample cabinet"); cabinet.save();
How to create file using DFC?
- You want to create a file in Documentum repository using DFC.
- Here, a quick example that is going to show you how to create
file, and save it into a folder.
Remember that you have to have a file in a directory somewhere in your system
- In Microsoft window, you need to use "\\" to set the file path.
If your file content is in the '''c:\mydocument\insurance\insurance_12.txt''' you need to set in the directory like this ''''c:\\mydocument\\insurance\\insurance_12.txt''';
code
package w3cyberlearning.framework.test; import com.documentum.fc.client.DfClient; import com.documentum.fc.client.IDfClient; import com.documentum.fc.client.IDfSession; import com.documentum.fc.common.DfLoginInfo; import com.documentum.fc.common.IDfLoginInfo; import com.documentum.fc.client.IDfDocument; public class CreateFileUsinDFC { /** * @param args */ private static final String userName ="Administrator"; private static final String userPassword="dmadmin"; private static final String docbase = "documentum"; private static final String fileName ="my first file"; private static final String fileType ="crtext"; private static final String filePath ="C:\\sample.txt"; public static void main(String[] args) { // TODO Auto-generated method stub try { IDfClient client = DfClient.getLocalClient(); IDfLoginInfo loginInfo = new DfLoginInfo(); loginInfo.setUser(userName); loginInfo.setPassword(userPassword); loginInfo.setDomain(""); IDfSession docbase_session = client.newSession(docbase,loginInfo); IDfDocument document1 = null; document1 = (IDfDocument)docbase_session.newObject("dm_document"); document1.setObjectName(fileName); document1.setContentType(fileType); document1.setFile(filePath); document1.link("/Temp/SubDir"); document1.save(); if(docbase_session != null){ System.out.println("successful create file"); } else { System.out.println("failed to create file"); } } catch(Exception e){ e.printStackTrace(); } } }
detail
- declare a null IDFDocument object
- create a IDFDocument object
- set file name and file content
- save the file in the /Temp/SubDir folder (the folder has to exist, else you get error!!!)
IDfDocument document1 = null; document1 = (IDfDocument)docbase_session.newObject("dm_document"); document1.setObjectName(fileName); document1.setContentType(fileType); document1.setFile(filePath); document1.link("/Temp/SubDir"); document1.save();
How to create folder?
- You want create a folder in Documentum repository.
- You need to create folder in a cabinet
- you need to use IDfFolder
Code
package w3cyberlearning.framework.test; import com.documentum.fc.client.DfClient; import com.documentum.fc.client.IDfClient; import com.documentum.fc.client.IDfFolder; import com.documentum.fc.client.IDfSession; import com.documentum.fc.common.DfLoginInfo; import com.documentum.fc.common.IDfLoginInfo; public class CreateFolder { /** * @param args */ private static final String userName ="Administrator"; private static final String userPassword="dmadmin"; private static final String docbase = "documentum"; private static final String folderName ="W3CyberLearningFolder"; public static void main(String[] args) { // TODO Auto-generated method stub try { IDfClient client = DfClient.getLocalClient(); IDfLoginInfo loginInfo = new DfLoginInfo(); loginInfo.setUser(userName); loginInfo.setPassword(userPassword); loginInfo.setDomain(""); IDfSession docbase_session = client.newSession(docbase,loginInfo); IDfFolder folder = null; folder = (IDfFolder) docbase_session.newObject("dm_folder"); folder.setObjectName(folderName); folder.link("/Temp"); folder.save(); if(docbase_session != null){ System.out.println("successful create a new folder"); } else { System.out.println("failed to create a folder"); } } catch(Exception e){ e.printStackTrace(); } } }
Code detail
- After you have successfully created a folder,
- You will be able to see your newly created folder in the Documentum repository.
- The folder path is: Cabinet/Temp/W3CyberLearningFolder
- Note if you run the program twice, you will get error message.
- You are not allow to create duplicate folder with the same name.
IDfFolder folder = null; folder = (IDfFolder) docbase_session.newObject("dm_folder"); folder.setObjectName(folderName); folder.link("/Temp"); folder.save();
You also can use IDfSysObject to create a folder
IDfSysObject folder = null; folder = (IDfSysObject) docbase_session.newObject("dm_folder"); folder.setObjectName(folderName); folder.link("/Temp"); folder.save();
Query file content in Documentum Repository
- You want to query a file content. You have to use DQL.
code
package w3cyberlearning.framework.test; import com.documentum.fc.client.DfClient; import com.documentum.fc.client.IDfClient; import com.documentum.fc.client.IDfQuery; import com.documentum.fc.client.DfQuery; import com.documentum.fc.client.IDfSession; import com.documentum.fc.client.IDfCollection; import com.documentum.fc.common.DfLoginInfo; import com.documentum.fc.common.IDfLoginInfo; public class QueryFileContentDFC{ /** * @param args */ private static final String userName ="Administrator"; private static final String userPassword="dmadmin"; private static final String docbase = "documentum"; public static void main(String[] args) { // TODO Auto-generated method stub String FileName ="two.doc"; try { IDfClient client = DfClient.getLocalClient(); IDfLoginInfo loginInfo = new DfLoginInfo(); loginInfo.setUser(userName); loginInfo.setPassword(userPassword); loginInfo.setDomain(""); String dql = "SELECT " + " r_object_id, " + " owner_name, " + " object_name " + " from dm_document " + " WHERE object_name='" + FileName + "'"; IDfQuery query = new DfQuery(); query.setDQL(dql); IDfSession docbase_session = client.newSession(docbase,loginInfo); IDfCollection coll = query.execute(docbase_session, IDfQuery.DF_READ_QUERY); while(coll.next()){ String id= coll.getString("r_object_id"); String owner_name = coll.getString("owner_name"); String object_name = coll.getString("object_name"); System.out.println("ID: " + id ); System.out.println("Owner Name: " + owner_name); System.out.println("Object Name: "+ object_name); } if(docbase_session != null){ System.out.println("successful"); } else { System.out.println("failed"); } } catch(Exception e){ e.printStackTrace(); } } }
Display Result
ID: 09de75d180003502 Owner Name: Administrator Object Name: two.doc ID: 09de75d180004101 Owner Name: Administrator Object Name: two.doc successful create a new folder
How to query folder content?
Before you process this tutorial, you need to know the folder path and you have to have a user access to the repository in order for you to run this example. Please refer to the setup and configure of eclipse if you have problem in configuring the jar files in the Eclipse environment.
Query the content of the W3CyberLearningFolder folder
- Note: You need to provide a full folder path else you will get an error
- This tutorial is only query the folder content, it will display an error if the folder contains another folder
- Folder full path is: /Temp/W3CyberLearningFolder
code
package w3cyberlearning.framework.test; import com.documentum.fc.client.DfClient; import com.documentum.fc.client.IDfClient; import com.documentum.fc.client.IDfFolder; import com.documentum.fc.client.IDfCollection; import com.documentum.fc.common.IDfId; import com.documentum.fc.client.IDfDocument; import com.documentum.fc.client.IDfSession; import com.documentum.fc.common.DfLoginInfo; import com.documentum.fc.common.IDfLoginInfo; public class DfcQueryContent { /** * @param args */ private static final String UserName = "Administrator"; private static final String Password = "dmadmin" private static final String DocBase = "documentum"; private static final String DIRPATH = "/Temp/W3CyberLearningFolder"; public static void main(String[] args) { // TODO Auto-generated method stub IDfFolder folder = null; IDfClient client = null; IDfCollection collection = null; IDfDocument doc = null; int count = 0; try { client = DfClient.getLocalClient(); IDfLoginInfo loginInfo = new DfLoginInfo(); loginInfo.setUser(UserName); loginInfo.setPassword(Password); loginInfo.setDomain(""); IDfSession docbase_session = client.newSession(DocBase, loginInfo); folder = docbase_session.getFolderByPath(DIRPATH); collection = folder.getContents("r_object_id"); while(collection.next()) { count++; IDfId id = collection.getId("r_object_id"); doc = (IDfDocument) docbase_session.getObject(id); System.out.println("Object Name: " + doc.getObjectName()); } if(docbase_session != null) { System.out.println("Successful"); } else { System.out.println("Unsuccessful"); } } catch (Exception e) { e.printStackTrace(); } } }
query content using DQL
package w3cyberlearning.framework.test; import com.documentum.fc.client.DfClient; import com.documentum.fc.client.IDfClient; import com.documentum.fc.client.IDfQuery; import com.documentum.fc.client.DfQuery; import com.documentum.fc.client.IDfCollection; import com.documentum.fc.client.IDfSession; import com.documentum.fc.common.DfLoginInfo; import com.documentum.fc.common.IDfLoginInfo; public class DfcQueryContentUseDQL { /** * @param args */ private static final String UserName = "Administrator"; private static final String Password = "dmadmin"; private static final String DocBase = "documentum"; private static final String DIRPATH = "/Temp/W3CyberLearningFolder"; public static void main(String[] args) { // TODO Auto-generated method stub IDfClient client = null; IDfCollection collection = null; int count = 0; String dql = ""; try { client = DfClient.getLocalClient(); IDfLoginInfo loginInfo = new DfLoginInfo(); loginInfo.setUser(UserName); loginInfo.setPassword(Password); loginInfo.setDomain(""); dql = "SELECT object_name, r_object_id from dm_document where folder('" + DIRPATH + "');"; IDfSession docbase_session = client.newSession(DocBase, loginInfo); IDfQuery query = new DfQuery(); query.setDQL(dql); collection = query.execute(docbase_session,IDfQuery.DF_READ_QUERY); while(collection.next()) { count++; System.out.println(count + " Object Id: " + collection.getString("r_object_id") + " Object Name: " + collection.getString("object_name")); } } catch (Exception e) { e.printStackTrace(); } } }