继续flowable的使用介绍哈
一、部署工作流6中方式
- 使用文件流stream,部署工作流
- 使用classpath,部署工作流
- 使用压缩文件格式(zip)ZipStream,部署工作流
- 使用纯文本格式text,部署工作流
- 使用字节数组,部署工作流
- 使用动态创建的流程图,部署工作流
1. 使用文件流stream,部署工作流
上传的文件必须是XXXbpmn20.xml格式的。resourceName的后缀格式必须是XXXbpmn20.xml。
/**【1】使用文件流stream,部署工作流*/
//假设不是null,忽略此处赋值为null。multipartFile对象是文件上传时用到的对象
MultipartFile multipartFile = null;
//resourceName是文件的全名称(包括文件后缀)
String resourceName = multipartFile.getOriginalFilename();
Deployment deployStream = repositoryService.createDeployment()
.addInputStream(resourceName, multipartFile.getInputStream())
.deploy();
2. 使用classpath,部署工作流
classpath是指项目的classes路径。如下图:
/**【2】使用classpath,部署工作流*/
Deployment deployClasspath = repositoryService.createDeployment()
.name("经理审批")
.addClasspathResource("processes/经理审批.bpmn20.xml")
.deploy();
3. 使用压缩文件格式(zip)ZipStream,部署工作流
上传的文件必须是zip压缩文件。resourceName的后缀格式必须是XXXbpmn20.xml。
/**【3】使用压缩文件格式(zip)ZipStream,部署工作流*/
//假设不是null,忽略此处赋值为null。multipartFile对象是文件上传时用到的对象
MultipartFile multipartFile = null;
//resourceName是文件的全名称(包括文件后缀)
String resourceName = multipartFile.getOriginalFilename();
Deployment deployZipStream = repositoryService.createDeployment()
.name(resourceName)
.addZipInputStream(new ZipInputStream(multipartFile.getInputStream()))
.deploy();
4. 使用纯文本格式text,部署工作流
resourceName的后缀格式必须是XXXbpmn20.xml。flowableText文本必须符合流程图的xml文件规范(格式)。
/**【4】使用纯文本格式text,部署工作流*/
//resourceName是文件的全名称(包括文件后缀)
String resourceName = "XXXXXbpmn20.xml";
String flowableText = ".....";
Deployment deployText = repositoryService.createDeployment()
.addString(resourceName, flowableText)
.deploy();
5. 使用字节数组,部署工作流
这种方式部署工作流,需要一个字节数组。resourceName的后缀格式必须是XXXbpmn20.xml。
/**【5】使用字节数组,部署工作流(这里举的例子的文件上传的方式获取字节数组)*/
//假设不是null,忽略此处赋值为null。multipartFile对象是文件上传时用到的对象
MultipartFile multipartFile = null;
//resourceName是文件的全名称(包括文件后缀)
String resourceName = multipartFile.getOriginalFilename();
byte[] bytes = multipartFile.getBytes();
Deployment deployByte = repositoryService.createDeployment()
.addBytes(resourceName, bytes)
.deploy();
6. 使用动态创建的流程图,部署工作流
这种方式部署工作流,需要自己创建(new)流程图的每个节点,每一条线,每个网关等等,然后将这些对象关联,最后才能部署。这种方式部署比较麻烦,不太建议使用。
/**【6】使用动态创建的流程图,部署工作流*/
BpmnModel bpmnModel = new BpmnModel();
Process process = new Process();
bpmnModel.addProcess(process);
Deployment deployBpmnModel = repositoryService.createDeployment()
.addBpmnModel("动态流程.bpmn20.xml", bpmnModel)
.deploy();