流程资源可以是各种类型的文件,在启动流程或流程实例运行过程中会被读取。下面介绍常用的流程资源。
一、流程资源
流程定义文件:扩展名为bpmn20.xml和bpmn;
流程定义的图片:用BPMN2.0规范的各种图形描绘,一般用PNG的格式;
表单文件:把表单内容保存在一个文件中,其扩展名为drl;
规则文件:其扩展名为drl;
二、部署流程资源
部署流程资源有很多种方法,包括classpath、InputStream、字符串、zip格式压缩包,下面将一一介绍。
1.classpath方式
- public class ProcessDefinitionTest {
-
- ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
-
-
- @Test
- public void deployementProcessDefinition(){
- Deployment deployment = processEngine.getRepositoryService()
- .createDeployment()
- .name("helloworld演示")
- .addClasspathResource("diagrams/helloworld.bpmn")
- .addClasspathResource("diagrams/helloworld.png")
- .deploy();
- System.out.println("部署ID:"+deployment.getId());
- System.out.println("部署时间:"+deployment.getDeploymentTime());
- }
- }
2.InputStream方式
使用InputStream方式部署流程资源需要传入一个输入流及资源的名称,输入流的来源不限,可以从classpath读取,也可以从一个绝对路径文件读取,也可以是从网络上读取。
-
- @Test
- public void deployementProcessDefinitionByInputStream() throws FileNotFoundException{
-
- String bpmnPath = "diagrams/helloworld.bpmn";
- String pngPath = "diagrams/helloworld.png";
-
-
- FileInputStream bpmnfileInputStream = new FileInputStream(bpmnPath);
- FileInputStream pngfileInputStream = new FileInputStream(pngPath);
-
- Deployment deployment = processEngine.getRepositoryService()
- .createDeployment()
- .addInputStream("helloworld.bpmn",bpmnfileInputStream)
- .addInputStream("helloworld.png", pngfileInputStream)
- .deploy();
- System.out.println("部署ID:"+deployment.getId());
- System.out.println("部署时间:"+deployment.getDeploymentTime());
- }
3.字符串方式
利用字符串方式可以直接传入纯文本作为资源的来源,和前两种方式类似,字符串方式的实现原理是把一组字符串的内容转化为字节流后再部署。
-
- @Test
- public void deployementProcessDefinitionByString() throws FileNotFoundException{
-
- String text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><definitions>...</definitions>";
-
- Deployment deployment = processEngine.getRepositoryService()
- .createDeployment()
- .addString("helloworld.bpmn",text)
- .deploy();
- System.out.println("部署ID:"+deployment.getId());
- System.out.println("部署时间:"+deployment.getDeploymentTime());
- }
4.zip/bar格式压缩包方式
以上3种部署方式一次只能部署一个资源,除非执行多次deployment.addXxx()方法,如何一次部署多个资源呢?很简单,是我们可以使用zip/bar格式压缩包方式。将资源文件手动或使用Ant脚本,打包文件扩展名可以是Activiti官方推荐的bar或普通的zip。
-
- @Test
- public void deployementProcessDefinitionByzip(){
-
- InputStream in = this.getClass().getClassLoader().getResourceAsStream("diagrams/helloworld.zip");
- ZipInputStream zipInputStream = new ZipInputStream(in);
- Deployment deployment = processEngine.getRepositoryService()
- .createDeployment()
- .addZipInputStream(zipInputStream)
- .deploy();
- System.out.println("部署ID:"+deployment.getId());
- System.out.println("部署时间:"+deployment.getDeploymentTime());
- }
三、数据库表变更
在部署流程定义这一步,数据库中操作三张表:
1)ACT_RE_DEPLOYMENT(部署对象表)
存放流程定义的显示名和部署时间,每部署一次增加一条记录

2)ACT_RE_PROCDEF(流程定义表)
存放流程定义的属性信息,部署每个新的流程定义都会在这张表中增加一条记录。
注意:当流程定义的key相同的情况下,使用的是版本升级
3)ACT_GE_BYTEARRAY(资源文件表)
存储流程定义相关的部署信息。即流程定义文档的存放地。每部署一次就会增加两条记录,一条是关于bpmn规则文件的,一条是图片的(如果部署时只指定了bpmn一个文件,activiti会在部署时解析bpmn文件内容自动生成流程图)。两个文件不是很大,都是以二进制形式存储在数据库中。

4)ACT_GE_PROPERTY(主键生成表)
主张表将生成下次流程部署的主键ID。
