From bd2a4dd16b541a745601888c037a97a7fa0d4c26 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Mon, 11 May 2015 17:55:06 +0200 Subject: [PATCH] fix(rules): connect message flow to message/untyped events only Closes #261 --- lib/features/modeling/rules/BpmnRules.js | 20 ++- .../rules/BpmnRules.collaboration.bpmn | 136 +++++++++++++----- .../features/modeling/rules/BpmnRulesSpec.js | 74 +++++++++- 3 files changed, 190 insertions(+), 40 deletions(-) diff --git a/lib/features/modeling/rules/BpmnRules.js b/lib/features/modeling/rules/BpmnRules.js index 7f721cb7..039aa3be 100644 --- a/lib/features/modeling/rules/BpmnRules.js +++ b/lib/features/modeling/rules/BpmnRules.js @@ -136,13 +136,19 @@ function isSameOrganization(a, b) { function isMessageFlowSource(element) { return is(element, 'bpmn:InteractionNode') && ( - !is(element, 'bpmn:Event') || is(element, 'bpmn:ThrowEvent') + !is(element, 'bpmn:Event') || ( + is(element, 'bpmn:ThrowEvent') && + hasEventDefinitionOrNone(element, 'bpmn:MessageEventDefinition') + ) ); } function isMessageFlowTarget(element) { return is(element, 'bpmn:InteractionNode') && ( - !is(element, 'bpmn:Event') || is(element, 'bpmn:CatchEvent') + !is(element, 'bpmn:Event') || ( + is(element, 'bpmn:CatchEvent') && + hasEventDefinitionOrNone(element, 'bpmn:MessageEventDefinition') + ) ); } @@ -175,7 +181,15 @@ function isSameScope(a, b) { function hasEventDefinition(element, eventDefinition) { var bo = getBusinessObject(element); - return find(bo.eventDefinitions || [], function(definition) { + return !!find(bo.eventDefinitions || [], function(definition) { + return is(definition, eventDefinition); + }); +} + +function hasEventDefinitionOrNone(element, eventDefinition) { + var bo = getBusinessObject(element); + + return (bo.eventDefinitions || []).every(function(definition) { return is(definition, eventDefinition); }); } diff --git a/test/spec/features/modeling/rules/BpmnRules.collaboration.bpmn b/test/spec/features/modeling/rules/BpmnRules.collaboration.bpmn index ba4cb455..89906be0 100644 --- a/test/spec/features/modeling/rules/BpmnRules.collaboration.bpmn +++ b/test/spec/features/modeling/rules/BpmnRules.collaboration.bpmn @@ -1,69 +1,133 @@ - + - - + + + + + + + + + + - - + + - + + + + + + + - + - - + + + + + + + - - + + - + - + - - - - - - - - - - - - - + - + - + - + - + - - - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - \ No newline at end of file + diff --git a/test/spec/features/modeling/rules/BpmnRulesSpec.js b/test/spec/features/modeling/rules/BpmnRulesSpec.js index cb049ec5..4afcd9af 100644 --- a/test/spec/features/modeling/rules/BpmnRulesSpec.js +++ b/test/spec/features/modeling/rules/BpmnRulesSpec.js @@ -119,7 +119,7 @@ describe('features/modeling/rules - BpmnRules', function() { })); - it('connect IntermediateCatchEvent_Link -> ', inject(function(bpmnRules) { + it('connect IntermediateCatchEvent_Link -> Task', inject(function(bpmnRules) { expectCanConnect('IntermediateCatchEvent_Link', 'Task', { sequenceFlow: true, @@ -284,6 +284,28 @@ describe('features/modeling/rules - BpmnRules', function() { })); + it('connect OtherParticipant -> StartEvent_Timer', inject(function(bpmnRules) { + + expectCanConnect('OtherParticipant', 'StartEvent_Timer', { + sequenceFlow: false, + messageFlow: false, + association: true + }); + + })); + + + it('connect OtherParticipant -> StartEvent_Message', inject(function(bpmnRules) { + + expectCanConnect('OtherParticipant', 'StartEvent_Message', { + sequenceFlow: false, + messageFlow: true, + association: true + }); + + })); + + it('connect EndEvent_None -> OtherParticipant', inject(function(bpmnRules) { expectCanConnect('EndEvent_None', 'OtherParticipant', { @@ -294,6 +316,26 @@ describe('features/modeling/rules - BpmnRules', function() { })); + it('connect EndEvent_Cancel -> OtherParticipant', inject(function(bpmnRules) { + + expectCanConnect('EndEvent_Cancel', 'OtherParticipant', { + sequenceFlow: false, + messageFlow: false, + association: true + }); + })); + + + it('connect EndEvent_Message -> OtherParticipant', inject(function(bpmnRules) { + + expectCanConnect('EndEvent_Message', 'OtherParticipant', { + sequenceFlow: false, + messageFlow: true, + association: true + }); + })); + + it('connect OtherParticipant -> EndEvent_None', inject(function(bpmnRules) { expectCanConnect('OtherParticipant', 'EndEvent_None', { @@ -314,6 +356,26 @@ describe('features/modeling/rules - BpmnRules', function() { })); + it('connect IntermediateThrowEvent_None -> OtherParticipant', inject(function(bpmnRules) { + + expectCanConnect('IntermediateThrowEvent_None', 'OtherParticipant', { + sequenceFlow: false, + messageFlow: true, + association: true + }); + })); + + + it('connect IntermediateThrowEvent_Signal -> OtherParticipant', inject(function(bpmnRules) { + + expectCanConnect('IntermediateThrowEvent_Signal', 'OtherParticipant', { + sequenceFlow: false, + messageFlow: false, + association: true + }); + })); + + it('connect OtherParticipant -> IntermediateThrowEvent_Message', inject(function(bpmnRules) { expectCanConnect('OtherParticipant', 'IntermediateThrowEvent_Message', { @@ -334,6 +396,16 @@ describe('features/modeling/rules - BpmnRules', function() { })); + it('connect EndEvent_None_in_SubProcess -> OtherParticipant', inject(function(bpmnRules) { + + expectCanConnect('EndEvent_None_in_SubProcess', 'OtherParticipant', { + sequenceFlow: false, + messageFlow: true, + association: true + }); + })); + + it('connect OtherParticipant -> Task_in_SubProcess', inject(function(bpmnRules) { expectCanConnect('OtherParticipant', 'Task_in_SubProcess', {