From adf34b7742370a36c50d2d1c1b96af78521b2662 Mon Sep 17 00:00:00 2001 From: Abdul Ahad Date: Mon, 2 Sep 2024 14:23:50 +0200 Subject: [PATCH 1/2] fix: no no-implicit-end error on compensation activity Closes #140 --- rules/helper.js | 29 +++++++++ rules/no-implicit-end.js | 39 +++++++++++- test/rules/no-implicit-end/valid.bpmn | 88 ++++++++++++++++++++++----- 3 files changed, 139 insertions(+), 17 deletions(-) diff --git a/rules/helper.js b/rules/helper.js index 6ceb51f..5b46f46 100644 --- a/rules/helper.js +++ b/rules/helper.js @@ -28,4 +28,33 @@ function disallowNodeType(type) { } +/** + * 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; module.exports.disallowNodeType = disallowNodeType; \ No newline at end of file diff --git a/rules/no-implicit-end.js b/rules/no-implicit-end.js index 9245f8c..29af042 100644 --- a/rules/no-implicit-end.js +++ b/rules/no-implicit-end.js @@ -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). @@ -17,6 +20,30 @@ module.exports = function() { ); } + function isCompensationEvent(node) { + const eventDefinitions = node.eventDefinitions || []; + + return eventDefinitions.length && eventDefinitions.every( + definition => is(definition, 'bpmn:CompensateEventDefinition') + ); + } + + function isConnectedToActivity(node) { + const parent = findParent(node, 'bpmn:Process'); + const artifacts = parent.artifacts || []; + return artifacts.some((element) => { + return ( + is(element, 'bpmn:Association') && + is(element.sourceRef, 'bpmn:BoundaryEvent') && + element.sourceRef.id === node.id + ); + }); + } + + function isForCompensation(node) { + return node.isForCompensation; + } + function isImplicitEnd(node) { const outgoing = node.outgoing || []; @@ -32,6 +59,16 @@ module.exports = function() { return false; } + if (is(node, 'bpmn:BoundaryEvent')) { + if (isCompensationEvent(node) && isConnectedToActivity(node)) { + return false; + } + } + + if (is(node, 'bpmn:Task') && isForCompensation(node)) { + return false; + } + return outgoing.length === 0; } @@ -47,4 +84,4 @@ module.exports = function() { } return { check }; -}; +}; \ No newline at end of file diff --git a/test/rules/no-implicit-end/valid.bpmn b/test/rules/no-implicit-end/valid.bpmn index 6863e2d..60109f4 100644 --- a/test/rules/no-implicit-end/valid.bpmn +++ b/test/rules/no-implicit-end/valid.bpmn @@ -1,5 +1,5 @@ - + Flow_1w3680k @@ -41,7 +41,24 @@ + + Flow_16zubsb + Flow_044vrdf + + + + + + + Flow_16zubsb + + + + Flow_044vrdf + + + @@ -85,36 +102,64 @@ - - + + + + + + + + + + - + + + + + + + - - + + - + - - - - - + + + + - - - - + + + + + + + + + + + + + + + + + + + @@ -131,6 +176,17 @@ + + + + + + + + + + + From a689cea8f737819803b83c9bbbdb612ee118da0c Mon Sep 17 00:00:00 2001 From: Philipp Fromme Date: Fri, 6 Sep 2024 13:21:48 +0200 Subject: [PATCH 2/2] chore: code style --- rules/helper.js | 5 +++-- rules/no-implicit-end.js | 22 ++++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/rules/helper.js b/rules/helper.js index 5b46f46..54b9835 100644 --- a/rules/helper.js +++ b/rules/helper.js @@ -28,6 +28,8 @@ function disallowNodeType(type) { } +module.exports.disallowNodeType = disallowNodeType; + /** * Find a parent for the given element * @@ -56,5 +58,4 @@ function findParent(node, type) { return findParent(parent, type); } -module.exports.findParent = findParent; -module.exports.disallowNodeType = disallowNodeType; \ No newline at end of file +module.exports.findParent = findParent; \ No newline at end of file diff --git a/rules/no-implicit-end.js b/rules/no-implicit-end.js index 29af042..3f6d74d 100644 --- a/rules/no-implicit-end.js +++ b/rules/no-implicit-end.js @@ -28,15 +28,19 @@ module.exports = function() { ); } - function isConnectedToActivity(node) { + function hasCompensationActivity(node) { const parent = findParent(node, 'bpmn:Process'); + const artifacts = parent.artifacts || []; + return artifacts.some((element) => { - return ( - is(element, 'bpmn:Association') && - is(element.sourceRef, 'bpmn:BoundaryEvent') && - element.sourceRef.id === node.id - ); + if (!is(element, 'bpmn:Association')) { + return false; + } + + const source = element.sourceRef; + + return source.id === node.id; }); } @@ -59,10 +63,8 @@ module.exports = function() { return false; } - if (is(node, 'bpmn:BoundaryEvent')) { - if (isCompensationEvent(node) && isConnectedToActivity(node)) { - return false; - } + if (is(node, 'bpmn:BoundaryEvent') && isCompensationEvent(node) && hasCompensationActivity(node)) { + return false; } if (is(node, 'bpmn:Task') && isForCompensation(node)) {