-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(camunda-platform): add delete error event definition behavior
Related to bpmn-io/bpmn-properties-panel#41
- Loading branch information
Niklas Kiefer
committed
Jul 29, 2021
1 parent
a3a5e02
commit 14290b8
Showing
4 changed files
with
286 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
lib/camunda-platform/features/modeling/behavior/DeleteErrorEventDefinitionBehavior.js
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,90 @@ | ||
import inherits from 'inherits'; | ||
|
||
import { | ||
getBusinessObject, | ||
is | ||
} from 'bpmn-js/lib/util/ModelUtil'; | ||
|
||
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor'; | ||
|
||
const HIGH_PRIORITY = 5000; | ||
|
||
|
||
/** | ||
* Camunda BPMN specific `camunda:errorEventDefinition` behavior. | ||
* | ||
* When `camunda:type` is set to something different than `external` | ||
* on an element, then `camunda:errorEventDefinition` extension elements | ||
* shall be removed. | ||
*/ | ||
export default function DeleteErrorEventDefinitionBehavior(eventBus) { | ||
|
||
CommandInterceptor.call(this, eventBus); | ||
|
||
this.executed([ 'properties-panel.update-businessobject', 'element.updateProperties' ], | ||
HIGH_PRIORITY, function(context) { | ||
const { | ||
element, | ||
oldProperties, | ||
properties | ||
} = context; | ||
|
||
const businessObject = getBusinessObject(element), | ||
extensionElements = businessObject.extensionElements; | ||
|
||
// (1) Check whether behavior is suitable | ||
if ( | ||
is(element, 'camunda:ExternalCapable') && | ||
extensionElements && | ||
externalTypeChanged(oldProperties, properties) | ||
) { | ||
|
||
// (2) Delete camunda:ErrorEventDefinition elements and save them for revert | ||
context.deleteErrorEventDefinitionsOld = extensionElements.values; | ||
|
||
extensionElements.values = extensionElements.values.filter( | ||
element => !is(element, 'camunda:ErrorEventDefinition') | ||
); | ||
} | ||
|
||
}, true); | ||
|
||
this.reverted([ 'properties-panel.update-businessobject', 'element.updateProperties' ], | ||
HIGH_PRIORITY, function({ context }) { | ||
const { | ||
element, | ||
deleteErrorEventDefinitionsOld: oldExtensionElements | ||
} = context; | ||
|
||
const businessObject = getBusinessObject(element); | ||
|
||
// Only intercept the revert, if the behavior became active | ||
if (oldExtensionElements) { | ||
const extensionElements = businessObject.extensionElements; | ||
|
||
extensionElements.values = oldExtensionElements; | ||
} | ||
}); | ||
} | ||
|
||
|
||
DeleteErrorEventDefinitionBehavior.$inject = [ | ||
'eventBus' | ||
]; | ||
|
||
inherits(DeleteErrorEventDefinitionBehavior, CommandInterceptor); | ||
|
||
|
||
// helper ////////////////// | ||
|
||
function externalTypeChanged(oldProperties, updatesProperties) { | ||
const { | ||
'camunda:type': oldType | ||
} = oldProperties; | ||
|
||
const { | ||
'camunda:type': newType | ||
} = updatesProperties; | ||
|
||
return oldType === 'external' && newType !== 'external'; | ||
} |
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
171 changes: 171 additions & 0 deletions
171
test/camunda-platform/features/modeling/DeleteErrorEventDefinitionBehaviorSpec.js
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,171 @@ | ||
import { | ||
bootstrapCamundaPlatformModeler, | ||
inject | ||
} from 'test/TestHelper'; | ||
|
||
import coreModule from 'bpmn-js/lib/core'; | ||
|
||
import modelingModule from 'bpmn-js/lib/features/modeling'; | ||
|
||
import { | ||
is, | ||
getBusinessObject | ||
} from 'bpmn-js/lib/util/ModelUtil'; | ||
|
||
import camundaModdleExtensions from 'camunda-bpmn-moddle/resources/camunda'; | ||
|
||
import camundaPlatformModelingModules from 'lib/camunda-platform/features/modeling'; | ||
|
||
import propertiesPanelCommandHandler from 'bpmn-js-properties-panel/lib/cmd'; | ||
|
||
import diagramXML from './camunda-error-event-definition-diagram.bpmn'; | ||
|
||
|
||
describe('camunda-platform/features/modeling - DeleteErrorEventDefinitionBehavior', function() { | ||
|
||
const testModules = [ | ||
camundaPlatformModelingModules, | ||
coreModule, | ||
modelingModule, | ||
propertiesPanelCommandHandler | ||
]; | ||
|
||
const moddleExtensions = { | ||
camunda: camundaModdleExtensions | ||
}; | ||
|
||
beforeEach(bootstrapCamundaPlatformModeler(diagramXML, { | ||
modules: testModules, | ||
moddleExtensions | ||
})); | ||
|
||
describe('properties-panel.update-businessobject', function() { | ||
|
||
describe('camunda:type to non-external', function() { | ||
|
||
let shape, context, businessObject; | ||
|
||
beforeEach(inject(function(elementRegistry, commandStack) { | ||
|
||
// given | ||
shape = elementRegistry.get('ServiceTask_1'); | ||
businessObject = getBusinessObject(shape); | ||
|
||
context = { | ||
element: shape, | ||
businessObject: businessObject, | ||
properties: { | ||
'camunda:type': 'foo' | ||
} | ||
}; | ||
|
||
// assume | ||
expect(getErrorEventDefinitions(businessObject)).to.have.length(3); | ||
|
||
// when | ||
commandStack.execute('properties-panel.update-businessobject', context); | ||
})); | ||
|
||
|
||
it('should execute', inject(function() { | ||
|
||
// then | ||
expect(getErrorEventDefinitions(businessObject)).to.be.empty; | ||
})); | ||
|
||
|
||
it('should undo', inject(function(commandStack) { | ||
|
||
// when | ||
commandStack.undo(); | ||
|
||
// then | ||
expect(getErrorEventDefinitions(businessObject)).to.have.length(3); | ||
})); | ||
|
||
|
||
it('should undo/redo', inject(function(commandStack) { | ||
|
||
// when | ||
commandStack.undo(); | ||
commandStack.redo(); | ||
|
||
// then | ||
expect(getErrorEventDefinitions(businessObject)).to.be.empty; | ||
})); | ||
|
||
}); | ||
|
||
}); | ||
|
||
|
||
describe('element.updateProperties', function() { | ||
|
||
describe('camunda:type to non-external', function() { | ||
|
||
let shape, businessObject; | ||
|
||
beforeEach(inject(function(elementRegistry, modeling) { | ||
|
||
// given | ||
shape = elementRegistry.get('ServiceTask_1'); | ||
businessObject = getBusinessObject(shape); | ||
|
||
// assume | ||
expect(getErrorEventDefinitions(businessObject)).to.have.length(3); | ||
|
||
// when | ||
modeling.updateProperties(shape, { | ||
'camunda:type': 'foo' | ||
}); | ||
})); | ||
|
||
|
||
it('should execute', inject(function() { | ||
|
||
// then | ||
expect(getErrorEventDefinitions(businessObject)).to.be.empty; | ||
})); | ||
|
||
|
||
it('should undo', inject(function(commandStack) { | ||
|
||
// when | ||
commandStack.undo(); | ||
|
||
// then | ||
expect(getErrorEventDefinitions(businessObject)).to.have.length(3); | ||
})); | ||
|
||
|
||
it('should undo/redo', inject(function(commandStack) { | ||
|
||
// when | ||
commandStack.undo(); | ||
commandStack.redo(); | ||
|
||
// then | ||
expect(getErrorEventDefinitions(businessObject)).to.be.empty; | ||
})); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
|
||
// helper /////////// | ||
|
||
function getErrorEventDefinitions(businessObject) { | ||
return getExtensionElementsList(businessObject, 'camunda:ErrorEventDefinition'); | ||
} | ||
|
||
function getExtensionElementsList(businessObject, type = undefined) { | ||
const elements = ((businessObject.get('extensionElements') && | ||
businessObject.get('extensionElements').get('values')) || []); | ||
|
||
return (elements.length && type) ? | ||
elements.filter((value) => is(value, type)) : | ||
elements; | ||
} |
22 changes: 22 additions & 0 deletions
22
test/camunda-platform/features/modeling/camunda-error-event-definition-diagram.bpmn
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,22 @@ | ||
<?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:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0gocifa" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.10.0-nightly.20210721" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.15.0"> | ||
<bpmn:process id="Process_1" isExecutable="true"> | ||
<bpmn:serviceTask id="ServiceTask_1" camunda:type="external" camunda:topic="topic"> | ||
<bpmn:extensionElements> | ||
<camunda:errorEventDefinition id="ErrorEventDefinition_1" errorRef="Error_1" /> | ||
<camunda:errorEventDefinition id="ErrorEventDefinition_2" errorRef="Error_2" /> | ||
<camunda:errorEventDefinition id="ErrorEventDefinition_3" errorRef="Error_3" /> | ||
</bpmn:extensionElements> | ||
</bpmn:serviceTask> | ||
</bpmn:process> | ||
<bpmn:error id="Error_1" name="Error_1" /> | ||
<bpmn:error id="Error_2" name="Error_2" /> | ||
<bpmn:error id="Error_3" name="Error_3" /> | ||
<bpmndi:BPMNDiagram id="BPMNDiagram_1"> | ||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1"> | ||
<bpmndi:BPMNShape id="Activity_09ir90a_di" bpmnElement="ServiceTask_1"> | ||
<dc:Bounds x="160" y="80" width="100" height="80" /> | ||
</bpmndi:BPMNShape> | ||
</bpmndi:BPMNPlane> | ||
</bpmndi:BPMNDiagram> | ||
</bpmn:definitions> |