Anda di halaman 1dari 5

//package com.bestbuy.ecm.vim.methods; import import import import import import import import import java.io.BufferedWriter; java.io.File; java.io.FileWriter; java.io.

IOException; java.io.OutputStream; java.io.PrintWriter; java.text.DateFormat; java.text.SimpleDateFormat; java.util.Date;

import java.util.Iterator; import java.util.Map; import java.util.Set; import import import import import import import import import import import import import import import import com.documentum.com.DfClientX; com.documentum.com.IDfClientX; com.documentum.fc.client.DfClient; com.documentum.fc.client.IDfClient; com.documentum.fc.client.IDfCollection; com.documentum.fc.client.IDfModule; com.documentum.fc.client.IDfQuery; com.documentum.fc.client.IDfSession; com.documentum.fc.client.IDfSessionManager; com.documentum.fc.client.IDfSysObject; com.documentum.fc.common.DfException; com.documentum.fc.common.DfLoginInfo; com.documentum.fc.common.DfTime; com.documentum.fc.common.IDfLoginInfo; com.documentum.fc.common.IDfTime; com.documentum.mthdservlet.IDmMethod;

/** * @authors Saidulu Chilka * * * */ public class AgingReport implements IDmMethod { protected static String m_docbase = null; protected static String m_userName = null; private static final String USER_KEY = "user_name"; private static final String DOCBASE_KEY = "docbase_name"; private IDfSession session = null; private static String rec_query = ""; private static String temp_path = "C:\\tcs\\"; private IDfSessionManager sessionManager = null; IDfCollection queueColl = null; BufferedWriter output = null; FileWriter fileWriter = null; File file = null; /* * Method for Testing */ public static void main(String s[]) throws IOException, DfException { try {

AgingReport a = new AgingReport(); a.genReport(); } catch (Exception e) { } } /* * Parameters initializations */ /*protected void initParams(Map params, OutputStream arg1) { Set keys = params.keySet(); Iterator iter = (Iterator) keys.iterator(); PrintWriter p = new PrintWriter(arg1); while (iter.hasNext()) { String key = (String) iter.next(); if ((key == null) (key.length() == 0)) { continue; } String[] value = (String[]) params.get(key); p.println("parameter is : " + key); if (key.equalsIgnoreCase(USER_KEY)) { m_userName = (value.length > 0) ? value[0] : ""; p.println("Username in passed arg is : " + m_use rName); } else if (key.equalsIgnoreCase(DOCBASE_KEY)) { m_docbase = (value.length > 0) ? value[0] : ""; p.println("Docbase name is : " + m_docbase); } p.flush(); } }*/ /* * Main Method for generating report */ public void genReport() throws Exception { System.out.println(" in genReport"); String document_class; String object_name; String title; String site_date; String site_attribute_03; String r_object_id; String asset_name; String source; BufferedWriter output = null; StringBuffer sb = null; FileWriter fileWriter = null; File file = null; try { sessionManager = getSessionManager(); session = sessionManager.getSession("CH_CPR_NOE"); //DfLogger.debug(this, "Got Session", null, null); rec_query = "select document_class, object_name, title, site_date, site_attribute_03, asset_name, r_object_id from manufacturing_site wh ere site_date <= dateadd(year,1,date(today)) and site_date is not nulldate and l fc_state = 'vault' order by r_object_id";

//DfLogger.debug(this, "Temp path-> "+temp_path, null, n ull); IDfClientX cx = new DfClientX(); IDfQuery query = cx.getQuery(); query.setDQL(rec_query); queueColl = query.execute(session, IDfQuery.READ_QUERY); Date sysdate = new Date(); String date = new SimpleDateFormat("ddmmyy").format(sysd ate); temp_path = (temp_path.concat(date)).concat(".csv"); file = new File(temp_path); fileWriter = new FileWriter(file); output = new BufferedWriter(fileWriter); int count = 0; //output.newLine(); StringBuffer sb1 = new StringBuffer(); //sb1.append("\""); sb1.append("Sub_TaskID");sb1.append("\"");sb1.append("," );sb1.append("\""); sb1.append("Title");sb1.append("\"");sb1.append(",");sb1 .append("\""); sb1.append("Description");sb1.append("\"");sb1.append(", ");sb1.append("\""); sb1.append("Due_Date");sb1.append("\"");sb1.append(","); sb1.append("\""); sb1.append("Assignee");sb1.append("\"");sb1.append(","); sb1.append("\""); sb1.append("Source");sb1.append("\"");sb1.append(",");sb 1.append("\""); sb1.append("Unit");sb1.append("\"");sb1.append(",");sb1. append("\""); sb1.append("\""); //sb1.append("r_object_id");sb1.append("\""); output.write(sb1.toString()); output.newLine(); count++; while (queueColl.next()) { sb = new StringBuffer(); r_object_id=queueColl.getValue("r_object_id").to String(); document_class = queueColl.getValue("document_cl ass").toString(); object_name = queueColl.getValue("object_name"). toString(); title = queueColl.getValue("title").toString(); site_date = queueColl.getValue("site_date").toSt ring(); site_attribute_03 = queueColl.getValue("site_att ribute_03").toString(); asset_name = queueColl.getValue("asset_name").to String(); source="Documentum"; sb.append("\""); sb.append(document_class);sb.append("\"");sb.app end(",");sb.append("\""); sb.append(object_name);sb.append("\"");sb.append (",");sb.append("\"");

sb.append(title);sb.append("\"");sb.append(","); sb.append("\""); sb.append(site_date);sb.append("\"");sb.append(" ,");sb.append("\""); sb.append(site_attribute_03);sb.append("\"");sb. append(",");sb.append("\""); sb.append(source);sb.append("\"");sb.append(",") ;sb.append("\""); sb.append(asset_name);sb.append("\""); //DfLogger.debug(this, " "+sb, null, nul l); output.write(sb.toString()); output.newLine(); count++; } if (count > 0) { output.close(); fileWriter.close(); } } catch (DfException e) { //DfLogger.error(this, "Exception"+e.getMessage(), null, e); // arg1.write(e.getMessage()); e.printStackTrace(); } finally { if (session != null) sessionManager.release(session); if (queueColl != null) queueColl.close(); if (output != null) output.close(); if (fileWriter != null) fileWriter.close(); //DfLogger.debug(this, "All Sessions and Collections clo sed", null, null); } } /** * Method to get Session Manager based on the parameters. * * @return Session Manager * @throws DfException */ protected IDfSessionManager getSessionManager() throws DfException { System.out.println("in getSessionManager"); //DfLogger.debug(this, "In getSessionManager", null, null); IDfClient dfClient = DfClient.getLocalClient(); IDfLoginInfo li = new DfLoginInfo(); li.setUser("dmadmin"); li.setPassword("kav8c3pR5jAj"); //li.setPassword(""); li.setDomain(""); IDfSessionManager sessionMgr = dfClient.newSessionManager();

sessionMgr.setIdentity("CH_CPR_NOE", li); System.out.println("in getSessionManager---"+sessionMgr.getSessi on("CH_CPR_NOE")); return sessionMgr; } /* Entry point of job * @see com.documentum.mthdservlet.IDmMethod#execute(java.util.Map, java .io.OutputStream) */ public void execute(Map params, OutputStream arg1) throws Exception { // TODO Auto-generated method stub //DfLogger.debug(this, "Execure Method Started", null, null); //initParams(params, arg1); //genReport(); } }