Skip to content

Commit

Permalink
feat(event-reference): handle signal
Browse files Browse the repository at this point in the history
  • Loading branch information
strangelookingnerd committed Jun 13, 2024
1 parent faecdbf commit ca307d3
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 3 deletions.
8 changes: 7 additions & 1 deletion rules/event-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = function() {
// helpers /////////////////////////////

function getEvents(definition) {
return definition.rootElements.filter(node => isAny(node, [ 'bpmn:Error', 'bpmn:Escalation', 'bpmn:Message' ]));
return definition.rootElements.filter(node => isAny(node, [ 'bpmn:Error', 'bpmn:Escalation', 'bpmn:Message', 'bpmn:Signal' ]));
}

function getEventDefinitions(definition) {
Expand Down Expand Up @@ -96,6 +96,12 @@ module.exports = function() {
eventDefinitions.some(node => is(node, 'bpmn:MessageEventDefinition') && event.id === node.messageRef?.id)
);
}

if (is(event, 'bpmn:Signal')) {
return (
eventDefinitions.some(node => is(node, 'bpmn:SignalEventDefinition') && event.id === node.signalRef?.id)
);
}
}

function isUnique(event, events) {
Expand Down
28 changes: 26 additions & 2 deletions test/rules/event-reference.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ RuleTester.verify('event-reference', rule, {
message: 'Event reference is missing name'
}
},
{
moddleElement: readModdle(__dirname + '/event-reference/invalid-signal-missing-name.bpmn'),
report: {
id: 'Signal',
message: 'Event reference is missing name'
}
},
{
moddleElement: readModdle(__dirname + '/event-reference/invalid-error-missing-reference.bpmn'),
report: {
Expand All @@ -70,8 +77,14 @@ RuleTester.verify('event-reference', rule, {
id: 'Message',
message: 'Event reference is unused'
}
}
,
},
{
moddleElement: readModdle(__dirname + '/event-reference/invalid-signal-missing-reference.bpmn'),
report: {
id: 'Signal',
message: 'Event reference is unused'
}
},
{
moddleElement: readModdle(__dirname + '/event-reference/invalid-error-duplicate-name.bpmn'),
report: [ {
Expand Down Expand Up @@ -104,6 +117,17 @@ RuleTester.verify('event-reference', rule, {
id: 'Message_2',
message: 'Event reference name is not unique'
} ]
},
{
moddleElement: readModdle(__dirname + '/event-reference/invalid-signal-duplicate-name.bpmn'),
report: [ {
id: 'Signal_1',
message: 'Event reference name is not unique'
},
{
id: 'Signal_2',
message: 'Event reference name is not unique'
} ]
}
]
});
52 changes: 52 additions & 0 deletions test/rules/event-reference/invalid-signal-duplicate-name.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0zv8bs3" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.23.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.21.0">
<bpmn:process id="Process_0im3pgs" isExecutable="true">
<bpmn:startEvent id="Event_1ek0ibx">
<bpmn:outgoing>Flow_1lbzt1x</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:task id="Activity_0ojgle7">
<bpmn:incoming>Flow_1lbzt1x</bpmn:incoming>
<bpmn:outgoing>Flow_12y8z81</bpmn:outgoing>
</bpmn:task>
<bpmn:sequenceFlow id="Flow_1lbzt1x" sourceRef="Event_1ek0ibx" targetRef="Activity_0ojgle7" />
<bpmn:endEvent id="Event_1n3szzo">
<bpmn:incoming>Flow_12y8z81</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_12y8z81" sourceRef="Activity_0ojgle7" targetRef="Event_1n3szzo" />
<bpmn:boundaryEvent id="Event_1dn4l2w" attachedToRef="Activity_0ojgle7">
<bpmn:signalEventDefinition id="SignalEventDefinition_1s5byv2" signalRef="Signal_1" />
</bpmn:boundaryEvent>
<bpmn:boundaryEvent id="Event_11h2smc" attachedToRef="Activity_0ojgle7">
<bpmn:signalEventDefinition id="SignalEventDefinition_1diu6pl" signalRef="Signal_2" />
</bpmn:boundaryEvent>
</bpmn:process>
<bpmn:signal id="Signal_1" name="Signal" />
<bpmn:signal id="Signal_2" name="Signal" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0im3pgs">
<bpmndi:BPMNShape id="Event_1ek0ibx_di" bpmnElement="Event_1ek0ibx">
<dc:Bounds x="152" y="82" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0ojgle7_di" bpmnElement="Activity_0ojgle7">
<dc:Bounds x="240" y="60" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1n3szzo_di" bpmnElement="Event_1n3szzo">
<dc:Bounds x="392" y="82" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1n7f50y_di" bpmnElement="Event_1dn4l2w">
<dc:Bounds x="252" y="122" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0ygzo67_di" bpmnElement="Event_11h2smc">
<dc:Bounds x="292" y="122" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_1lbzt1x_di" bpmnElement="Flow_1lbzt1x">
<di:waypoint x="188" y="100" />
<di:waypoint x="240" y="100" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_12y8z81_di" bpmnElement="Flow_12y8z81">
<di:waypoint x="340" y="100" />
<di:waypoint x="392" y="100" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
45 changes: 45 additions & 0 deletions test/rules/event-reference/invalid-signal-missing-name.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0zv8bs3" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.23.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.21.0">
<bpmn:process id="Process_0im3pgs" isExecutable="true">
<bpmn:startEvent id="Event_1ek0ibx">
<bpmn:outgoing>Flow_1lbzt1x</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:task id="Activity_0ojgle7">
<bpmn:incoming>Flow_1lbzt1x</bpmn:incoming>
<bpmn:outgoing>Flow_12y8z81</bpmn:outgoing>
</bpmn:task>
<bpmn:sequenceFlow id="Flow_1lbzt1x" sourceRef="Event_1ek0ibx" targetRef="Activity_0ojgle7" />
<bpmn:endEvent id="Event_1n3szzo">
<bpmn:incoming>Flow_12y8z81</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_12y8z81" sourceRef="Activity_0ojgle7" targetRef="Event_1n3szzo" />
<bpmn:boundaryEvent id="Event_11h2smc" attachedToRef="Activity_0ojgle7">
<bpmn:signalEventDefinition id="SignalEventDefinition_18471yn" signalRef="Signal" />
</bpmn:boundaryEvent>
</bpmn:process>
<bpmn:signal id="Signal" name="" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0im3pgs">
<bpmndi:BPMNShape id="Event_1ek0ibx_di" bpmnElement="Event_1ek0ibx">
<dc:Bounds x="152" y="82" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0ojgle7_di" bpmnElement="Activity_0ojgle7">
<dc:Bounds x="240" y="60" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1n3szzo_di" bpmnElement="Event_1n3szzo">
<dc:Bounds x="392" y="82" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0q67c7n_di" bpmnElement="Event_11h2smc">
<dc:Bounds x="292" y="122" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_1lbzt1x_di" bpmnElement="Flow_1lbzt1x">
<di:waypoint x="188" y="100" />
<di:waypoint x="240" y="100" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_12y8z81_di" bpmnElement="Flow_12y8z81">
<di:waypoint x="340" y="100" />
<di:waypoint x="392" y="100" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
39 changes: 39 additions & 0 deletions test/rules/event-reference/invalid-signal-missing-reference.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0zv8bs3" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.23.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.21.0">
<bpmn:process id="Process_0im3pgs" isExecutable="true">
<bpmn:startEvent id="Event_1ek0ibx">
<bpmn:outgoing>Flow_1lbzt1x</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:task id="Activity_0ojgle7">
<bpmn:incoming>Flow_1lbzt1x</bpmn:incoming>
<bpmn:outgoing>Flow_12y8z81</bpmn:outgoing>
</bpmn:task>
<bpmn:sequenceFlow id="Flow_1lbzt1x" sourceRef="Event_1ek0ibx" targetRef="Activity_0ojgle7" />
<bpmn:endEvent id="Event_1n3szzo">
<bpmn:incoming>Flow_12y8z81</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_12y8z81" sourceRef="Activity_0ojgle7" targetRef="Event_1n3szzo" />
</bpmn:process>
<bpmn:signal id="Signal" name="Signal" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0im3pgs">
<bpmndi:BPMNShape id="Event_1ek0ibx_di" bpmnElement="Event_1ek0ibx">
<dc:Bounds x="152" y="82" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0ojgle7_di" bpmnElement="Activity_0ojgle7">
<dc:Bounds x="240" y="60" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1n3szzo_di" bpmnElement="Event_1n3szzo">
<dc:Bounds x="392" y="82" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_1lbzt1x_di" bpmnElement="Flow_1lbzt1x">
<di:waypoint x="188" y="100" />
<di:waypoint x="240" y="100" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_12y8z81_di" bpmnElement="Flow_12y8z81">
<di:waypoint x="340" y="100" />
<di:waypoint x="392" y="100" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
48 changes: 48 additions & 0 deletions test/rules/event-reference/valid-signal.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?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" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0zv8bs3" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.23.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.21.0">
<bpmn:process id="Process_0im3pgs" isExecutable="true">
<bpmn:startEvent id="Event_1ek0ibx">
<bpmn:outgoing>Flow_1lbzt1x</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:task id="Activity_0ojgle7">
<bpmn:incoming>Flow_1lbzt1x</bpmn:incoming>
<bpmn:outgoing>Flow_12y8z81</bpmn:outgoing>
</bpmn:task>
<bpmn:sequenceFlow id="Flow_1lbzt1x" sourceRef="Event_1ek0ibx" targetRef="Activity_0ojgle7" />
<bpmn:endEvent id="Event_1n3szzo">
<bpmn:incoming>Flow_12y8z81</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_12y8z81" sourceRef="Activity_0ojgle7" targetRef="Event_1n3szzo" />
<bpmn:boundaryEvent id="Event_11h2smc" attachedToRef="Activity_0ojgle7">
<bpmn:signalEventDefinition id="SignalEventDefinition_08cmi9t" signalRef="Signal" />
</bpmn:boundaryEvent>
</bpmn:process>
<bpmn:signal id="Signal" name="Signal" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0im3pgs">
<bpmndi:BPMNShape id="Event_1ek0ibx_di" bpmnElement="Event_1ek0ibx">
<dc:Bounds x="152" y="82" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0ojgle7_di" bpmnElement="Activity_0ojgle7">
<dc:Bounds x="240" y="60" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1n3szzo_di" bpmnElement="Event_1n3szzo">
<dc:Bounds x="392" y="82" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_01gaag9_di" bpmnElement="Event_11h2smc">
<dc:Bounds x="292" y="122" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="295" y="165" width="32" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_1lbzt1x_di" bpmnElement="Flow_1lbzt1x">
<di:waypoint x="188" y="100" />
<di:waypoint x="240" y="100" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_12y8z81_di" bpmnElement="Flow_12y8z81">
<di:waypoint x="340" y="100" />
<di:waypoint x="392" y="100" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

0 comments on commit ca307d3

Please sign in to comment.