Reputation: 51
May I ask you a question about using the BpmnAutoLayout class in the maven dependency activiti-bpmn-layout?
I programatically created an XML format .bpmn file without DI information (bpmnWithoutDI.bpmn) using activiti-bpmn-model api. I want to use the BpmnAutoLayout class to generate the DI information automatically for my bpmnWithoutDI.bpmn xml file. But when I run my program I get the folloing Exception:
Could anyone please tell me how to solve this problem?
You can download my source code from the following URL:
https://drive.google.com/file/d/1V9LUZLLZ1c-3JWzcSqDyM7IyywKB7Bvj/view?usp=sharing
It is zip file of an Eclipse maven project containing my java source code and the input file bpmnWithoutDI.bpmn . You can simply import the maven project and run the AutoLayoutDemo.java to reproduce the exception.
I also include my code below:
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>
Thank you!
Upvotes: 0
Views: 641
Reputation: 1084
Your correct bpmn file is below , I've changed and test it, I hope this could help you.
<?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 exported image:
Upvotes: 4
Reputation: 1084
I your code, everything is OK. the problem is your bpmn file.
I've created a new bpmn file (bpmnWithoutDI2) with xml content :
<?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="myProcess" name="My process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="User Task"></userTask>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
</process>
</definitions>
Everything is ok and after running code bpmnWithDI.bpmn is generated. But I think the problem is somewhere in sequenceFlow elements because without them the code was run successfully.
Upvotes: 3