Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
import java.util.Map;
import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import org.joget.apps.app.service.AppUtil;
import org.joget.plugin.base.Plugin;
import org.joget.plugin.base.PluginManager;
import org.joget.workflow.util.WorkflowUtil;
import org.joget.apps.app.model.AppDefinition;
import org.joget.apps.app.service.AppPluginUtil;
import org.joget.plugin.property.model.PropertyEditable;

import org.joget.workflow.model.service.WorkflowManager;
import org.joget.workflow.model.WorkflowProcess;
import org.joget.apps.app.service.AppUtil;
import org.joget.workflow.model.WorkflowProcessLink;
import org.joget.workflow.model.WorkflowProcessResult;
import org.joget.workflow.model.WorkflowActivity;
import org.joget.workflow.model.WorkflowVariable;
import org.joget.commons.util.LogUtil;
import org.joget.apps.app.lib.JsonTool;

public void callPlugin(){
	try {    
        PluginManager pluginManager = (PluginManager) AppUtil.getApplicationContext().getBean("pluginManager");
        
		//plugin to call
        String pluginName = "org.joget.apps.app.lib.JsonTool";
        Plugin plugin = pluginManager.getPlugin(pluginName);
        AppDefinition appDef = AppUtil.getCurrentAppDefinition();
        
		//JSON API to call to start a new process
        String jsonURL = "http://localhost:8080/jw/web/json/workflow/process/start/expenseclaim:latest:process1";
        
		//prepare workflow variables for the process
        List params = new ArrayList();
        
        Map param = new HashMap();
        param.put("name", "var_approval");
        param.put("value", "New");
        params.add(param);

		param = new HashMap();
        param.put("name", "var_SelectApprover");
        param.put("value", "clark");
        params.add(param);
        
        Object[] paramsArray = params.toArray();
        
		//prepare propertiesMap mapped specifically for JSON tool
        Map propertiesMap = new HashMap();
        propertiesMap.put("jsonUrl", jsonURL);
        propertiesMap.put("requestType", "post");
        propertiesMap.put("debugMode", "true");
        propertiesMap.put("headers", new Object[]{});
        //propertiesMap.put("params", new Object[]{ params });
        propertiesMap.put("params", paramsArray );
        
		//obtain default properties set, if any
		propertiesMap = AppPluginUtil.getDefaultProperties(plugin, propertiesMap, appDef, null);

        //set properties into the JSON tool programmatically
        if (plugin instanceof PropertyEditable) {
            ((PropertyEditable) plugin).setProperties(propertiesMap);
            LogUtil.info("migrateProcess", "set properties");
        }
        
        //invoke the JSON plugin
		plugin.execute(propertiesMap);
        
        LogUtil.info("callPlugin", "execution finished");
    } catch (Exception ex) {
        LogUtil.error("callPlugin", ex, "Error");
    }
}

callPlugin();