-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove
zeebe:subscription
when no properties are left
Related to bpmn-io/bpmn-js-element-templates#21
- Loading branch information
Showing
4 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { | ||
getBusinessObject, | ||
is | ||
} from 'bpmn-js/lib/util/ModelUtil'; | ||
|
||
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor'; | ||
|
||
import { getExtensionElementsList, removeExtensionElements } from '../util/ExtensionElementsUtil'; | ||
|
||
/** | ||
* Zeebe BPMN behavior ensuring that zeebe:subscription is removed from bpmn:Message | ||
* when it has no properties anymore. | ||
*/ | ||
export default class CleanUpSubscriptionBehavior extends CommandInterceptor { | ||
constructor(eventBus, commandStack) { | ||
super(eventBus); | ||
|
||
this.postExecuted([ | ||
'element.updateProperties', | ||
'element.updateModdleProperties' | ||
], context => { | ||
const element = context.shape || context.newShape || context.element; | ||
|
||
if (element.labelTarget) { | ||
return; | ||
} | ||
|
||
if (!is(element, 'bpmn:Event')) { | ||
return; | ||
} | ||
|
||
const messageEventDefinition = getMessageEventDefinition(element); | ||
|
||
if (!messageEventDefinition) { | ||
return; | ||
} | ||
|
||
const message = messageEventDefinition.get('messageRef'); | ||
|
||
if (!message) { | ||
return; | ||
} | ||
|
||
const subscription = getSubscription(message); | ||
|
||
if (!subscription) { | ||
return; | ||
} | ||
|
||
if (!hasNoProperties(subscription)) { | ||
return; | ||
} | ||
|
||
removeExtensionElements(element, message, subscription, commandStack); | ||
}, true); | ||
} | ||
} | ||
|
||
CleanUpSubscriptionBehavior.$inject = [ | ||
'eventBus', | ||
'commandStack' | ||
]; | ||
|
||
|
||
// helpers ////////// | ||
|
||
function getMessageEventDefinition(event) { | ||
const businessObject = getBusinessObject(event); | ||
|
||
return businessObject.get('eventDefinitions').find(eventDefinition => { | ||
return is(eventDefinition, 'bpmn:MessageEventDefinition'); | ||
}); | ||
} | ||
|
||
function getSubscription(message) { | ||
return getExtensionElementsList(message, 'zeebe:Subscription')[ 0 ]; | ||
} | ||
|
||
function hasNoProperties(element) { | ||
const descriptor = element.$descriptor; | ||
|
||
return descriptor.properties.every(property => { | ||
return element.get(property.name) === undefined; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { | ||
bootstrapCamundaCloudModeler, | ||
inject | ||
} from 'test/TestHelper'; | ||
|
||
import { getBusinessObject } from 'bpmn-js/lib/util/ModelUtil'; | ||
|
||
import { getExtensionElementsList } from 'lib/util/ExtensionElementsUtil'; | ||
|
||
import diagramXML from './message-subscription.bpmn'; | ||
|
||
|
||
describe('camunda-cloud/features/modeling - CleanUpSubscriptionBehavior', function() { | ||
|
||
beforeEach(bootstrapCamundaCloudModeler(diagramXML)); | ||
|
||
|
||
describe('removing zeebe:subscription when correlationKey is removed', function() { | ||
|
||
let element; | ||
|
||
beforeEach(inject(function(elementRegistry, modeling) { | ||
|
||
// given | ||
element = elementRegistry.get('Event'); | ||
|
||
const subscription = getSubscription(element); | ||
|
||
// when | ||
modeling.updateModdleProperties(element, subscription, { | ||
correlationKey: undefined | ||
}); | ||
})); | ||
|
||
|
||
it('should execute', function() { | ||
|
||
// then | ||
const subscription = getSubscription(element); | ||
|
||
expect(subscription).not.to.exist; | ||
}); | ||
|
||
|
||
it('should undo', inject(function(commandStack) { | ||
|
||
// when | ||
commandStack.undo(); | ||
|
||
// then | ||
const subscription = getSubscription(element); | ||
|
||
expect(subscription).to.exist; | ||
expect(subscription.get('correlationKey')).to.equal('=abc'); | ||
})); | ||
|
||
|
||
it('should undo/redo', inject(function(commandStack) { | ||
|
||
// when | ||
commandStack.undo(); | ||
commandStack.redo(); | ||
|
||
// then | ||
const subscription = getSubscription(element); | ||
|
||
expect(subscription).not.to.exist; | ||
})); | ||
|
||
}); | ||
}); | ||
|
||
// helpers ////////// | ||
|
||
function getSubscription(element) { | ||
const businessObject = getBusinessObject(element); | ||
const eventDefiniton = businessObject.get('eventDefinitions')[ 0 ]; | ||
const message = eventDefiniton.get('messageRef'); | ||
|
||
return getExtensionElementsList(message, 'zeebe:Subscription')[ 0 ]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?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_0nxh8y3" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.17.0-nightly.20231015" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.3.0"> | ||
<bpmn:process id="Process_1qnptza" isExecutable="true"> | ||
<bpmn:intermediateCatchEvent id="Event"> | ||
<bpmn:messageEventDefinition id="MessageEventDefinition_0bwaev1" messageRef="Message_1lnjcbt" /> | ||
</bpmn:intermediateCatchEvent> | ||
</bpmn:process> | ||
<bpmn:message id="Message_1lnjcbt" name="Message"> | ||
<bpmn:extensionElements> | ||
<zeebe:subscription correlationKey="=abc" /> | ||
</bpmn:extensionElements> | ||
</bpmn:message> | ||
<bpmndi:BPMNDiagram id="BPMNDiagram_1"> | ||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1qnptza"> | ||
<bpmndi:BPMNShape id="Event_101rckl_di" bpmnElement="Event"> | ||
<dc:Bounds x="152" y="79" width="36" height="36" /> | ||
</bpmndi:BPMNShape> | ||
</bpmndi:BPMNPlane> | ||
</bpmndi:BPMNDiagram> | ||
</bpmn:definitions> |