diff --git a/lib/features/modeling/BpmnFactory.js b/lib/features/modeling/BpmnFactory.js index c89126d9..2cb12572 100644 --- a/lib/features/modeling/BpmnFactory.js +++ b/lib/features/modeling/BpmnFactory.js @@ -42,6 +42,10 @@ BpmnFactory.prototype._needsId = function(element) { }; BpmnFactory.prototype._ensureId = function(element) { + if (element.id) { + this._model.ids.claim(element.id, element); + return; + } // generate semantic ids for elements // bpmn:SequenceFlow -> SequenceFlow_ID diff --git a/lib/features/modeling/behavior/UnclaimIdBehavior.js b/lib/features/modeling/behavior/UnclaimIdBehavior.js index 7e3560df..49493fe4 100644 --- a/lib/features/modeling/behavior/UnclaimIdBehavior.js +++ b/lib/features/modeling/behavior/UnclaimIdBehavior.js @@ -47,7 +47,9 @@ export default function UnclaimIdBehavior(canvas, injector, moddle, modeling) { var rootElement = canvas.getRootElement(), rootElementBo = rootElement.businessObject; - moddle.ids.unclaim(rootElementBo.id); + if (is(rootElement, 'bpmn:Collaboration')) { + moddle.ids.unclaim(rootElementBo.id); + } }); } diff --git a/test/spec/features/modeling/BpmnFactorySpec.js b/test/spec/features/modeling/BpmnFactorySpec.js index a388ff13..e3422d63 100644 --- a/test/spec/features/modeling/BpmnFactorySpec.js +++ b/test/spec/features/modeling/BpmnFactorySpec.js @@ -116,6 +116,16 @@ describe('features - bpmn-factory', function() { }) ); }); + + + it('should claim provided id', inject(function(bpmnFactory, moddle) { + var task = bpmnFactory.create('bpmn:Task', { id: 'foo' }); + + expect(task).to.exist; + expect(task.id).to.eql('foo'); + expect(moddle.ids.assigned('foo')).to.exist; + })); + }); diff --git a/test/spec/features/modeling/behavior/UnclaimIdBehaviorSpec.js b/test/spec/features/modeling/behavior/UnclaimIdBehaviorSpec.js index ed62fef7..3b0378f8 100644 --- a/test/spec/features/modeling/behavior/UnclaimIdBehaviorSpec.js +++ b/test/spec/features/modeling/behavior/UnclaimIdBehaviorSpec.js @@ -82,4 +82,21 @@ describe('features/modeling - unclaim id', function() { expect(moddle.ids.assigned('Collaboration_1')).to.be.false; })); + + describe('morphing', function() { + var simpleXML = require('../../../../fixtures/bpmn/simple.bpmn'); + + beforeEach(bootstrapModeler(simpleXML, { modules: testModules })); + + it('should keep ID of root', inject(function(moddle, modeling) { + + // when + modeling.makeCollaboration(); + + // then + expect(moddle.ids.assigned('Process_1')).to.exist; + })); + + }); + }); \ No newline at end of file