-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(modeling/behaviors): add behavior for deleting boundaries on rece…
…ive tasks after connecting to event based gateway
- Loading branch information
Niklas Kiefer
committed
Oct 16, 2018
1 parent
4de0e01
commit b8b84e3
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
lib/features/modeling/behavior/ConnectEventBasedGatewayBehavior.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,47 @@ | ||
import inherits from 'inherits'; | ||
|
||
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor'; | ||
|
||
import { is } from '../../../util/ModelUtil'; | ||
|
||
import { | ||
filter | ||
} from 'min-dash'; | ||
|
||
|
||
/** | ||
* Behavior for deleting boundaries from receive task after connecting them with event based gateway | ||
*/ | ||
export default function ConnectEventBasedGatewayBehavior(eventBus, modeling) { | ||
|
||
CommandInterceptor.call(this, eventBus); | ||
|
||
function extractBoundaryEvents(element) { | ||
return filter(element.attachers, function(attacher) { | ||
return is(attacher, 'bpmn:BoundaryEvent'); | ||
}); | ||
} | ||
|
||
this.postExecute('connection.create', function(context) { | ||
var source = context.context.source, | ||
target = context.context.target, | ||
boundaries = extractBoundaryEvents(target); | ||
|
||
if ( | ||
is(source, 'bpmn:EventBasedGateway') && | ||
is(target, 'bpmn:ReceiveTask') && | ||
boundaries.length > 0 | ||
) { | ||
modeling.removeElements(boundaries); | ||
} | ||
|
||
}); | ||
} | ||
|
||
ConnectEventBasedGatewayBehavior.$inject = [ | ||
'eventBus', | ||
'modeling', | ||
'bpmnRules' | ||
]; | ||
|
||
inherits(ConnectEventBasedGatewayBehavior, CommandInterceptor); |
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
21 changes: 21 additions & 0 deletions
21
test/spec/features/modeling/behavior/ConnectEventBasedGatewayBehavior.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,21 @@ | ||
<?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:dc="http://www.omg.org/spec/DD/20100524/DC" id="Definitions_1ipuizk" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="2.0.3"> | ||
<bpmn:process id="Process_1" isExecutable="true"> | ||
<bpmn:eventBasedGateway id="EventBasedGateway_1" /> | ||
<bpmn:receiveTask id="ReceiveTask_1" /> | ||
<bpmn:boundaryEvent id="BoundaryEvent_1" attachedToRef="ReceiveTask_1" /> | ||
</bpmn:process> | ||
<bpmndi:BPMNDiagram id="BPMNDiagram_1"> | ||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1"> | ||
<bpmndi:BPMNShape id="EventBasedGateway_1cu8t9h_di" bpmnElement="EventBasedGateway_1"> | ||
<dc:Bounds x="172" y="118" width="50" height="50" /> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNShape id="ReceiveTask_1vk05s6_di" bpmnElement="ReceiveTask_1"> | ||
<dc:Bounds x="300" y="103" width="100" height="80" /> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNShape id="BoundaryEvent_0xg8xmx_di" bpmnElement="BoundaryEvent_1"> | ||
<dc:Bounds x="331" y="165" width="36" height="36" /> | ||
</bpmndi:BPMNShape> | ||
</bpmndi:BPMNPlane> | ||
</bpmndi:BPMNDiagram> | ||
</bpmn:definitions> |
36 changes: 36 additions & 0 deletions
36
test/spec/features/modeling/behavior/ConnectEventBasedGatewayBehaviorSpec.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,36 @@ | ||
import { | ||
bootstrapModeler, | ||
inject | ||
} from 'test/TestHelper'; | ||
|
||
import modelingModule from 'lib/features/modeling'; | ||
import coreModule from 'lib/core'; | ||
|
||
|
||
describe('features/modeling/behavior - connect event based gateway to receive task with boundary', function() { | ||
|
||
var testModules = [ coreModule, modelingModule ]; | ||
|
||
var diagramXML = require('./ConnectEventBasedGatewayBehavior.bpmn'); | ||
|
||
beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); | ||
|
||
|
||
it('should remove the boundary event from the receive task after connecting the task with an event based gateway', | ||
inject(function(modeling, elementRegistry) { | ||
|
||
// given | ||
var eventBasedGateway = elementRegistry.get('EventBasedGateway_1'), | ||
receiveTask = elementRegistry.get('ReceiveTask_1'), | ||
boundaryEvent = elementRegistry.get('BoundaryEvent_1'); | ||
|
||
// when | ||
modeling.connect(eventBasedGateway, receiveTask, { | ||
type: 'bpmn:SequenceFlow' | ||
}); | ||
|
||
// then | ||
expect(elementRegistry.get(boundaryEvent.id)).to.be.undefined; | ||
})); | ||
|
||
}); |