activiti 通过xml上传 直接部署模型

通过流程xml 直接先发布模型,然后再通过发布模型之后的流程定义获取bpmn model来创建Model.

1、通过xml先发布模型

bash 复制代码
InputStream bpmnStream = multipartFile.getInputStream()
deployment = repositoryService.createDeployment()
                    .addInputStream(multipartFile.getOriginalFilename(), bpmnStream).deploy();
            List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery()
                    .deploymentId(deployment.getId()).list();
            String processDefinitionId = list.get(0).getId();
            convertToModel(processDefinitionId);

2. 发布之后 通过流程定义获取bpmn model新建model

注意这里的addModelEditorSource addModelEditorSourceExtra获取。

bash 复制代码
 Model modelData = repositoryService.newModel();
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
                .processDefinitionId(processDefinitionId).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();
        com.fasterxml.jackson.databind.node.ObjectNode modelNode = converter.convertToJson(bpmnModel);
        modelData.setKey(processDefinition.getKey());
        modelData.setName(processDefinition.getKey());
        ObjectNode modelObjectNode = objectMapper.createObjectNode();
        modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, processDefinition.getResourceName());
        modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);// 版本
        modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION,processDefinition.getResourceName());
        modelData.setMetaInfo(modelObjectNode.toString());
        repositoryService.saveModel(modelData);
        DefaultProcessDiagramGenerator generator = new DefaultProcessDiagramGenerator();
        generator.generateDiagram(bpmnModel,  new ArrayList<>());
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        IoUtil.copy(bpmnStream, bos);
        byte[] bytes = bos.toByteArray();
        repositoryService.addModelEditorSource(modelData.getId(), modelNode.toString().getBytes("utf-8"));
        repositoryService.addModelEditorSourceExtra(
                modelData.getId(), bytes);
        deploy(modelData.getId());
相关推荐
乌夷3 天前
在pom.xml中通过repositories在Maven构建过程中访问setting.xml之外的仓库
xml·java·maven
振宇i3 天前
Mybatis xml动态SQL 判断失效问题
xml·sql·mybatis
程序员老王wd6 天前
java xml 文本解析
xml·java
小百菜7 天前
dom4j解析含有命名空间的XML
xml·dom4j
黎明晓月7 天前
MyBatis XML一个方法执行插入或更新操做(PostgreSQL)
xml·postgresql·mybatis
GoKu~7 天前
项目配置文件选择(Json,xml,Yaml, INI)
xml·json
枫叶落雨2227 天前
mybatis-plus: mapper-locations: “classpath*:/mapper/**/*.xml“配置!!!解释
xml·java·mybatis
double丶flower7 天前
mybatis在mapper.xml中怎么处理大于、小于、不等于号
xml·java·mybatis
一只爱打拳的程序猿7 天前
pom.xml和spring-config.xml
xml·java·spring
tonysh_zds7 天前
freemarker 读取template.xml ,通过response 输出文件,解决中文乱码问题
xml·java·开发语言