Skip to content

Commit

Permalink
feat: support camunda:executionListener with implementationType p…
Browse files Browse the repository at this point in the history
…roperty binding

This also updates `@bpmn-io/element-templates-validator` to v1.2.0.

Closes #13

Co-authored-by: Maciej Barelkowski <[email protected]>
  • Loading branch information
AlexanderSkrock and barmac authored Oct 12, 2023
1 parent ac526ec commit f0b5f43
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 42 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ All notable changes to [bpmn-js-element-templates](https://github.com/bpmn-io/bp

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

* `DEPS`: update to `@bpmn-io/[email protected]`

## 1.4.0

* `FEAT`: visually show deprecated templates ([#11](https://github.com/bpmn-io/bpmn-js-element-templates/issues/11))
Expand Down Expand Up @@ -43,4 +45,4 @@ ___Note:__ Yet to be released changes appear here._

## 1.0.0

* initial release
* initial release
46 changes: 23 additions & 23 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 @@ -45,7 +45,7 @@
],
"license": "MIT",
"dependencies": {
"@bpmn-io/element-templates-validator": "^1.0.0",
"@bpmn-io/element-templates-validator": "^1.2.0",
"@bpmn-io/extract-process-variables": "^0.8.0",
"bpmnlint": "^8.3.2",
"classnames": "^2.3.1",
Expand Down
23 changes: 11 additions & 12 deletions src/element-templates/CreateHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,28 +150,27 @@ export function createCamundaOut(binding, value, bpmnFactory) {
*
* @return {ModdleElement}
*/
export function createCamundaExecutionListenerScript(binding, value, bpmnFactory) {
export function createCamundaExecutionListener(binding, value, bpmnFactory) {
const {
event,
implementationType,
scriptFormat
} = binding;

let parameterValue,
parameterDefinition;

if (scriptFormat) {
parameterDefinition = bpmnFactory.create('camunda:Script', {
scriptFormat,
value
// To guarantee backwards compatibility scriptFormat is taken into account and has precedence before any other type
if (implementationType === 'script' || scriptFormat) {
return bpmnFactory.create('camunda:ExecutionListener', {
event,
script: bpmnFactory.create('camunda:Script', {
scriptFormat,
value
})
});
} else {
parameterValue = value;
}

return bpmnFactory.create('camunda:ExecutionListener', {
event,
value: parameterValue,
script: parameterDefinition
[implementationType]: value
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/element-templates/cmd/ChangeElementTemplateHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import handleLegacyScopes from '../util/handleLegacyScopes';

import {
createCamundaExecutionListenerScript,
createCamundaExecutionListener,
createCamundaFieldInjection,
createCamundaIn,
createCamundaInWithBusinessKey,
Expand Down Expand Up @@ -253,7 +253,7 @@ export default class ChangeElementTemplateHandler {
const newBinding = newProperty.binding,
propertyValue = newProperty.value;

return createCamundaExecutionListenerScript(newBinding, propertyValue, bpmnFactory);
return createCamundaExecutionListener(newBinding, propertyValue, bpmnFactory);
});

commandStack.execute('element.updateModdleProperties', {
Expand Down
116 changes: 113 additions & 3 deletions test/spec/element-templates/CreateHelper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import camundaModdlePackage from 'camunda-bpmn-moddle/resources/camunda';
import { getBusinessObject } from 'bpmn-js/lib/util/ModelUtil';

import {
createCamundaExecutionListenerScript,
createCamundaExecutionListener,
createCamundaIn,
createCamundaInWithBusinessKey,
createCamundaOut,
Expand Down Expand Up @@ -461,17 +461,42 @@ describe('provider/element-templates - CreateHelper', function() {

describe('createExecutionListener', function() {

it('should create script', inject(function(bpmnFactory) {
it('should create script without explicit implementation type', inject(function(bpmnFactory) {

// given
const binding = {
type: 'camunda:executionListener',
event: 'end',
scriptFormat: 'groovy'
};

// when
const listener = createCamundaExecutionListener(binding, 'println execution.eventName', bpmnFactory);

// then
expect(listener).to.jsonEqual({
$type: 'camunda:ExecutionListener',
event: 'end',
script: {
$type: 'camunda:Script',
scriptFormat: 'groovy',
value: 'println execution.eventName'
}
});
}));

it('should create script with implementation type script', inject(function(bpmnFactory) {

// given
const binding = {
type: 'camunda:executionListener',
event: 'end',
implementationType: 'script',
scriptFormat: 'groovy'
};

// when
const listener = createCamundaExecutionListenerScript(binding, 'println execution.eventName', bpmnFactory);
const listener = createCamundaExecutionListener(binding, 'println execution.eventName', bpmnFactory);

// then
expect(listener).to.jsonEqual({
Expand All @@ -485,6 +510,91 @@ describe('provider/element-templates - CreateHelper', function() {
});
}));

it('should create script with with script format ignoring the implementation type for backwards compatibility', inject(function(bpmnFactory) {

// given
const binding = {
type: 'camunda:executionListener',
event: 'end',
implementationType: 'class',
scriptFormat: 'groovy'
};

// when
const listener = createCamundaExecutionListener(binding, 'println execution.eventName', bpmnFactory);

// then
expect(listener).to.jsonEqual({
$type: 'camunda:ExecutionListener',
event: 'end',
script: {
$type: 'camunda:Script',
scriptFormat: 'groovy',
value: 'println execution.eventName'
}
});
}));

it('should create class-based execution listener', inject(function(bpmnFactory) {

// given
const binding = {
type: 'camunda:executionListener',
event: 'end',
implementationType: 'class'
};

// when
const listener = createCamundaExecutionListener(binding, 'path.to.my.class', bpmnFactory);

// then
expect(listener).to.jsonEqual({
$type: 'camunda:ExecutionListener',
event: 'end',
class: 'path.to.my.class'
});
}));

it('should create expression-based execution listener', inject(function(bpmnFactory) {

// given
const binding = {
type: 'camunda:executionListener',
event: 'end',
implementationType: 'expression'
};

// when
const listener = createCamundaExecutionListener(binding, '${expression}', bpmnFactory);

// then
expect(listener).to.jsonEqual({
$type: 'camunda:ExecutionListener',
event: 'end',
expression: '${expression}'
});
}));

it('should create delegateExpression-based execution listener', inject(function(bpmnFactory) {

// given
const binding = {
type: 'camunda:executionListener',
event: 'end',
implementationType: 'delegateExpression'
};

// when
const listener = createCamundaExecutionListener(binding, '${delegate}', bpmnFactory);

// then
expect(listener).to.jsonEqual({
$type: 'camunda:ExecutionListener',
event: 'end',
delegateExpression: '${delegate}'
});
}));

});


Expand Down

0 comments on commit f0b5f43

Please sign in to comment.