From 2f2816a0d4e53b82a360faa10e4ba8a8dfb40548 Mon Sep 17 00:00:00 2001 From: Abdul Ahad Date: Wed, 14 Aug 2024 16:56:31 +0200 Subject: [PATCH] fix: compensation activity paste now results simple activity Closes #2070 --- lib/features/replace/BpmnReplace.js | 2 +- lib/features/rules/BpmnRules.js | 12 +++++++++++- lib/util/DiUtil.js | 9 +++++++++ test/spec/features/replace/BpmnReplaceSpec.js | 4 ++-- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/features/replace/BpmnReplace.js b/lib/features/replace/BpmnReplace.js index 8449614664..6ca5e597cd 100644 --- a/lib/features/replace/BpmnReplace.js +++ b/lib/features/replace/BpmnReplace.js @@ -211,7 +211,7 @@ export default function BpmnReplace( } if (propertyName === 'isForCompensation') { - return !isEventSubProcess(newBusinessObject); + return false; } return true; diff --git a/lib/features/rules/BpmnRules.js b/lib/features/rules/BpmnRules.js index 42979c92c9..0dc115d8b1 100644 --- a/lib/features/rules/BpmnRules.js +++ b/lib/features/rules/BpmnRules.js @@ -27,7 +27,8 @@ import { isInterrupting, hasErrorEventDefinition, hasEscalationEventDefinition, - hasCompensateEventDefinition + hasCompensateEventDefinition, + isCompensationActivityElement } from '../../util/DiUtil'; import RuleProvider from 'diagram-js/lib/features/rules/RuleProvider'; @@ -888,6 +889,15 @@ function canReplace(elements, target, position) { }); } } + + if (is(element,'bpmn:Task') && canDrop(element, target)) { + if (isCompensationActivityElement(element)) { + canExecute.replacements.push({ + oldElementId: element.id, + newElementType: 'bpmn:Task' + }); + } + } } if (!is(target, 'bpmn:Transaction')) { diff --git a/lib/util/DiUtil.js b/lib/util/DiUtil.js index c2731ea518..aa5efc539e 100644 --- a/lib/util/DiUtil.js +++ b/lib/util/DiUtil.js @@ -120,3 +120,12 @@ export function hasEscalationEventDefinition(element) { export function hasCompensateEventDefinition(element) { return hasEventDefinition(element, 'bpmn:CompensateEventDefinition'); } + +/** + * @param {Element} element + * + * @return {boolean} + */ +export function isCompensationActivityElement(element) { + return getBusinessObject(element).isForCompensation; +} \ No newline at end of file diff --git a/test/spec/features/replace/BpmnReplaceSpec.js b/test/spec/features/replace/BpmnReplaceSpec.js index 88ee7053c6..c478ed5e13 100644 --- a/test/spec/features/replace/BpmnReplaceSpec.js +++ b/test/spec/features/replace/BpmnReplaceSpec.js @@ -1438,7 +1438,7 @@ describe('features/replace - bpmn replace', function() { })); - it('should keep isForCompensation attr', inject(function(elementRegistry, bpmnReplace) { + it('should not keep isForCompensation attr', inject(function(elementRegistry, bpmnReplace) { // given var task = elementRegistry.get('Task_1'); @@ -1450,7 +1450,7 @@ describe('features/replace - bpmn replace', function() { var newElement = bpmnReplace.replaceElement(task, newElementData); // then - expect(newElement.businessObject.isForCompensation).to.be.true; + expect(newElement.businessObject.isForCompensation).to.be.false; })); });