Skip to content

Commit

Permalink
chore(rules): remove <connection.reconnectStart/End> rule
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme authored and nikku committed Nov 18, 2019
1 parent 1fa1670 commit 06e1478
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 178 deletions.
115 changes: 42 additions & 73 deletions lib/features/modeling/BpmnUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,14 @@ export default function BpmnUpdater(
'connection.create',
'connection.move',
'connection.delete',
'connection.reconnectEnd',
'connection.reconnectStart'
'connection.reconnect'
], ifBpmn(updateConnection));

this.reverted([
'connection.create',
'connection.move',
'connection.delete',
'connection.reconnectEnd',
'connection.reconnectStart'
'connection.reconnect'
], ifBpmn(updateConnection));


Expand All @@ -208,85 +206,56 @@ export default function BpmnUpdater(
'connection.updateWaypoints',
], ifBpmn(updateConnectionWaypoints));


// update Default & Conditional flows
this.executed([
'connection.reconnectEnd',
'connection.reconnectStart'
], ifBpmn(function(e) {
var context = e.context,
// update conditional/default flows
this.executed('connection.reconnect', ifBpmn(function(event) {
var context = event.context,
connection = context.connection,
businessObject = getBusinessObject(connection),
oldSource = getBusinessObject(context.oldSource),
oldTarget = getBusinessObject(context.oldTarget),
newSource = getBusinessObject(connection.source),
newTarget = getBusinessObject(connection.target);

if (oldSource === newSource || oldTarget === newTarget) {
return;
}

// on reconnectStart -> default flow
if (oldSource && oldSource.default === businessObject) {
context.default = oldSource.default;
oldSource.default = undefined;
oldSource = context.oldSource,
newSource = context.newSource,
connectionBo = getBusinessObject(connection),
oldSourceBo = getBusinessObject(oldSource),
newSourceBo = getBusinessObject(newSource);

// remove condition from connection on reconnect to new source
// if new source can NOT have condional sequence flow
if (connectionBo.conditionExpression && !isAny(newSourceBo, [
'bpmn:Activity',
'bpmn:ExclusiveGateway',
'bpmn:InclusiveGateway'
])) {
context.oldConditionExpression = connectionBo.conditionExpression;

delete connectionBo.conditionExpression;
}

// on reconnectEnd -> default flow
if ((businessObject.sourceRef && businessObject.sourceRef.default) &&
!isAny(newTarget, [
'bpmn:Activity',
'bpmn:EndEvent',
'bpmn:Gateway',
'bpmn:IntermediateThrowEvent',
'bpmn:IntermediateCatchEvent'
])) {
context.default = businessObject.sourceRef.default;
businessObject.sourceRef.default = undefined;
}

// on reconnectStart -> conditional flow
if (oldSource && (businessObject.conditionExpression) &&
!(is(newSource, 'bpmn:Activity') ||
is(newSource, 'bpmn:Gateway'))) {
context.conditionExpression = businessObject.conditionExpression;
businessObject.conditionExpression = undefined;
}
// remove default from old source flow on reconnect to new source
// if source changed
if (oldSource !== newSource && oldSourceBo.default === connectionBo) {
context.oldDefault = oldSourceBo.default;

// on reconnectEnd -> conditional flow
if (oldTarget && (businessObject.conditionExpression) &&
!isAny(newTarget, [
'bpmn:Activity',
'bpmn:EndEvent',
'bpmn:Gateway',
'bpmn:IntermediateThrowEvent',
'bpmn:IntermediateCatchEvent'
])) {
context.conditionExpression = businessObject.conditionExpression;
businessObject.conditionExpression = undefined;
delete oldSourceBo.default;
}
}));

this.reverted([
'connection.reconnectEnd',
'connection.reconnectStart'
], ifBpmn(function(e) {
var context = e.context,
this.reverted('connection.reconnect', ifBpmn(function(event) {
var context = event.context,
connection = context.connection,
businessObject = getBusinessObject(connection),
newSource = getBusinessObject(connection.source);

// default flow
if (context.default) {
if (is(newSource, 'bpmn:ExclusiveGateway') || is(newSource, 'bpmn:InclusiveGateway') ||
is(newSource, 'bpmn:Activity')) {
newSource.default = context.default;
}
oldSource = context.oldSource,
newSource = context.newSource,
connectionBo = getBusinessObject(connection),
oldSourceBo = getBusinessObject(oldSource),
newSourceBo = getBusinessObject(newSource);

// add condition to connection on revert reconnect to new source
if (context.oldConditionExpression) {
connectionBo.conditionExpression = context.oldConditionExpression;
}

// conditional flow
if (context.conditionExpression && is(newSource, 'bpmn:Activity')) {
businessObject.conditionExpression = context.conditionExpression;
// add default to old source on revert reconnect to new source
if (context.oldDefault) {
oldSourceBo.default = context.oldDefault;

delete newSourceBo.default;
}
}));

Expand Down
2 changes: 1 addition & 1 deletion lib/features/modeling/behavior/BoundaryEventBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function BoundaryEventBehavior(eventBus, modeling) {
});

// remove after replacing connected gateway with event-based gateway
this.postExecute('connection.reconnectStart', function(event) {
this.postExecute('connection.reconnect', function(event) {
var oldSource = event.context.oldSource,
newSource = event.context.newSource;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ export default function DataInputAssociationBehavior(eventBus, bpmnFactory) {
'connection.create',
'connection.delete',
'connection.move',
'connection.reconnectEnd'
'connection.reconnect'
], ifDataInputAssociation(fixTargetRef));

this.reverted([
'connection.create',
'connection.delete',
'connection.move',
'connection.reconnectEnd'
'connection.reconnect'
], ifDataInputAssociation(fixTargetRef));


Expand Down
10 changes: 3 additions & 7 deletions lib/features/modeling/behavior/ReplaceConnectionBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,7 @@ export default function ReplaceConnectionBehavior(eventBus, modeling, bpmnRules,
forEach(allConnections, fixConnection);
}, true);

this.preExecute([
'connection.reconnect',
'connection.reconnectStart',
'connection.reconnectEnd'
], replaceReconnectedConnection);
this.preExecute('connection.reconnect', replaceReconnectedConnection);

this.postExecuted('element.updateProperties', function(event) {
var context = event.context,
Expand All @@ -159,7 +155,7 @@ export default function ReplaceConnectionBehavior(eventBus, modeling, bpmnRules,
businessObject = element.businessObject,
connection;

// remove condition expression when morphing to default flow
// remove condition on change to default
if (properties.default) {
connection = find(
element.outgoing,
Expand All @@ -171,7 +167,7 @@ export default function ReplaceConnectionBehavior(eventBus, modeling, bpmnRules,
}
}

// remove default property from source when morphing to conditional flow
// remove default from source on change to conditional
if (properties.conditionExpression && businessObject.sourceRef.default === businessObject) {
modeling.updateProperties(element.source, { default: undefined });
}
Expand Down
18 changes: 0 additions & 18 deletions lib/features/rules/BpmnRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,6 @@ BpmnRules.prototype.init = function() {
}
});

this.addRule('connection.reconnectStart', function(context) {

var connection = context.connection,
source = context.hover || context.source,
target = connection.target;

return canConnect(source, target, connection);
});

this.addRule('connection.reconnectEnd', function(context) {

var connection = context.connection,
source = connection.source,
target = context.hover || context.target;

return canConnect(source, target, connection);
});

this.addRule('connection.reconnect', function(context) {

var connection = context.connection,
Expand Down
13 changes: 2 additions & 11 deletions test/integration/custom-elements/CustomRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,15 @@ CustomRules.prototype.init = function() {
return canConnect(source, target);
});

this.addRule('connection.reconnectStart', HIGH_PRIORITY, function(context) {
this.addRule('connection.reconnect', HIGH_PRIORITY, function(context) {

var connection = context.connection,
source = context.hover || context.source,
source = context.source,
target = connection.target;

return canConnect(source, target, connection);
});

this.addRule('connection.reconnectEnd', HIGH_PRIORITY, function(context) {

var connection = context.connection,
source = connection.source,
target = context.hover || context.target;

return canConnect(source, target, connection);
});

this.addRule('connection.updateWaypoints', HIGH_PRIORITY, function(context) {

// OK! but visually ignore
Expand Down
66 changes: 0 additions & 66 deletions test/spec/features/popup-menu/ReplaceMenuProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1353,40 +1353,6 @@ describe('features/popup-menu - replace menu provider', function() {
);


[
'bpmn:StartEvent'
].forEach(function(type) {

it('should replace DefaultFlow with SequenceFlow when changing target to ' + type,
inject(function(elementRegistry, elementFactory, canvas, popupMenu, modeling) {

// given
var sequenceFlow = elementRegistry.get('SequenceFlow_1'),
root = canvas.getRootElement();

var intermediateEvent = elementFactory.createShape({ type: type });

modeling.createShape(intermediateEvent, { x: 686, y: 50 }, root);

openPopup(sequenceFlow);

triggerAction(popupMenu, 'replace-with-default-flow');

// when
modeling.reconnectEnd(sequenceFlow, intermediateEvent, [
{ x: 686, y: 267, original: { x: 686, y: 307 } },
{ x: 686, y: 50, original: { x: 686, y: 75 } }
]);

var gateway = elementRegistry.get('ExclusiveGateway_1');

// then
expect(gateway.businessObject.default).not.to.exist;
})
);
});


[
'bpmn:Activity',
'bpmn:EndEvent',
Expand Down Expand Up @@ -1686,38 +1652,6 @@ describe('features/popup-menu - replace menu provider', function() {
);


[
'bpmn:StartEvent'
].forEach(function(type) {

it('should replace ConditionalFlow with SequenceFlow when changing target to ' + type,
inject(function(elementRegistry, elementFactory, canvas, popupMenu, modeling) {

// given
var sequenceFlow = elementRegistry.get('SequenceFlow_3'),
root = canvas.getRootElement(),
intermediateEvent = elementFactory.createShape({ type: type });

modeling.createShape(intermediateEvent, { x: 497, y: 197 }, root);

openPopup(sequenceFlow);

triggerAction(popupMenu, 'replace-with-conditional-flow');

// when
modeling.reconnectEnd(sequenceFlow, intermediateEvent, [
{ x: 389, y: 197, original: { x: 389, y: 197 } },
{ x: 497, y: 197, original: { x: 497, y: 197 } }
]);

// then
expect(sequenceFlow.businessObject.conditionExpression).not.to.exist;
})
);

});


[
'bpmn:Activity',
'bpmn:EndEvent',
Expand Down

0 comments on commit 06e1478

Please sign in to comment.