Springboot整合Flowable6.x導(dǎo)出bpmn20的步驟詳解
BPMN2.0(Business Process Model and Notation)是一套業(yè)務(wù)流程模型與符號(hào)建模標(biāo)準(zhǔn),以XML為載體,以符號(hào)可視化業(yè)務(wù),支持精準(zhǔn)的執(zhí)行語(yǔ)義來(lái)描述元素的操作。
Flowable誕生于Activiti,是一個(gè)使用Java編寫的輕量級(jí)業(yè)務(wù)流程引擎。Flowable流程引擎可用于部署B(yǎng)PMN 2.0流程定義,可以十分靈活地加入你的應(yīng)用/服務(wù)/構(gòu)架。
本文給出兩種從flowable導(dǎo)出流程定義bpmn20.xml的方式。
導(dǎo)入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>從流程模型導(dǎo)出流程定義bpmn20.xml
通過(guò)流程編輯器制作的流程模型(如下圖所示), 可以通過(guò)模型ID(Model.id),調(diào)用flowable 的 RepositoryService 來(lái)生成bpmn20.xml。
@Service
public class MyModelServiceImpl implements MyModelService {
@Autowired
private RepositoryService repositoryService;
/**
* 通過(guò)模型ID,生成模型BPMN20.xml
* @param guid 模型id,即model.id
* @return
* @throws Exception
*/
@Override
public ResultDTO genXml(String guid) throws Exception {
/**通過(guò)ID獲取模型 **/
Model modelData = repositoryService.getModel(guid);
byte[] bytes = repositoryService.getModelEditorSource(modelData.getId());
if (bytes == null) {
return ResultDTO.failureCustom("模型數(shù)據(jù)為空,請(qǐng)先設(shè)計(jì)流程并成功保存,再進(jìn)行發(fā)布。");
}
JsonNode modelNode = new ObjectMapper().readTree(bytes);
BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode);
if (model.getProcesses().size() == 0) {
return ResultDTO.failureCustom("數(shù)據(jù)模型不符要求,請(qǐng)至少設(shè)計(jì)一條主線流程。");
}
/** 設(shè)置名稱 **/
model.getMainProcess().setName(modelData.getName());
/** 設(shè)置 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);
}
}
運(yùn)行效果如下:
{% asset_img res1.gif 導(dǎo)出效果 %}

從流程定義導(dǎo)出流程定義bpmn20.xml
對(duì)于flowable已經(jīng)部署的流程,可根據(jù)流程定義(ProcessDefinition.id),調(diào)用flowable 的RepositoryService來(lái)導(dǎo)出其bpmn20.xml。
@RestController
@Slf4j
public class ProcessController {
@Autowired
private MyProcessService processService;
/**
* 通過(guò)processDefinition.id和resType導(dǎo)出流程XML或圖片資源
* @param id processDefinition.id
* @param resType 取值 “image/png”或“text/xml”
* @param response
* @throws Exception
*/
@GetMapping(value = "/res/exp")
@ApiOperation("通過(guò)processDefinition.id和resType導(dǎo)出流程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;
}
}運(yùn)行效果如下:

到此這篇關(guān)于Springboot整合Flowable6.x導(dǎo)出bpmn20的文章就介紹到這了,更多相關(guān)Springboot整合Flowable內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
spring @Validated 注解開發(fā)中使用group分組校驗(yàn)的實(shí)現(xiàn)
這篇文章主要介紹了spring @Validated 注解開發(fā)中使用group分組校驗(yàn)的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05
使用?mybatis?自定義日期類型轉(zhuǎn)換器的示例代碼
這篇文章主要介紹了使用?mybatis?自定義日期類型轉(zhuǎn)換器的示例代碼,這里使用mybatis中的typeHandlers?實(shí)現(xiàn)的,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-03-03
JavaFX Metro UI 和 開發(fā)庫(kù)使用簡(jiǎn)介
這篇文章主要介紹了JavaFX Metro UI 和 開發(fā)庫(kù)解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08
springboot中不能獲取post請(qǐng)求參數(shù)的解決方法
這篇文章主要介紹了springboot中不能獲取post請(qǐng)求參數(shù)的解決方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06
java鎖機(jī)制ReentrantLock源碼實(shí)例分析
這篇文章主要為大家介紹了java鎖機(jī)制ReentrantLock源碼實(shí)例分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10
Java實(shí)現(xiàn)Kafka生產(chǎn)者消費(fèi)者代碼實(shí)例
這篇文章主要介紹了Java實(shí)現(xiàn)Kafka生產(chǎn)者消費(fèi)者代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-04-04
IntelliJ IDEA 2020.1.2激活工具下載及破解方法免費(fèi)可用至2089年(強(qiáng)烈推薦)
這篇文章主要介紹了IntelliJ IDEA 2020.1.2激活工具下載及破解方法免費(fèi)可用至2089年(強(qiáng)烈推薦),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-09-09
Java獲取本機(jī)IP地址的方法代碼示例(內(nèi)網(wǎng)、公網(wǎng))
在IT領(lǐng)域獲取本機(jī)IP地址是一項(xiàng)基礎(chǔ)但重要的任務(wù),特別是在網(wǎng)絡(luò)編程、遠(yuǎn)程協(xié)作和設(shè)備通信中,這篇文章主要給大家介紹了關(guān)于Java獲取本機(jī)IP地址的方法(內(nèi)網(wǎng)、公網(wǎng)),需要的朋友可以參考下2024-07-07

