From ea681df2d31527f10d575f6a16eb9f53e5cd86f4 Mon Sep 17 00:00:00 2001 From: Niklas Kiefer Date: Tue, 16 Oct 2018 11:07:28 +0200 Subject: [PATCH] fix(bpmn-rules): adjust canAttach rule for boundary events after event based gateways --- lib/features/rules/BpmnRules.js | 14 +++++++++ test/spec/features/rules/BpmnRulesSpec.js | 35 +++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/lib/features/rules/BpmnRules.js b/lib/features/rules/BpmnRules.js index e0fcba5a..3da4986d 100644 --- a/lib/features/rules/BpmnRules.js +++ b/lib/features/rules/BpmnRules.js @@ -555,6 +555,15 @@ function isBoundaryCandidate(element) { (is(element, 'bpmn:IntermediateThrowEvent') && !element.parent); } +function isReceiveTaskAfterEventBasedGateway(element) { + return ( + is(element, 'bpmn:ReceiveTask') && + find(element.incoming, function(incoming) { + return is(incoming.source, 'bpmn:EventBasedGateway'); + }) + ); +} + function canAttach(elements, target, source, position) { @@ -604,6 +613,11 @@ function canAttach(elements, target, source, position) { return false; } + // do not attach on receive tasks after event based gateways + if (isReceiveTaskAfterEventBasedGateway(target)) { + return false; + } + return 'attach'; } diff --git a/test/spec/features/rules/BpmnRulesSpec.js b/test/spec/features/rules/BpmnRulesSpec.js index 0f6beb59..b246dec5 100644 --- a/test/spec/features/rules/BpmnRulesSpec.js +++ b/test/spec/features/rules/BpmnRulesSpec.js @@ -1377,6 +1377,41 @@ describe('features/modeling/rules - BpmnRules', function() { } )); + it('not attach IntermediateEvent to ReceiveTask after EventBasedGateway', inject( + function(canvas, modeling, elementFactory, bpmnRules) { + + // given + var rootElement = canvas.getRootElement(), + eventBasedGatewayShape = elementFactory.createShape({ type: 'bpmn:EventBasedGateway' }), + receiveTaskShape = elementFactory.createShape({ type: 'bpmn:ReceiveTask' }), + eventShape = elementFactory.createShape({ + type: 'bpmn:IntermediateThrowEvent', + x: 0, y: 0 + }); + + var boundaryPosition = { + x: 175, + y: 100 + receiveTaskShape.height + }; + + // when + modeling.createShape(eventBasedGatewayShape, { x: 100, y: 100 }, rootElement); + modeling.createShape(receiveTaskShape, { x : 150, y: 100 }, rootElement); + modeling.connect(eventBasedGatewayShape, receiveTaskShape, { + type: 'bpmn:SequenceFlow' + }); + + var canAttach = bpmnRules.canAttach( + [ eventShape ], + receiveTaskShape, + null, + boundaryPosition + ); + + // then + expect(canAttach).to.be.false; + } + )); it('create IntermediateEvent in SubProcess body', inject( function(elementFactory, elementRegistry, bpmnRules) {