Skip to content

Commit

Permalink
Create Root folders for older persistence stores (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvigliotta authored Mar 6, 2024
1 parent e22d35b commit b654e8b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 38 deletions.
30 changes: 0 additions & 30 deletions src/persistence/missingUserFolderInterceptor.js

This file was deleted.

45 changes: 45 additions & 0 deletions src/persistence/oldPersistenceFolderInterceptor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {
createModelFromNamespaceDefinition,
interpolateUsername
} from './utils';

export default async function oldPersistenceFolderInterceptor(openmct, namespaces, ROOT_IDENTIFIERS) {
let usersNamespace = namespaces.find((namespace) => namespace.containsNamespaces);
usersNamespace = structuredClone(usersNamespace);

const userTemplate = usersNamespace.childTemplate.key.split('$')[0];
const userKeyCheck = new RegExp(`^${userTemplate}([^:]+)$`);

openmct.objects.addGetInterceptor({
appliesTo: (identifier, domainObject) => {
const isMissing = !domainObject;
const isNotUserRoot = identifier.key !== 'container';
const isUserFolderIdentifier = userKeyCheck.test(identifier.namespace);
const nonUserRoots = ROOT_IDENTIFIERS.filter(rootId => rootId.key !== 'container');
const isRootFolder = nonUserRoots.find(rootId => openmct.objects.areIdsEqual(rootId, identifier)) !== undefined;

// we will create domain objects for empty older persistence user or
// root (ex: shared) folders, not for the user root or other folders
return isMissing && isNotUserRoot && (isUserFolderIdentifier || isRootFolder);
},
invoke: (identifier, object) => {
const isUserNamespace = identifier.key === 'container';

const userId = identifier.namespace.match(userKeyCheck)[1];
let namespaceDefinition;

if (isUserNamespace) {
namespaceDefinition = interpolateUsername(usersNamespace.childTemplate, userId);
namespaceDefinition.location = usersNamespace.id;
} else {
namespaceDefinition = namespaces.find(namespace => namespace.key === identifier.namespace);
}

const model = createModelFromNamespaceDefinition(userId, namespaceDefinition);

openmct.objects.save(model);

return model;
}
});
}
13 changes: 5 additions & 8 deletions src/persistence/plugin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createIdentifierFromNamespaceDefinition, createNamespace } from './utils';
import existingNamespaceUpdateInterceptor from './existingNamespaceUpdateInterceptor';
import MCWSPersistenceProvider from './MCWSPersistenceProvider';
import missingUserFolderInterceptor from './missingUserFolderInterceptor';
import oldPersistenceFolderInterceptor from './oldPersistenceFolderInterceptor';

export default function MCWSPersistenceProviderPlugin(configNamespaces) {
return async function install(openmct) {
Expand All @@ -11,8 +11,6 @@ export default function MCWSPersistenceProviderPlugin(configNamespaces) {
});
openmct.objects.addRoot(() => rootsPromise);
const namespaces = configNamespaces.map(createNamespace);
let usersNamespace = namespaces.find((namespace) => namespace.containsNamespaces);
usersNamespace = structuredClone(usersNamespace);
const mcwsPersistenceProvider = new MCWSPersistenceProvider(openmct, namespaces);

// install the provider for each persistence space,
Expand All @@ -25,11 +23,10 @@ export default function MCWSPersistenceProviderPlugin(configNamespaces) {
const ROOT_IDENTIFIERS = rootNamespaces.map(createIdentifierFromNamespaceDefinition);

// user namespaces are not required
if (usersNamespace) {
const checkOldNamespaces = localStorage.getItem(`r5.0_old_namespace_checked:${usersNamespace.key}`) === null;
existingNamespaceUpdateInterceptor(openmct, usersNamespace, checkOldNamespaces);
missingUserFolderInterceptor(openmct, usersNamespace, ROOT_IDENTIFIERS);
}
let usersNamespace = namespaces.find((namespace) => namespace.containsNamespaces);
const checkOldNamespaces = usersNamespace ? localStorage.getItem(`r5.0_old_namespace_checked:${usersNamespace.key}`) === null : false;
existingNamespaceUpdateInterceptor(openmct, usersNamespace, checkOldNamespaces);
oldPersistenceFolderInterceptor(openmct, namespaces, ROOT_IDENTIFIERS);

rootsResolve(ROOT_IDENTIFIERS);
};
Expand Down

0 comments on commit b654e8b

Please sign in to comment.