Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Root folders for older persistence stores #153

Merged
merged 7 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading