-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add
isForCompensation
on connect
Closes #2038
- Loading branch information
Showing
7 changed files
with
284 additions
and
14 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
lib/features/modeling/behavior/CompensateBoundaryEventBehaviour.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import inherits from 'inherits-browser'; | ||
|
||
import { is } from '../../../util/ModelUtil'; | ||
|
||
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor'; | ||
import { hasEventDefinition } from '../../../util/DiUtil'; | ||
|
||
/** | ||
* @typedef {import('diagram-js/lib/core/EventBus').default} EventBus | ||
* @typedef {import('diagram-js/lib/features/modeling/Modeling').default} Modeling | ||
*/ | ||
|
||
export default function CompensateBoundaryEventBehaviour(eventBus, modeling) { | ||
|
||
CommandInterceptor.call(this, eventBus); | ||
|
||
function addIsForCompensationProperty(source, target) { | ||
if (isCompensationBoundaryEvent(source)) { | ||
if (is(target, 'bpmn:Activity') && !isForCompensation(target)) { | ||
modeling.updateProperties(target, { isForCompensation: true }); | ||
} | ||
} | ||
} | ||
|
||
function removeIsForCompensationProperty(source, target) { | ||
if (isCompensationBoundaryEvent(source)) { | ||
if (is(target, 'bpmn:Activity') && isForCompensation(target)) { | ||
modeling.updateProperties(target, { isForCompensation: false }); | ||
} | ||
} | ||
} | ||
|
||
this.preExecute('connection.create', function(context) { | ||
var source = context.source, | ||
target = context.target; | ||
|
||
addIsForCompensationProperty(source, target); | ||
}, true); | ||
|
||
this.postExecute('connection.reconnect', function(context) { | ||
var newSource = context.newSource, | ||
newTarget = context.newTarget, | ||
oldSource = context.oldSource, | ||
oldTarget = context.oldTarget; | ||
|
||
// add `isForCompensation` to new target | ||
addIsForCompensationProperty(newSource, newTarget); | ||
|
||
// remove `isForCompensation` from old target | ||
removeIsForCompensationProperty(oldSource, oldTarget); | ||
}, true); | ||
|
||
this.postExecute('connection.delete', function(context) { | ||
var source = context.source, | ||
target = context.target; | ||
|
||
removeIsForCompensationProperty(source, target); | ||
}, true); | ||
|
||
} | ||
|
||
inherits(CompensateBoundaryEventBehaviour, CommandInterceptor); | ||
|
||
CompensateBoundaryEventBehaviour.$inject = [ | ||
'eventBus', | ||
'modeling' | ||
]; | ||
|
||
// helpers ////////// | ||
|
||
function isForCompensation(element) { | ||
return element && element.businessObject.isForCompensation; | ||
} | ||
|
||
function isCompensationBoundaryEvent(element) { | ||
return element && is(element, 'bpmn:BoundaryEvent') && | ||
hasEventDefinition(element, 'bpmn:CompensateEventDefinition'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
test/spec/features/modeling/behavior/CompensateBoundaryEventBehaviour.bpmn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="sid-38422fae-e03e-43a3-bef4-bd33b32041b2" targetNamespace="http://bpmn.io/bpmn" exporter="Camunda Modeler" exporterVersion="5.17.0-rc.0"> | ||
<process id="Process_1" isExecutable="false"> | ||
<task id="Task_BoundaryEvent" /> | ||
<boundaryEvent id="Attached_Event" attachedToRef="Task_BoundaryEvent"> | ||
<compensateEventDefinition id="CompensateEventDefinition_1v5ffnt" /> | ||
</boundaryEvent> | ||
<task id="Task" /> | ||
<task id="Task_BoundaryEvent2" /> | ||
<boundaryEvent id="Attached_Event2" attachedToRef="Task_BoundaryEvent2"> | ||
<compensateEventDefinition id="CompensateEventDefinition_0o69h2g" /> | ||
</boundaryEvent> | ||
<task id="Task_Compensation" isForCompensation="true" /> | ||
<association id="Association" associationDirection="One" sourceRef="Attached_Event2" targetRef="Task_Compensation" /> | ||
</process> | ||
<bpmndi:BPMNDiagram id="BpmnDiagram_1"> | ||
<bpmndi:BPMNPlane id="BpmnPlane_1" bpmnElement="Process_1"> | ||
<bpmndi:BPMNShape id="Activity_0ne36hy_di" bpmnElement="Task_BoundaryEvent"> | ||
<omgdc:Bounds x="200" y="80" width="100" height="80" /> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNShape id="Activity_0l16eqc_di" bpmnElement="Task"> | ||
<omgdc:Bounds x="360" y="80" width="100" height="80" /> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNShape id="BPMNShape_14r8htx" bpmnElement="Task_BoundaryEvent2"> | ||
<omgdc:Bounds x="210" y="270" width="100" height="80" /> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNShape id="Activity_0asoxmo_di" bpmnElement="Task_Compensation"> | ||
<omgdc:Bounds x="320" y="390" width="100" height="80" /> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNEdge id="Association_di" bpmnElement="Association"> | ||
<di:waypoint x="250" y="368" /> | ||
<di:waypoint x="250" y="430" /> | ||
<di:waypoint x="320" y="430" /> | ||
</bpmndi:BPMNEdge> | ||
<bpmndi:BPMNShape id="Event_12wgrmv_di" bpmnElement="Attached_Event"> | ||
<omgdc:Bounds x="222" y="142" width="36" height="36" /> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNShape id="BPMNShape_0lrjsju" bpmnElement="Attached_Event2"> | ||
<omgdc:Bounds x="232" y="332" width="36" height="36" /> | ||
</bpmndi:BPMNShape> | ||
</bpmndi:BPMNPlane> | ||
</bpmndi:BPMNDiagram> | ||
</definitions> |
115 changes: 115 additions & 0 deletions
115
test/spec/features/modeling/behavior/CompensateBoundaryEventBehaviourSpec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { | ||
bootstrapModeler, | ||
inject | ||
} from 'test/TestHelper'; | ||
|
||
import modelingModule from 'lib/features/modeling'; | ||
import coreModule from 'lib/core'; | ||
|
||
import diagramXML from './CompensateBoundaryEventBehaviour.bpmn'; | ||
|
||
|
||
describe('features/modeling/behavior - compensation boundary event', function() { | ||
|
||
var testModules = [ coreModule, modelingModule ]; | ||
|
||
beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); | ||
|
||
|
||
describe('should add `isForCompensation`', function() { | ||
|
||
it('on append', inject(function(elementFactory, modeling, elementRegistry) { | ||
|
||
// given | ||
var boundaryEventShape = elementRegistry.get('Attached_Event'); | ||
var taskShape = elementFactory.createShape({ type: 'bpmn:Task' }); | ||
|
||
// when | ||
var task = modeling.appendShape(boundaryEventShape, taskShape, { x: 100, y: 100 }); | ||
|
||
// then | ||
expect(task.businessObject.isForCompensation).to.be.true; | ||
})); | ||
|
||
|
||
it('on connect', inject(function(modeling, elementRegistry) { | ||
|
||
// given | ||
var boundaryEventShape = elementRegistry.get('Attached_Event'); | ||
var taskShape = elementRegistry.get('Task'); | ||
|
||
// when | ||
modeling.connect(boundaryEventShape, taskShape); | ||
|
||
// then | ||
expect(taskShape.businessObject.isForCompensation).to.be.true; | ||
})); | ||
|
||
|
||
it('on reconnect', inject(function(modeling, elementRegistry) { | ||
|
||
// given | ||
var taskShape = elementRegistry.get('Task'); | ||
var connection = elementRegistry.get('Association'); | ||
|
||
// when | ||
modeling.reconnectEnd(connection, taskShape, { x: 100, y: 100 }); | ||
|
||
// then | ||
expect(taskShape.businessObject.isForCompensation).to.be.true; | ||
})); | ||
}); | ||
|
||
|
||
describe('should remove `isForCompensation`', function() { | ||
|
||
it('on remove element', inject(function(elementRegistry, modeling) { | ||
|
||
// given | ||
var taskShape = elementRegistry.get('Task_Compensation'); | ||
var boundaryEventShape = elementRegistry.get('Attached_Event2'); | ||
|
||
// then | ||
expect(taskShape.businessObject.isForCompensation).to.be.true; | ||
|
||
// when | ||
modeling.removeElements([ boundaryEventShape ]); | ||
|
||
// then | ||
expect(taskShape.businessObject.isForCompensation).to.be.false; | ||
})); | ||
|
||
|
||
it('on delete connection', inject(function(elementRegistry, modeling) { | ||
|
||
// given | ||
var taskShape = elementRegistry.get('Task_Compensation'); | ||
var connection = elementRegistry.get('Association'); | ||
|
||
// then | ||
expect(taskShape.businessObject.isForCompensation).to.be.true; | ||
|
||
// when | ||
modeling.removeConnection(connection); | ||
|
||
// then | ||
expect(taskShape.businessObject.isForCompensation).to.be.false; | ||
})); | ||
|
||
|
||
it('on reconnect', inject(function(modeling, elementRegistry) { | ||
|
||
// given | ||
var oldShape = elementRegistry.get('Task_Compensation'); | ||
var taskShape = elementRegistry.get('Task'); | ||
var connection = elementRegistry.get('Association'); | ||
|
||
// when | ||
modeling.reconnectEnd(connection, taskShape, { x: 100, y: 100 }); | ||
|
||
// then | ||
expect(oldShape.businessObject.isForCompensation).to.be.false; | ||
})); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters