首页 > 解决方案 > 为什么在没有它的情况下使用 org.activiti.bpmn.BpmnAutoLayout 为我的 bpmn 文件生成 DI 信息时会出现 NullPointerException?

问题描述

请问maven依赖activiti-bpmn-layout中使用BpmnAutoLayout类的问题?

我使用 activiti-bpmn-model api 以编程方式创建了一个没有 DI 信息的 XML 格式 .bpmn 文件 (bpmnWithoutDI.bpmn)。我想使用 BpmnAutoLayout 类为我的 bpmnWithoutDI.bpmn xml 文件自动生成 DI 信息。但是当我运行我的程序时,我得到了以下异常:

异常信息

谁能告诉我如何解决这个问题?

您可以从以下 URL 下载我的源代码:

https://drive.google.com/file/d/1V9LUZLLZ1c-3JWzcSqDyM7IyywKB7Bvj/view?usp=sharing

它是一个 Eclipse maven 项目的 zip 文件,其中包含我的 java 源代码和输入文件 bpmnWithoutDI.bpmn 。您可以简单地导入 maven 项目并运行 AutoLayoutDemo.java 来重现异常。

我还包括下面的代码:

AutoLayoutDemo.java

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

import org.activiti.bpmn.BpmnAutoLayout;
import org.activiti.bpmn.converter.BpmnXMLConverter;
import org.activiti.bpmn.model.BpmnModel;


public class AutoLayoutDemo {

    private BpmnModel convertXmlFileWithoutDIToBpmnModel(String fileName) throws FileNotFoundException, UnsupportedEncodingException, XMLStreamException {
        InputStream xmlStream = new FileInputStream(new File(fileName));
        XMLInputFactory xif = XMLInputFactory.newInstance();
        InputStreamReader in = new InputStreamReader(xmlStream, "UTF-8");
        XMLStreamReader xtr = xif.createXMLStreamReader(in);
        return new BpmnXMLConverter().convertToBpmnModel(xtr);
    }

    private void autoLayoutBpmnModel(BpmnModel model) {
        BpmnAutoLayout autoLayout = new BpmnAutoLayout(model);
        autoLayout.execute();
    }

    private void generateXmlFileWithDI(BpmnModel model, String fileName) {
        File file = new File(fileName);



        try (FileOutputStream fos = new FileOutputStream(file)) {

            if (!file.exists()) {
                file.createNewFile();
            }
            byte[] byteArray = new BpmnXMLConverter().convertToXML(model);
            fos.write(byteArray);
            fos.flush();
            fos.close();

            System.out.println("Done");

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException, XMLStreamException {
        AutoLayoutDemo demo = new AutoLayoutDemo();
        BpmnModel model = demo.convertXmlFileWithoutDIToBpmnModel("bpmnWithoutDI.bpmn");
        demo.autoLayoutBpmnModel(model);
        demo.generateXmlFileWithDI(model, "bpmnWithDI.bpmn");
    }

}

bpmnWithoutDI.bpmn

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="process_dispute_extractor" name="dispute_extractor" isExecutable="true">
    <subProcess id="process_dispute_extractor-extract_urls" name="STEP extract_urls: This step opens the AVC portal and gathers all the unresolved chargeback urls">
      <startEvent id="process_dispute_extractor-extract_urls-start" name="start"></startEvent>
      <endEvent id="process_dispute_extractor-extract_urls-end" name="end"></endEvent>
      <exclusiveGateway id="process_dispute_extractor-extract_urls-0"></exclusiveGateway>
      <subProcess id="process_dispute_extractor-extract_urls-1" name="get the chargeback id">
        <startEvent id="process_dispute_extractor-extract_urls-1-0" name="Start"></startEvent>
        <exclusiveGateway id="process_dispute_extractor-extract_urls-1-1"></exclusiveGateway>
        <exclusiveGateway id="process_dispute_extractor-extract_urls-1-2"></exclusiveGateway>
        <serviceTask id="process_dispute_extractor-extract_urls-1-3" name="add to the list of urls to process" activiti:delegateExpression="process_dispute_extractor-extract_urls-1-3implementation"></serviceTask>
        <endEvent id="process_dispute_extractor-extract_urls-1-4" name="End"></endEvent>
      </subProcess>
      <exclusiveGateway id="process_dispute_extractor-extract_urls-2"></exclusiveGateway>
      <subProcess id="process_dispute_extractor-extract_urls-3" name="Send 150 urls to image analyzer process module">
        <startEvent id="process_dispute_extractor-extract_urls-3-0" name="Start"></startEvent>
        <serviceTask id="process_dispute_extractor-extract_urls-3-1" name="JUMP TO image_analyzer" activiti:delegateExpression="process_dispute_extractor-extract_urls-3-1implementation"></serviceTask>
        <endEvent id="process_dispute_extractor-extract_urls-3-2" name="End"></endEvent>
      </subProcess>
    </subProcess>
    <sequenceFlow id="process_dispute_extractor-extract_urls-1-1--process_dispute_extractor-extract_urls-1-2" name="Else" sourceRef="process_dispute_extractor-extract_urls-1-1" targetRef="process_dispute_extractor-extract_urls-1-2"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-1-1--process_dispute_extractor-extract_urls-1-3" name="If the id hasn't been processed" sourceRef="process_dispute_extractor-extract_urls-1-1" targetRef="process_dispute_extractor-extract_urls-1-3"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-1-3--process_dispute_extractor-extract_urls-1-2" sourceRef="process_dispute_extractor-extract_urls-1-3" targetRef="process_dispute_extractor-extract_urls-1-2"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-1-0--process_dispute_extractor-extract_urls-1-1" sourceRef="process_dispute_extractor-extract_urls-1-0" targetRef="process_dispute_extractor-extract_urls-1-1"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-1-2--process_dispute_extractor-extract_urls-1-4" sourceRef="process_dispute_extractor-extract_urls-1-2" targetRef="process_dispute_extractor-extract_urls-1-4"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-0--process_dispute_extractor-extract_urls-1" name="For each url" sourceRef="process_dispute_extractor-extract_urls-0" targetRef="process_dispute_extractor-extract_urls-1"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-1--process_dispute_extractor-extract_urls-0" sourceRef="process_dispute_extractor-extract_urls-1" targetRef="process_dispute_extractor-extract_urls-0"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-3-0--process_dispute_extractor-extract_urls-3-1" sourceRef="process_dispute_extractor-extract_urls-3-0" targetRef="process_dispute_extractor-extract_urls-3-1"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-3-1--process_dispute_extractor-extract_urls-3-2" sourceRef="process_dispute_extractor-extract_urls-3-1" targetRef="process_dispute_extractor-extract_urls-3-2"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-2--process_dispute_extractor-extract_urls-3" name="For each time" sourceRef="process_dispute_extractor-extract_urls-2" targetRef="process_dispute_extractor-extract_urls-3"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-3--process_dispute_extractor-extract_urls-2" sourceRef="process_dispute_extractor-extract_urls-3" targetRef="process_dispute_extractor-extract_urls-2"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-0--process_dispute_extractor-extract_urls-2" name="Loop over" sourceRef="process_dispute_extractor-extract_urls-0" targetRef="process_dispute_extractor-extract_urls-2"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-start--process_dispute_extractor-extract_urls-0" sourceRef="process_dispute_extractor-extract_urls-start" targetRef="process_dispute_extractor-extract_urls-0"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls-2--process_dispute_extractor-extract_urls-end" sourceRef="process_dispute_extractor-extract_urls-2" targetRef="process_dispute_extractor-extract_urls-end"></sequenceFlow>
    <startEvent id="process_dispute_extractor-start" name="Start"></startEvent>
    <endEvent id="process_dispute_extractor-end" name="End"></endEvent>
    <sequenceFlow id="process_dispute_extractor-start--process_dispute_extractor-extract_urls" sourceRef="process_dispute_extractor-start" targetRef="process_dispute_extractor-extract_urls"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls--process_dispute_extractor-end" sourceRef="process_dispute_extractor-extract_urls" targetRef="process_dispute_extractor-end"></sequenceFlow>
  </process>
</definitions>

谢谢!

标签: javaxmlactivitibpmn

解决方案


您正确的 bpmn 文件如下,我已经更改并测试了它,希望对您有所帮助。

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="process_dispute_extractor" name="dispute_extractor" isExecutable="true">
    <subProcess id="process_dispute_extractor-extract_urls" name="STEP extract_urls: This step opens the AVC portal and gathers all the unresolved chargeback urls">
      <startEvent id="process_dispute_extractor-extract_urls-start" name="start"></startEvent>
      <endEvent id="process_dispute_extractor-extract_urls-end" name="end"></endEvent>
      <exclusiveGateway id="process_dispute_extractor-extract_urls-0"></exclusiveGateway>
      <subProcess id="process_dispute_extractor-extract_urls-1" name="get the chargeback id">
        <startEvent id="process_dispute_extractor-extract_urls-1-0" name="Start"></startEvent>
        <exclusiveGateway id="process_dispute_extractor-extract_urls-1-1"></exclusiveGateway>
        <exclusiveGateway id="process_dispute_extractor-extract_urls-1-2"></exclusiveGateway>
        <serviceTask id="process_dispute_extractor-extract_urls-1-3" name="add to the list of urls to process" activiti:delegateExpression="process_dispute_extractor-extract_urls-1-3implementation"></serviceTask>
        <endEvent id="process_dispute_extractor-extract_urls-1-4" name="End"></endEvent>
        <sequenceFlow id="xprocess_dispute_extractor-extract_urls-1-2" sourceRef="process_dispute_extractor-extract_urls-1-1" targetRef="process_dispute_extractor-extract_urls-1-2"></sequenceFlow>
        <sequenceFlow id="process_dispute_extractor-extract_urls-1-1--process_dispute_extractor-extract_urls-1-3" name="If the id hasn't been processed" sourceRef="process_dispute_extractor-extract_urls-1-1" targetRef="process_dispute_extractor-extract_urls-1-3"></sequenceFlow>
        <sequenceFlow id="process_dispute_extractor-extract_urls-1-3--process_dispute_extractor-extract_urls-1-2" sourceRef="process_dispute_extractor-extract_urls-1-3" targetRef="process_dispute_extractor-extract_urls-1-2"></sequenceFlow>     
        <sequenceFlow id="process_dispute_extractor-extract_urls-1-0--process_dispute_extractor-extract_urls-1-1" sourceRef="process_dispute_extractor-extract_urls-1-0" targetRef="process_dispute_extractor-extract_urls-1-1"></sequenceFlow>     
        <sequenceFlow id="process_dispute_extractor-extract_urls-1-2--process_dispute_extractor-extract_urls-1-4" sourceRef="process_dispute_extractor-extract_urls-1-2" targetRef="process_dispute_extractor-extract_urls-1-4"></sequenceFlow>     
      </subProcess>
      <exclusiveGateway id="process_dispute_extractor-extract_urls-2"></exclusiveGateway>
      <sequenceFlow id="process_dispute_extractor-extract_urls-2--process_dispute_extractor-extract_urls-3" name="For each time" sourceRef="process_dispute_extractor-extract_urls-2" targetRef="process_dispute_extractor-extract_urls-3"></sequenceFlow>
      <sequenceFlow id="process_dispute_extractor-extract_urls-3--process_dispute_extractor-extract_urls-2" sourceRef="process_dispute_extractor-extract_urls-3" targetRef="process_dispute_extractor-extract_urls-2"></sequenceFlow>
      <sequenceFlow id="process_dispute_extractor-extract_urls-0--process_dispute_extractor-extract_urls-2" name="Loop over" sourceRef="process_dispute_extractor-extract_urls-0" targetRef="process_dispute_extractor-extract_urls-2"></sequenceFlow>
      <sequenceFlow id="process_dispute_extractor-extract_urls-start--process_dispute_extractor-extract_urls-0" sourceRef="process_dispute_extractor-extract_urls-start" targetRef="process_dispute_extractor-extract_urls-0"></sequenceFlow>
      <sequenceFlow id="process_dispute_extractor-extract_urls-2--process_dispute_extractor-extract_urls-end" sourceRef="process_dispute_extractor-extract_urls-2" targetRef="process_dispute_extractor-extract_urls-end"></sequenceFlow>     
      <subProcess id="process_dispute_extractor-extract_urls-3" name="Send 150 urls to image analyzer process module">
        <startEvent id="process_dispute_extractor-extract_urls-3-0" name="Start"></startEvent>
        <serviceTask id="process_dispute_extractor-extract_urls-3-1" name="JUMP TO image_analyzer" activiti:delegateExpression="process_dispute_extractor-extract_urls-3-1implementation"></serviceTask>
        <endEvent id="process_dispute_extractor-extract_urls-3-2" name="End"></endEvent>
        <sequenceFlow id="process_dispute_extractor-extract_urls-3-0--process_dispute_extractor-extract_urls-3-1" sourceRef="process_dispute_extractor-extract_urls-3-0" targetRef="process_dispute_extractor-extract_urls-3-1"></sequenceFlow>
        <sequenceFlow id="process_dispute_extractor-extract_urls-3-1--process_dispute_extractor-extract_urls-3-2" sourceRef="process_dispute_extractor-extract_urls-3-1" targetRef="process_dispute_extractor-extract_urls-3-2"></sequenceFlow>
      </subProcess>
      <sequenceFlow id="process_dispute_extractor-extract_urls-0--process_dispute_extractor-extract_urls-1" name="For each url" sourceRef="process_dispute_extractor-extract_urls-0" targetRef="process_dispute_extractor-extract_urls-1"></sequenceFlow>       
      <sequenceFlow id="process_dispute_extractor-extract_urls-1--process_dispute_extractor-extract_urls-0" sourceRef="process_dispute_extractor-extract_urls-1" targetRef="process_dispute_extractor-extract_urls-0"></sequenceFlow>
    </subProcess>
    <startEvent id="process_dispute_extractor-start" name="Start"></startEvent>
    <endEvent id="process_dispute_extractor-end" name="End"></endEvent>
    <sequenceFlow id="process_dispute_extractor-start--process_dispute_extractor-extract_urls" sourceRef="process_dispute_extractor-start" targetRef="process_dispute_extractor-extract_urls"></sequenceFlow>
    <sequenceFlow id="process_dispute_extractor-extract_urls--process_dispute_extractor-end" sourceRef="process_dispute_extractor-extract_urls" targetRef="process_dispute_extractor-end"></sequenceFlow>

  </process>
</definitions>

BPMN 导出图像:

BPMN 导出图像


推荐阅读