Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint zeebe:TaskSchedule Extension Elements #48

Merged
merged 5 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ ___Note:__ Yet to be released changes appear here._
## 0.17.0

* `FEAT`: require history time to live in Camunda 7.19 ([#83](https://github.com/camunda/bpmnlint-plugin-camunda-compat/pull/83))
* `DEPS`: update to `[email protected]`
* `FEAT`: add `task-schedule` and `no-task-schedule` rules ([#86](https://github.com/camunda/bpmnlint-plugin-camunda-compat/issues/86))
* `DEPS`: update to `[email protected]`

## 0.16.0

Expand Down
28 changes: 23 additions & 5 deletions lib/utils/error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ function getExtensionElementNotAllowedErrorMessage(report, executionPlatform, ex
return getSupportedMessage('A <Script Task> with <Implementation: FEEL expression>', executionPlatform, executionPlatformVersion, allowedVersion);
}

if (is(node, 'bpmn:UserTask') && is(extensionElement, 'zeebe:TaskSchedule')) {
return getSupportedMessage('A <User Task> with <Due date> or <Follow up date>', executionPlatform, executionPlatformVersion, allowedVersion);
}

return message;
}

Expand Down Expand Up @@ -444,7 +448,8 @@ function getPropertyRequiredErrorMessage(report, executionPlatform, executionPla

function getExpressionRequiredErrorMessage(report) {
const {
data
data,
message
} = report;

const {
Expand All @@ -458,11 +463,14 @@ function getExpressionRequiredErrorMessage(report) {
if (is(node, 'bpmn:FormalExpression') && TIMER_PROPERTIES.includes(property)) {
return `${ getIndefiniteArticle(typeString) } <${ typeString }> must have a defined <Timer value>`;
}

return message;
}

function getExpressionValueNotAllowedErrorMessage(report) {
const {
data
data,
message
} = report;

const {
Expand All @@ -474,16 +482,26 @@ function getExpressionValueNotAllowedErrorMessage(report) {
const typeString = getTypeString(parentNode || node);

if (is(node, 'bpmn:FormalExpression') && property === 'timeCycle') {
return `${ getIndefiniteArticle(typeString) } <${ typeString }> <Time cycle> should be an expression, an ISO 8601 repeating interval, or a cron expression (cron requires Camunda Platform 8.1 or newer)`;
return `${ getIndefiniteArticle(typeString) } <${ typeString }> <Time cycle> must be an expression, an ISO 8601 repeating interval, or a cron expression (cron requires Camunda Platform 8.1 or newer)`;
}

if (is(node, 'bpmn:FormalExpression') && property === 'timeDate') {
return `${ getIndefiniteArticle(typeString) } <${ typeString }> <Time date> should be an expression, or an ISO 8601 date`;
return `${ getIndefiniteArticle(typeString) } <${ typeString }> <Time date> must be an expression, or an ISO 8601 date`;
}

if (is(node, 'bpmn:FormalExpression') && property === 'timeDuration') {
return `${ getIndefiniteArticle(typeString) } <${ typeString }> <Time duration> should be an expression, or an ISO 8601 interval`;
return `${ getIndefiniteArticle(typeString) } <${ typeString }> <Time duration> must be an expression, or an ISO 8601 interval`;
}

if (is(node, 'zeebe:TaskSchedule') && property === 'dueDate') {
return `${ getIndefiniteArticle(typeString) } <${ typeString }> <Due date> must be an ISO 8601 date`;
}

if (is(node, 'zeebe:TaskSchedule') && property === 'followUpDate') {
return `${ getIndefiniteArticle(typeString) } <${ typeString }> <Follow up date> must be an ISO 8601 date`;
}

return message;
}

function getSupportedMessage(prefix, executionPlatform, executionPlatformVersion, allowedVersion) {
Expand Down
40 changes: 40 additions & 0 deletions lib/utils/properties-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,30 @@ export function getEntryIds(report) {
return [ 'historyTimeToLive' ];
}

if (isExpressionValueNotAllowedError(data, 'dueDate', 'zeebe:TaskSchedule')) {
return [ 'taskScheduleDueDate' ];
}

if (isExpressionValueNotAllowedError(data, 'followUpDate', 'zeebe:TaskSchedule')) {
return [ 'taskScheduleFollowUpDate' ];
}

if (isExtensionElementNotAllowedError(data, 'zeebe:TaskSchedule', 'bpmn:UserTask')) {
const { extensionElement: taskSchedule } = data;

let ids = [];

if (taskSchedule.get('dueDate')) {
ids = [ ...ids, 'taskScheduleDueDate' ];
}

if (taskSchedule.get('followUpDate')) {
ids = [ ...ids, 'taskScheduleFollowUpDate' ];
}

return ids;
}

return [];
}

Expand Down Expand Up @@ -362,6 +386,22 @@ export function getErrorMessage(id, report) {
if (id === 'historyTimeToLive') {
return 'Time to live must be defined.';
}

if (id === 'taskScheduleDueDate') {
if (data.type === ERROR_TYPES.EXTENSION_ELEMENT_NOT_ALLOWED) {
return 'Not supported.';
} else {
return 'Must be an ISO 8601 date.';
}
}

if (id === 'taskScheduleFollowUpDate') {
if (data.type === ERROR_TYPES.EXTENSION_ELEMENT_NOT_ALLOWED) {
return 'Not supported.';
} else {
return 'Must be an ISO 8601 date.';
}
}
}

function isExtensionElementNotAllowedError(data, extensionElement, type) {
Expand Down
45 changes: 22 additions & 23 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@
"dependencies": {
"bpmn-moddle": "^8.0.0",
"bpmnlint": "^8.0.0",
"bpmnlint-plugin-camunda-compat": "^0.23.0",
"bpmnlint-plugin-camunda-compat": "^0.24.0",
"bpmnlint-utils": "^1.0.2",
"min-dash": "^4.0.0",
"min-dom": "^4.1.0",
"zeebe-bpmn-moddle": "^0.17.0"
"zeebe-bpmn-moddle": "^0.18.0"
},
"devDependencies": {
"bpmn-js": "^11.1.1",
"bpmn-js-properties-panel": "^1.15.1",
"camunda-bpmn-js-behaviors": "^0.5.0",
"chai": "^4.3.7",
"cross-env": "^7.0.3",
"eslint": "^8.32.0",
Expand Down
3 changes: 3 additions & 0 deletions test/spec/modeler/Linting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
ElementTemplatesPropertiesProviderModule as elementTemplatesPropertiesProviderModule
} from 'bpmn-js-properties-panel';

import camundaCloudBehaviors from 'camunda-bpmn-js-behaviors/lib/camunda-cloud';

import { domify } from 'min-dom';

import sinon from 'sinon';
Expand Down Expand Up @@ -110,6 +112,7 @@ describe('Linting', function() {
lintingModule,
propertiesPanelModule,
bpmnPropertiesProviderModule,
camundaCloudBehaviors,
...additionalModules
],
moddleExtensions: {
Expand Down
Loading