fix(rules): allow data-association + participant move

Closes #638
This commit is contained in:
Nico Rehwaldt 2016-12-06 14:49:45 +01:00
parent c308151474
commit bf133bb8da
6 changed files with 110 additions and 40 deletions

View File

@ -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.
*

View File

@ -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',

View File

@ -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,
@ -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;
@ -405,7 +419,7 @@ 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);
}
@ -413,6 +427,12 @@ function canDrop(element, target, position) {
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',

View File

@ -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;
}

View File

@ -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>

View File

@ -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) {
it('move selection including data association', inject(function(elementRegistry) {
// when
var elements = [
elementRegistry.get('Task'),
elementRegistry.get('DataAssociation'),
elementRegistry.get('DataObjectReference')
];
// when
var elements = [
elementRegistry.get('Task'),
elementRegistry.get('DataAssociation'),
elementRegistry.get('DataObjectReference')
];
// then
expectCanMove(elements, 'Process', {
attach: false,
move: true
});
}));
// 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
});
}));
});
});