Skip to content

Commit

Permalink
fix(modeling): update association's refs on element id change
Browse files Browse the repository at this point in the history
Closes #397
  • Loading branch information
barmac authored and fake-join[bot] committed Mar 12, 2020
1 parent 733bfc7 commit 10eb3ad
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,41 @@ describe('IdChangeBehavior', function() {
});
}));


it('should update IDs on decision ID change', inject(function(modeling, sheet) {

// given
const root = sheet.getRoot(),
decisionTable = root.businessObject;

const decision = decisionTable.$parent;

const definitions = decision.$parent;

const {
artifacts,
drgElements
} = definitions;

const dishDecision = drgElements.filter(
drgElement => drgElement.id === 'dish-decision'
)[0];

const association = artifacts.filter(
element => element.id === 'Association'
)[0];

const dmnJS = getDmnJS();

dmnJS._viewers.decisionTable.open(dishDecision, () => {

// when
modeling.editDecisionTableId('foo');

// then
expect(association.sourceRef.href).to.eql('#foo');
expect(association.extensionElements.values[0].source).to.eql('foo');
});
}));

});
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/DMN/20151101/dmn.xsd" xmlns:biodi="http://bpmn.io/schema/dmn/biodi/1.0" id="dish" name="Dish" namespace="http://camunda.org/schema/1.0/dmn">
<definitions xmlns="http://www.omg.org/spec/DMN/20151101/dmn.xsd" xmlns:biodi="http://bpmn.io/schema/dmn/biodi/1.0" id="dish" name="Dish" namespace="http://camunda.org/schema/1.0/dmn" exporter="Camunda Modeler" exporterVersion="3.7.0">
<decision id="dish-decision" name="Dish Decision">
<extensionElements>
<biodi:bounds x="140" y="5" width="180" height="80" />
<biodi:bounds x="290" y="85" width="180" height="80" />
<biodi:edge source="season">
<biodi:waypoints x="80" y="132" />
<biodi:waypoints x="140" y="81" />
<biodi:waypoints x="230" y="212" />
<biodi:waypoints x="290" y="161" />
</biodi:edge>
</extensionElements>
<informationRequirement>
Expand All @@ -25,75 +25,75 @@
<output id="output1" label="Dish" name="desiredDish" typeRef="string" />
<rule id="row-495762709-1">
<inputEntry id="UnaryTests_1nxcsjr">
<text><![CDATA["Winter"]]></text>
<text>"Winter"</text>
</inputEntry>
<inputEntry id="UnaryTests_1r9yorj">
<text><![CDATA[<= 8]]></text>
<text>&lt;= 8</text>
</inputEntry>
<outputEntry id="LiteralExpression_1mtwzqz">
<text><![CDATA["Spareribs"]]></text>
<text>"Spareribs"</text>
</outputEntry>
</rule>
<rule id="row-495762709-2">
<inputEntry id="UnaryTests_1lxjbif">
<text><![CDATA["Winter"]]></text>
<text>"Winter"</text>
</inputEntry>
<inputEntry id="UnaryTests_0nhiedb">
<text><![CDATA[> 8]]></text>
<text>&gt; 8</text>
</inputEntry>
<outputEntry id="LiteralExpression_1h30r12">
<text><![CDATA["Pasta"]]></text>
<text>"Pasta"</text>
</outputEntry>
</rule>
<rule id="row-495762709-3">
<inputEntry id="UnaryTests_0ifgmfm">
<text><![CDATA["Summer"]]></text>
<text>"Summer"</text>
</inputEntry>
<inputEntry id="UnaryTests_12cib9m">
<text><![CDATA[> 10]]></text>
<text>&gt; 10</text>
</inputEntry>
<outputEntry id="LiteralExpression_0wgaegy">
<text><![CDATA["Light salad"]]></text>
<text>"Light salad"</text>
</outputEntry>
</rule>
<rule id="row-495762709-7">
<inputEntry id="UnaryTests_0ozm9s7">
<text><![CDATA["Summer"]]></text>
<text>"Summer"</text>
</inputEntry>
<inputEntry id="UnaryTests_0sesgov">
<text><![CDATA[<= 10]]></text>
<text>&lt;= 10</text>
</inputEntry>
<outputEntry id="LiteralExpression_1dvc5x3">
<text><![CDATA["Beans salad"]]></text>
<text>"Beans salad"</text>
</outputEntry>
</rule>
<rule id="row-445981423-3">
<inputEntry id="UnaryTests_1er0je1">
<text><![CDATA["Spring"]]></text>
<text>"Spring"</text>
</inputEntry>
<inputEntry id="UnaryTests_1uzqner">
<text><![CDATA[< 10]]></text>
<text>&lt; 10</text>
</inputEntry>
<outputEntry id="LiteralExpression_1pxy4g1">
<text><![CDATA["Stew"]]></text>
<text>"Stew"</text>
</outputEntry>
</rule>
<rule id="row-445981423-4">
<inputEntry id="UnaryTests_06or48g">
<text><![CDATA["Spring"]]></text>
<text>"Spring"</text>
</inputEntry>
<inputEntry id="UnaryTests_0wa71sy">
<text><![CDATA[>= 10]]></text>
<text>&gt;= 10</text>
</inputEntry>
<outputEntry id="LiteralExpression_09ggol9">
<text><![CDATA["Steak"]]></text>
<text>"Steak"</text>
</outputEntry>
</rule>
</decisionTable>
</decision>
<decision id="season" name="Season decision">
<extensionElements>
<biodi:bounds x="10" y="132" width="180" height="80" />
<biodi:bounds x="160" y="212" width="180" height="80" />
</extensionElements>
<decisionTable id="seasonDecisionTable">
<input id="temperatureInput" label="Weather in Celsius">
Expand All @@ -104,28 +104,43 @@
<output id="seasonOutput" label="season" name="season" typeRef="string" />
<rule id="row-495762709-5">
<inputEntry id="UnaryTests_1fd0eqo">
<text><![CDATA[>30]]></text>
<text>&gt;30</text>
</inputEntry>
<outputEntry id="LiteralExpression_0l98klb">
<text><![CDATA["Summer"]]></text>
<text>"Summer"</text>
</outputEntry>
</rule>
<rule id="row-495762709-6">
<inputEntry id="UnaryTests_1nz6at2">
<text><![CDATA[<10]]></text>
<text>&lt;10</text>
</inputEntry>
<outputEntry id="LiteralExpression_08moy1k">
<text><![CDATA["Winter"]]></text>
<text>"Winter"</text>
</outputEntry>
</rule>
<rule id="row-445981423-2">
<inputEntry id="UnaryTests_1a0imxy">
<text>[10..30]</text>
</inputEntry>
<outputEntry id="LiteralExpression_1poftw4">
<text><![CDATA["Spring"]]></text>
<text>"Spring"</text>
</outputEntry>
</rule>
</decisionTable>
</decision>
<textAnnotation id="TextAnnotation">
<extensionElements>
<biodi:bounds x="500" y="230" width="100" height="80" />
</extensionElements>
</textAnnotation>
<association id="Association">
<extensionElements>
<biodi:edge source="dish-decision">
<biodi:waypoints x="427" y="165" />
<biodi:waypoints x="503" y="230" />
</biodi:edge>
</extensionElements>
<sourceRef href="#dish-decision" />
<targetRef href="#TextAnnotation" />
</association>
</definitions>
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,36 @@ describe('IdChangeBehavior', function() {
expect(connection.businessObject.requiredDecision.href).to.eql('#newId');
})
);


it('should update association sourceRef on source ID change', inject(
function(elementRegistry,modeling) {

// given
const source = elementRegistry.get('dayType_id'),
connection = source.outgoing[0];

// when
modeling.updateProperties(source, { id: 'newId' });

// then
expect(connection.businessObject.sourceRef.href).to.eql('#newId');
})
);


it('should update association targetRef on target ID change', inject(
function(elementRegistry,modeling) {

// given
const target = elementRegistry.get('annotation_1'),
connection = target.incoming[0];

// when
modeling.updateProperties(target, { id: 'newId' });

// then
expect(connection.businessObject.targetRef.href).to.eql('#newId');
})
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,31 @@ export default class IdChangeBehavior extends CommandInterceptor {

const bo = getBusinessObject(element);

if (!is(bo, 'dmn:DRGElement') || !isIdChange(oldProperties, properties)) {
if (this.shouldSkipUpdate(bo, oldProperties, properties)) {
return;
}

const drgElements = getDrgElements(bo);
const definitions = getDefinitions(bo);

const drgElements = definitions.get('drgElements');
drgElements.forEach(drgElement => {
updateElementReferences(drgElement, oldProperties.id, properties.id);

updateEdges(drgElement, oldProperties.id, properties.id);
});

const artifacts = definitions.get('artifacts');
artifacts.forEach(artifact => {
updateAssociationReferences(artifact, oldProperties.id, properties.id);

updateEdges(artifact, oldProperties.id, properties.id);
});
}

shouldSkipUpdate(bo, oldProperties, newProperties) {
return !isIdChange(oldProperties, newProperties) ||
(!is(bo, 'dmn:DRGElement') && !is(bo, 'dmn:TextAnnotation'));
}
}

IdChangeBehavior.$inject = [ 'eventBus' ];
Expand All @@ -49,14 +61,6 @@ function isIdChange(oldProperties, properties) {
return ID in oldProperties && ID in properties;
}

function getDrgElements(element) {
const definitions = getDefinitions(element);

const drgElements = definitions.drgElements;

return drgElements;
}


/**
* Walk up the tree until at the root to get to dmn:Definitions.
Expand Down Expand Up @@ -150,4 +154,31 @@ function updateEdges(element, oldId, id) {
});
}

}
}
function updateAssociationReferences(element, oldId, id) {

const handlers = {
sourceRef: () => {
const { sourceRef } = element;

if (sourceRef.href === `#${oldId}`) {
sourceRef.href = `#${id}`;
}
},
targetRef: () => {
const { targetRef } = element;

if (targetRef.href === `#${oldId}`) {
targetRef.href = `#${id}`;
}
}
};

forEach(handlers, (handler, key) => {

if (element[key]) {
handler();
}

});
}

0 comments on commit 10eb3ad

Please sign in to comment.