Skip to content

Commit

Permalink
fix(import): handle missing BPMNDiagram#plane
Browse files Browse the repository at this point in the history
Without this change any auxiliary <bpmndi:BPMNDiagram /> without a plane
would crash the importer.

Now the (broken) BPMN diagram is simply ignored during import.
  • Loading branch information
nikku committed May 27, 2024
1 parent 07bf015 commit bc24a60
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/import/Importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export function importBpmnDiagram(diagram, definitions, bpmnDiagram) {
* @return {ModdleElement[]}
*/
function getDiagramsToImport(definitions, bpmnDiagram) {
if (!bpmnDiagram) {
if (!bpmnDiagram || !bpmnDiagram.plane) {
return;
}

Expand Down Expand Up @@ -173,6 +173,11 @@ function getDiagramsToImport(definitions, bpmnDiagram) {
var handledElements = [ bpmnElement ];

forEach(definitions.diagrams, function(diagram) {

if (!diagram.plane) {
return;
}

var businessObject = diagram.plane.bpmnElement;

if (
Expand Down
42 changes: 42 additions & 0 deletions test/spec/import/ImporterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,48 @@ describe('import - Importer', function() {
});


it('should import with missing BPMNDiagram#plane DI', function() {

// given
var xml = require('./missing-di-plane.bpmn');

// when
return runImport(diagram, xml).then(function(result) {

var {
error,
warnings
} = result;

// then
expect(warnings).to.be.empty;
expect(error).not.to.exist;
});
});


it('should error import with missing BPMNDiagram#plane DI', function() {

// given
var xml = require('./missing-di-plane-root-element.bpmn');

// when
return runImport(diagram, xml).then(function(result) {

var {
error,
warnings
} = result;

// then
// warning: no bpmnElement referenced in <bpmndi:BPMNPlane />
// warning: correcting missing bpmnElement on <bpmndi:BPMNPlane />
expect(warnings).to.have.length(2);
expect(error).not.to.exist;
});
});


it('should import sequence flow without waypoints', function() {

// given
Expand Down
14 changes: 14 additions & 0 deletions test/spec/import/missing-di-plane-root-element.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_01360mp" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.23.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.21.0">
<bpmn:process id="PROCESS" isExecutable="true">
<bpmn:subProcess id="SUB_PROCESS">
</bpmn:subProcess>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1">
<bpmndi:BPMNShape id="SUB_PROCESS_di" bpmnElement="SUB_PROCESS" isExpanded="false">
<dc:Bounds x="355" y="160" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
18 changes: 18 additions & 0 deletions test/spec/import/missing-di-plane.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_01360mp" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.23.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.21.0">
<bpmn:process id="PROCESS" isExecutable="true">
<bpmn:subProcess id="SUB_PROCESS">
<bpmn:subProcess id="SUB_PROCESS_MISSING_DI" />
</bpmn:subProcess>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="PROCESS">
<bpmndi:BPMNShape id="SUB_PROCESS_di" bpmnElement="SUB_PROCESS" isExpanded="false">
<dc:Bounds x="355" y="160" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
<!-- missing plane element -->
<bpmndi:BPMNDiagram id="BPMNDiagram_2">
</bpmndi:BPMNDiagram>
</bpmn:definitions>

0 comments on commit bc24a60

Please sign in to comment.