Skip to content

Commit

Permalink
feat(zeebe): add zeebe:versionTag behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Aug 23, 2024
1 parent 823a3d1 commit 331e43d
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 2 deletions.
50 changes: 50 additions & 0 deletions lib/camunda-cloud/VersionTagBehavior.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { isDefined } from 'min-dash';

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

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

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

/**
* Ensure that `zeebe:BindingTypeSupported` (`zeebe:CalledDecision`,
* `zeebe:CalledElement` and `zeebe:FormDefinition`) only has
* `zeebe:versionTag` if `zeebe:bindingType` is `versionTag`.
*/
this.preExecute('element.updateModdleProperties', function(context) {
const {
moddleElement,
properties
} = context;

if (!isAny(moddleElement, [
'zeebe:CalledDecision',
'zeebe:CalledElement',
'zeebe:FormDefinition'
])) {
return;
}

// unset `zeebe:versionTag` if `zeebe:bindingType` is not set to `versionTag`
if ('bindingType' in properties
&& properties.bindingType !== 'versionTag'
&& isDefined(moddleElement.get('versionTag'))) {
properties.versionTag = undefined;
}

// set `zeebe:bindingType` to `versionTag` if `zeebe:versionTag` is set
if ('versionTag' in properties && moddleElement.get('bindingType') !== 'versionTag') {
properties.bindingType = 'versionTag';
}
}, true);
}
}

VersionTagBehavior.$inject = [
'eventBus'
];
7 changes: 5 additions & 2 deletions lib/camunda-cloud/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import DeleteParticipantBehaviour from '../shared/DeleteParticipantBehaviour';
import FormsBehavior from './FormsBehavior';
import RemoveAssignmentDefinitionBehavior from './RemoveAssignmentDefinitionBehavior';
import RemoveTaskScheduleBehavior from './RemoveTaskScheduleBehavior';
import VersionTagBehavior from './VersionTagBehavior';

export default {
__init__: [
Expand All @@ -22,7 +23,8 @@ export default {
'deleteParticipantBehaviour',
'formsBehavior',
'removeAssignmentDefinitionBehavior',
'removeTaskScheduleBehavior'
'removeTaskScheduleBehavior',
'versionTagBehavior'
],
cleanUpBusinessRuleTaskBehavior: [ 'type', CleanUpBusinessRuleTaskBehavior ],
cleanUpEndEventBehavior: [ 'type', CleanUpEndEventBehavior ],
Expand All @@ -34,5 +36,6 @@ export default {
deleteParticipantBehaviour: [ 'type', DeleteParticipantBehaviour ],
formsBehavior: [ 'type', FormsBehavior ],
removeAssignmentDefinitionBehavior: [ 'type', RemoveAssignmentDefinitionBehavior ],
removeTaskScheduleBehavior: [ 'type', RemoveTaskScheduleBehavior ]
removeTaskScheduleBehavior: [ 'type', RemoveTaskScheduleBehavior ],
versionTagBehavior: [ 'type', VersionTagBehavior ]
};
94 changes: 94 additions & 0 deletions test/camunda-cloud/VersionTagBehaviorSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import {
bootstrapCamundaCloudModeler,
inject
} from 'test/TestHelper';

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

import diagramXML from './version-tag.bpmn';


describe('camunda-cloud/features/modeling - VersionTagBehavior', function() {

beforeEach(bootstrapCamundaCloudModeler(diagramXML));


[
'CallActivity',
'BusinessRuleTask',
'UserTask'
].forEach(function(type) {

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

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

// given
const element = elementRegistry.get(`${ type }_1`);

const extensionElement = getExtensionElement(element);

expect(extensionElement.get('bindingType')).to.equal('versionTag');
expect(extensionElement.get('versionTag')).to.equal('v1.0.0');

// when
modeling.updateModdleProperties(element, extensionElement, {
bindingType: 'deployment'
});

// then
expect(extensionElement.get('bindingType')).to.equal('deployment');
expect(extensionElement.get('versionTag')).not.to.exist;
}));

});

describe('set binding type', function() {

it('should set binding type', inject(function(elementRegistry, modeling) {

// given
const element = elementRegistry.get(`${ type }_2`);

const extensionElement = getExtensionElement(element);

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

// when
modeling.updateModdleProperties(element, extensionElement, {
versionTag: 'v1.0.0'
});

// then
expect(extensionElement.get('bindingType')).to.equal('versionTag');
expect(extensionElement.get('versionTag')).to.equal('v1.0.0');
}));

});

});

});

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

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

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

if (!extensionElements) {
return null;
}

return extensionElements.get('values').find(extensionElement => {
return isAny(extensionElement, [
'zeebe:CalledDecision',
'zeebe:CalledElement',
'zeebe:FormDefinition'
]);
});
}
57 changes: 57 additions & 0 deletions test/camunda-cloud/version-tag.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?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:callActivity id="CallActivity_1">
<bpmn:extensionElements>
<zeebe:calledElement propagateAllChildVariables="false" bindingType="versionTag" versionTag="v1.0.0" />
</bpmn:extensionElements>
</bpmn:callActivity>
<bpmn:businessRuleTask id="BusinessRuleTask_1">
<bpmn:extensionElements>
<zeebe:calledDecision bindingType="versionTag" versionTag="v1.0.0" />
</bpmn:extensionElements>
</bpmn:businessRuleTask>
<bpmn:userTask id="UserTask_1">
<bpmn:extensionElements>
<zeebe:formDefinition formId="" bindingType="versionTag" versionTag="v1.0.0" />
</bpmn:extensionElements>
</bpmn:userTask>
<bpmn:callActivity id="CallActivity_2">
<bpmn:extensionElements>
<zeebe:calledElement propagateAllChildVariables="false" bindingType="deployment" />
</bpmn:extensionElements>
</bpmn:callActivity>
<bpmn:businessRuleTask id="BusinessRuleTask_2">
<bpmn:extensionElements>
<zeebe:calledDecision bindingType="deployment" />
</bpmn:extensionElements>
</bpmn:businessRuleTask>
<bpmn:userTask id="UserTask_2">
<bpmn:extensionElements>
<zeebe:formDefinition formId="" bindingType="deployment" />
</bpmn:extensionElements>
</bpmn:userTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0xt54td">
<bpmndi:BPMNShape id="Activity_04qoo0e_di" bpmnElement="CallActivity_1">
<dc:Bounds x="160" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0rpa9kq_di" bpmnElement="BusinessRuleTask_1">
<dc:Bounds x="290" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1t7eh0a_di" bpmnElement="UserTask_1">
<dc:Bounds x="420" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1ad2nfv_di" bpmnElement="CallActivity_2">
<dc:Bounds x="160" y="190" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1ylf3wd_di" bpmnElement="BusinessRuleTask_2">
<dc:Bounds x="290" y="190" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_09ac9pr_di" bpmnElement="UserTask_2">
<dc:Bounds x="420" y="190" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

0 comments on commit 331e43d

Please sign in to comment.