Repository: bpmn-io/bpmn-js (JavaScript)

Issue:
Copy and paste does not copy process
<!--

Thanks for filing this bug report!

Please take your time to provide the relevant context to your bug report. This helps us to process it and get it fixed, eventually.

-->


__Describe the Bug__

Copying a participant should copy the referenced process, similar to how we copy the `bpmn:Group#categoryRef`. Right now the process will not even be considered on copy. As a result meta-data attached to the linked process cannot be copied:

```xml
  <bpmn:collaboration id="Collaboration_0gj24es">
    <bpmn:participant id="Participant_1qmphg2" processRef="Process_0kpcz3a" />
  </bpmn:collaboration>
  <bpmn:process id="Process_0kpcz3a" isExecutable="false">
    <bpmn:extensionElements>
      <camunda:executionListener class="asddas" event="start" />
    </bpmn:extensionElements>
  </bpmn:process>
```


__Steps to Reproduce__

* Open [test diagram](https://github.com/bpmn-io/bpmn-js/files/3491301/test.bpmn.txt)
* The process linked to the participant contains execution related meta-data as shown above
* Copy participant
* Paste participant
* __See that the execution related meta-data is not copied__


__Expected Behavior__

* [ ] Processes copy and paste with their participants, preserving custom meta-data

__Environment__

 - Browser: Any
 - OS: Any
 - Library version: v3, v4, v5.0.0-beta.2


Discussion:
Not a regression, this never worked :wolf:.
Closed via https://github.com/bpmn-io/bpmn-js/pull/1183.



Patch:
diff --git a/lib/features/copy-paste/BpmnCopyPaste.js b/lib/features/copy-paste/BpmnCopyPaste.js
index 0060df80b2..39f3403f7d 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;
-
-    if (is(parent, 'bpmn:Participant') &&
-      is(property, 'bpmn:Process') &&
-      propertyName === 'processRef') {
-      return bpmnFactory.create('bpmn:Process');
+        propertyName = context.propertyName,
+        bpmnProcess;
+
+    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);
     }
   });
 


Test patch:
diff --git a/test/spec/features/copy-paste/BpmnCopyPasteSpec.js b/test/spec/features/copy-paste/BpmnCopyPasteSpec.js
index a54dbc32eb..398fea4f15 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 862bac0698..7fd8b7e236 100644
--- a/test/spec/features/copy-paste/data-associations.bpmn
+++ b/test/spec/features/copy-paste/data-associations.bpmn
@@ -1,10 +1,13 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.1.2">
+<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.3.2">
   <bpmn:collaboration id="Collaboration_1">
     <bpmn:participant id="Participant_Output" processRef="Process_Output" />
     <bpmn:participant id="Participant_Input" processRef="Process_Input" />
   </bpmn:collaboration>
-  <bpmn:process id="Process_Output" isExecutable="false">
+  <bpmn:process id="Process_Output" isExecutable="true">
+    <bpmn:extensionElements>
+      <camunda:executionListener class="Foo" event="start" />
+    </bpmn:extensionElements>
     <bpmn:task id="Task_1">
       <bpmn:dataOutputAssociation id="DataOutputAssociation_1">
         <bpmn:targetRef>DataStoreReference_1</bpmn:targetRef>
@@ -12,7 +15,10 @@
     </bpmn:task>
     <bpmn:dataStoreReference id="DataStoreReference_1" />
   </bpmn:process>
-  <bpmn:process id="Process_Input" isExecutable="false">
+  <bpmn:process id="Process_Input" isExecutable="true">
+    <bpmn:extensionElements>
+      <camunda:executionListener class="Foo" event="start" />
+    </bpmn:extensionElements>
     <bpmn:dataStoreReference id="DataStoreReference_2" />
     <bpmn:task id="Task_2">
       <bpmn:property id="Property_0l7g57i" name="__targetRef_placeholder" />
@@ -24,37 +30,37 @@
   </bpmn:process>
   <bpmndi:BPMNDiagram id="BPMNDiagram_1">
     <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_1">
-      <bpmndi:BPMNShape id="Participant_166hvof_di" bpmnElement="Participant_Output">
-        <dc:Bounds x="302" y="60" width="600" height="250" />
+      <bpmndi:BPMNShape id="Participant_166hvof_di" bpmnElement="Participant_Output" isHorizontal="true">
+        <dc:Bounds x="152" y="60" width="600" height="250" />
       </bpmndi:BPMNShape>
       <bpmndi:BPMNShape id="Task_17elucr_di" bpmnElement="Task_1">
-        <dc:Bounds x="416" y="100" width="100" height="80" />
+        <dc:Bounds x="266" y="100" width="100" height="80" />
       </bpmndi:BPMNShape>
       <bpmndi:BPMNShape id="DataStoreReference_1muhdww_di" bpmnElement="DataStoreReference_1">
-        <dc:Bounds x="746" y="216" width="50" height="50" />
+        <dc:Bounds x="596" y="216" width="50" height="50" />
         <bpmndi:BPMNLabel>
           <dc:Bounds x="726" y="266" width="90" height="20" />
         </bpmndi:BPMNLabel>
       </bpmndi:BPMNShape>
       <bpmndi:BPMNEdge id="DataOutputAssociation_0bncpb8_di" bpmnElement="DataOutputAssociation_1">
-        <di:waypoint x="516" y="157" />
-        <di:waypoint x="746" y="233" />
+        <di:waypoint x="366" y="157" />
+        <di:waypoint x="596" y="233" />
       </bpmndi:BPMNEdge>
-      <bpmndi:BPMNShape id="Participant_1duzt5k_di" bpmnElement="Participant_Input">
-        <dc:Bounds x="302" y="354" width="600" height="250" />
+      <bpmndi:BPMNShape id="Participant_1duzt5k_di" bpmnElement="Participant_Input" isHorizontal="true">
+        <dc:Bounds x="152" y="354" width="600" height="250" />
       </bpmndi:BPMNShape>
       <bpmndi:BPMNShape id="DataStoreReference_0q26vzn_di" bpmnElement="DataStoreReference_2">
-        <dc:Bounds x="758" y="491" width="50" height="50" />
+        <dc:Bounds x="608" y="491" width="50" height="50" />
         <bpmndi:BPMNLabel>
           <dc:Bounds x="738" y="541" width="90" height="20" />
         </bpmndi:BPMNLabel>
       </bpmndi:BPMNShape>
       <bpmndi:BPMNShape id="Task_10pzi8y_di" bpmnElement="Task_2">
-        <dc:Bounds x="426" y="375" width="100" height="80" />
+        <dc:Bounds x="276" y="375" width="100" height="80" />
       </bpmndi:BPMNShape>
       <bpmndi:BPMNEdge id="DataInputAssociation_1sf5ecg_di" bpmnElement="DataInputAssociation_1">
-        <di:waypoint x="758" y="508" />
-        <di:waypoint x="526" y="431" />
+        <di:waypoint x="608" y="508" />
+        <di:waypoint x="376" y="431" />
       </bpmndi:BPMNEdge>
     </bpmndi:BPMNPlane>
   </bpmndi:BPMNDiagram>