fix(import): gracefully handle missing waypoints

This ensures we do not blow up if a diagram
is missing waypoints for connections.

Related to camunda/camunda-modeler#1294
This commit is contained in:
Nico Rehwaldt 2019-03-07 10:39:27 +01:00 committed by merge-me[bot]
parent 0a9efb793b
commit 45486f2afe
3 changed files with 50 additions and 5 deletions

View File

@ -1,6 +1,5 @@
import {
assign,
map
assign
} from 'min-dash';
import { is } from '../util/ModelUtil';
@ -31,8 +30,15 @@ function elementData(semantic, attrs) {
}, attrs);
}
function collectWaypoints(waypoints) {
return map(waypoints, function(p) {
function getWaypoints(bo, source, target) {
var waypoints = bo.di.waypoint;
if (!waypoints || waypoints.length < 2) {
return [ getMid(source), getMid(target) ];
}
return waypoints.map(function(p) {
return { x: p.x, y: p.y };
});
}
@ -151,7 +157,7 @@ BpmnImporter.prototype.add = function(semantic, parentElement) {
hidden: hidden,
source: source,
target: target,
waypoints: collectWaypoints(semantic.di.waypoint)
waypoints: getWaypoints(semantic, source, target)
}));
if (is(semantic, 'bpmn:DataAssociation')) {

View File

@ -418,6 +418,21 @@ describe('import - Importer', function() {
});
it('should import sequence flow without waypoints', function(done) {
// given
var xml = require('./sequenceFlow-missingWaypoints.bpmn');
// when
runImport(diagram, xml, function(err, warnings) {
expect(warnings).to.be.empty;
done(err);
});
});
it('should extend attributes with default value', function(done) {
// given

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="sid-38422fae-e03e-43a3-bef4-bd33b32041b2" targetNamespace="http://bpmn.io/bpmn" exporter="bpmn-js (https://demo.bpmn.io)" exporterVersion="3.2.1">
<process id="Process_1" isExecutable="false">
<startEvent id="Event">
<outgoing>SequenceFlow</outgoing>
</startEvent>
<task id="Task">
<incoming>SequenceFlow</incoming>
</task>
<sequenceFlow id="SequenceFlow" sourceRef="Event" targetRef="Task" />
</process>
<bpmndi:BPMNDiagram id="BpmnDiagram_1">
<bpmndi:BPMNPlane id="BpmnPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="Event_di" bpmnElement="Event">
<omgdc:Bounds x="163" y="151" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Task_di" bpmnElement="Task">
<omgdc:Bounds x="249" y="129" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_di" bpmnElement="SequenceFlow">
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>