Friday, August 24, 2012

DFC Code: Print names objects in a Cabinet

Loop through the cabinet content print all the names of sub folders and files in cabinet

import com.documentum.fc.client.IDfCollection;
import com.documentum.fc.client.IDfFolder;
import com.documentum.fc.client.IDfSession;
public class LoopThroughDocumentumFolder {
 private static final String STATE_PROBLEM_CABINET = "/CabinetName";
 public static void main(String[] args){
  IDfSession session = session = getSessionByIdentity("dmadmin", "password","repositoryName", "server", "port");
  loopThroughFolder(session, STATE_PROBLEM_CABINET);
 }

 public static void loopThroughFolder(IDfSession session, String path) { {
  try
        {  
   IDfFolder folder = session.getFolderByPath(path);
   if (folder == null) {
    System.out.println("Folder or cabinet does not exist in the Repository!");
   } else
   {
    IDfCollection collection = folder.getContents(null);
    while (collection.next()) {
     if (collection.getString("r_object_type").equalsIgnoreCase("dm_folder"))
     {
      System.out.println("Folder :"+ collection.getString("object_name"));
      loopThroughFolder(session, path+"/"+ collection.getString("object_name"));
     } else
     {
      System.out.println("       File: " + collection.getString("object_name"));
     }
    }
   }
            //Set the result to 0 - indicates success
        }
        catch( Exception e )
        {
         System.out.println( e.getMessage() );
        }
 }
 }
public static IDfSession getSessionByIdentity(String username,
   String password, String repoName, String primary_host,
   String primary_port) {
  IDfSession sess = null;
  try {
   IDfClientX clientX = new DfClientX();
   IDfClient localClient = clientX.getLocalClient();
   IDfSessionManager sessMgr = localClient.newSessionManager();
   localClient.getClientConfig().setString("primary_host", primary_host);
   localClient.getClientConfig().setString("primary_port", primary_port);
   IDfLoginInfo li = clientX.getLoginInfo();
   li.setUser(username);
   li.setPassword(password);
   if (sessMgr.hasIdentity(repoName)) {
    sessMgr.clearIdentity(repoName);
   }
   sessMgr.setIdentity(repoName, li);
   sess = sessMgr.getSession(repoName);
  } catch (Exception ex) {
   ex.printStackTrace();
  }
  return sess;
 }
 
}


No comments:

Post a Comment

Total Pageviews