Skip to content

Commit

Permalink
feat: support task listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
misiekhardcore authored Nov 14, 2024
1 parent 41f1ad6 commit 5e72cc8
Show file tree
Hide file tree
Showing 9 changed files with 374 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ All notable changes to [bpmnlint-plugin-camunda-compat](https://github.com/camun

___Note:__ Yet to be released changes appear here._

* `DEPS`: bump `[email protected]`
* `FEAT`: support task listeners ([#181](https://github.com/camunda/bpmnlint-plugin-camunda-compat/pull/181))
* `FEAT`: add `no-task-listeners` rule
* `FEAT`: add `task-listener` rule

# 2.27.0

* `FEAT`: add `zeebe-user-task` rule ([#179](https://github.com/camunda/bpmnlint-plugin-camunda-compat/pull/179))
Expand Down
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const camundaCloud10Rules = withConfig({
'no-multiple-none-start-events': 'error',
'no-priority-definition': 'error',
'no-propagate-all-parent-variables': 'error',
'no-task-listeners': 'error',
'no-task-schedule': 'error',
'no-template': 'error',
'no-version-tag': 'error',
Expand Down Expand Up @@ -94,8 +95,9 @@ const camundaCloud86Rules = withConfig({
}, { version: '8.6' });

const camundaCloud87Rules = withConfig({
...camundaCloud86Rules,
'zeebe-user-task': 'error'
...omit(camundaCloud86Rules, [ 'no-task-listeners' ]),
'zeebe-user-task': 'error',
'task-listener': 'error'
}, { version: '8.7' });

const camundaPlatform719Rules = withConfig({
Expand Down Expand Up @@ -155,6 +157,7 @@ const rules = {
'no-propagate-all-parent-variables': './rules/camunda-cloud/no-propagate-all-parent-variables',
'no-signal-event-sub-process': './rules/camunda-cloud/no-signal-event-sub-process',
'no-task-schedule': './rules/camunda-cloud/no-task-schedule',
'no-task-listeners': './rules/camunda-cloud/no-task-listeners',
'no-template': './rules/camunda-cloud/no-template',
'no-version-tag': './rules/camunda-cloud/no-version-tag',
'no-zeebe-properties': './rules/camunda-cloud/no-zeebe-properties',
Expand All @@ -165,6 +168,7 @@ const rules = {
'signal-reference': './rules/camunda-cloud/signal-reference',
'start-event-form': './rules/camunda-cloud/start-event-form',
'subscription': './rules/camunda-cloud/subscription',
'task-listener': './rules/camunda-cloud/task-listener',
'task-schedule': './rules/camunda-cloud/task-schedule',
'timer': './rules/camunda-cloud/timer',
'user-task-definition': './rules/camunda-cloud/user-task-definition',
Expand Down
17 changes: 9 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"modeler-moddle": "^0.2.0",
"sinon": "^17.0.1",
"sinon-chai": "^3.7.0",
"zeebe-bpmn-moddle": "^1.6.0"
"zeebe-bpmn-moddle": "^1.7.0"
},
"dependencies": {
"@bpmn-io/feel-lint": "^1.2.0",
Expand Down
21 changes: 21 additions & 0 deletions rules/camunda-cloud/no-task-listeners.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { reportErrors } = require('../utils/reporter');

const { skipInNonExecutableProcess } = require('../utils/rule');

const { hasNoExtensionElement } = require('../utils/element');

const ALLOWED_VERSION = '8.7';

module.exports = skipInNonExecutableProcess(function() {
function check(node, reporter) {
const errors = hasNoExtensionElement(node, 'zeebe:TaskListeners', node, ALLOWED_VERSION);

if (errors && errors.length) {
reportErrors(node, reporter, errors);
}
}

return {
check
};
});
47 changes: 47 additions & 0 deletions rules/camunda-cloud/task-listener.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const { is } = require('bpmnlint-utils');

const {
findExtensionElement,
hasProperties,
hasExtensionElement
} = require('../utils/element');

const { reportErrors } = require('../utils/reporter');

const { skipInNonExecutableProcess } = require('../utils/rule');


module.exports = skipInNonExecutableProcess(function() {
function check(node, reporter) {
if (!is(node, 'bpmn:UserTask')) {
return;
}

let errors = hasExtensionElement(node, 'zeebe:UserTask', node);

if (errors && errors.length) {
reportErrors(node, reporter, errors);
}

const taskListeners = findExtensionElement(node, 'zeebe:TaskListeners');

if (!taskListeners) {
return;
}

const listeners = taskListeners.get('listeners');
errors = listeners.flatMap(listener => hasProperties(listener, {
type: {
required: true
}
}, node));

if (errors.length) {
reportErrors(node, reporter, errors);
}
}

return {
check
};
});
57 changes: 57 additions & 0 deletions test/camunda-cloud/no-task-listeners.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const RuleTester = require('bpmnlint/lib/testers/rule-tester');

const rule = require('../../rules/camunda-cloud/no-task-listeners');

const {
createModdle,
createProcess
} = require('../helper');

const { ERROR_TYPES } = require('../../rules/utils/element');

const valid = [
{
name: 'user task without task listeners',
config: { version: '8.6' },
moddleElement: createModdle(createProcess(`
<bpmn:userTask id="UserTask_1" />
`))
}
];

const invalid = [
{
name: 'no task listeners (Camunda 8.6)',
config: { version: '8.6' },
moddleElement: createModdle(createProcess(`
<bpmn:userTask id="UserTask_1">
<bpmn:extensionElements>
<zeebe:taskListeners>
<zeebe:taskListener eventType="start" type="com.example.StartListener" />
</zeebe:taskListeners>
</bpmn:extensionElements>
</bpmn:userTask>
`)),
report: {
id: 'UserTask_1',
message: 'Extension element of type <zeebe:TaskListeners> only allowed by Camunda 8.7',
path: [
'extensionElements',
'values',
0
],
data: {
type: ERROR_TYPES.EXTENSION_ELEMENT_NOT_ALLOWED,
node: 'UserTask_1',
parentNode: null,
extensionElement: 'zeebe:TaskListeners',
allowedVersion: '8.7'
}
}
}
];

RuleTester.verify('no-task-listeners', rule, {
valid,
invalid
});
Loading

0 comments on commit 5e72cc8

Please sign in to comment.