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 ...
随机推荐
- IT工具知识-14:如何通过adb操作安卓剪切板?
1.安装apk 下载地址 2.运行服务(每次重启系统都需要运行一次) adb shell am startservice ca.zgrs.clipper/.ClipboardService 3.设置剪 ...
- Q:oracle 日期筛选
一.oracle where条件日期筛选 两种方法:tochar和todate todate:将字符串按照指定的格式输出,得到的是日期类型. to_date('2019-12-01','yyyy-MM ...
- Edge 访问网站强制HTTPS
edge://net-internals/#hsts 1)開啟Edge chromium 瀏覽器,輸入edge://net-internals/#hsts,開啟設定介面2)找到 Delete doma ...
- mysql驱动下载
下载地址:https://dev.mysql.com/downloads/connector/j/ 下载步骤:Select Operating System: Platform Independent
- python&C++区别
1.类的定义 struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), ne ...
- vs2022和wsl2开发和调试c++代码(转载)
看见一个不错的帖子(知乎) https://zhuanlan.zhihu.com/p/390757559 里面最主要就是要保证wsl里面安装的东西够了,第二就是vs2022已经安装了linux的相关模 ...
- Qt打包win应用的流程(转载)
基本就是命令:windeployqt 目标文件.exe 一定要新开一个文件夹再执行这个命令. 参考网站: https://blog.csdn.net/weixin_39504048/article/ ...
- Docker安装:Centos7.6安装Docker
Docker03:Centos7.6安装Docker 前提条件 内核版本 更新yum 包 卸载旧版本(如果安装过旧版本的话) 安装依赖包 设置yum源(阿里云源) 更新缓存 安装容器 启动并加入开机启 ...
- [rk3568][common] 环境搭建
1. 安装依赖 sudo apt-get install uuid uuid-dev zlib1g-dev liblz-dev liblzo2-2 liblzo2-dev lzop \ git-cor ...
- FPGA实现国密算法SM4
本文基于FPGA实现高速SM4加密与解密,提供开源Verilog RTL设计和可综合工程:https://github.com/cassuto/SM4-FPGA. 本文仅讨论实现细节,不涉及算法原理. ...