Method

 

import com.documentum.fc.client.*;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.DfId;
import com.documentum.fc.common.IDfLoginInfo;
import com.documentum.com.DfClientX;
import com.documentum.fc.methodserver.*;

import java.util.*;
import java.io.PrintWriter;


public class CustomJavaMethodPrintParams implements IDfMethod
{

    // fields to store Workflow specific params passed by Content Server
    private String m_docbasename = null;
    private String m_serviceconfigname = null;
    private String m_workflowid = null;
    private String m_actseqno = null;
    private int m_timertype = 0;
    private String m_username = null;
    private String m_loginTicket=null;

    // the following are the param names passed by Server
    private static final String DOCBASE_NAME = "docbase_name";
    private static final String SERVERCONFIG_NAME = "serverconfig_name";
    private static final String WORKFLOW_ID = "workflow_id";
    private static final String ACT_SEQNO = "act_seqno";
    private static final String TIMER_TYPE = "timer_type";
    private static final String USER_NAME = "user_name";
    private static final String TICKET_KEY = "ticket";

 

    public int execute (Map params, PrintWriter ostream) throws Exception
    {

        IDfSession session = null;

        initWorkflowParams(params);
        System.out.println("Username is .."+m_username);
            System.out.println("Docbase name is ...."+m_docbasename);
            System.out.println("Workflow Id is ..."+m_workflowid);
            System.out.println("Activity seq no is.."+m_actseqno);
            System.out.println("Timer type is..."+m_timertype);
            System.out.println("ServerConfig name is ..."+m_serviceconfigname);
        IDfSessionManager sessionMgr = null;

        try {

            sessionMgr  = login();
            session = sessionMgr.getSession(m_docbasename);


            return 0;
        }
        catch (DfException e)
            {

                String msg = "Exception in CustomJavaMethodPrintParams::execute() for WorkitemID: " + m_workflowid;
                System.err.println(msg + " - " + e.getMessage());
  e.printStackTrace();
                return -1;
            }
        finally
            {
                if ( session != null )
                    sessionMgr.release(session);

               // if(sessionMgr != null)
                //    sessionMgr.clearIdentities(); // Has side effect of flushing the session pool before garbage collection
            }

    } // end execute()


    /****************************************************************
        This method reads the passed in params and store them in class member variables
     ******************************************************************/
      protected void initWorkflowParams(Map params)
    {
        // get the 6 WF-related parameters always passed in by Server
       Set keys = params.keySet();
       Iterator iter = keys.iterator();
       while (iter.hasNext())
       {
           String key = (String) iter.next();
           //int timerkey = 0;
           if( (key == null) || (key.length() == 0) )
           {
               continue;
           }
           String []value = (String[])params.get(key);

           if ( key.equalsIgnoreCase(USER_NAME) )
               m_username = (value.length > 0) ? value[0] : "";
           else if ( key.equalsIgnoreCase(DOCBASE_NAME) ) {
               m_docbasename = (value.length > 0) ? value[0] : "";
                System.out. println("docbase name............: " + m_docbasename);
           }
           else if ( key.equalsIgnoreCase(WORKFLOW_ID) )
               m_workflowid = (value.length > 0) ? value[0] : "";
           else if ( key.equalsIgnoreCase(ACT_SEQNO) )
               m_actseqno = (value.length > 0) ? value[0] : "";
           else if ( key.equalsIgnoreCase(TIMER_TYPE) )
               m_timertype = (value.length > 0) ? (Integer.parseInt(value[0])) : 1 ;
           else if ( key.equalsIgnoreCase(SERVERCONFIG_NAME) )
               m_serviceconfigname = (value.length > 0) ? value[0] : "";
           else if ( key.equalsIgnoreCase(TICKET_KEY) )
               m_loginTicket = (value.length > 0) ? value[0] : "";
       }
   }

   protected IDfSessionManager login() throws DfException
   {
       if (m_docbasename == null || m_username == null || m_loginTicket == null )
           return null;

       IDfLoginInfo li = new DfClientX().getLoginInfo();
       li.setUser(m_username);
       li.setPassword(m_loginTicket);
       li.setDomain(null);

       IDfSessionManager sessionMgr = DfClient.getLocalClient().newSessionManager();
       sessionMgr.setIdentity(m_docbasename, li);
       return sessionMgr;

    }
}

你可能感兴趣的:(method)