Skip to content

Commit

Permalink
feat(cloud/create): allow creation of LinkedResource bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
marstamm committed Jan 17, 2025
1 parent 34c13f5 commit 7fd01b7
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 3 deletions.
38 changes: 38 additions & 0 deletions src/cloud-element-templates/create/LinkedResourceProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { getBusinessObject } from 'bpmn-js/lib/util/ModelUtil';
import { createElement } from '../../utils/ElementUtil';

import {
ensureExtension
} from '../CreateHelper';
import { getDefaultValue } from '../Helper';


export default class LinkedResourcePropertyBindingProvider {
static create(element, options) {
const {
property,
bpmnFactory
} = options;

const {
binding: {
property: bindingProperty,
linkName
}
} = property;

const value = getDefaultValue(property);

const bo = getBusinessObject(element);
const linkedResources = ensureExtension(element, 'zeebe:LinkedResources', bpmnFactory);

let linkedResource = linkedResources.get('values').find(linkedResource => linkedResource.get('linkName') === linkName);

if (!linkedResource) {
linkedResource = createElement('zeebe:LinkedResource', { linkName }, bo, bpmnFactory);
linkedResources.get('values').push(linkedResource);
}

linkedResource.set(bindingProperty, value);
}
}
7 changes: 5 additions & 2 deletions src/cloud-element-templates/create/TemplateElementFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ZeebePropertiesProvider from './ZeebePropertiesProvider';
import { MessagePropertyBindingProvider } from './MessagePropertyBindingProvider';
import { MessageZeebeSubscriptionBindingProvider } from './MessageZeebeSubscriptionBindingProvider';
import { CalledElementBindingProvider } from './CalledElementBindingProvider';
import LinkedResourcePropertyBindingProvider from './LinkedResourceProvider';

import {
MESSAGE_PROPERTY_TYPE,
Expand All @@ -24,7 +25,8 @@ import {
ZEEBE_OUTPUT_TYPE,
ZEEBE_TASK_HEADER_TYPE,
ZEBBE_PROPERTY_TYPE,
ZEEBE_CALLED_ELEMENT
ZEEBE_CALLED_ELEMENT,
ZEEBE_LINKED_RESOURCE_PROPERTY
} from '../util/bindingTypes';

import {
Expand All @@ -47,7 +49,8 @@ export default class TemplateElementFactory {
[ZEEBE_TASK_HEADER_TYPE]: TaskHeaderBindingProvider,
[MESSAGE_PROPERTY_TYPE]: MessagePropertyBindingProvider,
[MESSAGE_ZEEBE_SUBSCRIPTION_PROPERTY_TYPE]: MessageZeebeSubscriptionBindingProvider,
[ZEEBE_CALLED_ELEMENT]: CalledElementBindingProvider
[ZEEBE_CALLED_ELEMENT]: CalledElementBindingProvider,
[ZEEBE_LINKED_RESOURCE_PROPERTY]: LinkedResourcePropertyBindingProvider
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2054,6 +2054,7 @@ describe('cloud-element-templates/cmd - ChangeElementTemplateHandler', function(

});


describe('zeebe:LinkedElement not specified', function() {
const newTemplate = require('./task-template-no-properties.json');

Expand Down Expand Up @@ -2113,7 +2114,6 @@ describe('cloud-element-templates/cmd - ChangeElementTemplateHandler', function(
expect(linkedResources).not.to.exist;
}));


});

});
Expand Down Expand Up @@ -4178,6 +4178,7 @@ describe('cloud-element-templates/cmd - ChangeElementTemplateHandler', function(


describe('update zeebe:LinkedResource', function() {

beforeEach(bootstrap(require('./linked-resource.bpmn').default));

it('property changed', inject(function(elementRegistry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,34 @@ describe('provider/cloud-element-templates - TemplateElementFactory', function()
processId: 'paymentProcess'
});
}));


it('should handle <zeebe:linkedElement>', inject(function(templateElementFactory) {

// given
const elementTemplate = findTemplate('linkedResource');

// when
const element = templateElementFactory.create(elementTemplate);

const linkedResources = findExtension(element, 'zeebe:LinkedResources');
const resources = linkedResources.get('values');

// then
expect(resources).to.exist;
expect(resources).to.jsonEqual([
{
$type: 'zeebe:LinkedResource',
linkName: 'Link1',
resourceType: 'foo'
},
{
$type: 'zeebe:LinkedResource',
linkName: 'Link2',
resourceId: 'bar'
},
]);
}));
});


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,5 +535,36 @@
}
}
]
},
{
"$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json",
"name": "linkedResource",
"id": "linkedResource",
"appliesTo": [
"bpmn:Task"
],
"elementType": {
"value": "bpmn:ServiceTask"
},
"properties": [
{
"type": "Hidden",
"value": "foo",
"binding": {
"type": "zeebe:linkedResource",
"linkName": "Link1",
"property": "resourceType"
}
},
{
"type": "Hidden",
"value": "bar",
"binding": {
"type": "zeebe:linkedResource",
"linkName": "Link2",
"property": "resourceId"
}
}
]
}
]

0 comments on commit 7fd01b7

Please sign in to comment.