From 7ab5f5a91f533533b788ed194f8056a2027b45bf Mon Sep 17 00:00:00 2001 From: Martin Stamm Date: Fri, 17 Jan 2025 11:35:06 +0100 Subject: [PATCH] feat(cloud/create): allow creation of `LinkedResource` bindings --- .../create/LinkedResourceProvider.js | 38 +++++++++++++++++++ .../create/TemplateElementFactory.js | 7 +++- .../create/TemplateElementFactory.spec.js | 28 ++++++++++++++ .../create/TemplatesElementFactory.json | 31 +++++++++++++++ 4 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 src/cloud-element-templates/create/LinkedResourceProvider.js diff --git a/src/cloud-element-templates/create/LinkedResourceProvider.js b/src/cloud-element-templates/create/LinkedResourceProvider.js new file mode 100644 index 00000000..0ff7bd5f --- /dev/null +++ b/src/cloud-element-templates/create/LinkedResourceProvider.js @@ -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); + } +} diff --git a/src/cloud-element-templates/create/TemplateElementFactory.js b/src/cloud-element-templates/create/TemplateElementFactory.js index add94066..deb441e6 100644 --- a/src/cloud-element-templates/create/TemplateElementFactory.js +++ b/src/cloud-element-templates/create/TemplateElementFactory.js @@ -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, @@ -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 { @@ -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 }; } diff --git a/test/spec/cloud-element-templates/create/TemplateElementFactory.spec.js b/test/spec/cloud-element-templates/create/TemplateElementFactory.spec.js index c55b45ab..ef4b48fb 100644 --- a/test/spec/cloud-element-templates/create/TemplateElementFactory.spec.js +++ b/test/spec/cloud-element-templates/create/TemplateElementFactory.spec.js @@ -486,6 +486,34 @@ describe('provider/cloud-element-templates - TemplateElementFactory', function() processId: 'paymentProcess' }); })); + + + it('should handle ', 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' + }, + ]); + })); }); diff --git a/test/spec/cloud-element-templates/create/TemplatesElementFactory.json b/test/spec/cloud-element-templates/create/TemplatesElementFactory.json index 3ad34db3..9c5e2b80 100644 --- a/test/spec/cloud-element-templates/create/TemplatesElementFactory.json +++ b/test/spec/cloud-element-templates/create/TemplatesElementFactory.json @@ -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" + } + } + ] } ] \ No newline at end of file