Fixes #2144. Identifiers for objects and links now exported as identifier objects.

Use keystring as map key on import. Also removed redundant step to re-add imported objects to parent composition.
This commit is contained in:
Andrew Henry 2018-08-09 19:53:42 -07:00
parent 9582fb2b06
commit 6a9cf3389d
3 changed files with 21 additions and 10 deletions

View File

@ -133,7 +133,7 @@ define(['lodash'], function (_) {
copyOfChild.location = parentId;
parent.composition[index] = copyOfChild.identifier;
this.tree[newIdString] = copyOfChild;
this.tree[parentId].composition[index] = newIdString;
this.tree[parentId].composition[index] = copyOfChild.identifier;
return copyOfChild;
};

View File

@ -79,16 +79,18 @@ define(['zepto'], function ($) {
var parentModel = parent.getModel();
var newObj;
seen.push(parent.getId());
seen.push(this.getKeyString(parent.getId()));
parentModel.composition.forEach(function (childId, index) {
if (!tree[childId] || seen.includes(childId)) {
var childIdString = this.getKeyString(childId);
if (!tree[childIdString] || seen.includes(childIdString)) {
return;
}
newObj = this.instantiate(tree[childId], childId);
parent.getCapability("composition").add(newObj);
newObj.getCapability("location")
.setPrimaryLocation(tree[childId].location);
newObj = this.instantiate(tree[childIdString], childIdString);
// New object has not been persisted yet so clear persisted
// timestamp from copied model.
delete newObj.getModel().persisted;
newObj.getCapability('persistence').persist();
this.deepInstantiate(newObj, tree, seen);
}, this);
}
@ -103,6 +105,10 @@ define(['zepto'], function ($) {
return tree;
};
ImportAsJSONAction.prototype.getKeyString = function (identifier) {
return this.openmct.objects.makeKeyString(identifier);
};
/**
* Rewrites all instances of a given id in the tree with a newly generated
* replacement to prevent collision.

View File

@ -47,7 +47,12 @@ define(
uniqueId = 0;
newObjects = [];
openmct = {
$injector: jasmine.createSpyObj('$injector', ['get'])
$injector: jasmine.createSpyObj('$injector', ['get']),
objects: {
makeKeyString: function (identifier) {
return identifier.key;
}
}
};
mockInstantiate = jasmine.createSpy('instantiate').and.callFake(
function (model, id) {
@ -154,7 +159,7 @@ define(
body: JSON.stringify({
"openmct": {
"infiniteParent": {
"composition": ["infinteChild"],
"composition": [{key: "infinteChild", namespace: ""}],
"name": "1",
"type": "folder",
"modified": 1503598129176,
@ -162,7 +167,7 @@ define(
"persisted": 1503598129176
},
"infinteChild": {
"composition": ["infiniteParent"],
"composition": [{key: "infinteParent", namespace: ""}],
"name": "2",
"type": "folder",
"modified": 1503598132428,