From f68054295b4a9fce07bcabae370160cf16f01d1d Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Wed, 21 Oct 2015 16:25:56 +0200 Subject: [PATCH] feat(modeling): allow data associations from and to events Closes #384 --- lib/features/modeling/BpmnUpdater.js | 3 +- lib/features/rules/BpmnRules.js | 29 +++++++++++-------- .../behavior/CreateDataObjectBehaviorSpec.js | 8 +++++ test/spec/features/rules/BpmnRulesSpec.js | 22 ++++++++++++++ 4 files changed, 48 insertions(+), 14 deletions(-) diff --git a/lib/features/modeling/BpmnUpdater.js b/lib/features/modeling/BpmnUpdater.js index 066de58f..218ea526 100644 --- a/lib/features/modeling/BpmnUpdater.js +++ b/lib/features/modeling/BpmnUpdater.js @@ -516,7 +516,6 @@ BpmnUpdater.prototype.updateSemanticParent = function(businessObject, newParent) BpmnUpdater.prototype.updateConnectionWaypoints = function(connection) { - connection.businessObject.di.set('waypoint', this._bpmnFactory.createDiWaypoints(connection.waypoints)); }; @@ -573,7 +572,7 @@ BpmnUpdater.prototype.updateConnection = function(context) { businessObject.targetRef = newTarget; } - businessObject.di.set('waypoint', this._bpmnFactory.createDiWaypoints(connection.waypoints)); + this.updateConnectionWaypoints(connection); }; diff --git a/lib/features/rules/BpmnRules.js b/lib/features/rules/BpmnRules.js index fa58adf2..3d348519 100644 --- a/lib/features/rules/BpmnRules.js +++ b/lib/features/rules/BpmnRules.js @@ -7,6 +7,7 @@ var find = require('lodash/collection/find'), var getParents = require('../modeling/util/ModelingUtil').getParents, is = require('../../util/ModelUtil').is, + isAny = require('../modeling/util/ModelingUtil').isAny, getBusinessObject = require('../../util/ModelUtil').getBusinessObject, isExpanded = require('../../util/DiUtil').isExpanded, isEventSubProcess = require('../../util/DiUtil').isEventSubProcess, @@ -327,14 +328,15 @@ function canDrop(element, target, position) { return isExpanded(target) !== false; } - return is(target, 'bpmn:Participant') || is(target, 'bpmn:Lane'); + return isAny(target, [ 'bpmn:Participant', 'bpmn:Lane' ]); } if (is(element, 'bpmn:Artifact')) { - return is(target, 'bpmn:Collaboration') || - is(target, 'bpmn:Lane') || - is(target, 'bpmn:Participant') || - is(target, 'bpmn:Process'); + return isAny(target, [ + 'bpmn:Collaboration', + 'bpmn:Lane', + 'bpmn:Participant', + 'bpmn:Process' ]); } if (is(element, 'bpmn:MessageFlow')) { @@ -578,12 +580,16 @@ function canConnectSequenceFlow(source, target) { !(is(source, 'bpmn:EventBasedGateway') && !isEventBasedTarget(target)); } + function canConnectDataAssociation(source, target) { - if (is(source, 'bpmn:DataObjectReference') && is(target, 'bpmn:Activity')) { + + if (is(source, 'bpmn:DataObjectReference') && + isAny(target, [ 'bpmn:Activity', 'bpmn:ThrowEvent' ])) { return { type: 'bpmn:DataInputAssociation' }; } - if (is(target, 'bpmn:DataObjectReference') && is(source, 'bpmn:Activity')) { + if (is(target, 'bpmn:DataObjectReference') && + isAny(source, [ 'bpmn:Activity', 'bpmn:CatchEvent' ])) { return { type: 'bpmn:DataOutputAssociation' }; } @@ -598,9 +604,8 @@ function canInsert(shape, flow, position) { // at this point we are not really able to talk // about connection rules (yet) return ( - is(flow, 'bpmn:SequenceFlow') || - is(flow, 'bpmn:MessageFlow') - ) && is(shape, 'bpmn:FlowNode') && !is(shape, 'bpmn:BoundaryEvent') && - - canDrop(shape, flow.parent, position); + isAny(flow, [ 'bpmn:SequenceFlow', 'bpmn:MessageFlow' ]) && + is(shape, 'bpmn:FlowNode') && + !is(shape, 'bpmn:BoundaryEvent') && + canDrop(shape, flow.parent, position)); } diff --git a/test/spec/features/modeling/behavior/CreateDataObjectBehaviorSpec.js b/test/spec/features/modeling/behavior/CreateDataObjectBehaviorSpec.js index bacde8dd..b3c87cd9 100644 --- a/test/spec/features/modeling/behavior/CreateDataObjectBehaviorSpec.js +++ b/test/spec/features/modeling/behavior/CreateDataObjectBehaviorSpec.js @@ -15,7 +15,9 @@ describe('features/modeling/behavior - data objects -', function() { var rootShape; + describe('DataObjectReference', function() { + var processDiagramXML = require('./CreateDataObjectBehavior.data-object-reference.bpmn'); beforeEach(bootstrapModeler(processDiagramXML, { modules: testModules })); @@ -27,6 +29,7 @@ describe('features/modeling/behavior - data objects -', function() { rootShape = canvas.getRootElement(); })); + it('should create the corresponding DataObject', inject(function(modeling) { // when @@ -63,6 +66,7 @@ describe('features/modeling/behavior - data objects -', function() { }); + describe('create', function() { var processDiagramXML = require('./CreateDataObjectBehavior.create-data-association.bpmn'); @@ -78,6 +82,7 @@ describe('features/modeling/behavior - data objects -', function() { taskShape = elementRegistry.get('Task_1'); })); + describe('dataOutputAssociation', function() { it('should execute', inject(function(modeling) { @@ -170,6 +175,7 @@ describe('features/modeling/behavior - data objects -', function() { }); + describe('remove', function() { var processDiagramXML = require('./CreateDataObjectBehavior.remove-data-association.bpmn'); @@ -191,6 +197,7 @@ describe('features/modeling/behavior - data objects -', function() { inputAssociation = elementRegistry.get('DataInputAssociation_1'); })); + describe('DataOutputAssociation', function() { it('should execute', inject(function(modeling) { @@ -235,6 +242,7 @@ describe('features/modeling/behavior - data objects -', function() { }); + describe('dataInputAssociation', function() { it('should execute', inject(function(modeling) { diff --git a/test/spec/features/rules/BpmnRulesSpec.js b/test/spec/features/rules/BpmnRulesSpec.js index 8b5de32f..817a6bc8 100644 --- a/test/spec/features/rules/BpmnRulesSpec.js +++ b/test/spec/features/rules/BpmnRulesSpec.js @@ -110,6 +110,28 @@ describe('features/modeling/rules - BpmnRules', function() { it('connect StartEvent_None -> DataObjectReference', inject(function() { expectCanConnect('StartEvent_None', 'DataObjectReference', { + sequenceFlow: false, + messageFlow: false, + association: true, + dataAssociation: { type: 'bpmn:DataOutputAssociation' } + }); + })); + + + it('connect DataObjectReference -> EndEvent_None', inject(function() { + + expectCanConnect('DataObjectReference', 'EndEvent_None', { + sequenceFlow: false, + messageFlow: false, + association: true, + dataAssociation: { type: 'bpmn:DataInputAssociation' } + }); + })); + + + it('connect EndEvent_None -> DataObjectReference', inject(function() { + + expectCanConnect('EndEvent_None', 'DataObjectReference', { sequenceFlow: false, messageFlow: false, association: true,