Skip to content

Commit

Permalink
Add Event Gateway rules
Browse files Browse the repository at this point in the history
  • Loading branch information
caleeli committed May 28, 2021
1 parent df19002 commit 4012f85
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
rules: {
'processmaker/custom-validation': 'error',
'processmaker/gateway-direction': 'error',
'processmaker/event-based-gateway': 'error',
'processmaker/call-activity-child-process': 'error',
'processmaker/call-activity-sequence-flow': 'error',
'processmaker/id-required': 'error',
Expand Down
44 changes: 44 additions & 0 deletions rules/event-based-gateway.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const { isAny } = require('bpmnlint-utils');

/**
* Rule that validates gateways according to the following rules:
*
* - An Event Based Gateway can only be connected to events.
*/
module.exports = function() {
let gateway = null;

function outgoingFlowsAreValid(gateway) {
const outgoing = gateway.get('outgoing');
return outgoing.filter(sequenceFlow => {
const target = sequenceFlow.get('targetRef');
return !isAny(target, ['bpmn:IntermediateCatchEvent', 'bpmn:EndEvent']);
}).length === 0;
}

function check(gateway, reporter) {
if (!isAny(gateway, ['bpmn:EventBasedGateway'])) {
return;
}

const outgoing = gateway.get('outgoing');
const valid = outgoing.filter(sequenceFlow => {
const target = sequenceFlow.get('targetRef');
const isValidType = isAny(target, ['bpmn:IntermediateCatchEvent', 'bpmn:EndEvent']);
const onlyOneIncoming = target.get('incoming').length === 1;
if (!isValidType) {
reporter.report(target.id, 'Event Gateways target elements must be Catch Events');
}
if (!onlyOneIncoming) {
reporter.report(target.id, 'Event Gateway target elements must not have additional incoming Sequence Flows');
}
return !isValidType || !onlyOneIncoming;
}).length === 0;

if (!valid) {
reporter.report(gateway.id, 'Event Gateways target elements must be valid Catch Events');
}
}

return { check };
};

0 comments on commit 4012f85

Please sign in to comment.