feat(modeling/BpmnUpdater): update existing (source/target)Element in di

Closes #620
This commit is contained in:
pedesen 2016-10-28 17:42:42 +02:00 committed by Nico Rehwaldt
parent 772112a646
commit 2c7aad5e0b
3 changed files with 195 additions and 0 deletions

View File

@ -372,6 +372,21 @@ BpmnUpdater.prototype.updateFlowNodeRefs = function(businessObject, newContainme
}
};
// update existing sourceElement and targetElement di information
BpmnUpdater.prototype.updateDiConnection = function(di, newSource, newTarget) {
if (di.sourceElement && di.sourceElement.bpmnElement !== newSource) {
di.sourceElement = newSource && newSource.di;
}
if (di.targetElement && di.targetElement.bpmnElement !== newTarget) {
di.targetElement = newTarget && newTarget.di;
}
};
BpmnUpdater.prototype.updateDiParent = function(di, parentDi) {
if (parentDi && !is(parentDi, 'bpmndi:BPMNPlane')) {
@ -636,6 +651,8 @@ BpmnUpdater.prototype.updateConnection = function(context) {
}
this.updateConnectionWaypoints(connection);
this.updateDiConnection(businessObject.di, newSource, newTarget);
};

View File

@ -0,0 +1,99 @@
<?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="1.4.0-nightly">
<bpmn:process id="Process_1" isExecutable="false">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>SequenceFlow_1</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="SequenceFlow_1" sourceRef="StartEvent_1" targetRef="Task_1" />
<bpmn:endEvent id="EndEvent_1">
<bpmn:incoming>SequenceFlow_2</bpmn:incoming>
</bpmn:endEvent>
<bpmn:task id="Task_1">
<bpmn:incoming>SequenceFlow_1</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_2</bpmn:outgoing>
</bpmn:task>
<bpmn:sequenceFlow id="SequenceFlow_2" sourceRef="Task_1" targetRef="EndEvent_1" />
<bpmn:startEvent id="StartEvent_2">
<bpmn:outgoing>SequenceFlow_3</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:endEvent id="EndEvent_2">
<bpmn:incoming>SequenceFlow_3</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_3" sourceRef="StartEvent_2" targetRef="EndEvent_2" />
<bpmn:startEvent id="StartEvent_3">
<bpmn:outgoing>SequenceFlow_4</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:endEvent id="EndEvent_3">
<bpmn:incoming>SequenceFlow_4</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_4" sourceRef="StartEvent_3" targetRef="EndEvent_3" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="StartEvent_1_di" bpmnElement="StartEvent_1">
<dc:Bounds x="173" y="102" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_1_di" bpmnElement="SequenceFlow_1" sourceElement="StartEvent_1_di" targetElement="Task_1_di">
<di:waypoint xsi:type="dc:Point" x="209" y="120" />
<di:waypoint xsi:type="dc:Point" x="258" y="120" />
<bpmndi:BPMNLabel>
<dc:Bounds x="234" y="105" width="0" height="0" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="EndEvent_1_di" bpmnElement="EndEvent_1">
<dc:Bounds x="418" y="102" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="436" y="138" width="0" height="0" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Task_1_di" bpmnElement="Task_1">
<dc:Bounds x="258" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_2_di" bpmnElement="SequenceFlow_2" sourceElement="Task_1_di" targetElement="EndEvent_1_di">
<di:waypoint xsi:type="dc:Point" x="358" y="120" />
<di:waypoint xsi:type="dc:Point" x="418" y="120" />
<bpmndi:BPMNLabel>
<dc:Bounds x="388" y="95" width="0" height="0" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="StartEvent_2_di" bpmnElement="StartEvent_2">
<dc:Bounds x="173" y="242" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="191" y="278" width="0" height="0" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="EndEvent_2_di" bpmnElement="EndEvent_2">
<dc:Bounds x="418" y="242" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="436" y="278" width="0" height="0" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_3_di" bpmnElement="SequenceFlow_3" sourceElement="StartEvent_2_di" targetElement="EndEvent_2_di">
<di:waypoint xsi:type="dc:Point" x="209" y="260" />
<di:waypoint xsi:type="dc:Point" x="418" y="260" />
<bpmndi:BPMNLabel>
<dc:Bounds x="314" y="245" width="0" height="0" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="StartEvent_1ua609k_di" bpmnElement="StartEvent_3">
<dc:Bounds x="173" y="371" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="191" y="407" width="0" height="0" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="EndEvent_10rrti7_di" bpmnElement="EndEvent_3">
<dc:Bounds x="418" y="371" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="436" y="407" width="0" height="0" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_1o287si_di" bpmnElement="SequenceFlow_4">
<di:waypoint xsi:type="dc:Point" x="209" y="389" />
<di:waypoint xsi:type="dc:Point" x="418" y="389" />
<bpmndi:BPMNLabel>
<dc:Bounds x="314" y="364" width="0" height="0" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -0,0 +1,79 @@
'use strict';
require('../../../TestHelper');
/* global bootstrapModeler, inject */
var modelingModule = require('../../../../lib/features/modeling'),
coreModule = require('../../../../lib/core');
describe('features - bpmn-updater', function() {
var diagramXML = require('./BpmnUpdater.bpmn');
var testModules = [ modelingModule, coreModule ];
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
describe('connection di', function() {
it('should update after deleting intermediate element', inject(function(modeling, elementRegistry) {
// given
// sequence flow with existing sourceElement and targetElement di information
var task = elementRegistry.get('Task_1'),
sequenceFlowDi = elementRegistry.get('SequenceFlow_1').businessObject.di,
startEventDi = elementRegistry.get('StartEvent_1').businessObject.di,
endEventDi = elementRegistry.get('EndEvent_1').businessObject.di;
// when
modeling.removeElements([ task ]);
// then
expect(sequenceFlowDi.sourceElement).to.equal(startEventDi);
expect(sequenceFlowDi.targetElement).to.equal(endEventDi);
}));
it('should update on drop on flow', inject(function(modeling, elementRegistry, elementFactory) {
// given
// sequence flow with existing sourceElement and targetElement di information
var sequenceFlow = elementRegistry.get('SequenceFlow_3'),
startEventDi = elementRegistry.get('StartEvent_2').businessObject.di;
var intermediateThrowEvent = elementFactory.createShape({ type: 'bpmn:IntermediateThrowEvent' }),
dropPosition = { x: 320, y: 260 };
// when
var event = modeling.createShape(intermediateThrowEvent, dropPosition, sequenceFlow);
// then
expect(sequenceFlow.businessObject.di.sourceElement).to.equal(startEventDi);
expect(sequenceFlow.businessObject.di.targetElement).to.equal(event.businessObject.di);
}));
it('should not create new di refs', inject(function(modeling, elementRegistry, elementFactory) {
// given
// sequence flow without any sourceElement and targetElement di information
var sequenceFlow = elementRegistry.get('SequenceFlow_4');
var intermediateThrowEvent = elementFactory.createShape({ type: 'bpmn:IntermediateThrowEvent' }),
dropPosition = { x: 320, y: 260 };
// when
modeling.createShape(intermediateThrowEvent, dropPosition, sequenceFlow);
// then
expect(sequenceFlow.businessObject.di.sourceElement).not.to.exist;
expect(sequenceFlow.businessObject.di.targetElement).not.to.exist;
}));
});
});