From 2f001e1f4af156e3ae0a444a3770b144d433226b Mon Sep 17 00:00:00 2001 From: Philipp Fromme Date: Thu, 5 Sep 2019 21:37:41 +0200 Subject: [PATCH] feat(copy-paste): copy process properties Clone the linked process when copying a participant. This ensures that properties attached to the process are not getting lost. Closes #1161 --- lib/features/copy-paste/BpmnCopyPaste.js | 16 ++++++--- .../features/copy-paste/BpmnCopyPasteSpec.js | 21 +++++++++-- .../copy-paste/data-associations.bpmn | 36 +++++++++++-------- 3 files changed, 50 insertions(+), 23 deletions(-) diff --git a/lib/features/copy-paste/BpmnCopyPaste.js b/lib/features/copy-paste/BpmnCopyPaste.js index 0060df80..39f3403f 100644 --- a/lib/features/copy-paste/BpmnCopyPaste.js +++ b/lib/features/copy-paste/BpmnCopyPaste.js @@ -73,12 +73,18 @@ export default function BpmnCopyPaste(bpmnFactory, eventBus, moddleCopy) { eventBus.on('moddleCopy.canCopyProperty', function(context) { var parent = context.parent, property = context.property, - propertyName = context.propertyName; + propertyName = context.propertyName, + bpmnProcess; - if (is(parent, 'bpmn:Participant') && - is(property, 'bpmn:Process') && - propertyName === 'processRef') { - return bpmnFactory.create('bpmn:Process'); + if ( + propertyName === 'processRef' && + is(parent, 'bpmn:Participant') && + is(property, 'bpmn:Process') + ) { + bpmnProcess = bpmnFactory.create('bpmn:Process'); + + // return copy of process + return moddleCopy.copyElement(property, bpmnProcess); } }); diff --git a/test/spec/features/copy-paste/BpmnCopyPasteSpec.js b/test/spec/features/copy-paste/BpmnCopyPasteSpec.js index a54dbc32..398fea4f 100644 --- a/test/spec/features/copy-paste/BpmnCopyPasteSpec.js +++ b/test/spec/features/copy-paste/BpmnCopyPasteSpec.js @@ -9,6 +9,8 @@ import copyPasteModule from 'diagram-js/lib/features/copy-paste'; import coreModule from 'lib/core'; import modelingModule from 'lib/features/modeling'; +import camundaPackage from 'camunda-bpmn-moddle/resources/camunda.json'; + import { find, forEach, @@ -509,7 +511,12 @@ describe('features/copy-paste', function() { describe('participants', function() { - beforeEach(bootstrapModeler(collaborationAssociationsXML, { modules: testModules })); + beforeEach(bootstrapModeler(collaborationAssociationsXML, { + modules: testModules, + moddleExtensions: { + camunda: camundaPackage + } + })); it('should copy process when copying participant', inject( @@ -543,6 +550,16 @@ describe('features/copy-paste', function() { expect(participantBo.processRef).not.to.equal(participantInputBo.processRef); expect(participantBo.processRef).not.to.equal(participantOutputBo.processRef); + + expect(participantBo.processRef.isExecutable).to.be.true; + + expect(participantBo.processRef.extensionElements.values).to.have.length(1); + + var executionListener = participantBo.processRef.extensionElements.values[0]; + + expect(executionListener.$type).to.equal('camunda:ExecutionListener'); + expect(executionListener.class).to.equal('Foo'); + expect(executionListener.event).to.equal('start'); }); expect(getBusinessObject(participants[0]).processRef) @@ -563,8 +580,6 @@ describe('features/copy-paste', function() { describe('nested properties', function() { - var camundaPackage = require('camunda-bpmn-moddle/resources/camunda.json'); - beforeEach(bootstrapModeler(copyPropertiesXML, { modules: testModules, moddleExtensions: { diff --git a/test/spec/features/copy-paste/data-associations.bpmn b/test/spec/features/copy-paste/data-associations.bpmn index 862bac06..7fd8b7e2 100644 --- a/test/spec/features/copy-paste/data-associations.bpmn +++ b/test/spec/features/copy-paste/data-associations.bpmn @@ -1,10 +1,13 @@ - + - + + + + DataStoreReference_1 @@ -12,7 +15,10 @@ - + + + + @@ -24,37 +30,37 @@ - - + + - + - + - - + + - - + + - + - + - - + +