JBPM4基础篇03-管理流程实例

来源:互联网 发布:情侣礼物一对知乎 编辑:程序博客网 时间:2024/05/21 14:46
本篇主要对流程进行启动,终止和删除操作。
package org.wxp;import java.util.List;import junit.framework.TestCase;import org.jbpm.api.Configuration;import org.jbpm.api.ExecutionService;import org.jbpm.api.ProcessEngine;import org.jbpm.api.ProcessInstance;/** * 管理流程实例 * 1.创建流程 * 2.判断流程是否终结 * 3.手动停止一个流程 * 4.删除流程 * @author Champion.Wong * */public class ProcessInstanceTest extends TestCase {ProcessEngine processEngine; // 创建流程引擎public ProcessInstanceTest() {processEngine = Configuration.getProcessEngine(); // 实例化流程引擎}protected void setUp() {processEngine.getRepositoryService().createDeployment().addResourceFromClasspath("helloworld.jpdl.xml").deploy(); // 启动流程引擎}public void testProcessInstance() {ExecutionService executionService = processEngine.getExecutionService(); // 获取一个流程执行ProcessInstance pi = executionService.startProcessInstanceByKey("helloworld"); // 启动一个流程定义System.out.println("刚启动的流程为:" + pi);System.out.println("流程是否终结:" + pi.isEnded()); // 流程为等待状态,所以没有终结pi = executionService.signalExecutionById(pi.getId()); // 手动执行流程System.out.println("流程是否终结:" + pi.isEnded());}public void testProcessInstanceEnd() {ExecutionService executionService = processEngine.getExecutionService(); // 获取一个流程执行ProcessInstance pi = executionService.startProcessInstanceByKey("helloworld"); // 启动一个流程定义executionService.endProcessInstance(pi.getId(), "cancel"); // 强制终止一个流程}public void testProcessInstanceDelete() {ExecutionService executionService = processEngine.getExecutionService(); // 获取一个流程执行ProcessInstance pi = executionService.startProcessInstanceByKey("helloworld"); // 启动一个流程定义executionService.deleteProcessInstanceCascade(pi.getId()); // 删除一个流程}public void testProcessInstanceList() {ExecutionService executionService = processEngine.getExecutionService(); // 获取一个流程执行ProcessInstance pi = executionService.startProcessInstanceByKey("helloworld"); // 启动一个流程定义ProcessInstance pi2 = executionService.startProcessInstanceByKey("helloworld"); // 启动一个流程定义List<ProcessInstance> list = executionService.createProcessInstanceQuery().list(); // 获取引擎中所有流程定义的信息for (ProcessInstance processInstance : list) {System.out.println(processInstance.getId());}}}


原创粉丝点击