JBPM 流程定义的增删改查
来源:互联网 发布:excel2003显示重复数据 编辑:程序博客网 时间:2024/04/29 04:39
package com.itcast.processdefinition;import java.io.File;import java.io.FileOutputStream;import java.io.InputStream;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Set;import java.util.zip.ZipInputStream;import org.jbpm.api.Configuration;import org.jbpm.api.ProcessDefinition;import org.jbpm.api.ProcessDefinitionQuery;import org.jbpm.api.ProcessEngine;import org.junit.Test;public class ProcessDefinitionTest { private static ProcessEngine processEngine; static{ //processEngine = new Configuration().setResource("jbpm.cfg.xml").buildProcessEngine(); //processEngine = new Configuration().buildProcessEngine(); processEngine = Configuration.getProcessEngine(); } //部署(添加) @Test public void deploy() throws Exception { String deployId = processEngine.getRepositoryService().createDeployment() .addResourceFromClasspath("helloworld/helloworld.jpdl.xml") .addResourceFromClasspath("helloworld/helloworld.png") .deploy(); System.out.println("部署成功:deployId=="+deployId); } //部署(添加) @Test public void deployZip() throws Exception { InputStream is = this.getClass().getClassLoader().getResourceAsStream("helloworld/helloworld.zip"); String deployId = processEngine.getRepositoryService().createDeployment() //.addResourceFromFile(new File("d:/helloworld.zip")) .addResourcesFromZipInputStream(new ZipInputStream(is)) .deploy(); System.out.println("部署成功:deployId=="+deployId); } //查询 @Test public void findAll() throws Exception { List<ProcessDefinition> list = processEngine.getRepositoryService().createProcessDefinitionQuery() .processDefinitionKey("helloworld") .processDefinitionNameLike("%helloworld%") .orderAsc(ProcessDefinitionQuery.PROPERTY_ID) .orderDesc(ProcessDefinitionQuery.PROPERTY_KEY) //.page(firstResult, maxResults) .list(); if(list != null){ for(ProcessDefinition pd : list){ System.out.println("deploymentId="+pd.getDeploymentId() +",name="+pd.getName() +",version="+pd.getVersion() +",id="+pd.getId() +",key="+pd.getKey() ); } } } //查询最新版本的流程 @Test public void findAllLatestVersions() throws Exception { List<ProcessDefinition> list = processEngine.getRepositoryService().createProcessDefinitionQuery() .orderAsc(ProcessDefinitionQuery.PROPERTY_VERSION) .list(); //这样map里存的就是最新的ProcessDefinition Map<String, ProcessDefinition> map = new HashMap<String, ProcessDefinition>(); for(ProcessDefinition pd : list){ map.put(pd.getKey(), pd); } if(list != null){ for(ProcessDefinition pd : map.values()){ System.out.println("deploymentId="+pd.getDeploymentId() +",name="+pd.getName() +",version="+pd.getVersion() +",id="+pd.getId() +",key="+pd.getKey() ); } } } //查询 @Test public void count() throws Exception { long count = processEngine.getRepositoryService().createProcessDefinitionQuery() .processDefinitionKey("helloworld") .processDefinitionNameLike("%helloworld%") .orderAsc(ProcessDefinitionQuery.PROPERTY_ID) .orderDesc(ProcessDefinitionQuery.PROPERTY_KEY) .count(); System.out.println("count=="+ count); } //查询 @Test public void find() throws Exception { String deploymentId = "80001"; ProcessDefinition pd = processEngine.getRepositoryService().createProcessDefinitionQuery() .processDefinitionKey("helloworld") .processDefinitionNameLike("%helloworld%") .orderAsc(ProcessDefinitionQuery.PROPERTY_ID) .orderDesc(ProcessDefinitionQuery.PROPERTY_KEY) .deploymentId(deploymentId) .uniqueResult(); System.out.println("id="+pd.getDeploymentId()+",name="+pd.getName()+",assigne="+pd.getVersion()); } //删除 @Test public void deleteById() throws Exception { String deploymentId = "80001"; //有关联的信息删除时会报错 //processEngine.getRepositoryService().deleteDeployment(deploymentId); //级联删除 processEngine.getRepositoryService().deleteDeploymentCascade(deploymentId); } //删除所有 @Test public void deleteAllByKey() throws Exception { List<ProcessDefinition> list = processEngine.getRepositoryService().createProcessDefinitionQuery() .orderAsc(ProcessDefinitionQuery.PROPERTY_VERSION) .list(); //有关联的信息删除时会报错 //processEngine.getRepositoryService().deleteDeployment(deploymentId); for(ProcessDefinition pd : list){ //级联删除 processEngine.getRepositoryService().deleteDeploymentCascade(pd.getDeploymentId()); } } //查看流程图(***.png) @Test public void getImageResource() throws Exception { String deploymentId = "80001"; String resourceName = "helloworld/helloworld.png"; Set<String> resourceNames = processEngine.getRepositoryService().getResourceNames(deploymentId); //processEngine.getRepositoryService().getResourceAsStream(deploymentId, resourceName); for(String name :resourceNames){ System.out.println("imageName=="+name + "\t\n"); } InputStream is = processEngine.getRepositoryService().getResourceAsStream(deploymentId, resourceName); FileOutputStream fos = new FileOutputStream(new File("d:/process.png")); int len = -1; while((len = is.read())!=-1){ fos.write(len); } is.close(); fos.close(); }}
0 0
- JBPM 流程定义的增删改查
- jbpm 流程增删改查
- 基本的增删改查流程
- JBPM的流程定义
- 流程总结:实现增删改查一组功能的步骤
- 数据库的增删改查和使用流程
- datagridview的增删改查
- jdbc的增删改查
- GridView 的增删改查
- 联系人的增删查改
- 数据库的增删改查
- Linq的增删改查
- Hibernate的增删改查
- 网页的增删改查
- struts2的增删改查
- XML的增删改查
- Hibernate的增删改查
- json的增删改查
- CentOS6.5 安装apache/mysql/php
- UGUI 实现物体的双击
- 学习资料
- Nginx负载均衡配置实例详解
- keras 的使用
- JBPM 流程定义的增删改查
- vs中ATL(exe)开发一些问题总结
- 块元素和行内元素
- vs2010 编译器报错:转换到COFF期间失败:文件无效或损坏
- unity3d DrawCall
- Android中自定义属性的使用
- cookie禁用了 session还能用吗
- 《锋利的JQuery》读书笔记——第一章
- HDU2844Coins