Skip to content

Commit

Permalink
wip wip optional inputs outputs
Browse files Browse the repository at this point in the history
Related to #559
  • Loading branch information
Niklas Kiefer committed Jan 31, 2022
1 parent 7dd4d0b commit d2e7201
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 15 deletions.
6 changes: 6 additions & 0 deletions src/provider/cloud-element-templates/CreateHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,9 @@ export function createTaskDefinitionWithType(value, bpmnFactory) {
type: value
});
}

export function shouldCreate(value, property) {
const { optional } = property;

return value || !optional;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
createInputParameter,
createOutputParameter,
createTaskDefinitionWithType,
createTaskHeader
createTaskHeader,
shouldCreate
} from '../CreateHelper';

import {
Expand Down Expand Up @@ -304,8 +305,8 @@ export default class ChangeElementTemplateHandler {
}
}

// (3) add new inputs and outputs
else {
// (3) add new inputs and outputs (unless optional)
else if (shouldCreate(newPropertyValue, newProperty)) {
if (newBindingType === 'zeebe:input') {
propertyName = 'inputParameters';

Expand Down
36 changes: 24 additions & 12 deletions src/provider/cloud-element-templates/properties/CustomProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import {
createInputParameter,
createOutputParameter,
createTaskDefinitionWithType,
createTaskHeader
createTaskHeader,
shouldCreate
} from '../CreateHelper';

import { createElement } from '../../../utils/ElementUtil';
Expand Down Expand Up @@ -285,6 +286,7 @@ function propertyGetter(element, property) {

const {
binding,
optional,
value: defaultValue = ''
} = property;

Expand Down Expand Up @@ -332,7 +334,8 @@ function propertyGetter(element, property) {
return inputParameter.get('source');
}

return defaultValue;
// allow empty values for optional parameters
return optional ? '' : defaultValue;
}

// zeebe:Output
Expand All @@ -343,7 +346,8 @@ function propertyGetter(element, property) {
return outputParameter.get('target');
}

return defaultValue;
// allow empty values for optional parameters
return optional ? '' : defaultValue;
}
}

Expand Down Expand Up @@ -373,7 +377,9 @@ function propertySetter(bpmnFactory, commandStack, element, property) {
return function setValue(value) {
let businessObject = getBusinessObject(element);

const { binding } = property;
const {
binding
} = property;

const {
name,
Expand Down Expand Up @@ -487,35 +493,41 @@ function propertySetter(bpmnFactory, commandStack, element, property) {
// zeebe:Input
if (type === ZEBBE_INPUT_TYPE) {
const oldZeebeInputParameter = findInputParameter(ioMapping, binding);

const newZeebeInputParameter = createInputParameter(binding, value, bpmnFactory);

const values = ioMapping.get('inputParameters').filter((value) => value !== oldZeebeInputParameter);

// do not persist empty parameters when configured as <optional>
if (shouldCreate(value, property)) {
const newZeebeInputParameter = createInputParameter(binding, value, bpmnFactory);
values.push(newZeebeInputParameter);
}

commands.push({
cmd: 'element.updateModdleProperties',
context: {
element,
moddleElement: ioMapping,
properties: { inputParameters: [ ...values, newZeebeInputParameter ] }
properties: { inputParameters: [ ...values ] }
}
});
}

// zeebe:Output
if (type === ZEEBE_OUTPUT_TYPE) {
const oldZeebeOutputParameter = findOutputParameter(ioMapping, binding);

const newZeebeOutputParameter = createOutputParameter(binding, value, bpmnFactory);

const values = ioMapping.get('outputParameters').filter((value) => value !== oldZeebeOutputParameter);

// do not persist empty parameters when configured as <optional>
if (shouldCreate(value, property)) {
const newZeebeOutputParameter = createOutputParameter(binding, value, bpmnFactory);
values.push(newZeebeOutputParameter);
}

commands.push({
cmd: 'element.updateModdleProperties',
context: {
element,
moddleElement: ioMapping,
properties: { 'outputParameters': [ ...values, newZeebeOutputParameter ] }
properties: { 'outputParameters': [ ...values ] }
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,52 @@ describe('cloud-element-templates - ChangeElementTemplateHandler', function() {
});


describe('optional', function() {

beforeEach(bootstrap(require('./task.bpmn').default));

const newTemplate = require('./task-template-optional.json');

it('should create (non empty value)', inject(function(elementRegistry) {

// given
const task = elementRegistry.get('Task_1');

// when
changeTemplate(task, newTemplate);

// then
expectElementTemplate(task, 'task-template-optional', 1);

const ioMapping = findExtension(task, 'zeebe:IoMapping');

expect(ioMapping).to.exist;
expect(getInputParameter(task, 'input-1-target')).to.exist;
expect(getOutputParameter(task, 'output-1-source')).to.exist;
}));


it('should NOT create (empty value)', inject(function(elementRegistry) {

// given
const task = elementRegistry.get('Task_1');

// when
changeTemplate(task, newTemplate);

// then
expectElementTemplate(task, 'task-template-optional', 1);

const ioMapping = findExtension(task, 'zeebe:IoMapping');

expect(ioMapping).to.exist;
expect(getInputParameter(task, 'input-2-target')).not.to.exist;
expect(getOutputParameter(task, 'output-2-source')).not.to.exist;
}));

});


describe('zeebe:Input and zeebe:Output not specified', function() {

beforeEach(bootstrap(require('./task-input-output.bpmn').default));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "Task Template (optional)",
"version": 1,
"id": "task-template-optional",
"appliesTo": [
"bpmn:ServiceTask"
],
"properties": [
{
"value": "input-1-source",
"type": "String",
"optional": true,
"binding": {
"type": "zeebe:input",
"name": "input-1-target"
}
},
{
"type": "String",
"optional": true,
"binding": {
"type": "zeebe:input",
"name": "input-2-target"
}
},
{
"value": "output-1-target",
"type": "String",
"optional": true,
"binding": {
"type": "zeebe:output",
"source": "output-1-source"
}
},
{
"type": "String",
"optional": true,
"binding": {
"type": "zeebe:output",
"source": "output-2-source"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"description": "Data to send to the endpoint.",
"value": "",
"type": "String",
"optional": true,
"binding": {
"type": "zeebe:input",
"name": "body"
Expand All @@ -61,6 +62,7 @@
"description": "Name of variable to store the response data in.",
"value": "response",
"type": "String",
"optional": true,
"binding": {
"type": "zeebe:output",
"source": "= body"
Expand Down

0 comments on commit d2e7201

Please sign in to comment.