From 6a9cf3389d98fd4be6b14a20187c05a3ab6fe8d5 Mon Sep 17 00:00:00 2001 From: Andrew Henry Date: Thu, 9 Aug 2018 19:53:42 -0700 Subject: [PATCH] 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. --- .../src/actions/ExportAsJSONAction.js | 2 +- .../src/actions/ImportAsJSONAction.js | 18 ++++++++++++------ .../test/actions/ImportAsJSONActionSpec.js | 11 ++++++++--- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/platform/import-export/src/actions/ExportAsJSONAction.js b/platform/import-export/src/actions/ExportAsJSONAction.js index 342198adb7..a0b37c054f 100644 --- a/platform/import-export/src/actions/ExportAsJSONAction.js +++ b/platform/import-export/src/actions/ExportAsJSONAction.js @@ -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; }; diff --git a/platform/import-export/src/actions/ImportAsJSONAction.js b/platform/import-export/src/actions/ImportAsJSONAction.js index 233486a965..92634a1b5f 100644 --- a/platform/import-export/src/actions/ImportAsJSONAction.js +++ b/platform/import-export/src/actions/ImportAsJSONAction.js @@ -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. diff --git a/platform/import-export/test/actions/ImportAsJSONActionSpec.js b/platform/import-export/test/actions/ImportAsJSONActionSpec.js index 305ab5cb3d..19e828a0f8 100644 --- a/platform/import-export/test/actions/ImportAsJSONActionSpec.js +++ b/platform/import-export/test/actions/ImportAsJSONActionSpec.js @@ -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,