Skip to content

Commit

Permalink
feat(simulator): support bpmn:Activity token sinks
Browse files Browse the repository at this point in the history
Closes #94
  • Loading branch information
nikku committed Dec 19, 2021
1 parent 9da9174 commit 69fd30c
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 5 deletions.
30 changes: 25 additions & 5 deletions lib/simulator/behaviors/ActivityBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,34 @@ ActivityBehavior.prototype.exit = function(context) {

const parentScope = scope.parent;

let sequenceFlowTaken = false;

for (const outgoing of element.outgoing) {
for (const outgoingFlow of element.outgoing) {

if (isSequenceFlow(outgoing)) {
if (!isSequenceFlow(outgoingFlow)) {
continue;
}

this._simulator.enter({
element: outgoingFlow,
scope: parentScope
});

sequenceFlowTaken = true;
}

// element has token sink semantics
if (!sequenceFlowTaken) {

const parentScope = scope.parent;

this._simulator.enter({
element: outgoing,
scope: parentScope
if (this._scopeBehavior.isFinished(parentScope, scope)) {
this._scopeBehavior.exit({
scope: parentScope,
initiator: {
element,
scope
}
});
}
}
Expand Down
26 changes: 26 additions & 0 deletions test/spec/simulator/Simulator.task-token-sink.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0avz3fy" targetNamespace="http://bpmn.io/schema/bpmn" exporter="bpmn-js (https://demo.bpmn.io)" exporterVersion="8.8.3">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:startEvent id="Start">
<bpmn:outgoing>Flow_1</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:task id="EndTask">
<bpmn:incoming>Flow_1</bpmn:incoming>
</bpmn:task>
<bpmn:sequenceFlow id="Flow_1" sourceRef="Start" targetRef="EndTask" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNEdge id="Flow_1_di" bpmnElement="Flow_1">
<di:waypoint x="188" y="120" />
<di:waypoint x="240" y="120" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="Start_di" bpmnElement="Start">
<dc:Bounds x="152" y="102" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="EndTask_di" bpmnElement="EndTask">
<dc:Bounds x="240" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
28 changes: 28 additions & 0 deletions test/spec/simulator/SimulatorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,34 @@ describe('simulator', function() {
});


verify('task-token-sink', () => {

// when
signal({
element: element('Process_1')
});

// then
expectTrace([
'createScope:Process_1:null',
'signal:Process_1:A',
'createScope:Start:A',
'signal:Start:B',
'exit:Start:B',
'createScope:Flow_1:A',
'destroyScope:Start:B',
'enter:Flow_1:A',
'exit:Flow_1:C',
'createScope:EndTask:A',
'destroyScope:Flow_1:C',
'enter:EndTask:A',
'exit:EndTask:D',
'destroyScope:EndTask:D',
'exit:Process_1:A',
'destroyScope:Process_1:A'
]);
});

verify('exclusive-gateway-fork-join', () => {

// given
Expand Down

0 comments on commit 69fd30c

Please sign in to comment.