Flowable增加流程转模型功能,现在导入的流程无法转为模型进行编辑
@Override
public FlowModel convertToModel(String processId) throws UnsupportedEncodingException, XMLStreamException {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processId).singleResult();
InputStream bpmnStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(),
processDefinition.getResourceName());
XMLInputFactory xif = XMLInputFactory.newInstance();
InputStreamReader in = new InputStreamReader(bpmnStream, "UTF-8");
XMLStreamReader xtr = xif.createXMLStreamReader(in);
BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
BpmnJsonConverter converter = new BpmnJsonConverter();
ObjectNode modelNode = converter.convertToJson(bpmnModel);
FlowModel modelData = new FlowModel();
modelData.setModelKey(processDefinition.getKey());
modelData.setName(processDefinition.getName());
modelData.setVersion(Integer.parseInt(String.valueOf(repositoryService.createModelQuery().modelKey(processId).count()+1)));
modelData.setModelType(1);
modelData.setCreated(org.flowable.dmn.engine.impl.el.util.DateUtil.now());
modelData.setLastUpdated(org.flowable.dmn.engine.impl.el.util.DateUtil.now());
modelData.setCreatedBy("admin");
modelData.setLastUpdatedBy("admin");
modelData.setModelEditorJson(modelNode.toString());
modelData.setTenantId("0000");
modelData.setThumbnail(modelNode.toString().getBytes("utf-8"));
modelData.setId(UUID.randomUUID().toString());
save(modelData);
return modelData;
}
按上述代码实现模型转换,仅供参考。
扫一扫访问 Blade技术社区 移动端