Skip to content

Commit

Permalink
fix: conditional-flows multiple flows no conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
DeanZamzow-abrigo committed Feb 9, 2024
1 parent 4321e65 commit 7d2faec
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 5 deletions.
13 changes: 12 additions & 1 deletion rules/conditional-flows.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const {
isAny
} = require('bpmnlint-utils');

/**
* A rule that checks that sequence flows outgoing from a
* conditional forking gateway or activity are
Expand Down Expand Up @@ -39,7 +43,14 @@ function isConditionalForking(node) {
const defaultFlow = node['default'];
const outgoing = node.outgoing || [];

return defaultFlow || outgoing.find(hasCondition);
const isConditionalGateway = isAny(node, [
'bpmn:ExclusiveGateway',
'bpmn:InclusiveGateway'
]);

return defaultFlow
|| (isConditionalGateway && outgoing.length > 1)
|| outgoing.some(hasCondition);
}

function hasCondition(flow) {
Expand Down
30 changes: 28 additions & 2 deletions test/rules/conditional-flows.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,51 @@ RuleTester.verify('conditional-flows', rule, {
name: 'split after task',
moddleElement: readModdle(__dirname + '/conditional-flows/valid-split-after-task.bpmn')
},
{
name: 'split after parallel gateway',
moddleElement: readModdle(__dirname + '/conditional-flows/valid-split-after-parallel-gateway.bpmn')
},
{
name: 'conditional fork',
moddleElement: readModdle(__dirname + '/conditional-flows/valid-conditional-fork.bpmn')
},
{
name: 'conditional fork default',
moddleElement: readModdle(__dirname + '/conditional-flows/valid-conditional-fork-default.bpmn')
},
{
name: 'no condition after merge',
moddleElement: readModdle(__dirname + '/conditional-flows/valid-no-condition-after-merge.bpmn')
}
],
invalid: [
{
name: 'fork after exclusive gateway',
moddleElement: readModdle(__dirname + '/conditional-flows/invalid-fork-after-exclusive-gateway.bpmn'),
name: 'fork after exclusive gateway sibling condition',
moddleElement: readModdle(__dirname + '/conditional-flows/invalid-fork-after-exclusive-gateway-sibling-condition.bpmn'),
report: {
id: 'Flow_2',
message: 'Sequence flow is missing condition',
path: [ 'conditionExpression' ]
}
},
{
name: 'fork after exclusive gateway no conditions',
moddleElement: readModdle(__dirname + '/conditional-flows/invalid-fork-after-exclusive-gateway-no-conditions.bpmn'),
report: [
{
id: 'Flow_1',
message: 'Sequence flow is missing condition',
path: [ 'conditionExpression' ],
category: 'error'
},
{
id: 'Flow_2',
message: 'Sequence flow is missing condition',
path: [ 'conditionExpression' ],
category: 'error'
}
]
},
{
name: 'fork after exclusive gateway default',
moddleElement: readModdle(__dirname + '/conditional-flows/invalid-fork-after-exclusive-gateway-default.bpmn'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_047m0ul" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.16.2">
<bpmn:process id="Process" isExecutable="true">
<bpmn:exclusiveGateway id="Source">
<bpmn:outgoing>Flow_1</bpmn:outgoing>
<bpmn:outgoing>Flow_2</bpmn:outgoing>
</bpmn:exclusiveGateway>
<bpmn:intermediateThrowEvent id="Target_1">
<bpmn:incoming>Flow_1</bpmn:incoming>
</bpmn:intermediateThrowEvent>
<bpmn:sequenceFlow id="Flow_1" sourceRef="Source" targetRef="Target_1" />
<bpmn:intermediateThrowEvent id="Target_2">
<bpmn:incoming>Flow_2</bpmn:incoming>
</bpmn:intermediateThrowEvent>
<bpmn:sequenceFlow id="Flow_2" sourceRef="Source" targetRef="Target_2" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process">
<bpmndi:BPMNShape id="Source_di" bpmnElement="Source" isMarkerVisible="true">
<dc:Bounds x="42" y="63" width="50" height="50" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Target_1_di" bpmnElement="Target_1">
<dc:Bounds x="142" y="70" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_1_di" bpmnElement="Flow_1">
<di:waypoint x="92" y="88" />
<di:waypoint x="142" y="88" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="Target_2_di" bpmnElement="Target_2">
<dc:Bounds x="142" y="180" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_2_di" bpmnElement="Flow_2">
<di:waypoint x="67" y="113" />
<di:waypoint x="67" y="198" />
<di:waypoint x="142" y="198" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
41 changes: 41 additions & 0 deletions test/rules/conditional-flows/valid-conditional-fork-default.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_047m0ul" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.16.2">
<bpmn:process id="Process" isExecutable="true">
<bpmn:exclusiveGateway id="Source" default="Flow_2">
<bpmn:outgoing>Flow_1</bpmn:outgoing>
<bpmn:outgoing>Flow_2</bpmn:outgoing>
</bpmn:exclusiveGateway>
<bpmn:intermediateThrowEvent id="Target_1">
<bpmn:incoming>Flow_1</bpmn:incoming>
</bpmn:intermediateThrowEvent>
<bpmn:sequenceFlow id="Flow_1" sourceRef="Source" targetRef="Target_1">
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${true}</bpmn:conditionExpression>
</bpmn:sequenceFlow>
<bpmn:intermediateThrowEvent id="Target_2">
<bpmn:incoming>Flow_2</bpmn:incoming>
</bpmn:intermediateThrowEvent>
<bpmn:sequenceFlow id="Flow_2" sourceRef="Source" targetRef="Target_2" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process">
<bpmndi:BPMNShape id="Source_di" bpmnElement="Source" isMarkerVisible="true">
<dc:Bounds x="42" y="63" width="50" height="50" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Target_1_di" bpmnElement="Target_1">
<dc:Bounds x="142" y="70" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_1_di" bpmnElement="Flow_1">
<di:waypoint x="92" y="88" />
<di:waypoint x="142" y="88" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="Target_2_di" bpmnElement="Target_2">
<dc:Bounds x="142" y="180" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_2_di" bpmnElement="Flow_2">
<di:waypoint x="67" y="113" />
<di:waypoint x="67" y="198" />
<di:waypoint x="142" y="198" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
6 changes: 4 additions & 2 deletions test/rules/conditional-flows/valid-conditional-fork.bpmn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?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:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_047m0ul" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.16.2">
<bpmn:process id="Process" isExecutable="true">
<bpmn:exclusiveGateway id="Source" default="Flow_2">
<bpmn:exclusiveGateway id="Source">
<bpmn:outgoing>Flow_1</bpmn:outgoing>
<bpmn:outgoing>Flow_2</bpmn:outgoing>
</bpmn:exclusiveGateway>
Expand All @@ -14,7 +14,9 @@
<bpmn:intermediateThrowEvent id="Target_2">
<bpmn:incoming>Flow_2</bpmn:incoming>
</bpmn:intermediateThrowEvent>
<bpmn:sequenceFlow id="Flow_2" sourceRef="Source" targetRef="Target_2" />
<bpmn:sequenceFlow id="Flow_2" sourceRef="Source" targetRef="Target_2">
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${false}</bpmn:conditionExpression>
</bpmn:sequenceFlow>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_047m0ul" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.16.2">
<bpmn:process id="Process" isExecutable="true">
<bpmn:parallelGateway id="Source">
<bpmn:outgoing>Flow_1</bpmn:outgoing>
<bpmn:outgoing>Flow_2</bpmn:outgoing>
</bpmn:parallelGateway>
<bpmn:intermediateThrowEvent id="Target_1">
<bpmn:incoming>Flow_1</bpmn:incoming>
</bpmn:intermediateThrowEvent>
<bpmn:sequenceFlow id="Flow_1" sourceRef="Source" targetRef="Target_1" />
<bpmn:intermediateThrowEvent id="Target_2">
<bpmn:incoming>Flow_2</bpmn:incoming>
</bpmn:intermediateThrowEvent>
<bpmn:sequenceFlow id="Flow_2" sourceRef="Source" targetRef="Target_2" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process">
<bpmndi:BPMNShape id="Source_di" bpmnElement="Source" isMarkerVisible="true">
<dc:Bounds x="42" y="63" width="50" height="50" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Target_1_di" bpmnElement="Target_1">
<dc:Bounds x="142" y="70" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_1_di" bpmnElement="Flow_1">
<di:waypoint x="92" y="88" />
<di:waypoint x="142" y="88" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="Target_2_di" bpmnElement="Target_2">
<dc:Bounds x="142" y="180" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_2_di" bpmnElement="Flow_2">
<di:waypoint x="67" y="113" />
<di:waypoint x="67" y="198" />
<di:waypoint x="142" y="198" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

0 comments on commit 7d2faec

Please sign in to comment.