Skip to content

Commit

Permalink
fix(rules): allow data-association + participant move
Browse files Browse the repository at this point in the history
Closes #638
  • Loading branch information
nikku committed Dec 19, 2016
1 parent c308151 commit bf133bb
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 40 deletions.
18 changes: 0 additions & 18 deletions lib/features/modeling/util/ModelingUtil.js
Expand Up @@ -5,24 +5,6 @@ var any = require('lodash/collection/any');
var is = require('../../../util/ModelUtil').is;


function getParents(element) {

var parents = [];

while (element) {
element = element.parent;

if (element) {
parents.push(element);
}
}

return parents;
}

module.exports.getParents = getParents;


/**
* Return true if element has any of the given types.
*
Expand Down
4 changes: 2 additions & 2 deletions lib/features/ordering/BpmnOrderingProvider.js
Expand Up @@ -33,8 +33,8 @@ function BpmnOrderingProvider(eventBus, translate) {
]
}
},
{ type: 'bpmn:DataInputAssociation', order: { level: 9, containers: [ 'bpmn:Collaboration', 'bpmn:Process' ] } },
{ type: 'bpmn:DataOutputAssociation', order: { level: 9, containers: [ 'bpmn:Collaboration', 'bpmn:Process' ] } },
// handle DataAssociation(s) like message flows and render them always on top
{ type: 'bpmn:DataAssociation', order: { level: 9, containers: [ 'bpmn:Collaboration', 'bpmn:Process' ] } },
{ type: 'bpmn:MessageFlow', order: { level: 9, containers: [ 'bpmn:Collaboration' ] } },
{
type: 'bpmn:Association',
Expand Down
26 changes: 23 additions & 3 deletions lib/features/rules/BpmnRules.js
Expand Up @@ -7,8 +7,7 @@ var find = require('lodash/collection/find'),
forEach = require('lodash/collection/forEach'),
inherits = require('inherits');

var getParents = require('../modeling/util/ModelingUtil').getParents,
is = require('../../util/ModelUtil').is,
var is = require('../../util/ModelUtil').is,
isAny = require('../modeling/util/ModelingUtil').isAny,
getBusinessObject = require('../../util/ModelUtil').getBusinessObject,
isExpanded = require('../../util/DiUtil').isExpanded,
Expand Down Expand Up @@ -310,6 +309,21 @@ function isConnection(element) {
return element.waypoints;
}

function getParents(element) {

var parents = [];

while (element) {
element = element.parent;

if (element) {
parents.push(element);
}
}

return parents;
}

function isParent(possibleParent, element) {
var allParents = getParents(element);
return allParents.indexOf(possibleParent) !== -1;
Expand Down Expand Up @@ -405,14 +419,20 @@ function canDrop(element, target, position) {

// drop flow elements onto flow element containers
// and participants
if (is(element, 'bpmn:FlowElement') || is(element, 'bpmn:DataAssociation')) {
if (is(element, 'bpmn:FlowElement')) {
if (is(target, 'bpmn:FlowElementsContainer')) {
return isExpanded(target);
}

return isAny(target, [ 'bpmn:Participant', 'bpmn:Lane' ]);
}

// account for the fact that data associations are always
// rendered and moved to top (Process or Collaboration level)
if (is(element, 'bpmn:DataAssociation')) {
return isAny(target, [ 'bpmn:Collaboration', 'bpmn:Process' ]);
}

if (is(element, 'bpmn:Artifact')) {
return isAny(target, [
'bpmn:Collaboration',
Expand Down
8 changes: 6 additions & 2 deletions lib/import/BpmnImporter.js
Expand Up @@ -118,8 +118,12 @@ BpmnImporter.prototype.add = function(semantic, parentElement) {
waypoints: collectWaypoints(semantic.di.waypoint)
}));

if (is(semantic, 'bpmn:DataInputAssociation') || is(semantic, 'bpmn:DataOutputAssociation')) {
// implicit root element
if (is(semantic, 'bpmn:DataAssociation')) {

// render always on top; this ensures DataAssociations
// are rendered correctly across different "hacks" people
// love to model such as cross participant / sub process
// associations
parentElement = null;
}

Expand Down
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.5.1">
<bpmn:collaboration id="Collaboration">
<bpmn:participant id="Participant" processRef="Process_1" />
</bpmn:collaboration>
<bpmn:process id="Process_1" isExecutable="false">
<bpmn:task id="Task">
<bpmn:property id="Property_1oyztzi" name="__targetRef_placeholder" />
<bpmn:dataInputAssociation id="DataInputAssociation">
<bpmn:sourceRef>DataStoreReference</bpmn:sourceRef>
<bpmn:targetRef>Property_1oyztzi</bpmn:targetRef>
</bpmn:dataInputAssociation>
</bpmn:task>
<bpmn:dataStoreReference id="DataStoreReference" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration">
<bpmndi:BPMNShape id="Participant_di" bpmnElement="Participant">
<dc:Bounds x="28" y="24" width="300" height="250" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="DataStoreReference_di" bpmnElement="DataStoreReference">
<dc:Bounds x="109" y="194" width="50" height="50" />
<bpmndi:BPMNLabel>
<dc:Bounds x="134" y="244" width="0" height="0" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Task_di" bpmnElement="Task">
<dc:Bounds x="153" y="64" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="DataInputAssociation_di" bpmnElement="DataInputAssociation">
<di:waypoint xsi:type="dc:Point" x="149" y="194" />
<di:waypoint xsi:type="dc:Point" x="179" y="144" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
58 changes: 43 additions & 15 deletions test/spec/features/rules/BpmnRulesSpec.js
Expand Up @@ -866,26 +866,54 @@ describe('features/modeling/rules - BpmnRules', function() {

describe('data association move', function() {

var testXML = require('./BpmnRules.dataAssociation.bpmn');
describe('on process diagram', function() {

beforeEach(bootstrapModeler(testXML, { modules: testModules }));
var testXML = require('./BpmnRules.dataAssociation.bpmn');

beforeEach(bootstrapModeler(testXML, { modules: testModules }));

it('mode selection including data association', inject(function(elementRegistry) {

// when
var elements = [
elementRegistry.get('Task'),
elementRegistry.get('DataAssociation'),
elementRegistry.get('DataObjectReference')
];
it('move selection including data association', inject(function(elementRegistry) {

// then
expectCanMove(elements, 'Process', {
attach: false,
move: true
});
}));
// when
var elements = [
elementRegistry.get('Task'),
elementRegistry.get('DataAssociation'),
elementRegistry.get('DataObjectReference')
];

// then
expectCanMove(elements, 'Process', {
attach: false,
move: true
});
}));

});


describe('on collaboration', function() {

var testXML = require('./BpmnRules.collaboration-dataAssociation.bpmn');

beforeEach(bootstrapModeler(testXML, { modules: testModules }));


it('move participant and data association', inject(function(elementRegistry) {

// when
var elements = [
elementRegistry.get('DataInputAssociation'),
elementRegistry.get('Participant')
];

// then
expectCanMove(elements, 'Collaboration', {
attach: false,
move: true
});
}));
});

});

Expand Down

0 comments on commit bf133bb

Please sign in to comment.