chore: throw error when accessing DI from business object
Related to https://github.com/bpmn-io/bpmn-js/issues/1472
This commit is contained in:
parent
0c40cbe9f3
commit
597c417dce
|
@ -22,6 +22,10 @@ import {
|
||||||
DEFAULT_LABEL_SIZE
|
DEFAULT_LABEL_SIZE
|
||||||
} from '../../util/LabelUtil';
|
} from '../../util/LabelUtil';
|
||||||
|
|
||||||
|
import {
|
||||||
|
ensureCompatDiRef
|
||||||
|
} from '../../util/CompatibilityUtil';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A bpmn-aware factory for diagram-js shapes
|
* A bpmn-aware factory for diagram-js shapes
|
||||||
|
@ -72,6 +76,8 @@ ElementFactory.prototype.createBpmnElement = function(elementType, attrs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
businessObject = this._bpmnFactory.create(attrs.type);
|
businessObject = this._bpmnFactory.create(attrs.type);
|
||||||
|
|
||||||
|
ensureCompatDiRef(businessObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!di) {
|
if (!di) {
|
||||||
|
|
|
@ -8,6 +8,11 @@ import {
|
||||||
elementToString
|
elementToString
|
||||||
} from './Util';
|
} from './Util';
|
||||||
|
|
||||||
|
import {
|
||||||
|
ensureCompatDiRef
|
||||||
|
} from '../util/CompatibilityUtil';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if an element has the given meta-model type
|
* Returns true if an element has the given meta-model type
|
||||||
*
|
*
|
||||||
|
@ -113,6 +118,8 @@ export default function BpmnTreeWalker(handler, translate) {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
diMap[bpmnElement.id] = di;
|
diMap[bpmnElement.id] = di;
|
||||||
|
|
||||||
|
ensureCompatDiRef(bpmnElement);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logError(
|
logError(
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
import { isFunction } from 'min-dash';
|
import {
|
||||||
|
has,
|
||||||
|
isFunction
|
||||||
|
} from 'min-dash';
|
||||||
|
|
||||||
// TODO(nikku): remove with future bpmn-js version
|
// TODO(nikku): remove with future bpmn-js version
|
||||||
|
|
||||||
|
@ -51,3 +54,20 @@ export function wrapForCompatibility(api) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO(nikku): remove with future bpmn-js version
|
||||||
|
|
||||||
|
var DI_ERROR_MESSAGE = 'Tried to access di from the businessObject. The di is available through the diagram element only. For more information, see https://github.com/bpmn-io/bpmn-js/issues/1472';
|
||||||
|
|
||||||
|
export function ensureCompatDiRef(businessObject) {
|
||||||
|
|
||||||
|
// bpmnElement can have multiple independent DIs
|
||||||
|
if (!has(businessObject, 'di')) {
|
||||||
|
Object.defineProperty(businessObject, 'di', {
|
||||||
|
get: function() {
|
||||||
|
throw new Error(DI_ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -468,6 +468,27 @@ describe('Modeler', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should error when accessing <di> from businessObject', function() {
|
||||||
|
|
||||||
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
||||||
|
|
||||||
|
var modeler = new Modeler({ container: container });
|
||||||
|
|
||||||
|
return modeler.importXML(xml).then(function() {
|
||||||
|
|
||||||
|
// given
|
||||||
|
var elementRegistry = modeler.get('elementRegistry'),
|
||||||
|
shape = elementRegistry.get('Task_1');
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(shape.di).to.exist;
|
||||||
|
expect(function() {
|
||||||
|
shape.businessObject.di;
|
||||||
|
}).to.throw(/The di is available through the diagram element only./);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should create new diagram', function() {
|
it('should create new diagram', function() {
|
||||||
var modeler = new Modeler({ container: container });
|
var modeler = new Modeler({ container: container });
|
||||||
return modeler.createDiagram();
|
return modeler.createDiagram();
|
||||||
|
|
|
@ -287,6 +287,27 @@ describe('Viewer', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should error when accessing <di> from businessObject', function() {
|
||||||
|
|
||||||
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
||||||
|
|
||||||
|
return createViewer(container, Viewer, xml).then(function(result) {
|
||||||
|
|
||||||
|
// given
|
||||||
|
var viewer = result.viewer,
|
||||||
|
elementRegistry = viewer.get('elementRegistry'),
|
||||||
|
shape = elementRegistry.get('Task_1');
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(shape.di).to.exist;
|
||||||
|
|
||||||
|
expect(function() {
|
||||||
|
shape.businessObject.di;
|
||||||
|
}).to.throw(/The di is available through the diagram element only./);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -141,7 +141,7 @@ describe('features/modeling - append shape', function() {
|
||||||
var connection = find(subProcess.get('flowElements'), function(e) {
|
var connection = find(subProcess.get('flowElements'), function(e) {
|
||||||
return e.sourceRef === startEvent && e.targetRef === target;
|
return e.sourceRef === startEvent && e.targetRef === target;
|
||||||
}),
|
}),
|
||||||
connectionDi = getDi(connection);
|
connectionDi = getDi(elementRegistry.get(connection.id));
|
||||||
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
|
@ -174,7 +174,7 @@ describe('features/modeling - append shape', function() {
|
||||||
var connection = find(subProcess.get('flowElements'), function(e) {
|
var connection = find(subProcess.get('flowElements'), function(e) {
|
||||||
return e.sourceRef === startEvent && e.targetRef === target;
|
return e.sourceRef === startEvent && e.targetRef === target;
|
||||||
}),
|
}),
|
||||||
connectionDi = getDi(connection);
|
connectionDi = getDi(elementRegistry.get(connection.id));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
commandStack.undo();
|
commandStack.undo();
|
||||||
|
@ -209,7 +209,7 @@ describe('features/modeling - append shape', function() {
|
||||||
var connection = find(subProcess.get('flowElements'), function(e) {
|
var connection = find(subProcess.get('flowElements'), function(e) {
|
||||||
return e.sourceRef === startEvent && e.targetRef === target;
|
return e.sourceRef === startEvent && e.targetRef === target;
|
||||||
}),
|
}),
|
||||||
connectionDi = getDi(connection);
|
connectionDi = getDi(elementRegistry.get(connection.id));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
commandStack.undo();
|
commandStack.undo();
|
||||||
|
@ -270,7 +270,7 @@ describe('features/modeling - append shape', function() {
|
||||||
var connection = find(subProcess.get('flowElements'), function(e) {
|
var connection = find(subProcess.get('flowElements'), function(e) {
|
||||||
return e.sourceRef === startEvent && e.targetRef === target;
|
return e.sourceRef === startEvent && e.targetRef === target;
|
||||||
}),
|
}),
|
||||||
connectionDi = getDi(connection);
|
connectionDi = getDi(elementRegistry.get(connection.id));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
commandStack.undo();
|
commandStack.undo();
|
||||||
|
|
|
@ -101,6 +101,21 @@ describe('features - element factory', function() {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
it('should error when accessing <di> via businessObject', inject(function(elementFactory) {
|
||||||
|
|
||||||
|
// given
|
||||||
|
var shape = elementFactory.createShape({
|
||||||
|
type: 'bpmn:Task',
|
||||||
|
});
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(shape.di).to.exist;
|
||||||
|
expect(function() {
|
||||||
|
shape.businessObject.di;
|
||||||
|
}).to.throw(/The di is available through the diagram element only./);
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
describe('integration', function() {
|
describe('integration', function() {
|
||||||
|
|
||||||
it('should create event definition with ID', inject(function(elementFactory) {
|
it('should create event definition with ID', inject(function(elementFactory) {
|
||||||
|
|
Loading…
Reference in New Issue