流程定義的管理

來源:互聯網
上載者:User
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@Testpublic void testDeploy() throws Exception {String deploymentId = processEngine.getRepositoryService()//.createDeployment()//.addResourceFromClasspath("first/test.jpdl.xml")//.addResourceFromClasspath("first/test.png")//.deploy();System.out.println("部署成功,deploymentId = " + deploymentId);}// 部署流程定義@Testpublic 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,擷取部署時添加的檔案內容@Testpublic 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,刪除@Testpublic void testDelete() throws Exception {String deploymentId = "40001";// // 刪除指定的部署對象,如果有關聯的執行資訊,則報錯// processEngine.getRepositoryService().deleteDeployment(deploymentId);// 刪除指定的部署對象,如果有關聯的執行資訊,則串聯刪除processEngine.getRepositoryService().deleteDeploymentCascade(deploymentId);}// 4,查詢流程定義@Testpublic 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}}}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.