feat(modeling/copy-paste): copy message referenced by ReceiveTask
Related to https://github.com/camunda/camunda-modeler/issues/1637
This commit is contained in:
parent
dc5a566e10
commit
dcc6d1ca94
|
@ -33,6 +33,15 @@ export default function RootElementReferenceBehavior(
|
|||
) {
|
||||
injector.invoke(CommandInterceptor, this);
|
||||
|
||||
function canHaveRootElementReference(element) {
|
||||
return is(element, 'bpmn:ReceiveTask') || hasAnyEventDefinition(element, [
|
||||
'bpmn:ErrorEventDefinition',
|
||||
'bpmn:EscalationEventDefinition',
|
||||
'bpmn:MessageEventDefinition',
|
||||
'bpmn:SignalEventDefinition'
|
||||
]);
|
||||
}
|
||||
|
||||
function hasRootElement(rootElement) {
|
||||
var definitions = bpmnjs.getDefinitions(),
|
||||
rootElements = definitions.get('rootElements');
|
||||
|
@ -52,27 +61,38 @@ export default function RootElementReferenceBehavior(
|
|||
}
|
||||
}
|
||||
|
||||
function getRootElementReferenced(eventDefinition) {
|
||||
function getRootElement(businessObject) {
|
||||
if (is(businessObject, 'bpmn:ReceiveTask')) {
|
||||
return businessObject.get('messageRef');
|
||||
}
|
||||
|
||||
var eventDefinitions = businessObject.get('eventDefinitions'),
|
||||
eventDefinition = eventDefinitions[ 0 ];
|
||||
|
||||
return eventDefinition.get(getRootElementReferencePropertyName(eventDefinition));
|
||||
}
|
||||
|
||||
function setRootElement(businessObject, rootElement) {
|
||||
if (is(businessObject, 'bpmn:ReceiveTask')) {
|
||||
return businessObject.set('messageRef', rootElement);
|
||||
}
|
||||
|
||||
var eventDefinitions = businessObject.get('eventDefinitions'),
|
||||
eventDefinition = eventDefinitions[ 0 ];
|
||||
|
||||
return eventDefinition.set(getRootElementReferencePropertyName(eventDefinition), rootElement);
|
||||
}
|
||||
|
||||
// create shape
|
||||
this.executed('shape.create', function(context) {
|
||||
var shape = context.shape;
|
||||
|
||||
if (!hasAnyEventDefinition(shape, [
|
||||
'bpmn:ErrorEventDefinition',
|
||||
'bpmn:EscalationEventDefinition',
|
||||
'bpmn:MessageEventDefinition',
|
||||
'bpmn:SignalEventDefinition'
|
||||
])) {
|
||||
if (!canHaveRootElementReference(shape)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var businessObject = getBusinessObject(shape),
|
||||
eventDefinitions = businessObject.get('eventDefinitions'),
|
||||
eventDefinition = eventDefinitions[ 0 ],
|
||||
rootElement = getRootElementReferenced(eventDefinition),
|
||||
rootElement = getRootElement(businessObject),
|
||||
rootElements;
|
||||
|
||||
if (rootElement && !hasRootElement(rootElement)) {
|
||||
|
@ -102,19 +122,12 @@ export default function RootElementReferenceBehavior(
|
|||
var descriptor = context.descriptor,
|
||||
element = context.element;
|
||||
|
||||
if (!hasAnyEventDefinition(element, [
|
||||
'bpmn:ErrorEventDefinition',
|
||||
'bpmn:EscalationEventDefinition',
|
||||
'bpmn:MessageEventDefinition',
|
||||
'bpmn:SignalEventDefinition'
|
||||
])) {
|
||||
if (!canHaveRootElementReference(element)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var businessObject = getBusinessObject(element),
|
||||
eventDefinitions = businessObject.get('eventDefinitions'),
|
||||
eventDefinition = eventDefinitions[ 0 ],
|
||||
rootElement = getRootElementReferenced(eventDefinition);
|
||||
rootElement = getRootElement(businessObject);
|
||||
|
||||
if (rootElement) {
|
||||
descriptor.referencedRootElement = rootElement;
|
||||
|
@ -125,18 +138,11 @@ export default function RootElementReferenceBehavior(
|
|||
var descriptor = context.descriptor,
|
||||
businessObject = descriptor.businessObject;
|
||||
|
||||
if (!hasAnyEventDefinition(businessObject, [
|
||||
'bpmn:ErrorEventDefinition',
|
||||
'bpmn:EscalationEventDefinition',
|
||||
'bpmn:MessageEventDefinition',
|
||||
'bpmn:SignalEventDefinition'
|
||||
])) {
|
||||
if (!canHaveRootElementReference(businessObject)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var eventDefinitions = businessObject.get('eventDefinitions'),
|
||||
eventDefinition = eventDefinitions[ 0 ],
|
||||
referencedRootElement = descriptor.referencedRootElement;
|
||||
var referencedRootElement = descriptor.referencedRootElement;
|
||||
|
||||
if (!referencedRootElement) {
|
||||
return;
|
||||
|
@ -149,7 +155,7 @@ export default function RootElementReferenceBehavior(
|
|||
);
|
||||
}
|
||||
|
||||
eventDefinition.set(getRootElementReferencePropertyName(eventDefinition), referencedRootElement);
|
||||
setRootElement(businessObject, referencedRootElement);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?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" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.4.1">
|
||||
<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" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.6.0">
|
||||
<bpmn:process id="Process_1" isExecutable="true">
|
||||
<bpmn:task id="Task_1" />
|
||||
<bpmn:boundaryEvent id="MessageBoundaryEvent_1" attachedToRef="Task_1">
|
||||
|
@ -15,30 +15,35 @@
|
|||
<bpmn:signalEventDefinition signalRef="Signal_1" />
|
||||
</bpmn:boundaryEvent>
|
||||
<bpmn:task id="Task_2" />
|
||||
<bpmn:receiveTask id="ReceiveTask" messageRef="Message_2" />
|
||||
</bpmn:process>
|
||||
<bpmn:message id="Message_1" name="Message_1" />
|
||||
<bpmn:escalation id="Escalation_1" name="Escalation_1" escalationCode="42" />
|
||||
<bpmn:error id="Error_1" name="Error_1" errorCode="1" />
|
||||
<bpmn:signal id="Signal_1" name="Signal_1" />
|
||||
<bpmn:message id="Message_2" name="Message_2" />
|
||||
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
|
||||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
|
||||
<bpmndi:BPMNShape id="Task_1_di" bpmnElement="Task_1">
|
||||
<dc:Bounds x="50" y="60" width="100" height="80" />
|
||||
<dc:Bounds x="170" y="60" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="MessageBoundaryEvent_1_di" bpmnElement="MessageBoundaryEvent_1">
|
||||
<dc:Bounds x="32" y="122" width="36" height="36" />
|
||||
<dc:Bounds x="152" y="122" width="36" height="36" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="EscalationBoundaryEvent_1_di" bpmnElement="EscalationBoundaryEvent_1">
|
||||
<dc:Bounds x="132" y="42" width="36" height="36" />
|
||||
<dc:Bounds x="252" y="42" width="36" height="36" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="ErrorBoundaryEvent_1_di" bpmnElement="ErrorBoundaryEvent_1">
|
||||
<dc:Bounds x="32" y="42" width="36" height="36" />
|
||||
<dc:Bounds x="152" y="42" width="36" height="36" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="SignalBoundaryEvent_1_di" bpmnElement="SignalBoundaryEvent_1">
|
||||
<dc:Bounds x="132" y="122" width="36" height="36" />
|
||||
<dc:Bounds x="252" y="122" width="36" height="36" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Task_2_di" bpmnElement="Task_2">
|
||||
<dc:Bounds x="250" y="60" width="100" height="80" />
|
||||
<dc:Bounds x="370" y="60" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="ReceiveTask_di" bpmnElement="ReceiveTask">
|
||||
<dc:Bounds x="170" y="220" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
</bpmndi:BPMNPlane>
|
||||
</bpmndi:BPMNDiagram>
|
||||
|
|
|
@ -145,6 +145,10 @@ describe('features/modeling - root element reference behavior', function() {
|
|||
|
||||
rootElement = getRootElementReferenced(eventDefinition);
|
||||
|
||||
var rootElementsOfTypeCount = filter(
|
||||
rootElements, matchPattern({ $type: rootElement.$type })
|
||||
).length;
|
||||
|
||||
copyPaste.copy(boundaryEvent);
|
||||
|
||||
modeling.removeShape(boundaryEvent);
|
||||
|
@ -174,13 +178,134 @@ describe('features/modeling - root element reference behavior', function() {
|
|||
// then
|
||||
var rootElementsOfType = filter(rootElements, matchPattern({ $type: rootElement.$type }));
|
||||
|
||||
expect(rootElementsOfType).to.have.lengthOf(1);
|
||||
expect(rootElementsOfType).to.have.lengthOf(rootElementsOfTypeCount);
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('receiveTask', function() {
|
||||
|
||||
var id = 'ReceiveTask';
|
||||
|
||||
var receiveTask,
|
||||
rootElement,
|
||||
pastedRootElement;
|
||||
|
||||
describe('should add a copy', function() {
|
||||
|
||||
beforeEach(inject(function(bpmnjs, copyPaste, elementRegistry, modeling, canvas) {
|
||||
|
||||
// given
|
||||
receiveTask = elementRegistry.get(id);
|
||||
|
||||
var businessObject = getBusinessObject(receiveTask),
|
||||
rootElement = businessObject.messageRef;
|
||||
|
||||
// when
|
||||
copyPaste.copy(receiveTask);
|
||||
|
||||
modeling.removeShape(receiveTask);
|
||||
|
||||
collectionRemove(bpmnjs.getDefinitions().get('rootElements'), rootElement);
|
||||
|
||||
expect(hasRootElement(rootElement)).to.be.false;
|
||||
|
||||
receiveTask = copyPaste.paste({
|
||||
element: canvas.getRootElement(),
|
||||
point: {
|
||||
x: receiveTask.x,
|
||||
y: receiveTask.y + 200
|
||||
}
|
||||
})[0];
|
||||
|
||||
businessObject = getBusinessObject(receiveTask);
|
||||
pastedRootElement = businessObject.messageRef;
|
||||
}));
|
||||
|
||||
|
||||
it('<do>', function() {
|
||||
|
||||
// then
|
||||
expect(hasRootElement(rootElement)).to.be.false;
|
||||
expect(hasRootElement(pastedRootElement)).to.be.true;
|
||||
});
|
||||
|
||||
|
||||
it('<undo>', inject(function(commandStack) {
|
||||
|
||||
// when
|
||||
commandStack.undo();
|
||||
|
||||
// then
|
||||
expect(hasRootElement(rootElement)).to.be.false;
|
||||
expect(hasRootElement(pastedRootElement)).to.be.false;
|
||||
}));
|
||||
|
||||
|
||||
it('<redo>', inject(function(commandStack) {
|
||||
|
||||
// given
|
||||
commandStack.undo();
|
||||
|
||||
// when
|
||||
commandStack.redo();
|
||||
|
||||
// then
|
||||
expect(hasRootElement(rootElement)).to.be.false;
|
||||
expect(hasRootElement(pastedRootElement)).to.be.true;
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
|
||||
it('should NOT add', inject(function(
|
||||
bpmnFactory, bpmnjs, copyPaste, elementRegistry, moddleCopy, modeling, canvas
|
||||
) {
|
||||
|
||||
// given
|
||||
receiveTask = elementRegistry.get(id);
|
||||
|
||||
var businessObject = getBusinessObject(receiveTask),
|
||||
rootElement = businessObject.messageRef,
|
||||
rootElements = bpmnjs.getDefinitions().get('rootElements');
|
||||
|
||||
var rootElementsOfTypeCount = filter(
|
||||
rootElements, matchPattern({ $type: rootElement.$type })
|
||||
).length;
|
||||
|
||||
copyPaste.copy(receiveTask);
|
||||
|
||||
modeling.removeShape(receiveTask);
|
||||
|
||||
collectionRemove(rootElements, rootElement);
|
||||
|
||||
expect(hasRootElement(rootElement)).to.be.false;
|
||||
|
||||
var rootElementWithSameId = bpmnFactory.create(rootElement.$type);
|
||||
|
||||
moddleCopy.copyElement(rootElement, rootElementWithSameId);
|
||||
|
||||
collectionRemove(rootElements, rootElementWithSameId);
|
||||
|
||||
// when
|
||||
receiveTask = copyPaste.paste({
|
||||
element: canvas.getRootElement(),
|
||||
point: {
|
||||
x: receiveTask.x,
|
||||
y: receiveTask.y + 200
|
||||
}
|
||||
})[0];
|
||||
|
||||
// then
|
||||
var rootElementsOfType = filter(rootElements, matchPattern({ $type: rootElement.$type }));
|
||||
|
||||
expect(rootElementsOfType).to.have.lengthOf(rootElementsOfTypeCount);
|
||||
}));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
@ -244,6 +369,44 @@ describe('features/modeling - root element reference behavior', function() {
|
|||
|
||||
});
|
||||
|
||||
|
||||
describe('receiveTask', function() {
|
||||
|
||||
var receiveTask,
|
||||
rootElement;
|
||||
|
||||
beforeEach(inject(function(copyPaste, elementRegistry, canvas) {
|
||||
|
||||
// given
|
||||
receiveTask = elementRegistry.get('ReceiveTask');
|
||||
|
||||
var businessObject = getBusinessObject(receiveTask);
|
||||
|
||||
rootElement = businessObject.messageRef;
|
||||
|
||||
copyPaste.copy(receiveTask);
|
||||
|
||||
// when
|
||||
receiveTask = copyPaste.paste({
|
||||
element: canvas.getRootElement(),
|
||||
point: {
|
||||
x: receiveTask.x,
|
||||
y: receiveTask.y + 200,
|
||||
}
|
||||
})[0];
|
||||
}));
|
||||
|
||||
|
||||
it('should copy root element reference', function() {
|
||||
|
||||
// then
|
||||
var businessObject = getBusinessObject(receiveTask),
|
||||
copiedRootElement = businessObject.messageRef;
|
||||
|
||||
expect(copiedRootElement).to.equal(rootElement);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -266,7 +429,7 @@ function hasRootElement(rootElement) {
|
|||
var definitions = getBpmnJS().getDefinitions(),
|
||||
rootElements = definitions.get('rootElements');
|
||||
|
||||
return !!find(rootElements, matchPattern({ id: rootElement.id }));
|
||||
return !!rootElement && !!find(rootElements, matchPattern({ id: rootElement.id }));
|
||||
}
|
||||
|
||||
function capitalizeFirstChar(string) {
|
||||
|
|
Loading…
Reference in New Issue