Skip to content

Commit

Permalink
fix(zeebe): remove empty zeebe:VersionTag
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Aug 27, 2024
1 parent 53cd05f commit 6f9af4d
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 9 deletions.
38 changes: 34 additions & 4 deletions lib/camunda-cloud/VersionTagBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ import { isDefined } from 'min-dash';

import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';

import { isAny } from 'bpmn-js/lib/util/ModelUtil';
import {
getBusinessObject,
is,
isAny
} from 'bpmn-js/lib/util/ModelUtil';
import { removeExtensionElements } from '../util/ExtensionElementsUtil';

/**
* Zeebe BPMN specific version tag behavior.
*/
export default class VersionTagBehavior extends CommandInterceptor {
constructor(eventBus) {
constructor(eventBus, commandStack) {
super(eventBus);

/**
Expand Down Expand Up @@ -42,9 +47,34 @@ export default class VersionTagBehavior extends CommandInterceptor {
properties.bindingType = 'versionTag';
}
}, true);

/**
* Remove `zeebe:VersionTag` if its value is empty.
*/
this.postExecuted('element.updateModdleProperties', function(context) {
const {
element,
moddleElement
} = context;

if (!is(moddleElement, 'zeebe:VersionTag')) {
return;
}

if (isEmpty(moddleElement.get('value'))) {
removeExtensionElements(element, getBusinessObject(element), moddleElement, commandStack);
}
}, true);
}
}

VersionTagBehavior.$inject = [
'eventBus'
];
'eventBus',
'commandStack'
];

// helpers //////////

function isEmpty(value) {
return value == undefined || value === '';
}
45 changes: 42 additions & 3 deletions test/camunda-cloud/VersionTagBehaviorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {

import {
getBusinessObject,
is,
isAny
} from 'bpmn-js/lib/util/ModelUtil';

Expand All @@ -29,7 +30,7 @@ describe('camunda-cloud/features/modeling - VersionTagBehavior', function() {
// given
const element = elementRegistry.get(`${ type }_1`);

const extensionElement = getExtensionElement(element);
const extensionElement = getExtensionElementWithVersionTag(element);

expect(extensionElement.get('bindingType')).to.equal('versionTag');
expect(extensionElement.get('versionTag')).to.equal('v1.0.0');
Expand All @@ -53,7 +54,7 @@ describe('camunda-cloud/features/modeling - VersionTagBehavior', function() {
// given
const element = elementRegistry.get(`${ type }_2`);

const extensionElement = getExtensionElement(element);
const extensionElement = getExtensionElementWithVersionTag(element);

expect(extensionElement.get('bindingType')).to.equal('deployment');

Expand All @@ -71,11 +72,35 @@ describe('camunda-cloud/features/modeling - VersionTagBehavior', function() {

});


describe('remove version tag', function() {

it('should remove version tag', inject(function(elementRegistry, modeling) {

// given
const element = elementRegistry.get('Process_1');

const versionTag = getVersionTag(element);

// assume
expect(versionTag).to.exist;

// when
modeling.updateModdleProperties(element, versionTag, {
value: ''
});

// then
expect(getVersionTag(element)).not.to.exist;
}));

});

});

// helpers //////////

function getExtensionElement(element) {
function getExtensionElementWithVersionTag(element) {
const businessObject = getBusinessObject(element);

const extensionElements = businessObject.get('extensionElements');
Expand All @@ -91,4 +116,18 @@ function getExtensionElement(element) {
'zeebe:FormDefinition'
]);
});
}

function getVersionTag(element) {
const businessObject = getBusinessObject(element);

const extensionElements = businessObject.get('extensionElements');

if (!extensionElements) {
return null;
}

return extensionElements.get('values').find(extensionElement => {
return is(extensionElement, 'zeebe:VersionTag');
});
}
7 changes: 5 additions & 2 deletions test/camunda-cloud/version-tag.bpmn
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0949dru" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.26.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.5.0">
<bpmn:process id="Process_0xt54td" isExecutable="true">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:extensionElements>
<zeebe:versionTag value="v1.0.0" />
</bpmn:extensionElements>
<bpmn:callActivity id="CallActivity_1">
<bpmn:extensionElements>
<zeebe:calledElement propagateAllChildVariables="false" bindingType="versionTag" versionTag="v1.0.0" />
Expand Down Expand Up @@ -33,7 +36,7 @@
</bpmn:userTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0xt54td">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="Activity_04qoo0e_di" bpmnElement="CallActivity_1">
<dc:Bounds x="160" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
Expand Down

0 comments on commit 6f9af4d

Please sign in to comment.