查了好多资料,发现还是不全,干脆自己整理吧,至少保证在我的做法正确的,以免误导读者,也是给自己做个记录吧!
package com.njupt.jbpm; 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; /** * 流程定义的管理 * * * */ public class ProcessDefinitionTest { // // 生成ProcessEngine对象,使用指定的配置文件 // private static ProcessEngine processEngine = new Configuration()// // .setResource("jbpm.cfg.xml")// // .buildProcessEngine(); // // 生成ProcessEngine对象,使用默认的配置文件(jbpm.cfg.xml) // private static ProcessEngine processEngine = new Configuration() .buildProcessEngine(); // 获得单例的ProcessEngine对象(使用的是默认的文件文件) private static ProcessEngine processEngine = Configuration.getProcessEngine(); // 1,添加流程定义(部署) // 对应的表:jbpm4_deployment @Test public void testDeploy() throws Exception { String deploymentId = processEngine.getRepositoryService()// .createDeployment()// .addResourceFromClasspath("first/test.jpdl.xml")// .addResourceFromClasspath("first/test.png")// .deploy(); System.out.println("部署胜利,deploymentId = " + deploymentId); } // 部署流程定义 @Test public void testDeploy2_zip() throws Exception { // 一次指定多个资源(同一个zip中的) InputStream in = getClass().getClassLoader().getResourceAsStream("first/first.zip"); ZipInputStream zipInputStream = new ZipInputStream(in); String deploymentId = processEngine.getRepositoryService()// .createDeployment()// .addResourcesFromZipInputStream(zipInputStream)// .deploy(); System.out.println("部署胜利,deploymentId = " + deploymentId); } // 2,获得部署时添加的文件内容 @Test public void testGetResource() throws Exception { String deploymentId = "40001"; // 获得某次部署时添加的全部文件资源的名称 Set<String> nameSet = processEngine.getRepositoryService().getResourceNames(deploymentId); for (String name : nameSet) { System.out.println("\t" + name); } // 获得某次部署时添加的指定的文件资源内容 String resourceName = "first/test.png"; InputStream in = processEngine.getRepositoryService().getResourceAsStream(deploymentId, resourceName); // >> 保存到文件中 FileOutputStream out = new FileOutputStream("c:/process.png"); for (int b = -1; (b = in.read()) != -1;) { out.write(b); } in.close(); out.close(); } // 3,删除 @Test public void testDelete() throws Exception { String deploymentId = "40001"; // // 删除指定的部署对象,如果有关联的执行信息,则报错 // processEngine.getRepositoryService().deleteDeployment(deploymentId); // 删除指定的部署对象,如果有关联的执行信息,则级联删除 processEngine.getRepositoryService().deleteDeploymentCascade(deploymentId); } // 4,查询流程定义 @Test public void testFindAll() throws Exception { // 查询 List<ProcessDefinition> list = processEngine.getRepositoryService()// .createProcessDefinitionQuery()// // 过滤条件 // .processDefinitionId(processDefinitionId)// // .processDefinitionKey(key)// // .processDefinitionName(name) // 排序条件 // .orderAsc(property)// // .orderDesc(property)// // 执行查询 // .count() // .uniqueResult() // .page(firstResult, maxResults) .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()// 可自动生成值,同名称的第一个为版本1,当前的版本号递增。 + ", deploymentId=" + pd.getDeploymentId()); // (对应的.jpdl.xml)所属的部署对象的ID } } }
文章结束给大家分享下程序员的一些笑话语录: 姿势要丰富,经常上百度!