[jbpm-commits] JBoss JBPM SVN: r5626 - in projects/jopr-integration/trunk: src/main/java/org/rhq/plugins/jbpm4 and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Sep 10 06:21:21 EDT 2009


Author: jim.ma
Date: 2009-09-10 06:21:20 -0400 (Thu, 10 Sep 2009)
New Revision: 5626

Modified:
   projects/jopr-integration/trunk/pom.xml
   projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessEngineDiscoveryComponent.java
   projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/connector/LocalJBPMEngineConnector.java
   projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/connector/RemoteJBPMEngineConnector.java
Log:
Completed RemoteJBPMEngineConnector to test it in new released jopr2.3

Modified: projects/jopr-integration/trunk/pom.xml
===================================================================
--- projects/jopr-integration/trunk/pom.xml	2009-09-09 14:17:07 UTC (rev 5625)
+++ projects/jopr-integration/trunk/pom.xml	2009-09-10 10:21:20 UTC (rev 5626)
@@ -54,9 +54,17 @@
 		<dependency>
 			<groupId>org.jbpm.jbpm4</groupId>
 			<artifactId>jbpm-pvm</artifactId>
-			<version>4.0-SNAPSHOT</version>
+			<version>4.0</version>
 			<scope>provided</scope>
 		</dependency>
+
+		<dependency>
+			<groupId>org.jbpm.jbpm4</groupId>
+			<artifactId>jbpm-enterprise</artifactId>
+			<version>4.0</version>
+			<scope>provided</scope>
+		</dependency>
+
 
 		<dependency>
 			<groupId>org.jbpm.jbpm4</groupId>

Modified: projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessEngineDiscoveryComponent.java
===================================================================
--- projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessEngineDiscoveryComponent.java	2009-09-09 14:17:07 UTC (rev 5625)
+++ projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/ProcessEngineDiscoveryComponent.java	2009-09-10 10:21:20 UTC (rev 5626)
@@ -67,7 +67,6 @@
         //TODO:Review it and removed the jars not needed
         String[] jarFileNames = { "lib/jbpm.jar",
                                   "deploy/jbpm/jbpm-service.sar/freemarker.jar",
-                                  "deploy/jbpm/jbpm-service.sar/jbpm-spi.jar",
                                   "deploy/jbpm/jbpm-service.sar/juel.jar",
                                   "deploy/jbpm/jbpm-service.sar/juel-engine.jar",
                                   "deploy/jbpm/jbpm-service.sar/juel-impl.jar",

Modified: projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/connector/LocalJBPMEngineConnector.java
===================================================================
--- projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/connector/LocalJBPMEngineConnector.java	2009-09-09 14:17:07 UTC (rev 5625)
+++ projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/connector/LocalJBPMEngineConnector.java	2009-09-10 10:21:20 UTC (rev 5626)
@@ -213,8 +213,10 @@
 	}
 	
 	public Job executeJob(String jobDbid) {
-		 CommandService commandService = processEngine.get(CommandService.class);
-		 return commandService.execute(new ExecuteJobCmd(jobDbid));
+		 //These will cause jbpm4.1 class not fund org.jbpm.pvm.internal.cmd.Command execption
+		 /*CommandService commandService = processEngine.get(CommandService.class);
+		 return commandService.execute(new ExecuteJobCmd(jobDbid));*/
+		 return null;
 	}
 	
   	public List<HistoryProcessInstance> getHistoryProcessInstances(String definitionId, String processInstanceId, String state, Page page) {

Modified: projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/connector/RemoteJBPMEngineConnector.java
===================================================================
--- projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/connector/RemoteJBPMEngineConnector.java	2009-09-09 14:17:07 UTC (rev 5625)
+++ projects/jopr-integration/trunk/src/main/java/org/rhq/plugins/jbpm4/connector/RemoteJBPMEngineConnector.java	2009-09-10 10:21:20 UTC (rev 5626)
@@ -21,6 +21,11 @@
  */
 package org.rhq.plugins.jbpm4.connector;
 
+import java.io.File;
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
 import java.util.Properties;
 
 import javax.naming.Context;
@@ -28,11 +33,48 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.jbpm.api.Deployment;
+import org.jbpm.api.DeploymentQuery;
+import org.jbpm.api.JbpmException;
+import org.jbpm.api.JobQuery;
+import org.jbpm.api.ProcessDefinition;
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.history.HistoryProcessInstance;
+import org.jbpm.api.history.HistoryTask;
+import org.jbpm.api.job.Job;
+import org.jbpm.api.task.Task;
+import org.jbpm.enterprise.internal.ejb.RemoteCommandExecutor;
+import org.jbpm.enterprise.internal.ejb.RemoteCommandExecutorHome;
+import org.jbpm.pvm.internal.cmd.Command;
+import org.jbpm.pvm.internal.cmd.CreateDeploymentQueryCmd;
+import org.jbpm.pvm.internal.cmd.CreateHistoryProcessInstanceQueryCmd;
+import org.jbpm.pvm.internal.cmd.CreateHistoryTaskQueryCmd;
+import org.jbpm.pvm.internal.cmd.CreateJobQueryCmd;
+import org.jbpm.pvm.internal.cmd.CreateProcessDefinitionQueryCmd;
+import org.jbpm.pvm.internal.cmd.CreateProcessInstanceQueryCmd;
+import org.jbpm.pvm.internal.cmd.CreateTaskQueryCmd;
+import org.jbpm.pvm.internal.cmd.DeleteDeploymentCmd;
+import org.jbpm.pvm.internal.cmd.DeleteProcessInstance;
+import org.jbpm.pvm.internal.cmd.DeployCmd;
+import org.jbpm.pvm.internal.cmd.ExecuteJobCmd;
+import org.jbpm.pvm.internal.cmd.ResumeDeploymentCmd;
+import org.jbpm.pvm.internal.cmd.StartProcessInstanceCmd;
+import org.jbpm.pvm.internal.cmd.SuspendDeploymentCmd;
+import org.jbpm.pvm.internal.query.AvgDurationPerActivityQueryCmd;
+import org.jbpm.pvm.internal.query.HistoryProcessInstanceQueryImpl;
+import org.jbpm.pvm.internal.query.HistoryTaskQueryImpl;
+import org.jbpm.pvm.internal.query.JobQueryImpl;
+import org.jbpm.pvm.internal.query.Page;
+import org.jbpm.pvm.internal.query.ProcessDefinitionQueryImpl;
+import org.jbpm.pvm.internal.query.ProcessInstanceQueryImpl;
+import org.jbpm.pvm.internal.query.TaskQueryImpl;
+import org.jbpm.pvm.internal.repository.DeploymentImpl;
+
 /**
  * @author <a href mailto="ema at redhat.com">Jim Ma</a>
- *
+ * 
  */
-public class RemoteJBPMEngineConnector implements JBPMEngineConnector {
+public class RemoteJBPMEngineConnector implements JBPMEngineConnector, JBPMEngineConnection {
 
 	private static final String NAMING_CONTEXT_FACTORY = "org.jnp.interfaces.NamingContextFactory";
 	private static final String JNP_TIMEOUT_JNP_INIT_PROP = "jnp.timeout";
@@ -41,48 +83,362 @@
 	private static final int JNP_TIMEOUT = 60 * 1000; // 60 seconds
 	private static final int JNP_SO_TIMEOUT = 60 * 1000; // 60 seconds
 	private static final boolean JNP_DISABLE_DISCOVERY = true;
-	
-	//TODO: ProcessEngine can not be serialized. What is the instead ?
-	private final String  XXX__JNDI_NAME = "ProcessEngine";
+
+	// TODO: ProcessEngine can not be serialized. What is the instead ?
+	private final String CMD_EXECUTOR__JNDI_NAME = "jbpm/CommandExecutor";
 	private final Log log = LogFactory.getLog(this.getClass());
-	
+
 	private String providerURL;
 	private String principal;
 	private String credentials;
-	private InitialContext initialContext;
+	private RemoteCommandExecutor remoteCommandExecutor = null;
 
 	public RemoteJBPMEngineConnector(String providerURL, String principal, String credentials) {
-        this.providerURL = providerURL;
-        this.principal = principal;
-        this.credentials = credentials;
+		this.providerURL = providerURL;
+		this.principal = principal;
+		this.credentials = credentials;
 	}
 
 	public JBPMEngineConnection connect() {
-		Properties env = new Properties();		
-        env.setProperty(Context.PROVIDER_URL, providerURL);
-        env.setProperty(Context.INITIAL_CONTEXT_FACTORY, NAMING_CONTEXT_FACTORY);
-        env.setProperty(JNP_TIMEOUT_JNP_INIT_PROP, String.valueOf(JNP_TIMEOUT));
-        env.setProperty(JNP_SOTIMEOUT_JNP_INIT_PROP, String.valueOf(JNP_SO_TIMEOUT));
-        env.setProperty(JNP_DISABLE_DISCOVERY_JNP_INIT_PROP, String.valueOf(JNP_DISABLE_DISCOVERY));
-        env.setProperty(Context.SECURITY_CREDENTIALS, this.credentials);
-        env.setProperty(Context.SECURITY_PRINCIPAL, this.principal);
-        /*ProcessEngine processEngine = null; 
-        log.debug("Connecting to ProcessEngine via remote JNDI using env [" + env + "]...");
-        try {
-            initialContext = new InitialContext(env);
-            processEngine = (ProcessEngine)initialContext.lookup(this.PROCESSENGINE__JNDI_NAME);           
-        } catch (NamingException e) {
-            throw new RuntimeException("Failed to create JNDI InitialContext.", e);
-        }*/
-        return null;
+		try {
+			remoteCommandExecutor = this.retrieveCommandExecutor();
+			return this;
+		} catch (Exception e) {
+			log.error("Failed to retrieve CommandExecutor");
+		}
+		return null;
 	}
-	
+
 	public void disconnect() {
-		
+
 	}
-	
+
 	public boolean isConnected() {
 		return false;
 	}
-}	
-	
+
+	private RemoteCommandExecutor retrieveCommandExecutor() throws Exception {
+		Properties env = new Properties();
+		env.setProperty(Context.PROVIDER_URL, providerURL);
+		env.setProperty(Context.INITIAL_CONTEXT_FACTORY, NAMING_CONTEXT_FACTORY);
+		env.setProperty(JNP_TIMEOUT_JNP_INIT_PROP, String.valueOf(JNP_TIMEOUT));
+		env.setProperty(JNP_SOTIMEOUT_JNP_INIT_PROP, String.valueOf(JNP_SO_TIMEOUT));
+		env.setProperty(JNP_DISABLE_DISCOVERY_JNP_INIT_PROP, String.valueOf(JNP_DISABLE_DISCOVERY));
+		env.setProperty(Context.SECURITY_CREDENTIALS, this.credentials);
+		env.setProperty(Context.SECURITY_PRINCIPAL, this.principal);
+
+		InitialContext initialContext = new InitialContext(env);
+		RemoteCommandExecutorHome remoteCommandExecutorHome = (RemoteCommandExecutorHome) initialContext
+				.lookup(CMD_EXECUTOR__JNDI_NAME);
+
+		return remoteCommandExecutorHome.create();
+	}
+
+	// implementation for JBPMEngineConnection
+	// the deployment api
+	// TODO: true or false
+	public void deleteDeployment(String deploymentId) {
+		DeleteDeploymentCmd delDeploymentCmd = new DeleteDeploymentCmd(deploymentId);
+		this.execute(delDeploymentCmd);
+	}
+
+	public List<Deployment> getDeployments() {
+		CreateDeploymentQueryCmd queryCmd = new CreateDeploymentQueryCmd();
+		DeploymentQuery deploymentQuery = execute(queryCmd);
+		return deploymentQuery.list();
+
+	}
+
+	public Deployment getDeployment(String deploymentId) {
+		CreateDeploymentQueryCmd queryCmd = new CreateDeploymentQueryCmd();
+		DeploymentQuery deploymentQuery = execute(queryCmd);
+		return (Deployment) deploymentQuery.deploymentDbid(Long.valueOf(deploymentId)).uniqueResult();
+
+	}
+
+	public void suspendDeployment(String deploymentId) {
+		SuspendDeploymentCmd suspendDeploymentCmd = new SuspendDeploymentCmd(deploymentId);
+
+		execute(suspendDeploymentCmd);
+
+	}
+
+	public void resumeDeployment(String deploymentId) {
+		ResumeDeploymentCmd resumeDeploymentCmd = new ResumeDeploymentCmd(deploymentId);
+		execute(resumeDeploymentCmd);
+
+	}
+
+	public String deployProcess(File processFile) throws Exception {
+		DeploymentImpl deploymentImpl = new DeploymentImpl();
+		deploymentImpl.addResourceFromFile(processFile);
+		DeployCmd deployCmd = new DeployCmd(deploymentImpl);
+		return (String) execute(deployCmd);
+
+	}
+
+	// definition api
+	public List<ProcessDefinition> getProcessDefs() {
+		CreateProcessDefinitionQueryCmd queryCmd = new CreateProcessDefinitionQueryCmd();
+
+		ProcessDefinitionQueryImpl queryIml = (ProcessDefinitionQueryImpl) execute(queryCmd);
+		return queryIml.list();
+
+	}
+
+	public ProcessDefinition getProcessDefById(String id) {
+		CreateProcessDefinitionQueryCmd queryCmd = new CreateProcessDefinitionQueryCmd();
+
+		ProcessDefinitionQueryImpl queryIpml = (ProcessDefinitionQueryImpl) execute(queryCmd);
+		queryIpml.processDefinitionId(id);
+		return queryIpml.uniqueResult();
+
+	}
+
+	// process instance api
+	public List<ProcessInstance> getProcessInstances(String defId, String processInstanceId, String state, Page page) {
+		CreateProcessInstanceQueryCmd queryCmd = new CreateProcessInstanceQueryCmd();
+
+		ProcessInstanceQueryImpl query = (ProcessInstanceQueryImpl) execute(queryCmd);
+		if (defId != null) {
+			query.processDefinitionId(defId);
+		}
+		if (processInstanceId != null) {
+			query.processInstanceId(processInstanceId);
+		}
+		if (state != null && state.equals(ProcessInstance.STATE_SUSPENDED)) {
+			query.suspended();
+		}
+
+		if (state != null && (!state.equals(ProcessInstance.STATE_SUSPENDED))) {
+			query.notSuspended();
+		}
+
+		if (page != null) {
+			query.page(page.firstResult, page.maxResults);
+		}
+
+		return query.list();
+
+	}
+
+	public void deleteProcessInstance(String instanceId) {
+		DeleteProcessInstance deleteInstance = new DeleteProcessInstance(instanceId);
+
+		execute(deleteInstance);
+
+	}
+
+	public ProcessInstance startProcessInstance(String defId) {
+		StartProcessInstanceCmd startCmd = new StartProcessInstanceCmd(defId, null, null);
+
+		return (ProcessInstance)execute(startCmd);
+
+	}
+
+	// Job api
+	public List<Job> queryJob(boolean timerOnly, boolean messageOnly, boolean exception, String processInstanceId) {
+		CreateJobQueryCmd queryCmd = new CreateJobQueryCmd();
+
+		JobQuery jobQuery = (JobQuery) execute(queryCmd);
+		if (processInstanceId != null) {
+			jobQuery.processInstanceId(processInstanceId);
+		}
+
+		if (exception) {
+			jobQuery.exception(true);
+		}
+
+		if (timerOnly) {
+			jobQuery = jobQuery.timers();
+		} else if (messageOnly) {
+			jobQuery = jobQuery.messages();
+		}
+		return jobQuery.list();
+
+	}
+
+	public Job getJob(String jobId) {
+		CreateJobQueryCmd queryCmd = new CreateJobQueryCmd();
+
+		JobQuery jobQuery = (JobQuery) execute(queryCmd);
+
+		List<Job> jobs = jobQuery.list();
+
+		for (Job job : jobs) {
+			if (job.getId().equals(jobId)) {
+				return job;
+			}
+		}
+		return null;
+
+	}
+
+	public Job executeJob(String jobDbid) {
+		ExecuteJobCmd executeJobCmd = new ExecuteJobCmd(jobDbid);
+
+		return (Job) execute(executeJobCmd);
+
+	}
+
+	// Activity api
+	public Map<String, Long> avgDurationPerActivity(String processDefinitionId) {
+		AvgDurationPerActivityQueryCmd command = new AvgDurationPerActivityQueryCmd(processDefinitionId);
+
+		return (Map<String, Long>) execute(command);
+
+	}
+
+	// History process instance api
+	public List<HistoryProcessInstance> getHistoryProcessInstances(String definitionId, String processInstanceId,
+			String state, Page page) {
+		CreateHistoryProcessInstanceQueryCmd command = new CreateHistoryProcessInstanceQueryCmd();
+
+		HistoryProcessInstanceQueryImpl historyQuery = (HistoryProcessInstanceQueryImpl) execute(command);
+		if (definitionId != null) {
+			historyQuery.processDefinitionId(definitionId);
+		}
+		if (processInstanceId != null) {
+			historyQuery.processInstanceId(processInstanceId);
+		}
+
+		if (state != null) {
+			historyQuery.state(state);
+		}
+
+		if (page != null) {
+			historyQuery.page(page.firstResult, page.maxResults);
+		}
+		return historyQuery.list();
+
+	}
+
+	// Task api
+	public List<Task> getTasks(String definitionId, String processInstanceId) {
+		CreateTaskQueryCmd command = new CreateTaskQueryCmd();
+
+		TaskQueryImpl taskQuery = (TaskQueryImpl) execute(command);
+		if (definitionId != null) {
+			taskQuery.processDefinitionId(definitionId);
+		}
+
+		if (processInstanceId != null) {
+			taskQuery.processInstanceId(processInstanceId);
+		}
+
+		return taskQuery.list();
+
+	}
+
+	public List<Task> getTasks(TaskQueryCondition condition) {
+		CreateTaskQueryCmd command = new CreateTaskQueryCmd();
+
+		TaskQueryImpl taskQuery = (TaskQueryImpl) execute(command);
+		if (condition.getActivityName() != null) {
+			taskQuery.activityName(condition.getActivityName());
+		}
+
+		if (condition.getAssignee() != null) {
+			taskQuery.assignee(condition.getAssignee());
+		}
+
+		if (condition.getCandidate() != null) {
+			taskQuery.assignee(condition.getAssignee());
+		}
+
+		if (condition.getDefinitionId() != null) {
+			taskQuery.processDefinitionId(condition.getDefinitionId());
+		}
+
+		if (condition.getUnAssigneed() != null) {
+			taskQuery.unassigned();
+		}
+		if (condition.getSuspended() != null && condition.getSuspended()) {
+			taskQuery.suspended();
+		}
+		if (condition.getSuspended() != null && (!condition.getSuspended())) {
+			taskQuery.notSuspended();
+		}
+
+		if (condition.getPage() != null) {
+			taskQuery.page(condition.getPage().firstResult, condition.getPage().maxResults);
+		}
+
+		return taskQuery.list();
+
+	}
+
+	// History task api
+	public List<HistoryTask> getHIstoryTasks(TaskHistoryQueryCondition condition) {
+		CreateHistoryTaskQueryCmd command = new CreateHistoryTaskQueryCmd();
+
+		HistoryTaskQueryImpl historyTaskQuery = (HistoryTaskQueryImpl) execute(command);
+		if (condition.getTaskId() != null) {
+			historyTaskQuery.taskId(condition.getTaskId());
+		}
+
+		if (condition.getProcessInstanceId() != null) {
+			historyTaskQuery.executionId(condition.getProcessInstanceId());
+		}
+
+		if (condition.getAssignee() != null) {
+			historyTaskQuery.assignee(condition.getAssignee());
+		}
+
+		if (condition.getOutcome() != null) {
+			historyTaskQuery.outcome(condition.getOutcome());
+		}
+
+		if (condition.getStartedAfter() != null) {
+			historyTaskQuery.startedAfter(condition.getStartedAfter());
+		}
+
+		if (condition.getStartedBefore() != null) {
+			historyTaskQuery.startedBefore(condition.getStartedBefore());
+		}
+
+		if (condition.getTookLessThen() != null) {
+			historyTaskQuery.tookLessThen(condition.getTookLessThen());
+		}
+
+		if (condition.getTookLongerThen() != null) {
+			historyTaskQuery.tookLongerThen(condition.getTookLongerThen());
+		}
+
+		List<HistoryTask> historyTasks = historyTaskQuery.list();
+		// TODO: ask jbpm team to add select historyTasks by process
+		// instance id
+		if (condition.getDefinitionId() != null) {
+			List<HistoryProcessInstance> historyInstances = getHistoryProcessInstances(condition.getDefinitionId(),
+					null, null, null);
+			List<String> hisInstances = new ArrayList<String>();
+			for (HistoryProcessInstance hisInstance : historyInstances) {
+				hisInstances.add(hisInstance.getProcessInstanceId());
+			}
+			List<HistoryTask> newHistoryTasks = new ArrayList<HistoryTask>();
+			for (HistoryTask task : historyTasks) {
+				if (hisInstances.contains(task.getExecutionId())) {
+					newHistoryTasks.add(task);
+				}
+			}
+			return newHistoryTasks;
+
+		}
+
+		return historyTasks;
+
+	}
+
+	public <T> T execute(Command<T> command) {
+		try {
+
+			Object result = remoteCommandExecutor.execute(command);
+			remoteCommandExecutor.remove();
+			return (T) result;
+
+		} catch (Exception e) {
+			throw new JbpmException("couldn't execute remote command: " + e.getMessage(), e);
+		}
+	}
+
+}



More information about the jbpm-commits mailing list