From d55e3afe3540656154874876a2d6d8b44059d00f Mon Sep 17 00:00:00 2001 From: Oguz Eroglu Date: Fri, 20 Sep 2019 16:12:59 +0200 Subject: [PATCH] fix(copy-paste): copy attacher properties Closes #1190 --- lib/features/copy-paste/BpmnCopyPaste.js | 15 +++++++-- .../features/copy-paste/BpmnCopyPasteSpec.js | 32 +++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/lib/features/copy-paste/BpmnCopyPaste.js b/lib/features/copy-paste/BpmnCopyPaste.js index 0060df80..c5e71d43 100644 --- a/lib/features/copy-paste/BpmnCopyPaste.js +++ b/lib/features/copy-paste/BpmnCopyPaste.js @@ -84,17 +84,26 @@ export default function BpmnCopyPaste(bpmnFactory, eventBus, moddleCopy) { var references; - function resolveReferences(descriptor) { + function resolveReferences(descriptor, cache) { var businessObject = getBusinessObject(descriptor); // default sequence flows if (descriptor.default) { + + // relationship cannot be resolved immediately references[ descriptor.default ] = { element: businessObject, property: 'default' }; } + // boundary events + if (descriptor.host) { + + // relationship can be resolved immediately + getBusinessObject(descriptor).attachedToRef = getBusinessObject(cache[ descriptor.host ]); + } + references = omit(references, reduce(references, function(array, reference, key) { var element = reference.element, property = reference.property; @@ -134,7 +143,7 @@ export default function BpmnCopyPaste(bpmnFactory, eventBus, moddleCopy) { ); // resolve references e.g. default sequence flow - resolveReferences(descriptor); + resolveReferences(descriptor, cache); copyProperties(descriptor, newBusinessObject, [ 'isExpanded', @@ -157,4 +166,4 @@ BpmnCopyPaste.$inject = [ function isLabel(element) { return !!element.labelTarget; -} \ No newline at end of file +} diff --git a/test/spec/features/copy-paste/BpmnCopyPasteSpec.js b/test/spec/features/copy-paste/BpmnCopyPasteSpec.js index a54dbc32..b30594e6 100644 --- a/test/spec/features/copy-paste/BpmnCopyPasteSpec.js +++ b/test/spec/features/copy-paste/BpmnCopyPasteSpec.js @@ -167,6 +167,38 @@ describe('features/copy-paste', function() { ); + it('should copy attacher properties', inject(function(canvas, copyPaste, elementRegistry) { + + // given + var task = elementRegistry.get('Task_1'), + boundaryEvent = elementRegistry.get('BoundaryEvent_1'), + rootElement = canvas.getRootElement(); + + // when + copyPaste.copy([ task, boundaryEvent ]); + + var elements = copyPaste.paste({ + element: rootElement, + point: { + x: 1000, + y: 1000 + } + }); + + // then + task = find(elements, function(element) { + return is(element, 'bpmn:Task'); + }); + + boundaryEvent = find(elements, function(element) { + return is(element, 'bpmn:BoundaryEvent'); + }); + + // then + expect(getBusinessObject(boundaryEvent).attachedToRef).to.equal(getBusinessObject(task)); + })); + + it('should copy loop characteristics porperties', inject(function(canvas, copyPaste, elementRegistry, modeling) {