Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: no no-implicit-end error on compensation activity #144

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion rules/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,34 @@ function disallowNodeType(type) {

}

module.exports.disallowNodeType = disallowNodeType;
module.exports.disallowNodeType = disallowNodeType;

/**
* Find a parent for the given element
*
* @param {ModdleElement} node
*
* @param {String} type
*
* @return {ModdleElement} element
*/

function findParent(node, type) {
if (!node) {
return null;
}

const parent = node.$parent;

if (!parent) {
return node;
}

if (is(parent, type)) {
return parent;
}

return findParent(parent, type);
}

module.exports.findParent = findParent;
41 changes: 40 additions & 1 deletion rules/no-implicit-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const {
isAny
} = require('bpmnlint-utils');

const {
findParent
} = require('./helper');

/**
* A rule that checks that an element is not an implicit end (token sink).
Expand All @@ -17,6 +20,34 @@ module.exports = function() {
);
}

function isCompensationEvent(node) {
const eventDefinitions = node.eventDefinitions || [];

return eventDefinitions.length && eventDefinitions.every(
definition => is(definition, 'bpmn:CompensateEventDefinition')
);
}

function hasCompensationActivity(node) {
const parent = findParent(node, 'bpmn:Process');

const artifacts = parent.artifacts || [];

return artifacts.some((element) => {
if (!is(element, 'bpmn:Association')) {
return false;
}

const source = element.sourceRef;

return source.id === node.id;
});
}

function isForCompensation(node) {
return node.isForCompensation;
}

function isImplicitEnd(node) {
const outgoing = node.outgoing || [];

Expand All @@ -32,6 +63,14 @@ module.exports = function() {
return false;
}

if (is(node, 'bpmn:BoundaryEvent') && isCompensationEvent(node) && hasCompensationActivity(node)) {
return false;
}

if (is(node, 'bpmn:Task') && isForCompensation(node)) {
return false;
}

return outgoing.length === 0;
}

Expand All @@ -47,4 +86,4 @@ module.exports = function() {
}

return { check };
};
};
88 changes: 72 additions & 16 deletions test/rules/no-implicit-end/valid.bpmn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="sid-38422fae-e03e-43a3-bef4-bd33b32041b2" targetNamespace="http://bpmn.io/bpmn" exporter="Camunda Modeler" exporterVersion="5.11.0">
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="sid-38422fae-e03e-43a3-bef4-bd33b32041b2" targetNamespace="http://bpmn.io/bpmn" exporter="Camunda Modeler" exporterVersion="5.25.0">
<process id="PROCESS" isExecutable="false">
<endEvent id="END_EVENT" name="END_EVENT">
<incoming>Flow_1w3680k</incoming>
Expand Down Expand Up @@ -41,7 +41,24 @@
<linkEventDefinition id="LinkEventDefinition_1eotqp9" name="" />
</intermediateCatchEvent>
<sequenceFlow id="Flow_0az7c7m" sourceRef="LINK_CATCH" targetRef="INTERMEDIATE_EVENT" />
<task id="Activity_157mlpt" name="TASK">
<incoming>Flow_16zubsb</incoming>
<outgoing>Flow_044vrdf</outgoing>
</task>
<boundaryEvent id="COMPENSATION_ACTIVITY_EVENT" name="COMPENSATION ACTIVITY EVENT" attachedToRef="Activity_157mlpt">
<compensateEventDefinition id="CompensateEventDefinition_0gqzw6g" />
</boundaryEvent>
<task id="COMPENSATION_ACTIVITY" name="COMPENSATION ACTIVITY" isForCompensation="true" />
<startEvent id="Event_0q72fbq" name="START_EVENT">
<outgoing>Flow_16zubsb</outgoing>
</startEvent>
<sequenceFlow id="Flow_16zubsb" sourceRef="Event_0q72fbq" targetRef="Activity_157mlpt" />
<endEvent id="Event_109rdfb" name="END_EVENT">
<incoming>Flow_044vrdf</incoming>
</endEvent>
<sequenceFlow id="Flow_044vrdf" sourceRef="Activity_157mlpt" targetRef="Event_109rdfb" />
<group id="Group_14ev8gw" />
<association id="Association_1ixehz7" associationDirection="One" sourceRef="COMPENSATION_ACTIVITY_EVENT" targetRef="COMPENSATION_ACTIVITY" />
</process>
<bpmndi:BPMNDiagram id="BpmnDiagram_1">
<bpmndi:BPMNPlane id="BpmnPlane_1" bpmnElement="PROCESS">
Expand Down Expand Up @@ -85,36 +102,64 @@
<omgdc:Bounds x="564" y="145" width="73" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1mfo1h4_di" bpmnElement="LINK_CATCH">
<omgdc:Bounds x="362" y="122" width="36" height="36" />
<bpmndi:BPMNShape id="Activity_157mlpt_di" bpmnElement="Activity_157mlpt">
<omgdc:Bounds x="630" y="540" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="COMPENSATION_ACTIVITY_di" bpmnElement="COMPENSATION_ACTIVITY">
<omgdc:Bounds x="770" y="660" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0q72fbq_di" bpmnElement="Event_0q72fbq">
<omgdc:Bounds x="522" y="562" width="36" height="36" />
<bpmndi:BPMNLabel>
<omgdc:Bounds x="346" y="98" width="68" height="14" />
<omgdc:Bounds x="501" y="605" width="78" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_109rdfb_di" bpmnElement="Event_109rdfb">
<omgdc:Bounds x="802" y="562" width="36" height="36" />
<bpmndi:BPMNLabel>
<omgdc:Bounds x="787" y="605" width="67" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0lxy7o7_di" bpmnElement="EVENT_SUB" isExpanded="true">
<omgdc:Bounds x="940" y="90" width="350" height="200" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0nahpgz_di" bpmnElement="BOUNDARY">
<omgdc:Bounds x="302" y="322" width="36" height="36" />
<bpmndi:BPMNShape id="Event_1mfo1h4_di" bpmnElement="LINK_CATCH">
<omgdc:Bounds x="362" y="122" width="36" height="36" />
<bpmndi:BPMNLabel>
<omgdc:Bounds x="289" y="365" width="63" height="14" />
<omgdc:Bounds x="346" y="98" width="68" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_04fxx9j_di" bpmnElement="Flow_04fxx9j">
<di:waypoint x="338" y="340" />
<di:waypoint x="358" y="340" />
<di:waypoint x="358" y="450" />
<di:waypoint x="295" y="450" />
<bpmndi:BPMNEdge id="Association_1ixehz7_di" bpmnElement="Association_1ixehz7">
<di:waypoint x="700" y="638" />
<di:waypoint x="700" y="700" />
<di:waypoint x="770" y="700" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0az7c7m_di" bpmnElement="Flow_0az7c7m">
<di:waypoint x="380" y="158" />
<di:waypoint x="380" y="230" />
<di:waypoint x="288" y="230" />
<bpmndi:BPMNShape id="Event_1gmxxzr_di" bpmnElement="COMPENSATION_ACTIVITY_EVENT">
<omgdc:Bounds x="682" y="602" width="36" height="36" />
<bpmndi:BPMNLabel>
<omgdc:Bounds x="655" y="645" width="90" height="27" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_16zubsb_di" bpmnElement="Flow_16zubsb">
<di:waypoint x="558" y="580" />
<di:waypoint x="630" y="580" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_044vrdf_di" bpmnElement="Flow_044vrdf">
<di:waypoint x="730" y="580" />
<di:waypoint x="802" y="580" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="Group_14ev8gw_di" bpmnElement="Group_14ev8gw">
<omgdc:Bounds x="560" y="190" width="300" height="300" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0nahpgz_di" bpmnElement="BOUNDARY">
<omgdc:Bounds x="302" y="322" width="36" height="36" />
<bpmndi:BPMNLabel>
<omgdc:Bounds x="289" y="365" width="63" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_1m6hogu_di" bpmnElement="Flow_1m6hogu">
<di:waypoint x="270" y="158" />
<di:waypoint x="270" y="212" />
Expand All @@ -131,6 +176,17 @@
<di:waypoint x="270" y="475" />
<di:waypoint x="270" y="532" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_04fxx9j_di" bpmnElement="Flow_04fxx9j">
<di:waypoint x="338" y="340" />
<di:waypoint x="358" y="340" />
<di:waypoint x="358" y="450" />
<di:waypoint x="295" y="450" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0az7c7m_di" bpmnElement="Flow_0az7c7m">
<di:waypoint x="380" y="158" />
<di:waypoint x="380" y="230" />
<di:waypoint x="288" y="230" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
Loading