@SuppressWarnings("unchecked") public Iterator<String> getRepositories() { return Components.getComponent(RepositoryManager.class).getWorkspaceNames().iterator(); }
/** * Register nodeType file in repository. * * @param repositoryName repository name * @param nodeTypeFile nodeType file */ private void registerNodeTypeFile(String repositoryName, String nodeTypeFile) { Provider provider = repositoryManager.getRepositoryProvider(repositoryName); try { provider.registerNodeTypes(nodeTypeFile); } catch (RepositoryException e) { log.error(e.getMessage(), e); } } }
/** * Get version store session. */ public static String getVersionWorkspaceForNode(RepositoryManager repositoryManager, Node node) throws RepositoryException { String workspaceName = node.getSession().getWorkspace().getName(); String repositoryId = repositoryManager.getRepositoryNameForWorkspace(workspaceName); return repositoryId + "-" + RepositoryConstants.VERSION_STORE; }
/** * Returns the repository definition for a repository or the repository for a given workspace. */ // method copied 1-to-1 from former ContentRepository#getRepositoryMapping // TODO: ditch the terminology mix-up between former repositories and workspaces for good private info.magnolia.repository.definition.RepositoryDefinition getRepositoryMapping(String repositoryOrLogicalWorkspace) { if (!repositoryManager.hasRepository(repositoryOrLogicalWorkspace)) { WorkspaceMappingDefinition mapping = repositoryManager.getWorkspaceMapping(repositoryOrLogicalWorkspace); repositoryOrLogicalWorkspace = mapping != null ? mapping.getRepositoryName() : repositoryOrLogicalWorkspace; } return repositoryManager.getRepositoryDefinition(repositoryOrLogicalWorkspace); }
@Inject public BaseVersionManager(SystemContext systemContext, RepositoryManager repositoryManager, CopyUtil copyUtil) { this.systemContext = systemContext; this.repositoryManager = repositoryManager; this.copyUtil = copyUtil; for (RepositoryDefinition repositoryDefinition : repositoryManager.getRepositoryDefinitions()) { String repositoryId = repositoryDefinition.getName(); String workspaceName = repositoryId + "-" + RepositoryConstants.VERSION_STORE; if (repositoryManager.getWorkspaceMapping(workspaceName) != null) { versionWorkspaces.add(workspaceName); } else { throw new RuntimeException(String.format("Something went wrong, version workspace for repository %s does not exist.", repositoryId)); } } }
/** * Returns the repository for a repository or a workspace. * * @throws IllegalArgumentException if there is no repository or workspace by this name * @deprecated since 4.5 - use {@link info.magnolia.repository.RepositoryManager#getRepository(String)} directly. */ public static Repository getRepository(String repositoryOrLogicalWorkspace) { RepositoryManager repositoryManager = Components.getComponent(RepositoryManager.class); if (!repositoryManager.hasRepository(repositoryOrLogicalWorkspace)) { repositoryOrLogicalWorkspace = getMappedRepositoryName(repositoryOrLogicalWorkspace); } return repositoryManager.getRepository(repositoryOrLogicalWorkspace); }
Collection<String> workspaceNames = repositoryManager.getWorkspaceNames(); BindableRepository br = ((BindableRepository) repositoryManager.getRepository(repositoryManager .getWorkspaceMapping(workspaceName) .getRepositoryName())); repositoryManager.shutdown(); if (true)
@Before public void setUp() throws Exception { MockContext ctx = new MockContext(); MgnlContext.setInstance(ctx); MockSession session = new MockSession(RepositoryConstants.WEBSITE); ctx.addSession(RepositoryConstants.WEBSITE, session); RepositoryManager repositoryManager = mock(RepositoryManager.class); RepositoryDefinition repositoryDefinition = mock(RepositoryDefinition.class); WorkspaceMappingDefinition workspaceMappingDefinition = mock(WorkspaceMappingDefinition.class); EventBus eventBus = mock(EventBus.class); when(repositoryManager.getRepositoryDefinition(RepositoryConstants.WEBSITE)).thenReturn(repositoryDefinition); when(repositoryManager.getWorkspaceMapping(RepositoryConstants.WEBSITE)).thenReturn(workspaceMappingDefinition); when(repositoryManager.getWorkspaceMapping(RepositoryConstants.USERS)).thenReturn(workspaceMappingDefinition); when(repositoryManager.getWorkspaceNames()).thenReturn(Arrays.asList(RepositoryConstants.WEBSITE, RepositoryConstants.USERS)); PowerMockito.mockStatic(ObservationUtil.class); EventListener eventListener = mock(EventListener.class); when(ObservationUtil.instanciateDeferredEventListener(any(EventListener.class), anyInt(), anyInt())).thenReturn(eventListener); ComponentsTestUtil.setInstance(RepositoryManager.class, repositoryManager); ComponentsTestUtil.setImplementation(TypeMapping.class, TypeMappingImpl.class); policy = new FlushAllListeningPolicy(new CacheModule(null, eventBus), repositoryManager); when(cache1.getName()).thenReturn("cache1"); }
/** * Check if repositories has any content, exclude mgnlVersion repository. */ private boolean checkIfInitialized() throws RepositoryException { boolean isClusteredWorkspace = false; boolean isMasterCluster = false; Collection<String> workspaceNames = repositoryManager.getWorkspaceNames(); for (String workspace : workspaceNames) { if (repositoryManager instanceof DefaultRepositoryManager) { isClusteredWorkspace = ((DefaultRepositoryManager) repositoryManager).isClusteredWorkspace(workspace); isMasterCluster = ((DefaultRepositoryManager) repositoryManager).isClusterMaster(); } if (isClusteredWorkspace && !isMasterCluster) { log.info("Skipped clustered workspace '{}' initializing check because it is not cluster master", workspace); continue; } if (!workspace.endsWith(RepositoryConstants.VERSION_STORE) && repositoryManager.checkIfInitialized(workspace)) { return true; } } return false; } }
@Before @Override public void setUp() throws Exception { super.setUp(); RepositoryManager repositoryManager = Components.getComponent(RepositoryManager.class); repositoryManager.loadWorkspace("magnolia", FavoriteStore.WORKSPACE_NAME); repositoryManager.getRepositoryProvider("magnolia").registerNodeTypes(new ByteArrayInputStream(FAVORITE_NODE_TYPES.getBytes())); session = MgnlContext.getJCRSession(FavoriteStore.WORKSPACE_NAME); MockContext ctx = (MockContext) MgnlContext.getInstance(); final User user = mock(User.class); when(user.getName()).thenReturn(TEST_USER); ctx.setUser(user); MgnlContext.setInstance(ctx); favoriteStore = new FavoriteStore(); favoritesManager = new FavoritesManagerImpl(favoriteStore); }
@Test public void testAddMixin() throws Exception { final Node content = getTestNode(); final String workspaceName = content.getSession().getWorkspace().getName(); final String mixDeleted = "mgnl:deleted"; RepositoryManager repositoryManager = Components.getComponent(RepositoryManager.class); String repoName = repositoryManager.getRepositoryNameForWorkspace(workspaceName); final Provider repoProvider = repositoryManager.getRepositoryProvider(repoName); final String mgnlMixDeleted = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<nodeTypes" + " xmlns:rep=\"internal\"" + " xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\"" + " xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\"" + " xmlns:mgnl=\"http://www.magnolia.info/jcr/mgnl\"" + " xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" + "<nodeType name=\"" + mixDeleted + "\" isMixin=\"true\" hasOrderableChildNodes=\"true\" primaryItemName=\"\">" + "<supertypes>" + "<supertype>nt:base</supertype>" + "</supertypes>" + "</nodeType>" + "</nodeTypes>"; try { repoProvider.registerNodeTypes(new ByteArrayInputStream(mgnlMixDeleted.getBytes())); } catch (RepositoryException e) { // ignore, either it's already registered and test will pass, or type can't be registered and test should fail } assertTrue(content.canAddMixin(mixDeleted)); content.addMixin(mixDeleted); }
/** * Returns the name of the repository for a logical workspace name. * * @returns the repository name or if the logical name doesn't exist it is returned * @deprecated since 4.5 - use {@link info.magnolia.repository.RepositoryManager#getWorkspaceMapping(String)}. */ public static String getMappedRepositoryName(String logicalWorkspaceName) { RepositoryManager repositoryManager = Components.getComponent(RepositoryManager.class); WorkspaceMappingDefinition mapping = repositoryManager.getWorkspaceMapping(logicalWorkspaceName); return mapping != null ? mapping.getRepositoryName() : logicalWorkspaceName; }
/** * Returns the repository provider for either a repository or the provider for the repository which contains the workspace. * * @throws IllegalArgumentException if there is no repository or workspace by this name * @deprecated since 4.5 - use {@link info.magnolia.repository.RepositoryManager#getRepositoryProvider(String)} directly. */ public static Provider getRepositoryProvider(String repositoryOrLogicalWorkspace) { RepositoryManager repositoryManager = Components.getComponent(RepositoryManager.class); if (!repositoryManager.hasRepository(repositoryOrLogicalWorkspace)) { repositoryOrLogicalWorkspace = getMappedRepositoryName(repositoryOrLogicalWorkspace); } return repositoryManager.getRepositoryProvider(repositoryOrLogicalWorkspace); }
/** * Checks if a workspace has been initialized. * * @throws RuntimeException if the workspace doesn't exist or has not yet been loaded * @deprecated since 4.5 - use {@link info.magnolia.repository.RepositoryManager#checkIfInitialized(String)} directly. */ public static boolean checkIfInitialized(String logicalWorkspaceName) throws RepositoryException, AccessDeniedException { return Components.getComponent(RepositoryManager.class).checkIfInitialized(logicalWorkspaceName); }
/** * Loads all configured repositories. * * @deprecated since 4.5 - use {@link info.magnolia.repository.RepositoryManager#init()} directly. */ public static void init() { Components.getComponent(RepositoryManager.class).init(); }
/** * Shuts down all repositories (through Provider instances) and clears all mappings. * * @deprecated since 4.5 - use {@link info.magnolia.repository.RepositoryManager#shutdown()} directly. */ public static void shutdown() { Components.getComponent(RepositoryManager.class).shutdown(); }
repositoryManager.loadRepository(rm); } catch (Exception e) { log.error(e.getMessage(), e); repositoryManager.loadWorkspace(repositoryName, workspace); } catch (RepositoryException e) {
/** * Loads a previously not loaded workspace. * * If there's no logical workspace defined with the name it is added, if there's no physical workspace name by this name it is added. * * @deprecated since 4.5 - use {@link info.magnolia.repository.RepositoryManager#loadWorkspace(String, String)} directly. */ public static void loadWorkspace(String repositoryId, String workspaceName) throws RepositoryException { Components.getComponent(RepositoryManager.class).loadWorkspace(repositoryId, workspaceName); }
@Test public void testGetCurrentlyInstalled() throws Exception{ //GIVEN RepositoryManager repoManager = mock(RepositoryManager.class); ComponentsTestUtil.setInstance(RepositoryManager.class, repoManager); String mgnlSystem = "magnolia-mgnlSystem"; String mgnlVersion = "magnolia-mgnlVersion"; Collection<String> workspaceNames = new ArrayList<>(); workspaceNames.add(mgnlSystem); workspaceNames.add(mgnlVersion); when(repoManager.getWorkspaceNames()).thenReturn(workspaceNames); when(repoManager.checkIfInitialized(mgnlSystem)).thenReturn(false); when(repoManager.checkIfInitialized(mgnlVersion)).thenReturn(true); WebappVersionHandler handler = new WebappVersionHandler(repoManager); //WHEN Version installedVersion = handler.getCurrentlyInstalled(mock(InstallContext.class)); //THEN //null is returned when no module is installed assertNull(installedVersion); }
@Override @Before public void setUp() throws Exception { super.setUp(); final RepositoryManager repositoryManager = Components.getComponent(RepositoryManager.class); repositoryManager.loadWorkspace(REPOSITORY, WORKSPACE); repositoryManager.getRepositoryProvider(REPOSITORY).registerNodeTypes(getClass().getResourceAsStream(NODE_TYPES)); messageStore = new MessageStore(); error = createMessage("1", MessageType.ERROR); warning = createMessage("2", MessageType.WARNING); info = createMessage("3", MessageType.INFO); messageStore.saveMessage(USER, error); messageStore.saveMessage(USER, warning); messageStore.saveMessage(USER, info); }