Springboot整合Flowable6.x导出bpmn20
BPMN2.0(Business Process Model and Notation)是一套业务流程模型与符号建模标准,以XML为载体,以符号可视化业务,支持精准的执行语义来描述元素的操作。
Flowable诞生于Activiti,是一个使用Java编写的轻量级业务流程引擎。Flowable流程引擎可用于部署BPMN 2.0流程定义,可以十分灵活地加入你的应用/服务/构架。
本文给出两种从flowable导出流程定义bpmn20.xml的方式。
导入Maven依赖
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter-basic</artifactId>
<version>6.4.1</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-json-converter</artifactId>
<version>6.4.1</version>
</dependency>
从流程模型导出流程定义bpmn20.xml
通过流程编辑器制作的流程模型(如下图所示), 可以通过模型ID(Model.id),调用flowable 的 RepositoryService 来生成bpmn20.xml。
@Service
public class MyModelServiceImpl implements MyModelService {
@Autowired
private RepositoryService repositoryService;
/**
* 通过模型ID,生成模型BPMN20.xml
* @param guid 模型id,即model.id
* @return
* @throws Exception
*/
@Override
public ResultDTO genXml(String guid) throws Exception {
/**通过ID获取模型 **/
Model modelData = repositoryService.getModel(guid);
byte[] bytes = repositoryService.getModelEditorSource(modelData.getId());
if (bytes == null) {
return ResultDTO.failureCustom("模型数据为空,请先设计流程并成功保存,再进行发布。");
}
JsonNode modelNode = new ObjectMapper().readTree(bytes);
BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode);
if (model.getProcesses().size() == 0) {
return ResultDTO.failureCustom("数据模型不符要求,请至少设计一条主线流程。");
}
/** 设置名称 **/
model.getMainProcess().setName(modelData.getName());
/** 设置 targetNamespace **/
if(StringUtils.isNotBlank(modelData.getCategory())) {
model.setTargetNamespace(modelData.getCategory());
}
byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(model);
String xml = new String(bpmnBytes, "UTF-8");
return ResultDTO.success(xml);
}
}
运行效果如下:
{% asset_img res1.gif 导出效果 %}

从流程定义导出流程定义bpmn20.xml
对于flowable已经部署的流程,可根据流程定义(ProcessDefinition.id),调用flowable 的RepositoryService来导出其bpmn20.xml。
@RestController
@Slf4j
public class ProcessController {
@Autowired
private MyProcessService processService;
/**
* 通过processDefinition.id和resType导出流程XML或图片资源
* @param id processDefinition.id
* @param resType 取值 “image/png”或“text/xml”
* @param response
* @throws Exception
*/
@GetMapping(value = "/res/exp")
@ApiOperation("通过processDefinition.id和resType导出流程XML或图片资源")
public void resourceRead(@RequestParam("id") String id,@RequestParam("resType") String resType, HttpServletResponse response) throws Exception {
/** resType取值 “image/png”或“text/xml” **/
InputStream resourceAsStream = processService.resourceRead(id,resType);
byte[] b = new byte[1024];
int len = -1;
while ((len = resourceAsStream.read(b, 0, 1024)) != -1) {
response.getOutputStream().write(b, 0, len);
}
}
}
@Service
public class MyProcessServiceImpl implements MyProcessService {
@Autowired
private RepositoryService repositoryService;
@Override
public InputStream resourceRead(String id, String resType) throws Exception {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(id).singleResult();
String resourceName = "";
if (resType.equals("image/png")) {
resourceName = processDefinition.getDiagramResourceName();
} else if (resType.equals("text/xml")) {
resourceName = processDefinition.getResourceName();
}
InputStream resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName);
return resourceAsStream;
}
}
运行效果如下:

Springboot整合Flowable6.x导出bpmn20的更多相关文章
- springboot整合elasticsearch(基于es7.2和官方high level client)
前言 最近写的一个个人项目(传送门:全终端云书签)中需要用到全文检索功能,目前 mysql,es 都可以做全文检索,mysql 胜在配置方便很快就能搞定上线(参考这里),不考虑上手难度,es 在全文检 ...
- SpringBoot 整合 MyCat 实现读写分离
MyCat一个彻底开源的,面向企业应用开发的大数据库集群.基于阿里开源的Cobar产品而研发.能满足数据库数据大量存储:提高了查询性能.文章介绍如何实现MyCat连接MySQL实现主从分离,并集成Sp ...
- Https双向验证与Springboot整合测试-人来人往我只认你
1 简介 不知不觉Https相关的文章已经写了6篇了,本文将是这个专题的最后一篇,起码近期是最后一篇.前面6篇讲的全都是单向的Https验证,本文将重点介绍一下双向验证.有兴趣的同学可以了解一下之前的 ...
- springboot整合xxl-job分布式定时任务【图文完整版】
一.前言 定时任务有很多种,有一些大的框架也有一些简单的实现. 比如常见的: JDK的Timer和TimerTask Quartz异步任务调度框架 分布式定时任务XXL-JOB Spring Task ...
- spring-boot整合mybatis(1)
sprig-boot是一个微服务架构,加快了spring工程快速开发,以及简便了配置.接下来开始spring-boot与mybatis的整合. 1.创建一个maven工程命名为spring-boot- ...
- SpringBoot整合Mybatis之项目结构、数据源
已经有好些日子没有总结了,不是变懒了,而是我一直在奋力学习springboot的路上,现在也算是完成了第一阶段的学习,今天给各位总结总结. 之前在网上找过不少关于springboot的教程,都是一些比 ...
- springboot整合mq接收消息队列
继上篇springboot整合mq发送消息队列 本篇主要在上篇基础上进行activiemq消息队列的接收springboot整合mq发送消息队列 第一步:新建marven项目,配置pom文件 < ...
- springboot整合mybaits注解开发
springboot整合mybaits注解开发时,返回json或者map对象时,如果一个字段的value为空,需要更改springboot的配置文件 mybatis: configuration: c ...
- SpringBoot整合Redis、ApachSolr和SpringSession
SpringBoot整合Redis.ApachSolr和SpringSession 一.简介 SpringBoot自从问世以来,以其方便的配置受到了广大开发者的青睐.它提供了各种starter简化很多 ...
- SpringBoot整合ElasticSearch实现多版本的兼容
前言 在上一篇学习SpringBoot中,整合了Mybatis.Druid和PageHelper并实现了多数据源的操作.本篇主要是介绍和使用目前最火的搜索引擎ElastiSearch,并和Spring ...
随机推荐
- 服务器安装node
卸载步骤[未安装请忽略] 1.卸载npm sudo npm uninstall npm -g 2.卸载node yum remove nodejs npm -y 安装步骤 1.下载 wget http ...
- 负数位运算的右移操作-C语言基础
这一篇探讨的是"负数位运算的右移操作",涉及到数据的源码.反码.补码的转换操作.属于C语言基础篇. 先看例子 #include <stdio.h> int main(v ...
- tensorflow出现Failed to get convolution algorithm, cuDNN failed to initialize
网上大多的教程是说tensorflow的版本过高,或者说cuda和cudnn的版本不对,需要降级,但这样会很麻烦!!! 以下值得推荐!!! 解决方法一:在代码前加上下面的代码 from tensorf ...
- 使用 ww.cad 完成dwg文件转shp(包含所有属性)
单纯使用ArcEngine提供的接口读取dwg数据转shp存在众多属性无法读取的情况(最直观的 南方cass生产的dwg文件有SOUTH这一字段,为目标要素的类型) private void Conv ...
- POI给单元格添加超链接(xls,xlsx)
package com.topcheer.html; import java.io.FileOutputStream; import java.io.IOException; import org.a ...
- EL表达式 总结
EL表达式,全称是Expression Language.意为表达式语言.它是Servlet规范中的一部分,是JSP2.0规范加入的内容.其作用是用于在JSP页面中获取数据,从而让我们的JSP脱离ja ...
- sap shift语法
shift xxx LEFT DELETING LEADING / RIGHT DELETING TRAILING mask 语法. xxx中的第一或最后一个字符出现在mask中,则xxx左移或者右 ...
- Matlab笔记--Matlab基础
Matlab基础 数据类型(共有15种数据类型) 整数 取整函数 浮点数(单精度浮点数和双精度浮点数--默认为双精度浮点数) 复数 数据的显示格式(format确定数据的显示格式): 数据格式经过改变 ...
- AC自动机模板题 HDU - 2222
Keywords Search HDU - 2222 贴个vj的链接https://vjudge.net/problem/HDU-2222 题意:T组数据,n个单词,再给你一个串,看有几个单词在这个 ...
- InstructPix2Pix: 动动嘴皮子,超越PS
摘要:InstructPix2Pix提出了一种使用文本编辑图像的方法:给定输入图像和编辑指令,告诉模型要做什么,模型将遵循这些指令来编辑图像. 本文分享自华为云社区<InstructPix2Pi ...