`
Supanccy2013
  • 浏览: 214961 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

jbpm学习笔记2 之 管理流程实例

    博客分类:
  • JBPM
阅读更多
注:原创作品,分享以供学习交流,转载请注明出处。

本博文主要介绍:
1,发起新流程
2,人工执行等待的流程
3,查看流程实例,
4,终止流程实例,
5,删除流程实例。

package com.supan;
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;
public class ManagerLiuCheng extends TestCase
{
	// 定义jbmp的引擎
	ProcessEngine processEngine;

	public ManagerLiuCheng()
	{
		// 初始化jbmp引擎
		processEngine = Configuration.getProcessEngine();
	}

	// 重写junit框架中的setUp函数,用来初始化一些对象
	protected void setUp() throws Exception
	{
		super.setUp();
		// 把已经定义好的流程发布到jbmp的引擎中(ExecutionService主要管理流程资源的)
		processEngine.getRepositoryService().createDeployment()
				.addResourceFromClasspath("helloworld.jpdl.xml").deploy();
	}

	// 启动已经发布到jbmp引擎中的流程
	public void testProcessStart()
	{
		// ExecutionService主要用来操作管理流程实例的
		ExecutionService executionService = processEngine.getExecutionService();
		// 启动流程实例(按照id,id就是流程图的文件名称)
		// 因为流程是 start-->state-->end所以启动后流程走到state后就不会继续往下走了。所以不会是end
		ProcessInstance pi = executionService
				.startProcessInstanceByKey("helloworld");
		System.out.println(pi);
		System.out.println(pi.isEnded()); // 打印false

		// 人为执行流程
		pi = executionService.signalExecutionById(pi.getId());
		System.out.println(pi.isEnded()); // 打印true
	}

	// 强制终结流程
	public void testProcessInstanceEnd()
	{
		// ExecutionService主要用来操作管理流程实例的
		ExecutionService executionService = processEngine.getExecutionService();
		// 启动流程实例(按照id,id就是流程图的文件名称)
		// 因为流程是 start-->state-->end所以启动后流程走到state后就不会继续往下走了。所以不会是end
		ProcessInstance pi = executionService
				.startProcessInstanceByKey("helloworld");
		
		//强制结束流程
		executionService.endProcessInstance(pi.getId(), "cancel");
	}
	
	// 强制删除流程
	public void testProcessInstanceDelete()
	{
		// ExecutionService主要用来操作管理流程实例的
		ExecutionService executionService = processEngine.getExecutionService();
		// 启动流程实例(按照id,id就是流程图的文件名称)
		// 因为流程是 start-->state-->end所以启动后流程走到state后就不会继续往下走了。所以不会是end
		ProcessInstance pi = executionService
				.startProcessInstanceByKey("helloworld");
		
		//强制删除流程
		executionService.deleteProcessInstanceCascade(pi.getId());
	}
	
	// 查询引擎中已经运行的流程
	public void testProcessInstanceList()
	{
		// ExecutionService主要用来操作管理流程实例的
		ExecutionService executionService = processEngine.getExecutionService();
		// 启动流程实例(按照id,id就是流程图的文件名称)
		// 因为流程是 start-->state-->end所以启动后流程走到state后就不会继续往下走了。所以不会是end
		ProcessInstance pi = executionService
				.startProcessInstanceByKey("helloworld");
		ProcessInstance p2 = executionService
				.startProcessInstanceByKey("helloworld");
		
		//查询引擎中已经运行的流程
		List<ProcessInstance> list = executionService.createProcessInstanceQuery().list();
		for(ProcessInstance processInstance: list)
		{
			System.out.println(processInstance.getId());
		}
	}
}




分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics