Java获取camunda的bpmn文件中的扩展信息

    @GetMapping("/bpmn/getExtensionElementsText")
    public ResponseData getExtensionElementsText(BpmnModelParam bpmnModelParam){
        InputStream processModel = ProcessEngines
                .getDefaultProcessEngine()
                .getRepositoryService()
                .getProcessModel("Process_0uz4e7e:11:30b89d94-236f-11ec-82fb-861b7790c7c0");
        BpmnModelInstance bpmnModelInstance = Bpmn.readModelFromStream(processModel);
        // 通过id获取元素
//        StartEvent startEvent = (StartEvent) bpmnModelInstance.getModelElementById("StartEvent_1");


        // 通过任务类型查找
//        ModelElementType type = bpmnModelInstance.getModel().getType(StartEvent.class);
//        Collection<ModelElementInstance> taskInstances = bpmnModelInstance.getModelElementsByType(type);

        /**
         *  通过类型查找开始节点
         */
        System.out.println("=================获取全局扩展配置信息========================");
        Collection<Process> processCollection = bpmnModelInstance.getModelElementsByType(Process.class);
        for (Process process: processCollection) {
            ExtensionElements extensionElements = process.getExtensionElements();
            Collection<CamundaProperty> properties = extensionElements.getElementsQuery()
                    .filterByType(CamundaProperties.class)
                    .singleResult()
                    .getCamundaProperties();
            for (CamundaProperty property : properties) {
                String name = property.getCamundaName();
                System.out.println("process:"+name);
                String value = property.getCamundaValue();
                System.out.println("process:"+value);
            }
        }

        System.out.println("=================获取开始节点配置信息========================");
        Collection<StartEvent> startEventCollection = bpmnModelInstance.getModelElementsByType(StartEvent.class);
        for (StartEvent startEvent: startEventCollection) {
            ExtensionElements extensionElements = startEvent.getExtensionElements();
            Collection<CamundaProperty> properties = extensionElements.getElementsQuery()
                    .filterByType(CamundaProperties.class)
                    .singleResult()
                    .getCamundaProperties();
            for (CamundaProperty property : properties) {
                String name = property.getCamundaName();
                System.out.println(name);
                String value = property.getCamundaValue();
                System.out.println(value);
            }
        }
        System.out.println("================获取所有扩展信息=========================");
        Collection<ExtensionElements> extensionElementsCollection = bpmnModelInstance.getModelElementsByType(ExtensionElements.class);
        for (ExtensionElements extensionElements: extensionElementsCollection) {
            Collection<CamundaProperty> properties = extensionElements.getElementsQuery()
                    .filterByType(CamundaProperties.class)
                    .singleResult()
                    .getCamundaProperties();
            for (CamundaProperty property : properties) {
                String name = property.getCamundaName();
                System.out.println(name);
                String value = property.getCamundaValue();
                System.out.println(value);
            }
        }
        System.out.println("================任务节点=========================");
        Task task = ProcessEngines
                .getDefaultProcessEngine()
                .getTaskService()
                .createTaskQuery()
                .taskId("926e98fb-239a-11ec-876c-861b7790c7c0").singleResult();
        String taskDefinitionKey = task.getTaskDefinitionKey();
        System.out.println(taskDefinitionKey);
        UserTask userTask = (UserTask) bpmnModelInstance.getModelElementById(taskDefinitionKey);
        ExtensionElements extensionElements = userTask.getExtensionElements();
        Collection<CamundaProperty> properties = extensionElements.getElementsQuery()
                .filterByType(CamundaProperties.class)
                .singleResult()
                .getCamundaProperties();
        for (CamundaProperty property : properties) {
            String name = property.getCamundaName();
            System.out.println(name);
            String value = property.getCamundaValue();
            System.out.println(value);
        }


//        StartEvent startEvent = bpmnModelInstance.newInstance(StartEvent.class);

//        ExtensionElements extensionElements = startEvent.getExtensionElements();
//
//        Collection<CamundaProperty> properties = extensionElements.getElementsQuery()
//                .filterByType(CamundaProperties.class)
//                .singleResult()
//                .getCamundaProperties();
//
//        for (CamundaProperty property : properties) {
//            String name = property.getCamundaName();
//            System.out.println(name);
//            String value = property.getCamundaValue();
//            System.out.println(value);
//        }

        return new SuccessResponseData();
    }

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

<每天一点>

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值