diff --git a/platform/import-export/src/actions/ImportAsJSONAction.js b/platform/import-export/src/actions/ImportAsJSONAction.js index 0a0195002a..ed20af2149 100644 --- a/platform/import-export/src/actions/ImportAsJSONAction.js +++ b/platform/import-export/src/actions/ImportAsJSONAction.js @@ -19,8 +19,7 @@ * this source code distribution or the Licensing information page available * at runtime from the About dialog for additional information. *****************************************************************************/ - -define(['zepto'], function ($) { +define(['zepto', '../../../../src/api/objects/object-utils.js'], function ($, objectUtils) { /** * The ImportAsJSONAction is available from context menus and allows a user @@ -61,7 +60,9 @@ define(['zepto'], function ($) { ImportAsJSONAction.prototype.importObjectTree = function (objTree) { var parent = this.context.domainObject; - var tree = this.generateNewIdentifiers(objTree); + var namespace = parent.useCapability('adapter').identifier.namespace; + + var tree = this.generateNewIdentifiers(objTree, namespace); var rootId = tree.rootId; var rootObj = this.instantiate(tree.openmct[rootId], rootId); var newStyleParent = parent.useCapability('adapter'); @@ -105,7 +106,6 @@ define(['zepto'], function ($) { if (!tree[keystring] || seen.includes(keystring)) { return; } - newObj = this.instantiate(tree[keystring], keystring); newObj.getCapability("location") .setPrimaryLocation(tree[keystring].location); @@ -114,11 +114,17 @@ define(['zepto'], function ($) { } }; - ImportAsJSONAction.prototype.generateNewIdentifiers = function (tree) { + ImportAsJSONAction.prototype.generateNewIdentifiers = function (tree, namespace) { // For each domain object in the file, generate new ID, replace in tree Object.keys(tree.openmct).forEach(function (domainObjectId) { - var newId = this.identifierService.generate(); - tree = this.rewriteId(domainObjectId, newId, tree); + let newId = { + namespace: namespace, + key: this.identifierService.generate() + }; + + let oldId = objectUtils.parseKeyString(domainObjectId); + + tree = this.rewriteId(oldId, newId, tree); }, this); return tree; }; @@ -129,9 +135,21 @@ define(['zepto'], function ($) { * * @private */ - ImportAsJSONAction.prototype.rewriteId = function (oldID, newID, tree) { - tree = JSON.stringify(tree).replace(new RegExp(oldID, 'g'), newID); - return JSON.parse(tree); + ImportAsJSONAction.prototype.rewriteId = function (oldId, newId, tree) { + let newIdKeyString = this.openmct.objects.makeKeyString(newId); + let oldIdKeyString = this.openmct.objects.makeKeyString(oldId); + tree = JSON.stringify(tree).replace(new RegExp(oldIdKeyString, 'g'), newIdKeyString); + + return JSON.parse(tree, (key, value) => { + if (Object.prototype.hasOwnProperty.call(value, 'key') && + Object.prototype.hasOwnProperty.call(value, 'namespace') && + value.key === oldId.key && + value.namespace === oldId.namespace) { + return newId + } else { + return value; + } + }); }; ImportAsJSONAction.prototype.getFormModel = function () { diff --git a/src/plugins/plugins.js b/src/plugins/plugins.js index 288c57f045..a1f9fd747a 100644 --- a/src/plugins/plugins.js +++ b/src/plugins/plugins.js @@ -73,7 +73,8 @@ define([ ) { var bundleMap = { LocalStorage: 'platform/persistence/local', - MyItems: 'platform/features/my-items' + MyItems: 'platform/features/my-items', + CouchDB: 'platform/persistence/couch' }; var plugins = _.mapValues(bundleMap, function (bundleName, pluginName) {