From b3e4b1dc1f8e3baa5600550f1b5749163a19cd95 Mon Sep 17 00:00:00 2001 From: Niklas Kiefer Date: Tue, 16 Oct 2018 12:40:56 +0200 Subject: [PATCH] fix(modeling/behaviors): add behavior for deleting boundaries on receive tasks after connecting to event based gateway --- .../ConnectEventBasedGatewayBehavior.js | 47 +++++++++++++++++++ lib/features/modeling/behavior/index.js | 3 ++ .../ConnectEventBasedGatewayBehavior.bpmn | 21 +++++++++ .../ConnectEventBasedGatewayBehaviorSpec.js | 36 ++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 lib/features/modeling/behavior/ConnectEventBasedGatewayBehavior.js create mode 100644 test/spec/features/modeling/behavior/ConnectEventBasedGatewayBehavior.bpmn create mode 100644 test/spec/features/modeling/behavior/ConnectEventBasedGatewayBehaviorSpec.js diff --git a/lib/features/modeling/behavior/ConnectEventBasedGatewayBehavior.js b/lib/features/modeling/behavior/ConnectEventBasedGatewayBehavior.js new file mode 100644 index 00000000..20ae70e5 --- /dev/null +++ b/lib/features/modeling/behavior/ConnectEventBasedGatewayBehavior.js @@ -0,0 +1,47 @@ +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); diff --git a/lib/features/modeling/behavior/index.js b/lib/features/modeling/behavior/index.js index de34a0a7..51a85a9c 100644 --- a/lib/features/modeling/behavior/index.js +++ b/lib/features/modeling/behavior/index.js @@ -1,5 +1,6 @@ import AdaptiveLabelPositioningBehavior from './AdaptiveLabelPositioningBehavior'; import AppendBehavior from './AppendBehavior'; +import ConnectEventBasedGatewayBehavior from './ConnectEventBasedGatewayBehavior'; import CopyPasteBehavior from './CopyPasteBehavior'; import CreateBoundaryEventBehavior from './CreateBoundaryEventBehavior'; import CreateDataObjectBehavior from './CreateDataObjectBehavior'; @@ -25,6 +26,7 @@ export default { __init__: [ 'adaptiveLabelPositioningBehavior', 'appendBehavior', + 'connectEventBasedGatewayBehavior', 'copyPasteBehavior', 'createBoundaryEventBehavior', 'createDataObjectBehavior', @@ -48,6 +50,7 @@ export default { ], adaptiveLabelPositioningBehavior: [ 'type', AdaptiveLabelPositioningBehavior ], appendBehavior: [ 'type', AppendBehavior ], + connectEventBasedGatewayBehavior: [ 'type', ConnectEventBasedGatewayBehavior ], copyPasteBehavior: [ 'type', CopyPasteBehavior ], createBoundaryEventBehavior: [ 'type', CreateBoundaryEventBehavior ], createDataObjectBehavior: [ 'type', CreateDataObjectBehavior ], diff --git a/test/spec/features/modeling/behavior/ConnectEventBasedGatewayBehavior.bpmn b/test/spec/features/modeling/behavior/ConnectEventBasedGatewayBehavior.bpmn new file mode 100644 index 00000000..f55186a4 --- /dev/null +++ b/test/spec/features/modeling/behavior/ConnectEventBasedGatewayBehavior.bpmn @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/test/spec/features/modeling/behavior/ConnectEventBasedGatewayBehaviorSpec.js b/test/spec/features/modeling/behavior/ConnectEventBasedGatewayBehaviorSpec.js new file mode 100644 index 00000000..86631196 --- /dev/null +++ b/test/spec/features/modeling/behavior/ConnectEventBasedGatewayBehaviorSpec.js @@ -0,0 +1,36 @@ +import { + bootstrapModeler, + inject +} from 'test/TestHelper'; + +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() { + + var testModules = [ coreModule, modelingModule ]; + + var diagramXML = require('./ConnectEventBasedGatewayBehavior.bpmn'); + + beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); + + + it('should remove the boundary event from the receive task after connecting the task with an event based gateway', + inject(function(modeling, elementRegistry) { + + // given + var eventBasedGateway = elementRegistry.get('EventBasedGateway_1'), + receiveTask = elementRegistry.get('ReceiveTask_1'), + boundaryEvent = elementRegistry.get('BoundaryEvent_1'); + + // when + modeling.connect(eventBasedGateway, receiveTask, { + type: 'bpmn:SequenceFlow' + }); + + // then + expect(elementRegistry.get(boundaryEvent.id)).to.be.undefined; + })); + +}); \ No newline at end of file