fix(modeling): correctly create connection replacement

Closes https://github.com/bpmn-io/bpmn-js/issues/1072
This commit is contained in:
Maciej Barelkowski 2019-07-02 13:28:34 +02:00 committed by merge-me[bot]
parent ca4e21224d
commit 9ee90ef089
3 changed files with 130 additions and 59 deletions

View File

@ -89,21 +89,18 @@ export default function ReplaceConnectionBehavior(eventBus, modeling, bpmnRules,
var context = event.context,
connection = context.connection,
source = context.newSource || connection.source,
target = context.newTarget || connection.target,
allowed,
replacement;
if (context.newTarget) {
allowed = bpmnRules.canConnect(connection.source, context.newTarget);
} else {
allowed = bpmnRules.canConnect(context.newSource, connection.target);
}
allowed = bpmnRules.canConnect(source, target);
if (!allowed || allowed.type === connection.type) {
return;
}
// temporarily connect old shapes with new connection
replacement = modeling.connect(connection.source, connection.target, {
replacement = modeling.connect(source, target, {
type: allowed.type,
waypoints: connection.waypoints.slice()
});

View File

@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd" id="_biH3sOTeEeS2YerRfpjPrw" exporter="camunda modeler" exporterVersion="2.6.0" targetNamespace="http://activiti.org/bpmn">
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="_biH3sOTeEeS2YerRfpjPrw" targetNamespace="http://activiti.org/bpmn" exporter="Camunda Modeler" exporterVersion="3.1.1" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd">
<bpmn2:collaboration id="_Collaboration_3">
<bpmn2:participant id="Participant_1" name="Pool" processRef="Process_1"/>
<bpmn2:participant id="Participant_2" name="Pool" processRef="Process_2"/>
<bpmn2:messageFlow id="MessageFlow_1" name="" sourceRef="Task_3" targetRef="Participant_1"/>
<bpmn2:messageFlow id="MessageFlow_4" name="" sourceRef="Participant_2" targetRef="StartEvent_1"/>
<bpmn2:messageFlow id="MessageFlow_5" name="" sourceRef="Task_2" targetRef="Task_4"/>
<bpmn2:messageFlow id="MessageFlow_3" name="" sourceRef="Task_1" targetRef="Participant_2"/>
<bpmn2:participant id="Participant_1" name="Pool" processRef="Process_1" />
<bpmn2:participant id="Participant_2" name="Pool" processRef="Process_2" />
<bpmn2:messageFlow id="MessageFlow_1" name="" sourceRef="Task_3" targetRef="Participant_1" />
<bpmn2:messageFlow id="MessageFlow_4" name="" sourceRef="Participant_2" targetRef="StartEvent_1" />
<bpmn2:messageFlow id="MessageFlow_5" name="" sourceRef="Task_2" targetRef="Task_4" />
<bpmn2:messageFlow id="MessageFlow_3" name="" sourceRef="Task_1" targetRef="Participant_2" />
<bpmn2:messageFlow id="MessageFlow_6" sourceRef="Participant_1" targetRef="Task_3" />
</bpmn2:collaboration>
<bpmn2:process id="Process_1" isExecutable="false">
<bpmn2:subProcess id="SubProcess_1">
@ -14,7 +15,7 @@
<bpmn2:task id="Task_1">
<bpmn2:outgoing>SequenceFlow_2</bpmn2:outgoing>
</bpmn2:task>
<bpmn2:sequenceFlow id="SequenceFlow_2" name="" sourceRef="Task_1" targetRef="EndEvent_1"/>
<bpmn2:sequenceFlow id="SequenceFlow_2" name="" sourceRef="Task_1" targetRef="EndEvent_1" />
<bpmn2:endEvent id="EndEvent_1">
<bpmn2:incoming>SequenceFlow_2</bpmn2:incoming>
</bpmn2:endEvent>
@ -23,100 +24,104 @@
<bpmn2:incoming>SequenceFlow_3</bpmn2:incoming>
<bpmn2:outgoing>SequenceFlow_1</bpmn2:outgoing>
</bpmn2:task>
<bpmn2:sequenceFlow id="SequenceFlow_1" name="" sourceRef="Task_2" targetRef="SubProcess_1"/>
<bpmn2:sequenceFlow id="SequenceFlow_1" name="" sourceRef="Task_2" targetRef="SubProcess_1" />
<bpmn2:startEvent id="StartEvent_1">
<bpmn2:outgoing>SequenceFlow_3</bpmn2:outgoing>
<bpmn2:messageEventDefinition id="_MessageEventDefinition_2"/>
<bpmn2:messageEventDefinition id="_MessageEventDefinition_2" />
</bpmn2:startEvent>
<bpmn2:sequenceFlow id="SequenceFlow_3" name="" sourceRef="StartEvent_1" targetRef="Task_2"/>
<bpmn2:sequenceFlow id="SequenceFlow_3" name="" sourceRef="StartEvent_1" targetRef="Task_2" />
</bpmn2:process>
<bpmn2:process id="Process_2" isExecutable="false">
<bpmn2:task id="Task_3"/>
<bpmn2:task id="Task_4"/>
<bpmn2:task id="Task_3" />
<bpmn2:task id="Task_4" />
</bpmn2:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="_Collaboration_3">
<bpmndi:BPMNShape id="_BPMNShape_Participant_3" bpmnElement="Participant_1" isHorizontal="true">
<dc:Bounds height="265.0" width="697.0" x="168.0" y="72.0"/>
<dc:Bounds x="168" y="72" width="697" height="265" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_SubProcess_3" bpmnElement="SubProcess_1" isExpanded="true">
<dc:Bounds height="205.0" width="248.0" x="576.0" y="96.0"/>
<dc:Bounds x="576" y="96" width="248" height="205" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_Task_3" bpmnElement="Task_1">
<dc:Bounds height="80.0" width="100.0" x="601.0" y="119.0"/>
<dc:Bounds x="601" y="119" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_Task_4" bpmnElement="Task_2">
<dc:Bounds height="80.0" width="100.0" x="360.0" y="159.0"/>
<dc:Bounds x="360" y="159" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_1" bpmnElement="SequenceFlow_1" sourceElement="_BPMNShape_Task_4" targetElement="_BPMNShape_SubProcess_3">
<di:waypoint xsi:type="dc:Point" x="460.0" y="198.0"/>
<di:waypoint xsi:type="dc:Point" x="576.0" y="198.0"/>
<di:waypoint x="460" y="198" />
<di:waypoint x="576" y="198" />
<bpmndi:BPMNLabel>
<dc:Bounds height="6.0" width="6.0" x="534.0" y="198.0"/>
<dc:Bounds x="534" y="198" width="6" height="6" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_3" bpmnElement="StartEvent_1">
<dc:Bounds height="36.0" width="36.0" x="240.0" y="181.0"/>
<dc:Bounds x="240" y="181" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds height="0.0" width="0.0" x="258.0" y="222.0"/>
<dc:Bounds x="258" y="222" width="0" height="0" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_EndEvent_3" bpmnElement="EndEvent_1">
<dc:Bounds height="36.0" width="36.0" x="768.0" y="141.0"/>
<dc:Bounds x="768" y="141" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds height="0.0" width="0.0" x="786.0" y="182.0"/>
<dc:Bounds x="786" y="182" width="0" height="0" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_2" bpmnElement="SequenceFlow_2" sourceElement="_BPMNShape_Task_3" targetElement="_BPMNShape_EndEvent_3">
<di:waypoint xsi:type="dc:Point" x="701.0" y="159.0"/>
<di:waypoint xsi:type="dc:Point" x="768.0" y="159.0"/>
<di:waypoint x="701" y="159" />
<di:waypoint x="768" y="159" />
<bpmndi:BPMNLabel>
<dc:Bounds height="6.0" width="6.0" x="723.0" y="159.0"/>
<dc:Bounds x="723" y="159" width="6" height="6" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_3" bpmnElement="SequenceFlow_3" sourceElement="_BPMNShape_StartEvent_3" targetElement="_BPMNShape_Task_4">
<di:waypoint xsi:type="dc:Point" x="276.0" y="199.0"/>
<di:waypoint xsi:type="dc:Point" x="360.0" y="199.0"/>
<di:waypoint x="276" y="199" />
<di:waypoint x="360" y="199" />
<bpmndi:BPMNLabel>
<dc:Bounds height="6.0" width="6.0" x="318.0" y="199.0"/>
<dc:Bounds x="318" y="199" width="6" height="6" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_Participant_4" bpmnElement="Participant_2" isHorizontal="true">
<dc:Bounds height="345.0" width="697.0" x="168.0" y="456.0"/>
<dc:Bounds x="168" y="456" width="697" height="345" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_Task_5" bpmnElement="Task_3">
<dc:Bounds height="80.0" width="100.0" x="708.0" y="489.0"/>
<dc:Bounds x="708" y="489" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="BPMNEdge_MessageFlow_1" bpmnElement="MessageFlow_1" sourceElement="_BPMNShape_Task_5" targetElement="_BPMNShape_Participant_3">
<di:waypoint xsi:type="dc:Point" x="758.0" y="489.0"/>
<di:waypoint xsi:type="dc:Point" x="758.0" y="413.0"/>
<di:waypoint xsi:type="dc:Point" x="758.0" y="413.0"/>
<di:waypoint xsi:type="dc:Point" x="758.0" y="336.0"/>
<di:waypoint x="758" y="489" />
<di:waypoint x="758" y="413" />
<di:waypoint x="758" y="413" />
<di:waypoint x="758" y="336" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="BPMNEdge_MessageFlow_4" bpmnElement="MessageFlow_4" sourceElement="_BPMNShape_Participant_4" targetElement="_BPMNShape_StartEvent_3">
<di:waypoint xsi:type="dc:Point" x="258.0" y="456.0"/>
<di:waypoint xsi:type="dc:Point" x="258.0" y="337.0"/>
<di:waypoint xsi:type="dc:Point" x="258.0" y="337.0"/>
<di:waypoint xsi:type="dc:Point" x="258.0" y="217.0"/>
<di:waypoint x="258" y="456" />
<di:waypoint x="258" y="337" />
<di:waypoint x="258" y="337" />
<di:waypoint x="258" y="217" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="BPMNEdge_MessageFlow_5" bpmnElement="MessageFlow_5" sourceElement="_BPMNShape_Task_4" targetElement="_BPMNShape_Task_7">
<di:waypoint xsi:type="dc:Point" x="410.0" y="239.0"/>
<di:waypoint xsi:type="dc:Point" x="410.0" y="390.0"/>
<di:waypoint xsi:type="dc:Point" x="554.0" y="390.0"/>
<di:waypoint xsi:type="dc:Point" x="554.0" y="489.0"/>
<di:waypoint x="410" y="239" />
<di:waypoint x="410" y="390" />
<di:waypoint x="554" y="390" />
<di:waypoint x="554" y="489" />
<bpmndi:BPMNLabel>
<dc:Bounds height="6.0" width="6.0" x="407.0" y="348.0"/>
<dc:Bounds x="407" y="348" width="6" height="6" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="BPMNEdge_MessageFlow_3" bpmnElement="MessageFlow_3" sourceElement="_BPMNShape_Task_3" targetElement="_BPMNShape_Participant_4">
<di:waypoint xsi:type="dc:Point" x="651.0" y="199.0"/>
<di:waypoint xsi:type="dc:Point" x="651.0" y="327.0"/>
<di:waypoint xsi:type="dc:Point" x="651.0" y="327.0"/>
<di:waypoint xsi:type="dc:Point" x="651.0" y="456.0"/>
<di:waypoint x="651" y="199" />
<di:waypoint x="651" y="327" />
<di:waypoint x="651" y="327" />
<di:waypoint x="651" y="456" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_Task_7" bpmnElement="Task_4">
<dc:Bounds height="80.0" width="100.0" x="504.0" y="489.0"/>
<dc:Bounds x="504" y="489" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="MessageFlow_0xafli8_di" bpmnElement="MessageFlow_6">
<di:waypoint x="729" y="337" />
<di:waypoint x="729" y="489" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn2:definitions>
</bpmn2:definitions>

View File

@ -11,6 +11,10 @@ import {
find
} from 'min-dash';
import {
getMid
} from 'diagram-js/lib/layout/LayoutUtil';
import modelingModule from 'lib/features/modeling';
import moveModule from 'diagram-js/lib/features/move';
import coreModule from 'lib/core';
@ -553,4 +557,69 @@ describe('features/modeling - replace connection', function() {
});
});
describe('reconnecting to create loops', function() {
var processDiagramXML = require('./ReplaceConnectionBehavior.message-sequence-flow.bpmn');
beforeEach(bootstrapModeler(processDiagramXML, {
modules: testModules
}));
it('should set correct parents when reconnecting message flow start to task',
inject(function(elementRegistry, modeling) {
// given
var task = elementRegistry.get('Task_4'),
connection = elementRegistry.get('MessageFlow_5');
// when
modeling.reconnectStart(connection, task, getMid(task));
// then
expect(connection.parent).to.not.exist;
expect(task.outgoing[0]).to.exist;
expect(task.outgoing[0]).to.have.property('parent', task.parent);
})
);
it('should set correct parents when reconnecting message flow end to task',
inject(function(elementRegistry, modeling) {
// given
var task = elementRegistry.get('Task_3'),
connection = elementRegistry.get('MessageFlow_1');
// when
modeling.reconnectEnd(connection, task, getMid(task));
// then
expect(connection.parent).to.not.exist;
expect(task.outgoing[0]).to.exist;
expect(task.outgoing[0]).to.have.property('parent', task.parent);
})
);
it('should set correct parents when reconnecting message flow from participant to task',
inject(function(elementRegistry, modeling) {
// given
var task = elementRegistry.get('Task_3'),
connection = elementRegistry.get('MessageFlow_6');
// when
modeling.reconnectStart(connection, task, getMid(task));
// then
expect(connection.parent).to.not.exist;
expect(task.outgoing[1]).to.exist;
expect(task.outgoing[1]).to.have.property('parent', task.parent);
})
);
});
});