Skip to content

Commit

Permalink
feat(templates): update scope element according to rules
Browse files Browse the repository at this point in the history
* `camunda:connector`
  • Loading branch information
philippfromme authored and barmac committed Dec 16, 2020
1 parent f6dd182 commit 1e839b3
Show file tree
Hide file tree
Showing 2 changed files with 226 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ ChangeElementTemplateHandler.prototype.preExecute = function(context) {
this._updateCamundaPropertyProperties(element, oldTemplate, newTemplate);

// Update properties for each scope
forEach(newTemplate.scopes, function(scopeTemplate, scopeName) {
self._updateScopeProperties(element, scopeName, scopeTemplate);
forEach(newTemplate.scopes, function(newScopeTemplate, scopeName) {
self._updateScopeProperties(element, scopeName, oldTemplate, newScopeTemplate);
});

}
Expand Down Expand Up @@ -730,40 +730,44 @@ ChangeElementTemplateHandler.prototype._updateProperties = function(element, old
* @param {string} scopeName
* @param {Object} scopeTemplate
*/
ChangeElementTemplateHandler.prototype._updateScopeProperties = function(element, scopeName, scopeTemplate) {
ChangeElementTemplateHandler.prototype._updateScopeProperties = function(element, scopeName, oldTemplate, newScopeTemplate) {
var bpmnFactory = this._bpmnFactory,
commandStack = this._commandStack;

var scopeElement = bpmnFactory.create(scopeName);
var scopeElement = findOldScopeElement(element, scopeName);

if (!scopeElement) {
scopeElement = bpmnFactory.create(scopeName);
}

var oldScopeTemplate = findOldScopeTemplate(scopeName, oldTemplate);

// Update properties
this._updateProperties(element, null, scopeTemplate, scopeElement);
this._updateProperties(element, oldScopeTemplate, newScopeTemplate, scopeElement);

// Update camunda:ExecutionListener properties
this._updateCamundaExecutionListenerProperties(element, scopeTemplate, scopeElement);
this._updateCamundaExecutionListenerProperties(element, newScopeTemplate);

// Update camunda:In and camunda:Out properties
this._updateCamundaInOutProperties(element, null, scopeTemplate, scopeElement);
this._updateCamundaInOutProperties(element, oldScopeTemplate, newScopeTemplate);

// Update camunda:InputParameter and camunda:OutputParameter properties
this._updateCamundaInputOutputParameterProperties(element, null, scopeTemplate, scopeElement);
this._updateCamundaInputOutputParameterProperties(element, oldScopeTemplate, newScopeTemplate, scopeElement);

// Update camunda:Field properties
this._updateCamundaFieldProperties(element, null, scopeTemplate, scopeElement);
this._updateCamundaFieldProperties(element, oldScopeTemplate, newScopeTemplate, scopeElement);

// Update camunda:Property properties
this._updateCamundaPropertyProperties(element, null, scopeTemplate, scopeElement);
this._updateCamundaPropertyProperties(element, oldScopeTemplate, newScopeTemplate, scopeElement);

var extensionElements = this._getOrCreateExtensionElements(element);

var oldScope = findExtension(extensionElements, scopeName);

commandStack.execute('properties-panel.update-businessobject-list', {
element: element,
currentObject: extensionElements,
propertyName: 'values',
objectsToAdd: [ scopeElement ],
objectsToRemove: oldScope ? [ oldScope ] : []
objectsToRemove: []
});
};

Expand Down Expand Up @@ -991,6 +995,18 @@ function findOldProperty(oldTemplate, newProperty) {
}
}

function findOldScopeElement(element, scopeName) {
if (scopeName === 'camunda:Connector') {
return findExtension(element, 'camunda:Connector');
}
}

function findOldScopeTemplate(scopeName, oldTemplate) {
var scopes = oldTemplate && oldTemplate.scopes;

return scopes && scopes[ scopeName ];
}

/**
* Check whether property was changed after being set by template.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ var coreModule = require('bpmn-js/lib/core').default,

var camundaModdlePackage = require('camunda-bpmn-moddle/resources/camunda');

var getBusinessObject = require('bpmn-js/lib/util/ModelUtil').getBusinessObject;
var getBusinessObject = require('bpmn-js/lib/util/ModelUtil').getBusinessObject,
is = require('bpmn-js/lib/util/ModelUtil').is;

var findExtension = require('lib/provider/camunda/element-templates/Helper').findExtension,
findExtensions = require('lib/provider/camunda/element-templates/Helper').findExtensions;
Expand Down Expand Up @@ -2563,6 +2564,173 @@ describe('element-templates - ChangeElementTemplateHandler', function() {

});


describe('update scope elements', function() {

describe('camunda:Connector', function() {

beforeEach(bootstrap(require('./service-task.bpmn')));


it('properties changed', inject(function(elementRegistry) {

// given
var serviceTask = elementRegistry.get('ServiceTask_1');

var oldTemplate = createTemplate([
{
value: 'input-1-old-value',
binding: {
type: 'camunda:inputParameter',
name: 'input-1-name'
}
},
{
value: 'output-1-old-value',
binding: {
type: 'camunda:outputParameter',
source: 'output-1-source'
}
}
], 'camunda:Connector');

var newTemplate = createTemplate([
{
value: 'input-1-new-value',
binding: {
type: 'camunda:inputParameter',
name: 'input-1-name'
}
},
{
value: 'output-1-new-value',
binding: {
type: 'camunda:outputParameter',
source: 'output-1-source'
}
}
], 'camunda:Connector');

changeTemplate('ServiceTask_1', oldTemplate);

var connector = findExtension(serviceTask, 'camunda:Connector');

var input = getInputParameter(connector, 'input-1-name');

updateBusinessObject(serviceTask, input, {
value: 'input-1-changed-value'
});

var output = getOutputParameter(connector, 'output-1-source');

updateBusinessObject(serviceTask, output, {
name: 'output-1-changed-value'
});

// when
changeTemplate(serviceTask, newTemplate, oldTemplate);

// then
connector = findExtension(serviceTask, 'camunda:Connector');

expect(connector).to.exist;
expect(connector).to.jsonEqual({
$type: 'camunda:Connector',
inputOutput: {
$type: 'camunda:InputOutput',
inputParameters: [
{
$type: 'camunda:InputParameter',
name: 'input-1-name',
value: 'input-1-changed-value'
}
],
outputParameters: [
{
$type: 'camunda:OutputParameter',
name: 'output-1-changed-value',
value: 'output-1-source'
}
]
}
});
}));


it('properties unchanged', inject(function(elementRegistry) {

// given
var serviceTask = elementRegistry.get('ServiceTask_1');

var oldTemplate = createTemplate([
{
value: 'input-1-old-value',
binding: {
type: 'camunda:inputParameter',
name: 'input-1-name'
}
},
{
value: 'output-1-old-value',
binding: {
type: 'camunda:outputParameter',
source: 'output-1-source'
}
}
], 'camunda:Connector');

var newTemplate = createTemplate([
{
value: 'input-1-new-value',
binding: {
type: 'camunda:inputParameter',
name: 'input-1-name'
}
},
{
value: 'output-1-new-value',
binding: {
type: 'camunda:outputParameter',
source: 'output-1-source'
}
}
], 'camunda:Connector');

changeTemplate('ServiceTask_1', oldTemplate);

// when
changeTemplate(serviceTask, newTemplate, oldTemplate);

// then
var connector = findExtension(serviceTask, 'camunda:Connector');

expect(connector).to.exist;
expect(connector).to.jsonEqual({
$type: 'camunda:Connector',
inputOutput: {
$type: 'camunda:InputOutput',
inputParameters: [
{
$type: 'camunda:InputParameter',
name: 'input-1-name',
value: 'input-1-new-value'
}
],
outputParameters: [
{
$type: 'camunda:OutputParameter',
name: 'output-1-new-value',
value: 'output-1-source'
}
]
}
});
}));

});

});

});


Expand Down Expand Up @@ -2694,16 +2862,25 @@ function expectNoElementTemplate(element) {
});
}

function createTemplate(properties, id, version) {
function createTemplate(properties, scope) {
if (!isArray(properties)) {
properties = [ properties ];
}

return {
id: id,
version: version,
properties: properties
var template = {
properties: [],
scopes: {}
};

if (scope) {
template.scopes[ scope ] = {
properties: properties
};
} else {
template.properties = properties;
}

return template;
}

function getCamundaProperty(element, name) {
Expand All @@ -2715,15 +2892,27 @@ function getCamundaProperty(element, name) {
}

function getInputParameter(element, name) {
var inputOutput = findExtension(element, 'camunda:InputOutput');
var inputOutput;

if (is(element, 'camunda:Connector')) {
inputOutput = element.get('camunda:inputOutput');
} else {
inputOutput = findExtension(element, 'camunda:InputOutput');
}

return find(inputOutput.get('camunda:inputParameters'), function(inputParameter) {
return inputParameter.get('camunda:name') === name;
});
}

function getOutputParameter(element, source) {
var inputOutput = findExtension(element, 'camunda:InputOutput');
var inputOutput;

if (is(element, 'camunda:Connector')) {
inputOutput = element.get('camunda:inputOutput');
} else {
inputOutput = findExtension(element, 'camunda:InputOutput');
}

return find(inputOutput.get('camunda:outputParameters'), function(outputParameter) {
var definition = outputParameter.get('camunda:definition');
Expand Down

0 comments on commit 1e839b3

Please sign in to comment.