fix(replace): assign passed properties to businessObject before cloning
This commit is contained in:
parent
2dcfb1b3c9
commit
432d7f4b7c
|
@ -9,7 +9,10 @@ var pick = require('lodash/object/pick'),
|
|||
var is = require('../../util/ModelUtil').is,
|
||||
isExpanded = require('../../util/DiUtil').isExpanded,
|
||||
isEventSubProcess = require('../../util/DiUtil').isEventSubProcess,
|
||||
getProperties = require('../../util/model/ModelCloneUtils').getProperties;
|
||||
ModelCloneUtils = require('../../util/model/ModelCloneUtils'),
|
||||
getProperties = ModelCloneUtils.getProperties;
|
||||
|
||||
var IGNORED_PROPERTIES = ModelCloneUtils.IGNORED_PROPERTIES;
|
||||
|
||||
var ModelCloneHelper = require('../../util/model/ModelCloneHelper');
|
||||
|
||||
|
@ -21,20 +24,6 @@ var CUSTOM_PROPERTIES = [
|
|||
'isInterrupting'
|
||||
];
|
||||
|
||||
var IGNORED_PROPERTIES = [
|
||||
'id',
|
||||
'lanes',
|
||||
'incoming',
|
||||
'outgoing',
|
||||
'eventDefinitions',
|
||||
'processRef',
|
||||
'flowElements',
|
||||
'triggeredByEvent',
|
||||
'dataInputAssociations',
|
||||
'dataOutputAssociations',
|
||||
'incomingConversationLinks',
|
||||
'outgoingConversationLinks'
|
||||
];
|
||||
|
||||
function toggeling(element, target) {
|
||||
|
||||
|
@ -108,8 +97,29 @@ function BpmnReplace(bpmnFactory, replace, selection, modeling, moddle) {
|
|||
newElementProps = getProperties(newBusinessObject.$descriptor, true),
|
||||
properties = intersection(elementProps, newElementProps);
|
||||
|
||||
// initialize special properties defined in target definition
|
||||
assign(newBusinessObject, pick(target, CUSTOM_PROPERTIES));
|
||||
|
||||
properties = filter(properties, function(property) {
|
||||
return IGNORED_PROPERTIES.indexOf(property.replace(/bpmn:/, '')) === -1;
|
||||
var propName = property.replace(/bpmn:/, '');
|
||||
|
||||
// so the applied properties from 'target' don't get lost
|
||||
if (newBusinessObject[property] !== undefined) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// retain loop characteristics if the target element is not an event sub process
|
||||
if (propName === 'loopCharacteristics') {
|
||||
return !isEventSubProcess(newBusinessObject);
|
||||
}
|
||||
|
||||
if ((propName === 'processRef' && target.isExpanded === false) ||
|
||||
propName === 'triggeredByEvent' ||
|
||||
propName === 'eventDefinitions') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return IGNORED_PROPERTIES.indexOf(propName) === -1;
|
||||
});
|
||||
|
||||
newBusinessObject = helper.clone(oldBusinessObject, newBusinessObject, properties);
|
||||
|
@ -119,10 +129,6 @@ function BpmnReplace(bpmnFactory, replace, selection, modeling, moddle) {
|
|||
newElement.eventDefinitionType = target.eventDefinitionType;
|
||||
}
|
||||
|
||||
// initialize special properties defined in target definition
|
||||
assign(newBusinessObject, pick(target, CUSTOM_PROPERTIES));
|
||||
|
||||
|
||||
if (is(oldBusinessObject, 'bpmn:Activity')) {
|
||||
|
||||
if (is(oldBusinessObject, 'bpmn:SubProcess')) {
|
||||
|
@ -141,17 +147,16 @@ function BpmnReplace(bpmnFactory, replace, selection, modeling, moddle) {
|
|||
newElement.width = element.width;
|
||||
newElement.height = element.height;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// transform collapsed/expanded pools
|
||||
if (is(oldBusinessObject, 'bpmn:Participant')) {
|
||||
|
||||
// create expanded pool
|
||||
// create expanded pool
|
||||
if (target.isExpanded === true) {
|
||||
newBusinessObject.processRef = bpmnFactory.create('bpmn:Process');
|
||||
} else {
|
||||
// remove children when transforming to collapsed pool
|
||||
// remove children when transforming to collapsed pool
|
||||
hints.moveChildren = false;
|
||||
}
|
||||
|
||||
|
@ -162,11 +167,6 @@ function BpmnReplace(bpmnFactory, replace, selection, modeling, moddle) {
|
|||
|
||||
newBusinessObject.name = oldBusinessObject.name;
|
||||
|
||||
// retain loop characteristics if the target element is not an event sub process
|
||||
if (!isEventSubProcess(newBusinessObject)) {
|
||||
newBusinessObject.loopCharacteristics = oldBusinessObject.loopCharacteristics;
|
||||
}
|
||||
|
||||
// retain default flow's reference between inclusive <-> exclusive gateways and activities
|
||||
if ((is(oldBusinessObject, 'bpmn:ExclusiveGateway') || is(oldBusinessObject, 'bpmn:InclusiveGateway') ||
|
||||
is(oldBusinessObject, 'bpmn:Activity')) &&
|
||||
|
@ -176,10 +176,6 @@ function BpmnReplace(bpmnFactory, replace, selection, modeling, moddle) {
|
|||
newBusinessObject.default = oldBusinessObject.default;
|
||||
}
|
||||
|
||||
if (oldBusinessObject.isForCompensation) {
|
||||
newBusinessObject.isForCompensation = true;
|
||||
}
|
||||
|
||||
newElement = replace.replaceElement(element, newElement, hints);
|
||||
|
||||
if (hints.select !== false) {
|
||||
|
|
|
@ -2,6 +2,21 @@
|
|||
|
||||
var forEach = require('lodash/collection/forEach');
|
||||
|
||||
/**
|
||||
* These are the properties that should be ignored when cloning elements.
|
||||
*
|
||||
* @type {Array}
|
||||
*/
|
||||
module.exports.IGNORED_PROPERTIES = [
|
||||
'lanes',
|
||||
'incoming',
|
||||
'outgoing',
|
||||
'artifacts',
|
||||
'default',
|
||||
'flowElements'
|
||||
];
|
||||
|
||||
|
||||
function getProperties(descriptor, keepDefault) {
|
||||
var properties = [];
|
||||
|
||||
|
@ -10,7 +25,7 @@ function getProperties(descriptor, keepDefault) {
|
|||
if (keepDefault && property.default) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
properties.push(property.ns.name);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,9 +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:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.7.0-dev">
|
||||
<bpmn:collaboration id="Collaboration_0j2pyna">
|
||||
<bpmn:participant id="Participant_0x9lnke" processRef="Process_1" />
|
||||
<bpmn:participant id="Participant_0x9lnke" name="foobar" processRef="Process_1" />
|
||||
</bpmn:collaboration>
|
||||
<bpmn:process id="Process_1" isExecutable="false">
|
||||
<bpmn:process id="Process_1" name="process_foo" isExecutable="false" camunda:versionTag="1.0">
|
||||
<bpmn:dataStoreReference id="DataStoreReference_1elrt45" />
|
||||
<bpmn:dataStoreReference id="DataStoreReference_1j8ymac" />
|
||||
<bpmn:dataObjectReference id="DataObjectReference_1js94kb" dataObjectRef="DataObject_1l0h55k" />
|
||||
|
|
|
@ -220,7 +220,7 @@ describe('features/replace - bpmn replace', function() {
|
|||
}));
|
||||
|
||||
|
||||
it('collapsed with expande pool', inject(function(elementRegistry, bpmnReplace) {
|
||||
it('collapsed with expanded pool', inject(function(elementRegistry, bpmnReplace) {
|
||||
|
||||
// given
|
||||
var shape = elementRegistry.get('Participant_2');
|
||||
|
|
Loading…
Reference in New Issue