-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
387 additions
and
11 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
const { | ||
is, | ||
Check failure on line 2 in rules/camunda-cloud/duplicate-execution-listeners.js GitHub Actions / Build (ubuntu-latest, 14)
|
||
isAny | ||
Check failure on line 3 in rules/camunda-cloud/duplicate-execution-listeners.js GitHub Actions / Build (ubuntu-latest, 14)
|
||
} = require('bpmnlint-utils'); | ||
|
||
const { | ||
ERROR_TYPES, | ||
findExtensionElement, | ||
hasDuplicatedPropertyValues | ||
Check failure on line 9 in rules/camunda-cloud/duplicate-execution-listeners.js GitHub Actions / Build (ubuntu-latest, 14)
|
||
} = require('../utils/element'); | ||
|
||
const { reportErrors } = require('../utils/reporter'); | ||
|
||
const { skipInNonExecutableProcess } = require('../utils/rule'); | ||
|
||
module.exports = skipInNonExecutableProcess(function() { | ||
function check(node, reporter) { | ||
const executionListeners = findExtensionElement(node, 'zeebe:ExecutionListeners'); | ||
|
||
if (!executionListeners) { | ||
return; | ||
} | ||
|
||
const errors = hasDuplicatedExecutionListeners(executionListeners, node); | ||
|
||
if (errors && errors.length) { | ||
reportErrors(node, reporter, errors); | ||
} | ||
} | ||
|
||
return { | ||
check | ||
}; | ||
}); | ||
|
||
// helpers ////////// | ||
function hasDuplicatedExecutionListeners(executionListeners, parentNode = null) { | ||
const listeners = executionListeners.get('listeners'); | ||
|
||
// (1) find duplicates | ||
const duplicates = []; | ||
const events = new Map(); | ||
for (const listener of listeners) { | ||
const eventName = listener.get('eventType'), | ||
type = listener.get('type'); | ||
|
||
if (!events.has(eventName)) { | ||
events.set(eventName, new Set([ type ])); | ||
continue; | ||
} | ||
|
||
const types = events.get(eventName); | ||
if (types.has(type)) { | ||
duplicates.push(listener); | ||
} else { | ||
types.add(type); | ||
} | ||
} | ||
|
||
// (2) report error for each duplicate | ||
if (duplicates.length) { | ||
return duplicates.map(duplicate => { | ||
const eventName = duplicate.get('eventType'), | ||
type = duplicate.get('type'); | ||
|
||
// (3) find properties with duplicate | ||
const duplicateProperties = listeners.filter(listener => listener.get('eventType') === eventName && listener.get('type') === type); | ||
|
||
// (4) report error | ||
return { | ||
message: `Duplicate execution listener with event type <${eventName}> and job type <${type}>`, | ||
path: null, | ||
data: { | ||
type: ERROR_TYPES.PROPERTY_VALUE_DUPLICATED, | ||
node: executionListeners, | ||
parentNode: parentNode === executionListeners ? null : parentNode, | ||
duplicatedProperty: 'type', | ||
duplicatedPropertyValue: type, | ||
properties: duplicateProperties, | ||
propertiesName: 'listeners' | ||
} | ||
}; | ||
}); | ||
} | ||
|
||
return []; | ||
} |
Oops, something went wrong.