使用java代码修改流程文件id

思路:     将文件解析为xml格式

                使用hutool工具类修改id

                将xml文件合并为bpmn流程文件,上传流程文件

String path = sysFile.getRelativePath();
        log.debug("获取文件下载路径====: {}", path);
        InputStream downloadInputStream = fileUpload.getDownloadInputStream(path, null);
        ByteArrayOutputStream output = cloneInputStream(downloadInputStream);
        BpmnModel bpmnModel = ProcessUtil.convertToBpmnModel(new ByteArrayInputStream(output.toByteArray()));
        //获取文件转化为xml
        BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();
        byte[] convertToXML = bpmnXMLConverter.convertToXML(bpmnModel);
        String xmlData = new String(convertToXML);
        log.info("该流程的流程xml为:{}", xmlData);
        //读取xml文件
        Document document = XmlUtil.parseXml(xmlData);
        Element rootElement = XmlUtil.getRootElement(document);

        Element process = XmlUtil.getElement(rootElement, "process");
        String timeD = "a"+new Date().getTime();
        process.setAttribute("id",timeD);

        Element bpmndiB = XmlUtil.getElement(rootElement, "bpmndi:BPMNDiagram");
        bpmndiB.setAttribute("id","BPMNDiagram_"+timeD);
        Element bpmndiP = XmlUtil.getElement(bpmndiB,"bpmndi:BPMNPlane");
        bpmndiP.setAttribute("bpmnElement",timeD);
        bpmndiP.setAttribute("id","BPMNPlane_"+timeD);


        String formatNew = XmlUtil.format(document);

        log.info("formatNew"+formatNew);

        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(formatNew.getBytes(StandardCharsets.UTF_8));
@Override
    @Transactional(rollbackFor = Exception.class)
    public HbpmsDeploymentOut uploadBpmn(InputStream ins, Boolean loadPreConfig) {
        ByteArrayOutputStream output = cloneInputStream(ins);
        if (output == null) {
            throw new BadArgumentException("导入流程定义文件失败,请检查文件内容是否正确!");
        }
        BpmnModel bpmnModel = ProcessUtil.convertToBpmnModel(new ByteArrayInputStream(output.toByteArray()));
        String defKey = bpmnModel.getMainProcess().getId();
        //为了防止导入的时候乱上传,需要对导入的文件进行校验
        HbpmsProcdefBase defBase = hbpmsDefBaseService.get(defKey);
        if (defBase == null) {
            throw new BadArgumentException("导入流程定义[ " + defKey + " ]不存在,请先完善流程的基础配置信息");
        }
        /*ProcessDefinition preDefinition = null;
        if (BooleanUtils.isTrue(loadPreConfig)) {
            preDefinition = hbpmsConfiguration.getRepositoryService()
                    .createProcessDefinitionQuery()
                    .processDefinitionKey(defKey)
                    .latestVersion()
                    .singleResult();
        }*/

        HbpmsDeploymentInputStream deploymentIns = new HbpmsDeploymentInputStream();
        deploymentIns.setInputStream(new ByteArrayInputStream(output.toByteArray()));
        deploymentIns.setValidateBomIs(new ByteArrayInputStream(output.toByteArray()));
        //  添加默认标签,否则查询不到
        List<Label> labels = new ArrayList<>(ONE);
        Label label = new Label();
        label.setLabelKey(BaseBizHandler.BIZ_NAME);
        label.setLabelValue(defBase.getBizType());
        labels.add(label);
        deploymentIns.setLabels(labels);

        // 部署
        HbpmsDeploymentOut deploy = hbpmsDeploymentService.deploy(deploymentIns);
        deploy.setKey(defKey);
        return deploy;

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值