Java - Camunda BPMN model API: how to save valid xml? - java
I'm building some test BPMN 2.0 models and saving them to xml files, in a Java project, by following the examples provided by the official doc, in this case the example 2.
I imported the lib in my pom like below:
<!-- https://mvnrepository.com/artifact/org.camunda.bpm.model/camunda-bpmn-model -->
<dependency>
<groupId>org.camunda.bpm.model</groupId>
<artifactId>camunda-bpmn-model</artifactId>
<version>7.10.0</version>
</dependency>
and this is my test class, following the example 2:
import org.camunda.bpm.model.bpmn.Bpmn;
import org.camunda.bpm.model.bpmn.BpmnModelInstance;
import org.camunda.bpm.model.bpmn.instance.*;
import org.camunda.bpm.model.bpmn.instance.Process;
import java.io.File;
import java.io.IOException;
public class Test {
protected static <T extends BpmnModelElementInstance> T createElement(BpmnModelInstance modelInstance, BpmnModelElementInstance parentElement, String id, Class<T> elementClass) {
T element = modelInstance.newInstance(elementClass);
element.setAttributeValue("id", id, true);
parentElement.addChildElement(element);
return element;
}
public static SequenceFlow createSequenceFlow(BpmnModelInstance modelInstance, Process process, FlowNode from, FlowNode to) {
String identifier = from.getId() + "-" + to.getId();
SequenceFlow sequenceFlow = createElement(modelInstance, process, identifier, SequenceFlow.class);
process.addChildElement(sequenceFlow);
sequenceFlow.setSource(from);
from.getOutgoing().add(sequenceFlow);
sequenceFlow.setTarget(to);
to.getIncoming().add(sequenceFlow);
return sequenceFlow;
}
public static void main(String[] args) throws IOException {
// create an empty model
BpmnModelInstance modelInstance = Bpmn.createEmptyModel();
Definitions definitions = modelInstance.newInstance(Definitions.class);
definitions.setTargetNamespace("http://camunda.org/examples");
modelInstance.setDefinitions(definitions);
// create a process
Process process = modelInstance.newInstance(Process.class);
process.setId("process");
definitions.addChildElement(process);
// create elements
StartEvent startEvent = createElement(modelInstance, process, "start", StartEvent.class);
ParallelGateway fork = createElement(modelInstance, process, "fork", ParallelGateway.class);
ServiceTask task1 = createElement(modelInstance, process, "task1", ServiceTask.class);
task1.setName("Service Task");
UserTask task2 = createElement(modelInstance, process, "task2", UserTask.class);
task2.setName("User Task");
ParallelGateway join = createElement(modelInstance, process, "join", ParallelGateway.class);
EndEvent endEvent = createElement(modelInstance, process, "end", EndEvent.class);
// create flows
createSequenceFlow(modelInstance, process, startEvent, fork);
createSequenceFlow(modelInstance, process, fork, task1);
createSequenceFlow(modelInstance, process, fork, task2);
createSequenceFlow(modelInstance, process, task1, join);
createSequenceFlow(modelInstance, process, task2, join);
createSequenceFlow(modelInstance, process, join, endEvent);
// validate and write model to file
Bpmn.validateModel(modelInstance);
File file = new File("bpmn-model.bpmn.xml");
file.createNewFile();
Bpmn.writeModelToFile(file, modelInstance);
}
}
Here the generated BPMN 2.0 xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<definitions id="definitions_7b2df680-1d9c-4897-ba8b-a83548ab937f" targetNamespace="http://camunda.org/examples" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL">
<process id="process">
<startEvent id="start">
<outgoing>start-fork</outgoing>
</startEvent>
<parallelGateway id="fork">
<incoming>start-fork</incoming>
<outgoing>fork-task1</outgoing>
<outgoing>fork-task2</outgoing>
</parallelGateway>
<serviceTask id="task1" name="Service Task">
<incoming>fork-task1</incoming>
<outgoing>task1-join</outgoing>
</serviceTask>
<userTask id="task2" name="User Task">
<incoming>fork-task2</incoming>
<outgoing>task2-join</outgoing>
</userTask>
<parallelGateway id="join">
<incoming>task1-join</incoming>
<incoming>task2-join</incoming>
<outgoing>join-end</outgoing>
</parallelGateway>
<endEvent id="end">
<incoming>join-end</incoming>
</endEvent>
<sequenceFlow id="start-fork" sourceRef="start" targetRef="fork"/>
<sequenceFlow id="fork-task1" sourceRef="fork" targetRef="task1"/>
<sequenceFlow id="fork-task2" sourceRef="fork" targetRef="task2"/>
<sequenceFlow id="task1-join" sourceRef="task1" targetRef="join"/>
<sequenceFlow id="task2-join" sourceRef="task2" targetRef="join"/>
<sequenceFlow id="join-end" sourceRef="join" targetRef="end"/>
</process>
</definitions>
Altough the validation method, the generated xml appears to be invalid when trying to display the BPMN using both the Camunda Modeler app and bpmn.io.
What is wrong with this example, hence with my code?
How can I make the generated xml to be valid? Since bpmn 2.0 is a standard, I'm also a bit surprised of this problem.
I finally got it working by switching to the fluent model builder API, following this https://blog.camunda.com/post/2014/02/the-new-camunda-bpmn-model-api/
This is my updated test calss:
import org.camunda.bpm.model.bpmn.Bpmn;
import org.camunda.bpm.model.bpmn.BpmnModelInstance;
import org.camunda.bpm.model.bpmn.GatewayDirection;
import java.io.File;
import java.io.IOException;
public class Test {
public static void main(String[] args) throws IOException {
BpmnModelInstance modelInstance = Bpmn.createProcess()
.name("BPMN API Invoice Process")
.executable()
.startEvent()
.name("Invoice received")
.camundaFormKey("embedded:app:forms/start-form.html")
.userTask()
.name("Assign Approver")
.camundaFormKey("embedded:app:forms/assign-approver.html")
.camundaAssignee("demo")
.userTask()
.id("approveInvoice")
.name("Approve Invoice")
.camundaFormKey("embedded:app:forms/approve-invoice.html")
.camundaAssignee("${approver}")
.exclusiveGateway()
.name("Invoice approved?")
.gatewayDirection(GatewayDirection.Diverging)
.condition("yes", "${approved}")
.userTask()
.name("Prepare Bank Transfer")
.camundaFormKey("embedded:app:forms/prepare-bank-transfer.html")
.camundaCandidateGroups("accounting")
.serviceTask()
.name("Archive Invoice")
.endEvent()
.name("Invoice processed")
.moveToLastGateway()
.condition("no", "${!approved}")
.userTask()
.name("Review Invoice")
.camundaFormKey("embedded:app:forms/review-invoice.html")
.camundaAssignee("demo")
.exclusiveGateway()
.name("Review successful?")
.gatewayDirection(GatewayDirection.Diverging)
.condition("no", "${!clarified}")
.endEvent()
.name("Invoice not processed")
.moveToLastGateway()
.condition("yes", "${clarified}")
.connectTo("approveInvoice")
.done();
// validate and write model to file
Bpmn.validateModel(modelInstance);
File file = new File("bpmn-model.bpmn.xml");
file.createNewFile();
String bpmnString = Bpmn.convertToString(modelInstance);
System.out.println("bpmnString");
System.out.println(bpmnString);
Bpmn.writeModelToFile(file, modelInstance);
}
}
and this is the generated xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<definitions xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="definitions_3bd3e094-3e53-4644-af0c-1a048653920c" targetNamespace="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL">
<process id="process_e14ca74e-6095-4a2b-bced-debcb3b37954" isExecutable="true" name="BPMN API Invoice Process">
<startEvent camunda:formKey="embedded:app:forms/start-form.html" id="startEvent_e8daa33a-af99-4b7a-87ee-200b0e7bedcd" name="Invoice received">
<outgoing>sequenceFlow_cb28e7e5-ebc0-4f27-b8b2-24403ab87ce3</outgoing>
</startEvent>
<userTask camunda:assignee="demo" camunda:formKey="embedded:app:forms/assign-approver.html" id="userTask_029f48b9-de24-4292-af49-845e81fdcc4b" name="Assign Approver">
<incoming>sequenceFlow_cb28e7e5-ebc0-4f27-b8b2-24403ab87ce3</incoming>
<outgoing>sequenceFlow_57a81fcd-fb35-42cd-afca-7c4c7914936d</outgoing>
</userTask>
<sequenceFlow id="sequenceFlow_cb28e7e5-ebc0-4f27-b8b2-24403ab87ce3" sourceRef="startEvent_e8daa33a-af99-4b7a-87ee-200b0e7bedcd" targetRef="userTask_029f48b9-de24-4292-af49-845e81fdcc4b"/>
<userTask camunda:assignee="${approver}" camunda:formKey="embedded:app:forms/approve-invoice.html" id="approveInvoice" name="Approve Invoice">
<incoming>sequenceFlow_57a81fcd-fb35-42cd-afca-7c4c7914936d</incoming>
<incoming>sequenceFlow_6987bcb8-5f6a-467b-9b25-e21b90dd0d4d</incoming>
<outgoing>sequenceFlow_1fe15a36-427e-4000-8fc7-50b8925ea1e5</outgoing>
</userTask>
<sequenceFlow id="sequenceFlow_57a81fcd-fb35-42cd-afca-7c4c7914936d" sourceRef="userTask_029f48b9-de24-4292-af49-845e81fdcc4b" targetRef="approveInvoice"/>
<exclusiveGateway gatewayDirection="Diverging" id="exclusiveGateway_b66a0444-2889-4cae-ac78-c1f65405ba0b" name="Invoice approved?">
<incoming>sequenceFlow_1fe15a36-427e-4000-8fc7-50b8925ea1e5</incoming>
<outgoing>sequenceFlow_9156c1d4-f756-447b-a384-e3bf17c43ff4</outgoing>
<outgoing>sequenceFlow_29bab2ba-6108-4731-94c3-93a6955d1946</outgoing>
</exclusiveGateway>
<sequenceFlow id="sequenceFlow_1fe15a36-427e-4000-8fc7-50b8925ea1e5" sourceRef="approveInvoice" targetRef="exclusiveGateway_b66a0444-2889-4cae-ac78-c1f65405ba0b"/>
<sequenceFlow id="sequenceFlow_9156c1d4-f756-447b-a384-e3bf17c43ff4" name="yes" sourceRef="exclusiveGateway_b66a0444-2889-4cae-ac78-c1f65405ba0b" targetRef="userTask_79a63b4f-96a7-43d7-aab3-e8e0e83769e5">
<conditionExpression id="conditionExpression_13d7607b-d7e7-4fa4-a364-aeabff28a0f1">${approved}</conditionExpression>
</sequenceFlow>
<userTask camunda:candidateGroups="accounting" camunda:formKey="embedded:app:forms/prepare-bank-transfer.html" id="userTask_79a63b4f-96a7-43d7-aab3-e8e0e83769e5" name="Prepare Bank Transfer">
<incoming>sequenceFlow_9156c1d4-f756-447b-a384-e3bf17c43ff4</incoming>
<outgoing>sequenceFlow_b82e04ab-a0cc-4969-989a-1ec64d74d990</outgoing>
</userTask>
<serviceTask id="serviceTask_9d976f99-f8fb-4705-ae6d-a606758111f4" name="Archive Invoice">
<incoming>sequenceFlow_b82e04ab-a0cc-4969-989a-1ec64d74d990</incoming>
<outgoing>sequenceFlow_f0f99688-25b1-417e-9a5d-0d17503cb3ba</outgoing>
</serviceTask>
<sequenceFlow id="sequenceFlow_b82e04ab-a0cc-4969-989a-1ec64d74d990" sourceRef="userTask_79a63b4f-96a7-43d7-aab3-e8e0e83769e5" targetRef="serviceTask_9d976f99-f8fb-4705-ae6d-a606758111f4"/>
<endEvent id="endEvent_affc9949-819a-4b79-98bd-0f2fd844d014" name="Invoice processed">
<incoming>sequenceFlow_f0f99688-25b1-417e-9a5d-0d17503cb3ba</incoming>
</endEvent>
<sequenceFlow id="sequenceFlow_f0f99688-25b1-417e-9a5d-0d17503cb3ba" sourceRef="serviceTask_9d976f99-f8fb-4705-ae6d-a606758111f4" targetRef="endEvent_affc9949-819a-4b79-98bd-0f2fd844d014"/>
<sequenceFlow id="sequenceFlow_29bab2ba-6108-4731-94c3-93a6955d1946" name="no" sourceRef="exclusiveGateway_b66a0444-2889-4cae-ac78-c1f65405ba0b" targetRef="userTask_7b955191-5741-44df-b7ba-d154ddfbe616">
<conditionExpression id="conditionExpression_ce06d35f-8638-4699-802b-7f1b94732f46">${!approved}</conditionExpression>
</sequenceFlow>
<userTask camunda:assignee="demo" camunda:formKey="embedded:app:forms/review-invoice.html" id="userTask_7b955191-5741-44df-b7ba-d154ddfbe616" name="Review Invoice">
<incoming>sequenceFlow_29bab2ba-6108-4731-94c3-93a6955d1946</incoming>
<outgoing>sequenceFlow_74d95e16-7907-4000-9ffb-cdba8c3ddde4</outgoing>
</userTask>
<exclusiveGateway gatewayDirection="Diverging" id="exclusiveGateway_5aa645c5-a5e7-4453-8498-8462092b85b1" name="Review successful?">
<incoming>sequenceFlow_74d95e16-7907-4000-9ffb-cdba8c3ddde4</incoming>
<outgoing>sequenceFlow_3bf21b37-c534-4541-b84f-03d3fe05c989</outgoing>
<outgoing>sequenceFlow_6987bcb8-5f6a-467b-9b25-e21b90dd0d4d</outgoing>
</exclusiveGateway>
<sequenceFlow id="sequenceFlow_74d95e16-7907-4000-9ffb-cdba8c3ddde4" sourceRef="userTask_7b955191-5741-44df-b7ba-d154ddfbe616" targetRef="exclusiveGateway_5aa645c5-a5e7-4453-8498-8462092b85b1"/>
<sequenceFlow id="sequenceFlow_3bf21b37-c534-4541-b84f-03d3fe05c989" name="no" sourceRef="exclusiveGateway_5aa645c5-a5e7-4453-8498-8462092b85b1" targetRef="endEvent_68057c88-fa46-43cc-a93c-774b26be7b50">
<conditionExpression id="conditionExpression_8bb43e50-dd2f-40ba-9cc9-91a69813a835">${!clarified}</conditionExpression>
</sequenceFlow>
<endEvent id="endEvent_68057c88-fa46-43cc-a93c-774b26be7b50" name="Invoice not processed">
<incoming>sequenceFlow_3bf21b37-c534-4541-b84f-03d3fe05c989</incoming>
</endEvent>
<sequenceFlow id="sequenceFlow_6987bcb8-5f6a-467b-9b25-e21b90dd0d4d" name="yes" sourceRef="exclusiveGateway_5aa645c5-a5e7-4453-8498-8462092b85b1" targetRef="approveInvoice">
<conditionExpression id="conditionExpression_c3fb4bcf-905a-47dd-84cf-6cfe1980ca2e">${clarified}</conditionExpression>
</sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_946186ab-976d-40e2-9ed2-4672566340a2">
<bpmndi:BPMNPlane bpmnElement="process_e14ca74e-6095-4a2b-bced-debcb3b37954" id="BPMNPlane_78d2c2b7-e5e7-414f-abae-0dcddaefbdfd">
<bpmndi:BPMNShape bpmnElement="startEvent_e8daa33a-af99-4b7a-87ee-200b0e7bedcd" id="BPMNShape_2da46013-859f-418a-8612-25bd57aabb52">
<dc:Bounds height="36.0" width="36.0" x="100.0" y="100.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="userTask_029f48b9-de24-4292-af49-845e81fdcc4b" id="BPMNShape_79fd4553-cfb0-4740-b4fe-093d1c96474b">
<dc:Bounds height="80.0" width="100.0" x="186.0" y="78.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sequenceFlow_cb28e7e5-ebc0-4f27-b8b2-24403ab87ce3" id="BPMNEdge_77315869-b425-4daf-85b6-6121867d91bc">
<di:waypoint x="136.0" y="118.0"/>
<di:waypoint x="186.0" y="118.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape bpmnElement="approveInvoice" id="BPMNShape_b54e1244-b4fb-4e70-8c0d-4b76eb2798b0">
<dc:Bounds height="80.0" width="100.0" x="336.0" y="78.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sequenceFlow_57a81fcd-fb35-42cd-afca-7c4c7914936d" id="BPMNEdge_dfa41f0e-273b-4d62-b8b8-ef9286b24f7d">
<di:waypoint x="286.0" y="118.0"/>
<di:waypoint x="336.0" y="118.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape bpmnElement="exclusiveGateway_b66a0444-2889-4cae-ac78-c1f65405ba0b" id="BPMNShape_bc1af4c3-ef1f-4c26-a42c-b1c2982bf35c" isMarkerVisible="true">
<dc:Bounds height="50.0" width="50.0" x="486.0" y="93.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sequenceFlow_1fe15a36-427e-4000-8fc7-50b8925ea1e5" id="BPMNEdge_9e81a730-2822-4c70-8061-9bbecf05022d">
<di:waypoint x="436.0" y="118.0"/>
<di:waypoint x="486.0" y="118.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape bpmnElement="userTask_79a63b4f-96a7-43d7-aab3-e8e0e83769e5" id="BPMNShape_8c455164-1097-43ca-814f-6d601735b27a">
<dc:Bounds height="80.0" width="100.0" x="586.0" y="78.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sequenceFlow_9156c1d4-f756-447b-a384-e3bf17c43ff4" id="BPMNEdge_47ba6c2b-fd10-4faf-8ee9-cbe019282080">
<di:waypoint x="536.0" y="118.0"/>
<di:waypoint x="586.0" y="118.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape bpmnElement="serviceTask_9d976f99-f8fb-4705-ae6d-a606758111f4" id="BPMNShape_d2e257f4-4c63-44e6-a8ab-d3179a83682c">
<dc:Bounds height="80.0" width="100.0" x="736.0" y="78.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sequenceFlow_b82e04ab-a0cc-4969-989a-1ec64d74d990" id="BPMNEdge_e5727f31-71a0-4f03-8a9d-7aca2cd9999a">
<di:waypoint x="686.0" y="118.0"/>
<di:waypoint x="736.0" y="118.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape bpmnElement="endEvent_affc9949-819a-4b79-98bd-0f2fd844d014" id="BPMNShape_4a1b2f6f-6929-4fd7-b6cf-9f49410242d7">
<dc:Bounds height="36.0" width="36.0" x="886.0" y="100.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sequenceFlow_f0f99688-25b1-417e-9a5d-0d17503cb3ba" id="BPMNEdge_28346c07-6da9-41d2-bcf2-76a9583ea933">
<di:waypoint x="836.0" y="118.0"/>
<di:waypoint x="886.0" y="118.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape bpmnElement="userTask_7b955191-5741-44df-b7ba-d154ddfbe616" id="BPMNShape_1c62b32d-2c17-48b0-bbc7-ac0074c97e62">
<dc:Bounds height="80.0" width="100.0" x="586.0" y="208.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sequenceFlow_29bab2ba-6108-4731-94c3-93a6955d1946" id="BPMNEdge_40c826c8-638d-4cd2-b9a1-ccdfa9a5ee6e">
<di:waypoint x="511.0" y="143.0"/>
<di:waypoint x="511.0" y="248.0"/>
<di:waypoint x="586.0" y="248.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape bpmnElement="exclusiveGateway_5aa645c5-a5e7-4453-8498-8462092b85b1" id="BPMNShape_36d66f18-3b46-4fde-9342-3ccd8d0f838d" isMarkerVisible="true">
<dc:Bounds height="50.0" width="50.0" x="736.0" y="223.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sequenceFlow_74d95e16-7907-4000-9ffb-cdba8c3ddde4" id="BPMNEdge_257a94d2-a5f6-4a88-9503-f5b9fd65cc7e">
<di:waypoint x="686.0" y="248.0"/>
<di:waypoint x="736.0" y="248.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape bpmnElement="endEvent_68057c88-fa46-43cc-a93c-774b26be7b50" id="BPMNShape_2dff264a-5f15-44d9-ba38-b962be76ea74">
<dc:Bounds height="36.0" width="36.0" x="836.0" y="230.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sequenceFlow_3bf21b37-c534-4541-b84f-03d3fe05c989" id="BPMNEdge_0a149725-d17c-4b6f-b7db-7854d0a27b00">
<di:waypoint x="786.0" y="248.0"/>
<di:waypoint x="836.0" y="248.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sequenceFlow_6987bcb8-5f6a-467b-9b25-e21b90dd0d4d" id="BPMNEdge_8b25f14c-9653-42ab-a57f-48fc07bd7ee8">
<di:waypoint x="761.0" y="273.0"/>
<di:waypoint x="761.0" y="118.0"/>
<di:waypoint x="336.0" y="118.0"/>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
By comparing it to the above xml, I notice a few new <bpmndi ...> elements not present before.
Missing isExecutable parameter in process
// create a process
Process process = modelInstance.newInstance(Process.class);
process.setExecutable(true);
Related
Traci4J with SUMO Returning Error
I’m very much a novice at both SUMO and Traci4J, however, I am interested in learning how to use these tools. I have ran into a problem when running virtually anything on Traci4J. When performing nextSimStep() on a SumoTraciConnection object I am met with the error it.polito.appeal.traci.TraCIException$UnexpectedData: Unexpected command/status ID: expected 164, got 2 I cannot find any reason for this occurring, I have attempted it on 2 machines with a clean install of both the latest version of SUMO, the latest version of Traci4J, and Java SE 1.7. Main method public static void main(String[] args) { SumoTraciConnection sumo; sumo = new SumoTraciConnection(URL_TO_SUMOCFG, (int) System.nanoTime()); sumo.addOption("start", "1"); try { sumo.runServer(true); sumo.nextSimStep(); sumo.close(); }catch(IOException | InterruptedException e) { e.printStackTrace(); } } hello.sumocfg File <input> <net-file value="hello.net.xml"/> <route-files value="hello.rou.xml"/> </input> <time> <begin value="0"/> <end value="10000"/> </time> <gui_only> <gui-settings-file value="hello.settings.xml"/> </gui_only> hello.net.xml File <?xml version="1.0" encoding="UTF-8"?> --> <location netOffset="250.00,0.00" convBoundary="0.00,-71.61,501.00,0.00" origBoundary="-250.00,0.00,251.00,0.00" projParameter="!"/> <edge id=":2_0" function="internal"> <lane id=":2_0_0" index="0" speed="13.90" length="0.10" shape="500.00,-1.65 500.00,-1.65"/> </edge> <edge id="1to2" from="1" to="2" priority="-1"> <lane id="1to2_0" index="0" speed="13.90" length="500.00" shape="0.00,-1.65 500.00,-1.65"/> </edge> <edge id="gneE0" from="gneJ0" to="gneJ1" priority="1"> <lane id="gneE0_0" index="0" speed="13.89" length="153.61" shape="227.09,-64.38 380.45,-73.25"/> </edge> <edge id="out" from="2" to="3" priority="-1"> <lane id="out_0" index="0" speed="13.90" length="1.00" shape="500.00,-1.65 501.00,-1.65"/> </edge> <junction id="1" type="dead_end" x="0.00" y="0.00" incLanes="" intLanes="" shape="0.00,-0.05 0.00,-3.25"/> <junction id="2" type="priority" x="500.00" y="0.00" incLanes="1to2_0" intLanes=":2_0_0" shape="500.00,-0.05 500.00,-3.25 500.00,-0.05"> <request index="0" response="0" foes="0" cont="0"/> </junction> <junction id="3" type="dead_end" x="501.00" y="0.00" incLanes="out_0" intLanes="" shape="501.00,-3.25 501.00,-0.05"/> <junction id="gneJ0" type="dead_end" x="227.19" y="-62.74" incLanes="" intLanes="" shape="227.18,-62.79 227.00,-65.98"/> <junction id="gneJ1" type="dead_end" x="380.54" y="-71.61" incLanes="gneE0_0" intLanes="" shape="380.35,-74.85 380.54,-71.66"/> <connection from="1to2" to="out" fromLane="0" toLane="0" via=":2_0_0" dir="s" state="M"/> <connection from=":2_0" to="out" fromLane="0" toLane="0" dir="s" state="M"/> hello.rou.xml File <?xml version="1.0" encoding="UTF-8"?> <!-- generated on 14/02/2018 21:20:37 by Netedit Version 0.31.0 <?xml version="1.0" encoding="UTF-8"?> <configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/netconvertConfiguration.xsd"> <input> <sumo-net-file value="hello.net.xml"/> </input> <output> <output-file value="hello.net.xml"/> </output> <processing> <no-turnarounds value="true"/> <offset.disable-normalization value="true"/> <lefthand value="false"/> <junctions.corner-detail value="0"/> <rectangular-lane-cut value="false"/> <walkingareas value="false"/> </processing> <visualisation> <registry-viewport value="true"/> </visualisation> </configuration> --> <net version="0.27" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/net_file.xsd"> <location netOffset="250.00,0.00" convBoundary="0.00,-71.61,501.00,0.00" origBoundary="-250.00,0.00,251.00,0.00" projParameter="!"/> <edge id=":2_0" function="internal"> <lane id=":2_0_0" index="0" speed="13.90" length="0.10" shape="500.00,-1.65 500.00,-1.65"/> </edge> <edge id="1to2" from="1" to="2" priority="-1"> <lane id="1to2_0" index="0" speed="13.90" length="500.00" shape="0.00,-1.65 500.00,-1.65"/> </edge> <edge id="gneE0" from="gneJ0" to="gneJ1" priority="1"> <lane id="gneE0_0" index="0" speed="13.89" length="153.61" shape="227.09,-64.38 380.45,-73.25"/> </edge> <edge id="out" from="2" to="3" priority="-1"> <lane id="out_0" index="0" speed="13.90" length="1.00" shape="500.00,-1.65 501.00,-1.65"/> </edge> <junction id="1" type="dead_end" x="0.00" y="0.00" incLanes="" intLanes="" shape="0.00,-0.05 0.00,-3.25"/> <junction id="2" type="priority" x="500.00" y="0.00" incLanes="1to2_0" intLanes=":2_0_0" shape="500.00,-0.05 500.00,-3.25 500.00,-0.05"> <request index="0" response="0" foes="0" cont="0"/> </junction> <junction id="3" type="dead_end" x="501.00" y="0.00" incLanes="out_0" intLanes="" shape="501.00,-3.25 501.00,-0.05"/> <junction id="gneJ0" type="dead_end" x="227.19" y="-62.74" incLanes="" intLanes="" shape="227.18,-62.79 227.00,-65.98"/> <junction id="gneJ1" type="dead_end" x="380.54" y="-71.61" incLanes="gneE0_0" intLanes="" shape="380.35,-74.85 380.54,-71.66"/> <connection from="1to2" to="out" fromLane="0" toLane="0" via=":2_0_0" dir="s" state="M"/> <connection from=":2_0" to="out" fromLane="0" toLane="0" dir="s" state="M"/> </net> Error Message Trace it.polito.appeal.traci.TraCIException$UnexpectedData: Unexpected command/status ID: expected 164, got 2 at it.polito.appeal.traci.Utils.checkStatusResponse(Utils.java:57) at it.polito.appeal.traci.ChangeStateQuery.pickResponses(ChangeStateQuery.java:83) at it.polito.appeal.traci.MultiQuery.run(MultiQuery.java:108) at it.polito.appeal.traci.SumoTraciConnection.nextSimStep(SumoTraciConnection.java:623) at it.polito.appeal.traci.test.TraCITest.getFirstVehicle(TraCITest.java:337) at it.polito.appeal.traci.test.TraCITest.testChangeTarget(TraCITest.java:577) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) I'm sorry if this is verbose, any help would be hugely appreciated
I meet the same question with using the Traci4J. If you want to use Traas, I can give you some tips. You could find the WebService class here: traas/src/main/java/de/tudresden/ws/WebService.java This is an executable java file. Then you will get a running server. If you create a web service client, you could connect with the traas server and do the simulation with sumo. Btw I still have some doubt that the api of traas is less than the api for python and C++; Here is a small demo, supposing that you have already imported the traas.jar; public class MyWebService { public static void main(String[] args) { Config.config_file = "resources/map.sumo.cfg"; de.tudresden.ws.WebService.main(new String[]{}); } } The web service client: public class HelloWorldClient { public static TraasWSLocator locator; public static ServiceImpl service; static { try { locator = new TraasWSLocator(); service = locator.getServiceImplPort(); } catch (Exception e){ e.printStackTrace(); } } public static void main(String[] argv) throws RemoteException{ service.setSumoBinary("sumo-gui"); service.start("username"); while (service.simulation_getMinExpectedNumber()>0){ service.doTimestep(); } } }
how to make a form field of type List<Inventory> for camunda rest api
We're going to build a workflow management system and We're embedding the camunda engine Rest API into our Rest Application. Now I have Inventory defined like this: public class Inventory { private String objectName; private int objectCount; // getters and setters } and this is a sample workflow: in xml: <?xml version="1.0" encoding="UTF-8"?> <bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.11.3"> <bpmn:process id="test" isExecutable="true"> <bpmn:startEvent id="StartEvent_1"> <bpmn:outgoing>SequenceFlow_1v6clcy</bpmn:outgoing> </bpmn:startEvent> <bpmn:sequenceFlow id="SequenceFlow_1v6clcy" sourceRef="StartEvent_1" targetRef="testtask" /> <bpmn:userTask id="testtask" name="testtask" camunda:formKey="testform"> <bpmn:extensionElements> <camunda:formData> <camunda:formField id="inventories" label="name" type="List<org.example.Inventory>" /> </camunda:formData> </bpmn:extensionElements> <bpmn:incoming>SequenceFlow_1v6clcy</bpmn:incoming> <bpmn:outgoing>SequenceFlow_07kdfp4</bpmn:outgoing> </bpmn:userTask> <bpmn:endEvent id="EndEvent_0vm605w"> <bpmn:incoming>SequenceFlow_07kdfp4</bpmn:incoming> </bpmn:endEvent> <bpmn:sequenceFlow id="SequenceFlow_07kdfp4" sourceRef="testtask" targetRef="EndEvent_0vm605w" /> </bpmn:process> <bpmndi:BPMNDiagram id="BPMNDiagram_1"> <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="test"> <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1"> <dc:Bounds x="173" y="102" width="36" height="36" /> </bpmndi:BPMNShape> <bpmndi:BPMNEdge id="SequenceFlow_1v6clcy_di" bpmnElement="SequenceFlow_1v6clcy"> <di:waypoint xsi:type="dc:Point" x="209" y="120" /> <di:waypoint xsi:type="dc:Point" x="275" y="120" /> <bpmndi:BPMNLabel> <dc:Bounds x="242" y="99" width="0" height="12" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNShape id="UserTask_1s01hea_di" bpmnElement="testtask"> <dc:Bounds x="275" y="80" width="100" height="80" /> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="EndEvent_0vm605w_di" bpmnElement="EndEvent_0vm605w"> <dc:Bounds x="439" y="109" width="36" height="36" /> <bpmndi:BPMNLabel> <dc:Bounds x="412" y="149" width="90" height="12" /> </bpmndi:BPMNLabel> </bpmndi:BPMNShape> <bpmndi:BPMNEdge id="SequenceFlow_07kdfp4_di" bpmnElement="SequenceFlow_07kdfp4"> <di:waypoint xsi:type="dc:Point" x="375" y="120" /> <di:waypoint xsi:type="dc:Point" x="407" y="120" /> <di:waypoint xsi:type="dc:Point" x="407" y="127" /> <di:waypoint xsi:type="dc:Point" x="439" y="127" /> <bpmndi:BPMNLabel> <dc:Bounds x="377" y="117.5" width="90" height="12" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </bpmn:definitions> I'll eventually have a html form which will submit something like this: { "inventories" : [{"name": "banana","count": 3},{"name":"orange","count": 4}] } I want to submit this to /task/{id}/submit-form but I don't know what to put as type. I tried putting the type in modeler as List<org.example.Inventory> but the rest api throws an exception when deploying the process definition like this: org.camunda.bpm.engine.ProcessEngineException: ENGINE-09005 Could not parse BPMN process. Errors: * unknown type 'List' | org.example/PM.bpmn | line 65 | column 90 I've seen this example as well but I'm only using the Rest API not the whole bpm platform(besides we prefer to have pure html forms). So how to do it ? what should I put in type ? my camunda.cfg.xml: <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="processEngineConfiguration" class="org.camunda.bpm.engine.impl.cfg.StandaloneProcessEngineConfiguration"> <property name="jdbcUrl" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" /> <property name="jdbcDriver" value="org.h2.Driver" /> <property name="jdbcUsername" value="sa" /> <property name="jdbcPassword" value="" /> <property name="databaseSchemaUpdate" value="true" /> </bean> </beans> my processengineprovider: public class MyProcessEngineProvider implements ProcessEngineProvider { #Override public ProcessEngine getDefaultProcessEngine() { ProcessEngine engine = ProcessEngines.getDefaultProcessEngine(); RepositoryService repositoryService = engine.getRepositoryService(); repositoryService.createDeployment() .addClasspathResource("org.newtech/PM.bpmn") .deploy(); return engine; } #Override public ProcessEngine getProcessEngine(String s) { return getDefaultProcessEngine(); } #Override public Set<String> getProcessEngineNames() { Set<String> names = new HashSet<>(1); names.add("default"); return names; } }
jBPM compilation error
Process Compilation error : org.drools.lang.descr.ProcessDescr#4c60d6e9 com/sample/Process_com_sample_ruleflowsample.java (21:862) : Type mismatch: cannot convert from int to String com/sample/Process_com_sample_ruleflowsample.java (29:1151) : Type mismatch: cannot convert from int to String This is my ruleflowsample.rf under src/main/rules that is throwing the above error. <?xml version="1.0" encoding="UTF-8"?> <process xmlns="http://drools.org/drools-5.0/process" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:schemaLocation="http://drools.org/drools-5.0/process drools-processes-5.0.xsd" type="RuleFlow" name="ruleflowsample" id="com.sample.ruleflowsample" package-name="com.sample" > <header> <imports> <import name="com.sample.Employee" /> </imports> <variables> <variable name="caffeineIntake" > <type name="org.drools.process.core.datatype.impl.type.FloatDataType" /> </variable> </variables> </header> <nodes> <start id="1" name="Start" x="12" y="129" width="48" height="48" /> <split id="2" name="Gateway" x="101" y="128" width="49" height="49" type="2" > <constraints> <constraint toNodeId="4" toType="DROOLS_DEFAULT" name="Coffee" priority="1" type="code" dialect="java" >return caffeineIntake>0.105F;</constraint> <constraint toNodeId="5" toType="DROOLS_DEFAULT" name="Tea" priority="1" type="code" dialect="java" >return caffeineIntake>0.04F;</constraint> </constraints> </split> <actionNode id="4" name="Coffee" x="198" y="205" width="80" height="48" > <action type="expression" dialect="java" >String noOfCups = 1; System.out.println("No of coffee cups = "+noOfCups); System.out.println("caffeineIntake");</action> </actionNode> <actionNode id="5" name="Tea" x="196" y="61" width="80" height="48" > <action type="expression" dialect="java" >String noOfCups = 1; System.out.println("No of tea cups = "+noOfCups); System.out.println("caffeineIntake");</action> </actionNode> <end id="6" name="End" x="386" y="127" width="48" height="48" /> <join id="7" name="Gateway" x="311" y="127" width="49" height="49" type="2" /> </nodes> <connections> <connection from="1" to="2" /> <connection from="2" to="4" /> <connection from="2" to="5" /> <connection from="7" to="6" /> <connection from="5" to="7" /> <connection from="4" to="7" /> </connections> </process> I know the error is occurring because of this line: System.out.println("caffeineIntake"); I want to access this input variable i.e. caffeineIntake to perform some operation on it.
The error is not occurring because of this line: System.out.println("caffeineIntake"); It is occurring because of the Dialect option selection: Using this option as mvel rather than java resolved the issue.
Well, from my point of view String noOfCups = 1; is the problem. perhaps change it to String noOfCups = "1";
Jasper Reports - Multi axis chart - Only one plot showing
I'm trying to create a multi axis chart with one plot which shows a bar chart and another plot which shows a line chart. I found the multi axis chart to do this, but when I run my code only one plot is showing (image provided here). Any idea's on how to solve this? In my search for a solution I came accross this post, but when I execute this it just does the same. (When I switch the order of the barChart and lineChart in the jrxml it only shows the lineChart. Code provided below.) Java bean public class OperationSuccessrateBean { private Integer week; private Integer totalOrders; private Double successrate; public OperationSuccessrateBean(Integer week, Integer totalOrders, Double successrate) { this.week = week; this.totalOrders = totalOrders; this.successrate = successrate; } public Integer getWeek() { return week; } public Integer getTotalOrders() { return totalOrders; } public Double getSuccessrate() { return successrate; } } Java: Filling the report private void setOperationSuccessrate(String operationType, Map<String, Object> paramMap, List<OperationSuccessrateBean> successrateBeans) { paramMap.put(operationType + "_OPERATION_SUCCESSRATE_SET", new JRBeanCollectionDataSource( successrateBeans)); paramMap.put(operationType + "_OPERATION_SUCCESSRATE_ORDERS_SET", new JRBeanCollectionDataSource(successrateBeans)); } jrxml: define datasets and parameters <subDataset name="loadOperationSuccesrateSet" uuid="247b3e44-ef98-45f4-a909-e8b5678acc8f"> <field name="week" class="java.lang.Integer"/> <field name="totalOrders" class="java.lang.Integer"/> <field name="successrate" class="java.lang.Double"/> </subDataset> <subDataset name="loadOperationSuccesrateOrdersSet" uuid="247b3e44-ef98-45f4-a909-e8b5678acc8f"> <field name="week" class="java.lang.Integer"/> <field name="totalOrders" class="java.lang.Integer"/> <field name="successrate" class="java.lang.Double"/> </subDataset> <parameter name="LOAD_OPERATION_SUCCESSRATE_SET" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource" isForPrompting="false"/> <parameter name="LOAD_OPERATION_SUCCESSRATE_ORDERS_SET" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource" isForPrompting="false"/> jrxml: multi chart <multiAxisChart> <chart evaluationTime="Report"> <reportElement x="0" y="41" width="550" height="200" uuid="5078c050-dd35-43db-bf30-d04152672bd6"/> <chartTitle/> <chartSubtitle/> <chartLegend/> </chart> <multiAxisPlot> <plot/> <axis position="rightOrBottom"> <lineChart> <chart evaluationTime="Report"> <reportElement positionType="Float" x="0" y="25" width="270" height="175" backcolor="#FFFFFF" uuid="013d7a7d-2280-46d0-8d44-d537d062a182"/> <chartTitle color="#000000"/> <chartSubtitle color="#000000"/> <chartLegend textColor="#000000" backgroundColor="#FFFFFF"/> </chart> <categoryDataset> <dataset> <datasetRun subDataset="loadOperationSuccesrateSet" uuid="53426928-1245-4443-97da-509b00ba1f98"> <dataSourceExpression><![CDATA[$P{LOAD_OPERATION_SUCCESSRATE_SET}]]></dataSourceExpression> </datasetRun> </dataset> <categorySeries> <seriesExpression><![CDATA["Success rate"]]></seriesExpression> <categoryExpression><![CDATA[$F{week}]]></categoryExpression> <valueExpression><![CDATA[$F{successrate}]]></valueExpression> </categorySeries> </categoryDataset> <linePlot> <plot/> <categoryAxisFormat> <axisFormat/> </categoryAxisFormat> <valueAxisLabelExpression><![CDATA["Success rate"]]></valueAxisLabelExpression> <valueAxisFormat> <axisFormat labelColor="#000000" tickLabelColor="#000000" tickLabelMask="#0%" axisLineColor="#000000"> <labelFont/> </axisFormat> </valueAxisFormat> <rangeAxisMinValueExpression><![CDATA[0]]></rangeAxisMinValueExpression> <rangeAxisMaxValueExpression><![CDATA[1]]></rangeAxisMaxValueExpression> </linePlot> </lineChart> </axis> <axis> <barChart> <chart evaluationTime="Report"> <reportElement x="0" y="0" width="0" height="0" backcolor="#FFFFFF" uuid="15a15c89-a2d4-4971-b4b3-1c5ac224a91e"/> <chartTitle color="#000000"/> <chartSubtitle color="#000000"/> <chartLegend textColor="#000000" backgroundColor="#FFFFFF"/> </chart> <categoryDataset> <dataset> <datasetRun subDataset="loadOperationSuccesrateOrdersSet" uuid="4d001c74-1fde-47cd-b525-85d828d6ccf2"> <dataSourceExpression><![CDATA[$P{LOAD_OPERATION_SUCCESSRATE_ORDERS_SET}]]></dataSourceExpression> </datasetRun> </dataset> <categorySeries> <seriesExpression><![CDATA["TotalOrders"]]></seriesExpression> <categoryExpression><![CDATA[$F{week}]]></categoryExpression> <valueExpression><![CDATA[$F{totalOrders}]]></valueExpression> </categorySeries> </categoryDataset> <barPlot> <plot/> <itemLabel/> <categoryAxisFormat> <axisFormat/> </categoryAxisFormat> <valueAxisLabelExpression><![CDATA["# Orders"]]></valueAxisLabelExpression> <valueAxisFormat> <axisFormat labelColor="#000000" tickLabelColor="#000000" tickLabelMask="# ##0" axisLineColor="#000000"> <labelFont/> </axisFormat> </valueAxisFormat> <rangeAxisMinValueExpression><![CDATA[0]]></rangeAxisMinValueExpression> </barPlot> </barChart> </axis> </multiAxisPlot> </multiAxisChart> When I run my code without the multi axis chart so just to create the 2 plots next to each other it creates just fine. So I assume the data is correctely passed to the report. The relevant libraries I use are: net.sf.jasperreports.engine-6.4.0.jar jfreechart-1.0.19.jar
Lorenz, I had the same issue. The reason for the missing graph was that I was passing directly a net.sf.jasperreports.engine.data.JRBeanCollectionDataSource as parameter in the report. Apparently for this to work you have to pass a List: <parameter name="FIRST_DATA_SOURCE" class="java.util.List" isForPrompting="false"/> <parameter name="SECOND_DATA_SOURCE" class="java.util.List" isForPrompting="false"/> and then create the JRBeanCollectionDataSource inside the report: <dataset> <datasetRun subDataset="YOUR_SUBDATASET" uuid="a5941ba5-2088-4a31-8236-64704b54d979"> <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{FIRST_DATA_SOURCE})]]></dataSourceExpression> </datasetRun> </dataset> In the post you referenced it was used this way and it worked!
How to delete/suspend a process instance in Activiti programmatically?
I created a Process Engine, Repository Service, Runtime Service and deployed a BPMN workflow. I also created a Process instance and was able to start it. The issue is that when I try to either suspend or delete the process instance using the "deleteProcessInstance" method I get an error saying that the ProcessInstanceId could not be found!! PS: I learnt somewhere that the processId in BPMN is treated as processKey in Activiti. Code: public void startProcess(String processDefinitionKey) { ListenerClass.processInstance=ListenerClass.runtimeService.startProcessInstanceByKey(processDefinitionKey); } public void deleteProcess(String processInstanceId) { System.out.println("Stopping Process instance id " +processInstanceId); ListenerClass.runtimeService.deleteProcessInstance(processInstanceId, "Ok"); } In the code above while starting the process instance, I pass the "Process Id" of the BPMN.xml file.(which means processId of BPMN.xml=processInstanceKey of Activiti) My BPMN.xml: <?xml version="1.0" encoding="UTF-8"?> <bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_1" xmlns:activiti="http://activiti.org/bpmn" targetNamespace="http://bpmn.io/schema/bpmn"> <bpmn:process id="Process_11" isExecutable="true" name="Hima"> <bpmn:startEvent id="StartEvent_1"> <bpmn:outgoing>SequenceFlow_06sykhd</bpmn:outgoing> </bpmn:startEvent> <bpmn:sequenceFlow id="SequenceFlow_06sykhd" sourceRef="StartEvent_1" targetRef="Task_1dt8brv" /> <bpmn:endEvent id="EndEvent_0cb0ioi"> <bpmn:incoming>SequenceFlow_1doj4n6</bpmn:incoming> </bpmn:endEvent> <bpmn:serviceTask id="Task_1dt8brv" name="My Java Service Task" activiti:class="com.bosch.bip.Service.task1" > <bpmn:incoming>SequenceFlow_06sykhd</bpmn:incoming> <bpmn:outgoing>SequenceFlow_156te78</bpmn:outgoing> </bpmn:serviceTask> <bpmn:serviceTask id="Task_10bfll9" activiti:class="com.bosch.bip.Service.task1"> <bpmn:incoming>SequenceFlow_156te78</bpmn:incoming> <bpmn:outgoing>SequenceFlow_1doj4n6</bpmn:outgoing> </bpmn:serviceTask> <bpmn:sequenceFlow id="SequenceFlow_156te78" sourceRef="Task_1dt8brv" targetRef="Task_10bfll9" /> <bpmn:sequenceFlow id="SequenceFlow_1doj4n6" sourceRef="Task_10bfll9" targetRef="EndEvent_0cb0ioi" /> </bpmn:process> <bpmndi:BPMNDiagram id="BPMNDiagram_1"> <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_11"> <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1"> <dc:Bounds x="173" y="102" width="36" height="36" /> </bpmndi:BPMNShape> <bpmndi:BPMNEdge id="SequenceFlow_06sykhd_di" bpmnElement="SequenceFlow_06sykhd"> <di:waypoint xsi:type="dc:Point" x="209" y="120" /> <di:waypoint xsi:type="dc:Point" x="264" y="120" /> <di:waypoint xsi:type="dc:Point" x="264" y="147" /> <di:waypoint xsi:type="dc:Point" x="318" y="147" /> <bpmndi:BPMNLabel> <dc:Bounds x="219" y="123.5" width="90" height="20" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNShape id="EndEvent_0cb0ioi_di" bpmnElement="EndEvent_0cb0ioi"> <dc:Bounds x="768" y="173" width="36" height="36" /> <bpmndi:BPMNLabel> <dc:Bounds x="741" y="209" width="90" height="20" /> </bpmndi:BPMNLabel> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="Task_1dt8brv_di" bpmnElement="Task_1dt8brv"> <dc:Bounds x="318" y="107" width="100" height="80" /> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="Task_10bfll9_di" bpmnElement="Task_10bfll9"> <dc:Bounds x="528" y="94" width="100" height="80" /> </bpmndi:BPMNShape> <bpmndi:BPMNEdge id="SequenceFlow_156te78_di" bpmnElement="SequenceFlow_156te78"> <di:waypoint xsi:type="dc:Point" x="418" y="147" /> <di:waypoint xsi:type="dc:Point" x="473" y="147" /> <di:waypoint xsi:type="dc:Point" x="473" y="134" /> <di:waypoint xsi:type="dc:Point" x="528" y="134" /> <bpmndi:BPMNLabel> <dc:Bounds x="386" y="202.5" width="90" height="20" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="SequenceFlow_1doj4n6_di" bpmnElement="SequenceFlow_1doj4n6"> <di:waypoint xsi:type="dc:Point" x="628" y="134" /> <di:waypoint xsi:type="dc:Point" x="698" y="134" /> <di:waypoint xsi:type="dc:Point" x="698" y="191" /> <di:waypoint xsi:type="dc:Point" x="768" y="191" /> <bpmndi:BPMNLabel> <dc:Bounds x="653" y="152.5" width="90" height="20" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </bpmn:definitions> Any help in this regards would be really helpful.
For a running process use this, as you did above: runtimeService.deleteProcessInstance(processInstanceId, null); If the process has been ended you need to delete it from the history, maybe your process has already ended? HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery() .processInstanceId(processInstanceId).singleResult(); if (historicProcessInstance != null) { historyService.deleteHistoricProcessInstance(historicProcessInstance.getId()); }