Monday 30 September 2013

Pass custom arguments in your job

If you want to pass custom arguments along with default one, you should write a code to fetch them manually.

In below piece of code we are passing -folder_path "/Cabinet/Folder1/Folder2" as custom argument.

-------------------------------------------------------------------------------------------
public class TestJobMethod implements IDmMethod{
                public void execute(Map arg0, OutputStream arg1) throws Exception {
      
        IDfSession session = getSession(arg0);
        IDfSysObject oIDfJob = null;
        oIDfJob = (IDfSysObject)session.getObject(new DfId("job id"));
        for (int i = 0; i < oIDfJob.getValueCount("method_arguments"); i++) {  
            String strArgument = oIDfJob.getRepeatingString("method_arguments", i);  
            if (strArgument.indexOf(" ") > 0) {  
                String strKey = strArgument.substring(0, strArgument.indexOf(" ")).trim();  
                String strValue = strArgument.substring(strArgument.indexOf(" ") + 1).trim();  
          
                if (strKey.equalsIgnoreCase("-folder_path")) {  
                                 DfLogger.warn(this, "Key: " + strKey + " value: " + strValue, null, null);
                    // Handle parameter  
                } 
            }  
        }  
      
                }
                private IDfSession getSession(Map map) {
        String userName[] = (String[]) map.get("user_name");
        String docbase[] = (String[]) map.get("docbase_name");
      
        IDfSession session = null;
        IDfClientX clientX = new DfClientX();
        IDfClient client;
        IDfLoginInfo loginInfo = new DfLoginInfo();
        loginInfo.setUser(userName[0]);
        loginInfo.setPassword("");
        IDfSessionManager sMgr = null;
        try {
            client = clientX.getLocalClient();
            sMgr = client.newSessionManager();
            sMgr.setIdentity(docbase[0], loginInfo);
            session = sMgr.getSession(docbase[0]);
        } catch (DfException e) {
            e.printStackTrace();
        }
        return session;
    }

}
----------------------------------------------------------------------------------------------


1 comment:

  1. Do we need to set password as blank while getting session...is it due to trusted login feature since this methoid would run on jms ?

    ReplyDelete