jbpm流程定义基本操作 布署 查询 删除

jbpm流程定义基本操作 布署 查询 删除packagecn.itcast.init;importjava.io.FileOutputStream;importjava.io.IOException;importjava.io.InputStream;importjava.io.InputStreamReader;importjava.io.OutputStreamWriter;importjava.util.

jbpm流程定义基本操作

package cn.itcast.init;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java.util.zip.ZipInputStream;

import org.hibernate.cfg.Configuration;
import org.jbpm.api.ProcessDefinition;
import org.jbpm.api.ProcessDefinitionQuery;
import org.jbpm.api.ProcessEngine;
import org.junit.Test;

/**
 * 基本操作,布署,CRD
 * 
 * @author Administrator
 * 
 */
public class CreateSchema {

	ProcessEngine processEngine = org.jbpm.api.Configuration.getProcessEngine();

	@Test
	public void createSchema() {// 初始化表
		new Configuration().configure("jbpm.hibernate.cfg.xml").buildSessionFactory();
	}

	@Test
	public void definition() {// 流程定义

		processEngine.getRepositoryService()//
				.createDeployment()//
				.addResourceFromClasspath("test.jpdl.xml")//
				.addResourceFromClasspath("test.png")//
				.deploy();
	}

	@Test
	public void deploy() {// 流程定义,从zip文件中布署
		InputStream is = this.getClass().getClassLoader().getResourceAsStream("test.zip");
		ZipInputStream zis = new ZipInputStream(is);
		processEngine.getRepositoryService()//
				.createDeployment()//
				.addResourcesFromZipInputStream(zis)//
				.deploy();
	}

	@Test
	public void query01() {// 取出所有流程
		List<ProcessDefinition> list = processEngine.getRepositoryService()//
				.createProcessDefinitionQuery()//
				.orderAsc(ProcessDefinitionQuery.PROPERTY_ID)//
				.list();
		for (ProcessDefinition p : list) {
			System.out.print("   name=");
			System.out.print(p.getName());
			System.out.print("   key=");
			System.out.print(p.getKey());
			System.out.print("   version=");
			System.out.print(p.getVersion());
			System.out.print("   deploymentId=");
			System.out.print(p.getDeploymentId());

			System.out.println();

		}
	}

	@Test
	public void query02() {// 按版本排序,并取出最新版本
		List<ProcessDefinition> list = processEngine.getRepositoryService()//
				.createProcessDefinitionQuery()//
				.orderAsc(ProcessDefinitionQuery.PROPERTY_VERSION)//
				.list();

		Map<String, ProcessDefinition> all = new HashMap<String, ProcessDefinition>();

		for (ProcessDefinition p : list) {
			System.out.print("   version=");
			System.out.print(p.getVersion());
			System.out.print("   name=");
			System.out.print(p.getName());
			System.out.print("   key=");
			System.out.print(p.getKey());
			System.out.print("   deploymentId=");
			System.out.print(p.getDeploymentId());
			System.out.println();
			all.put(p.getKey(), p);
		}
		Set<Entry<String, ProcessDefinition>> entrySet = all.entrySet();
		for (Entry<String, ProcessDefinition> entry : entrySet) {
			System.out.println("   key=" + entry.getKey() + "   version=" + entry.getValue().getVersion());
		}
	}

	@Test
	public void query03() {// 按版本排序,并分页
		ProcessDefinitionQuery query = processEngine.getRepositoryService()//
				.createProcessDefinitionQuery()//
				.orderAsc(ProcessDefinitionQuery.PROPERTY_VERSION);//

		long count = query.count();
		List<ProcessDefinition> list = query.page(1, 10).list();
	}

	@Test
	public void deleteById() {
		processEngine.getRepositoryService().deleteDeployment("50001");// 单个删除,有关联信息会报错
	}

	@Test
	public void deleteByCascade() {
		processEngine.getRepositoryService().deleteDeploymentCascade("60001");// 级联删除有关联信息
	}

	@Test
	public void deleteByKey() {
		List<ProcessDefinition> list = processEngine.getRepositoryService()// 单个删除,关联key都会删除
				.createProcessDefinitionQuery()//
				.processDefinitionKey("dddt")//
				.list();
		for (ProcessDefinition p : list) {
			String id = p.getDeploymentId();
			processEngine.getRepositoryService()//
					.deleteDeploymentCascade(id);
		}
	}

	@Test
	public void getResourceNameByDeployment() {
		Set<String> resourceNames = processEngine.getRepositoryService().getResourceNames("100001");// 获取资源名称
		for (String s : resourceNames) {
			System.out.println(s);
		}

	}

	@Test
	public void getResourceByDeployment() {// 获取资源
		InputStream is = processEngine.getRepositoryService().getResourceAsStream("70001", "test.jpdl.xml");
		InputStreamReader isr = null;
		OutputStreamWriter osw = null;
		try {
			isr = new InputStreamReader(is);
			osw = new OutputStreamWriter(new FileOutputStream("c:/test.jpdl.xml"), "utf-8");
			char[] b = new char[1024];
			while (isr.read(b) != -1) {
				osw.write(b);
				osw.flush();
			}
		} catch (Exception e) {

			e.printStackTrace();
		} finally {
			try {
				osw.close();
				isr.close();
			} catch (IOException e) {

				e.printStackTrace();
			}
		}

	}

}

详细相关项目实例,可到我的资料列表去下载

http://download.csdn.net/detail/albert_lz/6744245

今天的文章jbpm流程定义基本操作 布署 查询 删除分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/28861.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注