fix(modeling/behaviors): add a behavior that deletes attached boundaries after replacing a gateway with an event based gateway
This commit is contained in:
parent
b3e4b1dc1f
commit
178e1cfccb
|
@ -0,0 +1,67 @@
|
|||
import inherits from 'inherits';
|
||||
|
||||
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
|
||||
|
||||
import { is } from '../../../util/ModelUtil';
|
||||
|
||||
import {
|
||||
filter,
|
||||
forEach
|
||||
} from 'min-dash';
|
||||
|
||||
|
||||
/**
|
||||
* BPMN specific boundary event behavior
|
||||
*/
|
||||
export default function ConnectEventBasedGatewayBehavior(eventBus, modeling) {
|
||||
|
||||
CommandInterceptor.call(this, eventBus);
|
||||
|
||||
function getBoundaryEvents(element) {
|
||||
return filter(element.attachers, function(attacher) {
|
||||
return is(attacher, 'bpmn:BoundaryEvent');
|
||||
});
|
||||
}
|
||||
|
||||
// remove after connecting to event-based gateway
|
||||
this.postExecute('connection.create', function(event) {
|
||||
var source = event.context.source,
|
||||
target = event.context.target,
|
||||
boundaryEvents = getBoundaryEvents(target);
|
||||
|
||||
if (
|
||||
is(source, 'bpmn:EventBasedGateway') &&
|
||||
is(target, 'bpmn:ReceiveTask') &&
|
||||
boundaryEvents.length > 0
|
||||
) {
|
||||
modeling.removeElements(boundaryEvents);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// remove after replacing connected gateway with event-based gateway
|
||||
this.postExecute('connection.reconnectStart', function(event) {
|
||||
var oldSource = event.context.oldSource,
|
||||
newSource = event.context.newSource;
|
||||
|
||||
if (is(oldSource, 'bpmn:Gateway') &&
|
||||
is(newSource, 'bpmn:EventBasedGateway')) {
|
||||
forEach(newSource.outgoing, function(connection) {
|
||||
var target = connection.target,
|
||||
attachedboundaryEvents = getBoundaryEvents(target);
|
||||
|
||||
if (is(target, 'bpmn:ReceiveTask') &&
|
||||
attachedboundaryEvents.length > 0) {
|
||||
modeling.removeElements(attachedboundaryEvents);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ConnectEventBasedGatewayBehavior.$inject = [
|
||||
'eventBus',
|
||||
'modeling'
|
||||
];
|
||||
|
||||
inherits(ConnectEventBasedGatewayBehavior, CommandInterceptor);
|
|
@ -1,47 +0,0 @@
|
|||
import inherits from 'inherits';
|
||||
|
||||
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
|
||||
|
||||
import { is } from '../../../util/ModelUtil';
|
||||
|
||||
import {
|
||||
filter
|
||||
} from 'min-dash';
|
||||
|
||||
|
||||
/**
|
||||
* Behavior for deleting boundaries from receive task after connecting them with event based gateway
|
||||
*/
|
||||
export default function ConnectEventBasedGatewayBehavior(eventBus, modeling) {
|
||||
|
||||
CommandInterceptor.call(this, eventBus);
|
||||
|
||||
function extractBoundaryEvents(element) {
|
||||
return filter(element.attachers, function(attacher) {
|
||||
return is(attacher, 'bpmn:BoundaryEvent');
|
||||
});
|
||||
}
|
||||
|
||||
this.postExecute('connection.create', function(context) {
|
||||
var source = context.context.source,
|
||||
target = context.context.target,
|
||||
boundaries = extractBoundaryEvents(target);
|
||||
|
||||
if (
|
||||
is(source, 'bpmn:EventBasedGateway') &&
|
||||
is(target, 'bpmn:ReceiveTask') &&
|
||||
boundaries.length > 0
|
||||
) {
|
||||
modeling.removeElements(boundaries);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
ConnectEventBasedGatewayBehavior.$inject = [
|
||||
'eventBus',
|
||||
'modeling',
|
||||
'bpmnRules'
|
||||
];
|
||||
|
||||
inherits(ConnectEventBasedGatewayBehavior, CommandInterceptor);
|
|
@ -1,6 +1,6 @@
|
|||
import AdaptiveLabelPositioningBehavior from './AdaptiveLabelPositioningBehavior';
|
||||
import AppendBehavior from './AppendBehavior';
|
||||
import ConnectEventBasedGatewayBehavior from './ConnectEventBasedGatewayBehavior';
|
||||
import BoundaryEventBehavior from './BoundaryEventBehavior';
|
||||
import CopyPasteBehavior from './CopyPasteBehavior';
|
||||
import CreateBoundaryEventBehavior from './CreateBoundaryEventBehavior';
|
||||
import CreateDataObjectBehavior from './CreateDataObjectBehavior';
|
||||
|
@ -26,7 +26,7 @@ export default {
|
|||
__init__: [
|
||||
'adaptiveLabelPositioningBehavior',
|
||||
'appendBehavior',
|
||||
'connectEventBasedGatewayBehavior',
|
||||
'boundaryEventBehavior',
|
||||
'copyPasteBehavior',
|
||||
'createBoundaryEventBehavior',
|
||||
'createDataObjectBehavior',
|
||||
|
@ -50,7 +50,7 @@ export default {
|
|||
],
|
||||
adaptiveLabelPositioningBehavior: [ 'type', AdaptiveLabelPositioningBehavior ],
|
||||
appendBehavior: [ 'type', AppendBehavior ],
|
||||
connectEventBasedGatewayBehavior: [ 'type', ConnectEventBasedGatewayBehavior ],
|
||||
boundaryEventBehavior: [ 'type', BoundaryEventBehavior ],
|
||||
copyPasteBehavior: [ 'type', CopyPasteBehavior ],
|
||||
createBoundaryEventBehavior: [ 'type', CreateBoundaryEventBehavior ],
|
||||
createDataObjectBehavior: [ 'type', CreateDataObjectBehavior ],
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
<bpmn:eventBasedGateway id="EventBasedGateway_1" />
|
||||
<bpmn:receiveTask id="ReceiveTask_1" />
|
||||
<bpmn:boundaryEvent id="BoundaryEvent_1" attachedToRef="ReceiveTask_1" />
|
||||
<bpmn:exclusiveGateway id="ExclusiveGateway_1" />
|
||||
</bpmn:process>
|
||||
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
|
||||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
|
||||
|
@ -16,6 +17,9 @@
|
|||
<bpmndi:BPMNShape id="BoundaryEvent_0xg8xmx_di" bpmnElement="BoundaryEvent_1">
|
||||
<dc:Bounds x="331" y="165" width="36" height="36" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="ExclusiveGateway_1qf26hs_di" bpmnElement="ExclusiveGateway_1" isMarkerVisible="true">
|
||||
<dc:Bounds x="172" y="221" width="50" height="50" />
|
||||
</bpmndi:BPMNShape>
|
||||
</bpmndi:BPMNPlane>
|
||||
</bpmndi:BPMNDiagram>
|
||||
</bpmn:definitions>
|
|
@ -7,11 +7,11 @@ import modelingModule from 'lib/features/modeling';
|
|||
import coreModule from 'lib/core';
|
||||
|
||||
|
||||
describe('features/modeling/behavior - connect event based gateway to receive task with boundary', function() {
|
||||
describe('features/modeling/behavior - boundary event', function() {
|
||||
|
||||
var testModules = [ coreModule, modelingModule ];
|
||||
|
||||
var diagramXML = require('./ConnectEventBasedGatewayBehavior.bpmn');
|
||||
var diagramXML = require('./BoundaryEvent.bpmn');
|
||||
|
||||
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
|
||||
|
||||
|
@ -33,4 +33,23 @@ describe('features/modeling/behavior - connect event based gateway to receive ta
|
|||
expect(elementRegistry.get(boundaryEvent.id)).to.be.undefined;
|
||||
}));
|
||||
|
||||
it('should remove Boundary from ReceiveTask after changing type of Gateway', inject(function(modeling, elementRegistry, bpmnReplace) {
|
||||
|
||||
// given
|
||||
var gateway = elementRegistry.get('ExclusiveGateway_1'),
|
||||
receiveTask = elementRegistry.get('ReceiveTask_1'),
|
||||
boundaryEvent = elementRegistry.get('BoundaryEvent_1');
|
||||
|
||||
// when
|
||||
modeling.connect(gateway, receiveTask, {
|
||||
type: 'bpmn:SequenceFlow'
|
||||
});
|
||||
bpmnReplace.replaceElement(gateway, {
|
||||
type: 'bpmn:EventBasedGateway'
|
||||
});
|
||||
|
||||
// then
|
||||
expect(elementRegistry.get(boundaryEvent.id)).not.to.exist;
|
||||
}));
|
||||
|
||||
});
|
Loading…
Reference in New Issue