Tuesday, March 3, 2020

How to get User Homecabinet names with file count and total size

/**
 *
 */
package Test;
import java.io.File;  // Import the File class
import java.io.FileNotFoundException;  // Import this class to handle errors
import java.util.Scanner;

import com.documentum.com.DfClientX;
import com.documentum.com.IDfClientX;
import com.documentum.fc.client.IDfClient;
import com.documentum.fc.client.IDfSessionManager;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.IDfLoginInfo;

import com.documentum.com.DfClientX;
import com.documentum.com.IDfClientX;
import com.documentum.fc.client.DfQuery;
import com.documentum.fc.client.IDfClient;
import com.documentum.fc.client.IDfCollection;
import com.documentum.fc.client.IDfQuery;
import com.documentum.fc.client.IDfSession;
import com.documentum.fc.client.IDfSessionManager;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.IDfLoginInfo;
/**
 * @author mpoli
 *
 */
public class ReadExcelFileDemo {
  public static void main(String[] args) throws DfException  {
    try {
    // TODO Auto-generated method stub
IDfSessionManager sessionMgr = null;
IDfClientX clientx = new DfClientX();
IDfClient client = clientx.getLocalClient();
sessionMgr = client.newSessionManager();
IDfLoginInfo loginInfoObj = clientx.getLoginInfo();
loginInfoObj.setUser("XXXXX");
loginInfoObj.setPassword("XXXXX");
sessionMgr.setIdentity("XXXXX", loginInfoObj);
IDfSessionManager sesMgr = getSessionMgr();
IDfSession session = sesMgr.getSession("XXX");
IDfClientX _clientx = new DfClientX();
IDfQuery query = new DfQuery();
IDfCollection rs = null;

      File myObj = new File("d://emp.txt");
      Scanner myReader = new Scanner(myObj);
      while (myReader.hasNextLine()) {
        String data = myReader.nextLine();
     
        query.setDQL(" SELECT   user_name FROM   dm_user WHERE  user_os_name='"+data+"'");
rs = query.execute(session, 0);
if (rs != null) {
while (rs.next()) {
IDfCollection rs1 = null;
query.setDQL(" select sum(r_content_size),count(r_object_id) from dm_document where folder('/Users/"+rs.getString("user_name")+"',descend) ");
rs1 = query.execute(session, 0);
if (rs1 != null) {
while (rs1.next()) {
//System.out.println(rs.getString("object_name"));
long i=Long.valueOf(rs1.getString("sum(dm_document.r_content_size)"));

System.out.println(rs.getString("user_name") +"::"+rs1.getString("count(dm_document.r_object_id)")+"::"+ getSize(i));
}
}
}
}
     
     
     
      }
      myReader.close();
    } catch (FileNotFoundException e) {
      System.out.println("An error occurred.");
      e.printStackTrace();
    }
  }
  public static String getSize(long size) {
        long n = 1000;
        String s = "";
        double kb = size / n;
        double mb = kb / n;
        double gb = mb / n;
        double tb = gb / n;
        if(size < n) {
            s = size + " Bytes";
        } else if(size >= n && size < (n * n)) {
            s =  String.format("%.2f", kb) + " KB";
        } else if(size >= (n * n) && size < (n * n * n)) {
            s = String.format("%.2f", mb) + " MB";
        } else if(size >= (n * n * n) && size < (n * n * n * n)) {
            s = String.format("%.2f", gb) + " GB";
        } else if(size >= (n * n * n * n)) {
            s = String.format("%.2f", tb) + " TB";
        }
        return s;
    }
private static IDfSessionManager getSessionMgr(){
IDfSessionManager sessionMgr = null;
try{

IDfClientX clientx = new DfClientX();
IDfClient client = clientx.getLocalClient();
sessionMgr = client.newSessionManager();
IDfLoginInfo loginInfoObj = clientx.getLoginInfo();
loginInfoObj.setUser("XXX");
loginInfoObj.setPassword(XXX");
sessionMgr.setIdentity("XXXXXXX", loginInfoObj);

}catch(DfException exp){
exp.printStackTrace();
}
return sessionMgr;

}
}