国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
activiti入門九(repositoryService介紹)

activiti入門一(簡單介紹中),簡單介紹了repositoryService的主要作用是管理流程倉庫,例如部署,刪除,讀取流程資源等。本文就repositoryService再做下詳細(xì)的說明

流程的部署

常用的流程定義文件擴(kuò)展名有:bpmn20.xml和bpmn。流程定義的圖片一般用png格式。

部署流程資源的實(shí)現(xiàn)方式有很多種,如classPath,InputStream,字符串,zip壓縮包格式等。下面簡單介紹下各種方式的使用。

通過classPath方式部署

classPath方式,就是以class目錄為根路徑來讀取相應(yīng)的資源文件并進(jìn)行部署。路徑的命名方式是用斜杠”/”來分割包名。
具體實(shí)現(xiàn)看代碼

@Testpublic void classPathDeploymentTest(){    //定義資源文件的classPath    String bpmnClassPath = "/bpmn/leave-dynamic-form.bpmn20.xml";    String pngClassPath = "/bpmn/leave-dynamic-form.png";    //創(chuàng)建部署構(gòu)建器    DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();    //添加資源    deploymentBuilder.addClasspathResource(bpmnClassPath);    deploymentBuilder.addClasspathResource(pngClassPath);    //執(zhí)行部署    deploymentBuilder.deploy();    //驗(yàn)證部署是否成功    ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();    long count = processDefinitionQuery.processDefinitionKey("leave-dynamic-from").count();    Assert.isTrue(count == 1);    //讀取圖片文件    ProcessDefinition processDefinition = processDefinitionQuery.singleResult();    String diagramResourceName = processDefinition.getDiagramResourceName();    System.out.println(diagramResourceName);}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

該方式的每行的代碼作用參看注釋。classPath一般用于開發(fā)階段,在真正的產(chǎn)品使用中,很少會用到這種方式。

InputStream方式部署

InputStream方式,簡單點(diǎn)說就是把文件轉(zhuǎn)換為輸入流,來進(jìn)行部署。輸入流的來源,可以從classPath讀取,也可以從一個絕對路徑讀取,也可以根據(jù)上傳下載的文件來。

@Testpublic void inputStreamFromAbsolutePathTest() throws Exception{    String filePath = "/Users/whatlookingfor/code/workfocus/src/test/resources/bpmn/leave-dynamic-form.bpmn20.xml";    //讀取filePath文件作為一個輸入流    FileInputStream fileInputStream = new FileInputStream(filePath);    repositoryService.createDeployment().addInputStream("leave-dynamic-form.bpmn20.xml",fileInputStream).deploy();    //驗(yàn)證部署是否成功    ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();    long count = processDefinitionQuery.processDefinitionKey("leave-dynamic-form").count();    Assert.isTrue(count == 1);}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

使用inputStream部署時,需要額外的參數(shù)是資源的名稱。以上的代碼是從一個絕對路徑去讀取文件,生成inputStream輸入流。
這種方式可能是在項(xiàng)目中最廣泛使用的,比如通過上傳bpmn文件來部署,或者給出文件URL地址來部署。

字符串方式部署

字符串的方式部署,就是把bpmn或者xml中的內(nèi)容轉(zhuǎn)換為純文本來作為資源部署的。

@Testpublic void stringDeploymentTest(){    String text = "xml內(nèi)容";    repositoryService.createDeployment().addString("leave-dynamic-form.bpmn20.xml",text);    //驗(yàn)證是否部署成功    ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();    long count = processDefinitionQuery.processDefinitionKey("leave-dynamic-form").count();    Assert.isTrue(count == 1);}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

zip/bar格式的壓縮包方式部署

無論是classPath,InputStream,還是字符串方式,每次部署,都只能部署一個流程資源。而壓縮包方式的部署,則可以同時部署多個流程資源。壓縮包中有多少個資源文件,則就可以部署多少個,其實(shí)類似于classPath的批量

@Test    public void zipStreamDeploymentTest(){        //讀取資源        InputStream zipStream = getClass().getClassLoader().getResourceAsStream("bpmn/leave.zip");        repositoryService.createDeployment().addZipInputStream(new ZipInputStream(zipStream)).deploy();        //統(tǒng)計已部署流程定義的數(shù)量        long count = repositoryService.createProcessDefinitionQuery().count();        Assert.isTrue(count == 1);        //查詢部署記錄        Deployment deployment = repositoryService.createDeploymentQuery().singleResult();        Assert.notNull(deployment);        String deploymentId = deployment.getId();        //驗(yàn)證資源文件是否都部署成功        Assert.notNull(repositoryService.getResourceAsStream(deploymentId,"leave-dynamic-form.bpmn"));        Assert.notNull(repositoryService.getResourceAsStream(deploymentId,"leave-dynamic-form.png"));    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

看代碼可以發(fā)現(xiàn),壓縮包方式,也是轉(zhuǎn)換為輸入流的。所以,在項(xiàng)目中,最常用的就是inputStream方式和壓縮包方式的整合。
通過上傳功能(格式包含bpmn,bpmn20.xml,zip,bar),然后根據(jù)文件格式,使用不同的部署方式。

讀取流程資源

讀取已部署流程定義

其實(shí)在上面的代碼中,驗(yàn)證是否部署成功,已經(jīng)實(shí)現(xiàn)了讀取已部署的流程定義

@Testpublic void findDefinitionTest(){    ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();    List<ProcessDefinition> processDefinitionList = processDefinitionQuery.listPage(0,10);}
  • 1
  • 2
  • 3
  • 4
  • 5

通過接口讀取資源流

InputStream getResourceAsStream(String deploymentId, String resourceName);
通過此方式,可以讀取資源流,然后根據(jù)各種不同的情況,輸入資源流即可。

List<String> getDeploymentResourceNames(String deploymentId);
讀取某個部署ID對應(yīng)的文件資源名稱

刪除部署

具體參看代碼

public void deleteDeployment(){    String deploymentId = "leave-dynamic-form:1:5004";    repositoryService.deleteDeployment(deploymentId,true);}
  • 1
  • 2
  • 3
  • 4

deleteDeployment方法有兩個參數(shù),第一個是部署ID,第二個參數(shù)true表示刪除時,會同時把流程相關(guān)的流程數(shù)據(jù)(包括運(yùn)行中的和已經(jīng)結(jié)束的流程實(shí)例)一并刪除掉。

額外的API方法

流程模型的激活和掛起

流程模型的激活
repositoryService.activateProcessDefinitionById(processDefinitionId, true, null);

流程模型的掛起
repositoryService.suspendProcessDefinitionById(processDefinitionId, true, null);
第二個參數(shù)就是用來控制在掛起流程定義時,是否同時掛起對應(yīng)的流程實(shí)例。同樣的,流程實(shí)例也有激活和掛起,這里不做詳細(xì)說明,參看runtimeService介紹。

其實(shí)repositoryService的常用方法并不止上面那些。比如流程模型的創(chuàng)建,設(shè)置,刪除等等。這方面沒有使用過,因?yàn)槟P驮O(shè)計主要通過的是Activiti Modeler。當(dāng)然如果想要自己設(shè)計一套流程模型界面的話,repositoryService中的很多方法,你需要詳細(xì)研究下。

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
activiti5.x 多種部署流程例子
activiti實(shí)現(xiàn)工作流審批
Activiti結(jié)合Spring自動部署流程資源
《Spring 手?jǐn)]專欄》第 6 章:氣吞山河,設(shè)計與實(shí)現(xiàn)資源加載器,從Spring.xml解析和注冊Bean對象
activiti學(xué)習(xí)筆記1
Activiti最全入門教程
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服