Author: rebody
Date: 2010-08-12 01:47:06 -0400 (Thu, 12 Aug 2010)
New Revision: 6582
Added:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/ResumeProcessInstanceCmd.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/SuspendProcessInstanceCmd.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/execution/SuspendProcessInstanceTest.java
Modified:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ExecutionService.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/EndProcessInstance.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java
Log:
JBPM-2815 expose suspend and resume process instance in api interface.
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ExecutionService.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ExecutionService.java 2010-08-12
03:19:01 UTC (rev 6581)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ExecutionService.java 2010-08-12
05:47:06 UTC (rev 6582)
@@ -35,13 +35,13 @@
* @param processDefinitionId the {@link ProcessDefinition#getId() unique id} of the
process definition. */
ProcessInstance startProcessInstanceById(String processDefinitionId);
- /** starts a new process instance for the ProcessDefinition with the given
processDefinitionDbid.
+ /** starts a new process instance for the ProcessDefinition with the given
processDefinitionDbid.
* @param processDefinitionId the {@link ProcessDefinition#getId() unique id} of the
process definition.
- * @param processInstanceKey is a user provided reference for the new process instance
that must be unique over all
+ * @param processInstanceKey is a user provided reference for the new process instance
that must be unique over all
* process definition versions with the same name. */
ProcessInstance startProcessInstanceById(String processDefinitionId, String
processInstanceKey);
- /** starts a new process instance for the ProcessDefinition with the given
processDefinitionDbid.
+ /** starts a new process instance for the ProcessDefinition with the given
processDefinitionDbid.
* @param processDefinitionId the {@link ProcessDefinition#getId() unique id} of the
process definition.
* @param variables are the initial values of the process variables that will be set
before the execution starts. */
ProcessInstance startProcessInstanceById(String processDefinitionId, Map<String,
?> variables);
@@ -49,7 +49,7 @@
/** starts a new process instance for the ProcessDefinition with the given
processDefinitionDbid.
* @param processDefinitionId the {@link ProcessDefinition#getId() unique id} of the
process definition.
* @param variables are the initial values of the process variables that will be set
before the execution starts.
- * @param processInstanceKey is a user provided reference for the new process instance
that must be unique over all
+ * @param processInstanceKey is a user provided reference for the new process instance
that must be unique over all
* process versions with the same name. */
ProcessInstance startProcessInstanceById(String processDefinitionId, Map<String,
?> variables, String processInstanceKey);
@@ -109,10 +109,10 @@
/** creates or overwrites variable values in the referenced execution */
void setVariables(String executionId, Map<String, ?> variables);
-
+
/** creates a variable value in the referenced execution. optionally enables variable
history tracking. */
void createVariable(String executionId, String name, Object value, boolean
historyEnabled);
-
+
/** creates variable values in the referenced execution. optionally enables variable
history tracking. */
void createVariables(String executionId, Map<String, ?> variables, boolean
historyEnabled);
@@ -124,11 +124,17 @@
/** retrieves a map of variables */
Map<String, Object> getVariables(String executionId, Set<String>
variableNames);
-
+
+ /** suspend a process instance. */
+ void suspendProcessInstance(String processInstanceId);
+
+ /** resume a process instance. */
+ void resumeProcessInstance(String processInstanceId);
+
/** end a process instance */
void endProcessInstance(String processInstanceId, String state);
- /** delete a process instance. The history information will still be in the database.
+ /** delete a process instance. The history information will still be in the database.
* @throws JbpmException if the given processInstanceId doesn't exist*/
void deleteProcessInstance(String processInstanceId);
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/EndProcessInstance.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/EndProcessInstance.java 2010-08-12
03:19:01 UTC (rev 6581)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/EndProcessInstance.java 2010-08-12
05:47:06 UTC (rev 6582)
@@ -22,7 +22,7 @@
package org.jbpm.pvm.internal.cmd;
import org.jbpm.api.cmd.Environment;
-import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.pvm.internal.client.ClientExecution;
import org.jbpm.pvm.internal.session.DbSession;
@@ -32,10 +32,10 @@
public class EndProcessInstance extends AbstractCommand<Object> {
private static final long serialVersionUID = 1L;
-
+
protected String processInstanceId;
protected String state;
-
+
public EndProcessInstance(String processInstanceId, String state) {
super();
this.processInstanceId = processInstanceId;
@@ -44,7 +44,7 @@
public Object execute(Environment environment) throws Exception {
DbSession dbSession = environment.get(DbSession.class);
- ExecutionImpl processInstance = (ExecutionImpl)
dbSession.findProcessInstanceById(processInstanceId);
+ ClientExecution processInstance =
dbSession.findProcessInstanceById(processInstanceId);
processInstance.end(state);
return null;
}
Added:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/ResumeProcessInstanceCmd.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/ResumeProcessInstanceCmd.java
(rev 0)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/ResumeProcessInstanceCmd.java 2010-08-12
05:47:06 UTC (rev 6582)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.cmd;
+
+import org.jbpm.api.JbpmException;
+import org.jbpm.api.cmd.Command;
+import org.jbpm.api.cmd.Environment;
+import org.jbpm.pvm.internal.client.ClientExecution;
+import org.jbpm.pvm.internal.session.DbSession;
+
+
+/**
+ * @author Huisheng Xu
+ */
+public class ResumeProcessInstanceCmd implements Command<Object> {
+
+ private static final long serialVersionUID = 1L;
+
+ private String processInstanceId;
+
+ public ResumeProcessInstanceCmd(String processInstanceId) {
+ if (processInstanceId == null) {
+ throw new JbpmException("process instance id cannot be null");
+ }
+ this.processInstanceId = processInstanceId;
+ }
+
+ public Object execute(Environment environment) throws Exception {
+ DbSession dbSession = environment.get(DbSession.class);
+ ClientExecution processInstance = dbSession.findExecutionById(processInstanceId);
+ if (processInstance == null) {
+ throw new JbpmException("cannot find process instance by [" +
processInstanceId + "]");
+ }
+ processInstance.resume();
+ return null;
+ }
+
+}
Added:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/SuspendProcessInstanceCmd.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/SuspendProcessInstanceCmd.java
(rev 0)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/SuspendProcessInstanceCmd.java 2010-08-12
05:47:06 UTC (rev 6582)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.cmd;
+
+import org.jbpm.api.JbpmException;
+import org.jbpm.api.cmd.Command;
+import org.jbpm.api.cmd.Environment;
+import org.jbpm.pvm.internal.client.ClientExecution;
+import org.jbpm.pvm.internal.session.DbSession;
+
+
+/**
+ * @author Huisheng Xu
+ */
+public class SuspendProcessInstanceCmd implements Command<Object> {
+
+ private static final long serialVersionUID = 1L;
+
+ private String processInstanceId;
+
+ public SuspendProcessInstanceCmd(String processInstanceId) {
+ if (processInstanceId == null) {
+ throw new JbpmException("process instance id cannot be null");
+ }
+ this.processInstanceId = processInstanceId;
+ }
+
+ public Object execute(Environment environment) throws Exception {
+ DbSession dbSession = environment.get(DbSession.class);
+ ClientExecution processInstance = dbSession.findExecutionById(processInstanceId);
+ if (processInstance == null) {
+ throw new JbpmException("cannot find process instance by [" +
processInstanceId + "]");
+ }
+ processInstance.suspend();
+ return null;
+ }
+
+}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java 2010-08-12
03:19:01 UTC (rev 6581)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java 2010-08-12
05:47:06 UTC (rev 6582)
@@ -33,6 +33,8 @@
import org.jbpm.pvm.internal.cmd.CreateProcessInstanceQueryCmd;
import org.jbpm.pvm.internal.cmd.DeleteProcessInstance;
import org.jbpm.pvm.internal.cmd.EndProcessInstance;
+import org.jbpm.pvm.internal.cmd.SuspendProcessInstanceCmd;
+import org.jbpm.pvm.internal.cmd.ResumeProcessInstanceCmd;
import org.jbpm.pvm.internal.cmd.FindExecutionCmd;
import org.jbpm.pvm.internal.cmd.GetExecutionVariableNamesCmd;
import org.jbpm.pvm.internal.cmd.GetExecutionVariablesCmd;
@@ -62,15 +64,15 @@
public ProcessInstance startProcessInstanceById(String processDefinitionId,
Map<String, ?> variables, String executionKey){
return commandService.execute(new StartProcessInstanceCmd(processDefinitionId,
variables, executionKey));
}
-
+
public ProcessInstance startProcessInstanceByKey(String processDefinitionKey) {
return commandService.execute(new
StartProcessInstanceInLatestCmd(processDefinitionKey, null, null));
}
-
+
public ProcessInstance startProcessInstanceByKey(String processDefinitionKey,
Map<String, ?> variables){
return commandService.execute(new
StartProcessInstanceInLatestCmd(processDefinitionKey, variables, null));
}
-
+
public ProcessInstance startProcessInstanceByKey(String processDefinitionKey, String
executionKey) {
return commandService.execute(new
StartProcessInstanceInLatestCmd(processDefinitionKey, null, executionKey));
}
@@ -79,8 +81,8 @@
return commandService.execute(new
StartProcessInstanceInLatestCmd(processDefinitionKey, variables, executionKey));
}
-
-
+
+
public ProcessInstance signalExecutionById(String executionId) {
return commandService.execute(new SignalCmd(executionId, null, null));
}
@@ -97,22 +99,30 @@
return commandService.execute(new SignalCmd(executionId, null, parameters));
}
-
+
public Execution findExecutionById(String executionId) {
return commandService.execute(new FindExecutionCmd(executionId));
}
-
+
public ProcessInstance findProcessInstanceById(String executionId) {
return (ProcessInstance) commandService.execute(new FindExecutionCmd(executionId));
}
-
+
public ProcessInstanceQuery createProcessInstanceQuery() {
ProcessInstanceQueryImpl query = commandService.execute(new
CreateProcessInstanceQueryCmd());
query.setCommandService(commandService);
return query;
}
+ public void suspendProcessInstance(String processInstanceId) {
+ commandService.execute(new SuspendProcessInstanceCmd(processInstanceId));
+ }
+
+ public void resumeProcessInstance(String processInstanceId) {
+ commandService.execute(new ResumeProcessInstanceCmd(processInstanceId));
+ }
+
public void endProcessInstance(String processInstanceId, String state) {
commandService.execute(new EndProcessInstance(processInstanceId, state));
}
@@ -120,7 +130,7 @@
public void deleteProcessInstance(String processInstanceId) {
commandService.execute(new DeleteProcessInstance(processInstanceId));
}
-
+
public void deleteProcessInstanceCascade(String processInstanceId) {
commandService.execute(new DeleteProcessInstance(processInstanceId, true));
}
@@ -151,7 +161,7 @@
cmd.setVariables(variables);
commandService.execute(cmd);
}
-
+
public void createVariable(String executionId, String name, Object value, boolean
historyEnabled) {
CreateExecutionVariablesCmd cmd = new CreateExecutionVariablesCmd(executionId,
historyEnabled);
cmd.addVariable(name, value);
Added:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/execution/SuspendProcessInstanceTest.java
===================================================================
---
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/execution/SuspendProcessInstanceTest.java
(rev 0)
+++
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/execution/SuspendProcessInstanceTest.java 2010-08-12
05:47:06 UTC (rev 6582)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jbpm.test.execution;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.jbpm.api.JbpmException;
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Huisheng Xu
+ */
+public class SuspendProcessInstanceTest extends JbpmTestCase {
+
+ public void testSuspendProcessInstance() {
+ deployJpdlXmlString(
+ "<process name='Insurance claim' key='ICL'>" +
+ " <start>" +
+ " <transition to='a' />" +
+ " </start>" +
+ " <state name='a'>" +
+ " <transition to='b' />" +
+ " </state>" +
+ " <state name='b'>" +
+ " <transition to='c' />" +
+ " </state>" +
+ " <state name='c' />" +
+ "</process>"
+ );
+
+ ProcessInstance processInstance =
executionService.startProcessInstanceByKey("ICL", "82436");
+
+ assertTrue(processInstance.isActive("a"));
+
+ executionService.suspendProcessInstance(processInstance.getId());
+ try {
+ processInstance = executionService.signalExecutionById("ICL.82436");
+ } catch(JbpmException ex) {
+ assertEquals("execution[ICL.82436] is not active: suspended",
ex.getMessage());
+ }
+ executionService.resumeProcessInstance(processInstance.getId());
+
+ processInstance = executionService.signalExecutionById("ICL.82436");
+
+ assertTrue(processInstance.isActive("b"));
+ }
+}