diff --git a/lib/utils/error-messages.js b/lib/utils/error-messages.js index f7e977c..92bfdf7 100644 --- a/lib/utils/error-messages.js +++ b/lib/utils/error-messages.js @@ -88,6 +88,10 @@ export function getErrorMessage(report, executionPlatform, executionPlatformVers return getElementCollapsedNotAllowedErrorMessage(report); } + if (type === ERROR_TYPES.ELEMENT_PROPERTY_VALUE_DUPLICATED) { + return getElementPropertyValueDuplicatedErrorMessage(report); + } + if (type === ERROR_TYPES.ELEMENT_TYPE_NOT_ALLOWED) { return getElementTypeNotAllowedErrorMessage(report, executionPlatform, executionPlatformVersion); } @@ -498,6 +502,10 @@ function getPropertyRequiredErrorMessage(report, executionPlatform, executionPla return `${ getIndefiniteArticle(typeString) } <${ typeString }> must have a defined `; } + if (is(node, 'bpmn:LinkEventDefinition') && requiredProperty === 'name') { + return `${ getIndefiniteArticle(typeString) } <${ typeString }> must have a defined `; + } + return message; } @@ -631,4 +639,25 @@ function getSecretExpressionInvalidErrorMessage(report) { const { property } = data; return `Property <${ property }> is not a valid secret`; +} + +function getElementPropertyValueDuplicatedErrorMessage(report) { + const { + data, + message + } = report; + + const { + node, + parentNode, + duplicatedProperty + } = data; + + const typeString = getTypeString(parentNode || node); + + if (is(node, 'bpmn:LinkEventDefinition') && duplicatedProperty === 'name') { + return `${ getIndefiniteArticle(typeString) } <${ typeString }> must have a unique `; + } + + return message; } \ No newline at end of file diff --git a/lib/utils/properties-panel.js b/lib/utils/properties-panel.js index 692756b..6001cc5 100644 --- a/lib/utils/properties-panel.js +++ b/lib/utils/properties-panel.js @@ -275,6 +275,11 @@ export function getEntryIds(report) { return [ 'propagateAllParentVariables' ]; } + if (isPropertyError(data, 'name', 'bpmn:LinkEventDefinition') + || isElementPropertyValueDuplicated(data, 'name', 'bpmn:LinkEventDefinition')) { + return [ 'linkName' ]; + } + return []; } @@ -458,6 +463,14 @@ export function getErrorMessage(id, report) { if (id === 'propagateAllParentVariables') { return 'Not supported.'; } + + if (id === 'linkName') { + if (data.type === ERROR_TYPES.ELEMENT_PROPERTY_VALUE_DUPLICATED) { + return 'Must be unique.'; + } else { + return 'Must be defined.'; + } + } } function isExtensionElementNotAllowedError(data, extensionElement, type) { @@ -520,6 +533,12 @@ function isExpressionValueNotAllowedError(data, propertyName, type) { && (!type || is(data.node, type)); } +function isElementPropertyValueDuplicated(data, propertyName, type) { + return data.type === ERROR_TYPES.ELEMENT_PROPERTY_VALUE_DUPLICATED + && data.duplicatedProperty === propertyName + && (!type || is(data.node, type)); +} + function getBusinessObject(element) { return element.businessObject || element; } \ No newline at end of file diff --git a/test/spec/utils/error-messages.spec.js b/test/spec/utils/error-messages.spec.js index cd899e2..702e21a 100644 --- a/test/spec/utils/error-messages.spec.js +++ b/test/spec/utils/error-messages.spec.js @@ -258,6 +258,47 @@ describe('utils/error-messages', function() { }); + describe('element property value duplicated', function() { + + it('should adjust (link name)', async function() { + + // given + const node = createElement('bpmn:Process', { + flowElements: [ + createElement('bpmn:IntermediateCatchEvent', { + eventDefinitions: [ + createElement('bpmn:LinkEventDefinition', { + name: 'foo' + }) + ] + }), + createElement('bpmn:IntermediateCatchEvent', { + eventDefinitions: [ + createElement('bpmn:LinkEventDefinition', { + name: 'foo' + }) + ] + }) + ] + }); + + const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/link-event'); + + const reports = await getLintErrors(node, rule); + + // when + reports.forEach(report => { + const errorMessage = getErrorMessage(report); + + // then + expect(errorMessage).to + .equal('A must have a unique '); + }); + }); + + }); + + describe('extension element not allowed', function() { it('should adjust (business rule task with called decision)', async function() { @@ -1299,6 +1340,27 @@ describe('utils/error-messages', function() { expect(errorMessage).to.equal('A