码迷,mamicode.com
首页 > 其他好文 > 详细

jbpm4.4 demo2

时间:2015-09-01 10:27:57      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

package cn.itcast.b_processdefinition;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.List;
import java.util.Set;
import java.util.zip.ZipInputStream;

import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessDefinition;
import org.jbpm.api.ProcessEngine;
import org.junit.Test;

/**
 * 管理流程定义有关的操作
 * 
 * <pre>
 * 	部署(添加)
 * 	删除
 * 	查询(查询所有、自定义条件查询)
 * 	获取部署添加的文件信息(查看流程图)
 *  !!没有更新操作!策略为:重新部署 + 版本递增。
 * 
 * </pre>
 * 
 * @author tyg
 * 
 */
public class ProcessDefinitionTest {

	private ProcessEngine processEngine = Configuration.getProcessEngine();

	// 部署(添加)
	@Test
	public void testDeploy() throws Exception {
		String deploymentId = processEngine.getRepositoryService()//
				.createDeployment()// 创建一个部署对象
				.addResourceFromClasspath("helloworld/helloworld.jpdl.xml")// 添加一个要部署的文件
				.addResourceFromClasspath("helloworld/helloworld.png")// 添加一个要部署的文件
				.deploy(); // 执行部署操作
		System.out.println("部署成功:deploymentId = " + deploymentId);
	}

	// 部署(把多个文件打包为一个zip一起部署)
	@Test
	public void testDeploy_zip() throws Exception {
		// 准备
		ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream("d:/helloworld.zip"));
		
		// 部署
		String deploymentId = processEngine.getRepositoryService()//
				.createDeployment()// 创建一个部署对象
				.addResourcesFromZipInputStream(zipInputStream)// 指定zip流
				.deploy(); // 执行部署操作
		System.out.println("部署成功:deploymentId = " + deploymentId);
	}

	
	// 删除
	@Test
	public void testDelete() throws Exception {
		// // 删除指定的部署对象,如果有关联的信息,就报错
		// processEngine.getRepositoryService().deleteDeployment(deploymentId);
		// // 删除指定的部署对象,如果有关联的信息,就一并删除
		// processEngine.getRepositoryService().deleteDeploymentCascade(deploymentId);

		String deploymentId = "40001";
		processEngine.getRepositoryService().deleteDeploymentCascade(deploymentId);
	}

	// 查询流程定义(查询所有、自定义条件查询)
	@Test
	public void testFindAllProcessDefinition() throws Exception {
		// 查询
		List<ProcessDefinition> list = processEngine.getRepositoryService()//
				.createProcessDefinitionQuery()//
				// 过滤条件
				// .processDefinitionId(processDefinitionId);
				// .deploymentId(deploymentId)
				// .processDefinitionKey(key)
				// .processDefinitionName(name)
				// 排序条件
				// .orderAsc(property)
				// .orderDesc(property)
				// .orderAsc(ProcessDefinitionQuery.PROPERTY_VERSION)//
				// 执行查询得到结果
				// .page(firstResult, maxResults)
				// .list()
				// .count()
				// .uniqueResult()
				.list();

		// 显示
		for (ProcessDefinition pd : list) {
			System.out.println("id=" + pd.getId()// 格式为:{key}-{version}
					+ ", name=" + pd.getName()// .jpdl.xml中根元素的name属性的值。
					+ ", key=" + pd.getKey()// .jpdl.xml中根元素的key属性的值。如果不写,默认为name属性的值。
					+ ", version=" + pd.getVersion()// .jpdl.xml中根元素的version属性的值。如果不写,默认的效果为同名称的第一个version为1,以后的就递增。(一般不要写)
					+ ", deploymentId=" + pd.getDeploymentId()); // 所属的部署对象的id
		}
	}

	// 获取部署时添加的文件信息(查看流程图)
	@Test
	public void testGetProcessImage() throws Exception {
		String deploymentId = "90001";
		String resourceName = "helloworld/helloworld.png";

		// 获取指定的部署对象中的所有的文件名称
		//使用给定的id 返回所有的资源存储
		Set<String> nameSet = processEngine.getRepositoryService().getResourceNames(deploymentId);
		System.out.println("所有的文件:");
		for (String name : nameSet) {
			System.out.println("\t" + name);
		}

		// 获取指定的部署对象中的指定名称的文件内容
		InputStream in = processEngine.getRepositoryService().getResourceAsStream(deploymentId, resourceName);

		// 存到d:/中
		FileOutputStream out = new FileOutputStream("d:/process.png");
		byte[] buf = new byte[1024];
		for (int len = -1; (len = in.read(buf)) != -1;) {
			out.write(buf, 0, len);
		}
		in.close();
		out.close();
	}
}

 

<?xml version="1.0" encoding="UTF-8"?>

<process name="hellokey" key="hellokey" xmlns="http://jbpm.org/4.4/jpdl">
   <start g="115,21,48,48" name="start1">
      <transition g="-71,-17" name="to 提交申请" to="提交申请"/>
   </start>
   <end g="115,353,48,48" name="end1"/>
   <task assignee="员工" g="81,101,117,52" name="提交申请">
      <transition g="-78,-15" name="to 部门经理[审批]" to="部门经理[审批]"/>
   </task>
   <task assignee="部门经理" g="81,185,117,52" name="部门经理[审批]">
      <transition g="-95,-17" name="to 总经理[审批]" to="总经理[审批]"/>
   </task>
   <task assignee="总经理" g="81,269,117,52" name="总经理[审批]">
      <transition g="-47,-17" name="to end1" to="end1"/>
   </task>
</process>

 

 下载demo

jbpm4.4 demo2

标签:

原文地址:http://www.cnblogs.com/a757956132/p/4774909.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!