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 ...
随机推荐
- K8s+Docker 学习笔记系列
学前知识 你需要掌握 Linux 的常用命令.你可以通过Linux 教程 来学习相关命令. Docker应用场景 Web 应用的自动化打包和发布. 自动化测试和持续集成.发布. 在服务型环境中部署和调 ...
- VMware虚拟机中Ubuntu18.04无法连接网络的有效解决办法
对VMware虚拟机进行恢复默认网络设置 恢复虚拟网络默认设置(在断网状态下): 1)Ubuntu网络设置自动获取IP 依次单击[System Settings]–>[Network]–> ...
- Spring Boot 配置文件加载位置及优先级
内容摘自http://c.biancheng.net/spring_boot/config-order.html 说明如下: /myBoot:表示 JAR 包所在目录,目录名称自定义: /childD ...
- TCP idle timeout 和TCP Keepalive 比较和分析
TCP idle timeout 和TCP Keepalive 是两个独立的功能. TCP idle timeout TCP idle timeout 是系统TCP配置文件中的空闲超时设 ...
- Unidbgrid自动调整列宽
UniDBGrid1 -> ClientEvents -> ExtEvents [Ext.data.Store[store] ] add store.load fn: function s ...
- JsonResult向前端返回值,报错500
1,问题原因 因为返回信息为json对象,我在controller方法所在的入口类上,添加的注解是:@Controller 而@Controller是不适合返回json内容的 2,解决方法 方法一:不 ...
- 11.4 显示窗口(harib08d)11.5 小实验(hearib08e) 11.6 高速计数器(harib08f)
11.4 显示窗口(harib08d) 书P206 11.5 小实验(hearib08e) 书P208 11.6 高速计数器(harib08f) 书P209
- BL808:【M1s DOCK开发板】与LVGL 使用体验
前言 念春时已夏,恋冬雪已融. 总是感叹时光匆匆,便努力在在平凡中挣扎,在平庸中努力,在平淡中积累.奈何时代飞速发展,时间又被工作占用,外加生活中的诱惑又太多了,很多想学.想做.想超越的事,都被抛之一 ...
- 全网最详细中英文ChatGPT接口文档(一)开始使用ChatGPT——导言
目录 Introduction 导言 Overview 概述 Key concepts 关键概念 Prompts and completions 提示和完成 Tokens 标记/符号 Models 模 ...
- 刘勇智:一码通缺陷分析与架构设计方案丨声网开发者创业讲堂 Vol.02
本文内容源自「声网开发者创业讲堂 Vol.02」的演讲分享,分享讲师为 Thoughtworks 专家级咨询师刘勇智.大家可以点击此链接,观看视频回放以及下载讲师 PPT. 从去年年底到现在,随着疫情 ...