mirror of
https://github.com/nasa/openmct.git
synced 2025-06-12 04:08:22 +00:00
[Import JSON] Support namespaces (#2483)
* Retain target namespace in generated identifiers * Also replace identifier objects * Do not duplicate newIds when replacing. Rename ID to Id
This commit is contained in:
committed by
Pegah Sarram
parent
e98d0cc7c5
commit
7c32700b69
@ -19,8 +19,7 @@
|
|||||||
* this source code distribution or the Licensing information page available
|
* this source code distribution or the Licensing information page available
|
||||||
* at runtime from the About dialog for additional information.
|
* at runtime from the About dialog for additional information.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
define(['zepto', '../../../../src/api/objects/object-utils.js'], function ($, objectUtils) {
|
||||||
define(['zepto'], function ($) {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ImportAsJSONAction is available from context menus and allows a user
|
* The ImportAsJSONAction is available from context menus and allows a user
|
||||||
@ -61,7 +60,9 @@ define(['zepto'], function ($) {
|
|||||||
|
|
||||||
ImportAsJSONAction.prototype.importObjectTree = function (objTree) {
|
ImportAsJSONAction.prototype.importObjectTree = function (objTree) {
|
||||||
var parent = this.context.domainObject;
|
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 rootId = tree.rootId;
|
||||||
var rootObj = this.instantiate(tree.openmct[rootId], rootId);
|
var rootObj = this.instantiate(tree.openmct[rootId], rootId);
|
||||||
var newStyleParent = parent.useCapability('adapter');
|
var newStyleParent = parent.useCapability('adapter');
|
||||||
@ -105,7 +106,6 @@ define(['zepto'], function ($) {
|
|||||||
if (!tree[keystring] || seen.includes(keystring)) {
|
if (!tree[keystring] || seen.includes(keystring)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
newObj = this.instantiate(tree[keystring], keystring);
|
newObj = this.instantiate(tree[keystring], keystring);
|
||||||
newObj.getCapability("location")
|
newObj.getCapability("location")
|
||||||
.setPrimaryLocation(tree[keystring].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
|
// For each domain object in the file, generate new ID, replace in tree
|
||||||
Object.keys(tree.openmct).forEach(function (domainObjectId) {
|
Object.keys(tree.openmct).forEach(function (domainObjectId) {
|
||||||
var newId = this.identifierService.generate();
|
let newId = {
|
||||||
tree = this.rewriteId(domainObjectId, newId, tree);
|
namespace: namespace,
|
||||||
|
key: this.identifierService.generate()
|
||||||
|
};
|
||||||
|
|
||||||
|
let oldId = objectUtils.parseKeyString(domainObjectId);
|
||||||
|
|
||||||
|
tree = this.rewriteId(oldId, newId, tree);
|
||||||
}, this);
|
}, this);
|
||||||
return tree;
|
return tree;
|
||||||
};
|
};
|
||||||
@ -129,9 +135,21 @@ define(['zepto'], function ($) {
|
|||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ImportAsJSONAction.prototype.rewriteId = function (oldID, newID, tree) {
|
ImportAsJSONAction.prototype.rewriteId = function (oldId, newId, tree) {
|
||||||
tree = JSON.stringify(tree).replace(new RegExp(oldID, 'g'), newID);
|
let newIdKeyString = this.openmct.objects.makeKeyString(newId);
|
||||||
return JSON.parse(tree);
|
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 () {
|
ImportAsJSONAction.prototype.getFormModel = function () {
|
||||||
|
@ -73,7 +73,8 @@ define([
|
|||||||
) {
|
) {
|
||||||
var bundleMap = {
|
var bundleMap = {
|
||||||
LocalStorage: 'platform/persistence/local',
|
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) {
|
var plugins = _.mapValues(bundleMap, function (bundleName, pluginName) {
|
||||||
|
Reference in New Issue
Block a user