/** * Get the set of workspace names that are known to this source and accessible by this {@link #getContext() context}. * * @return the set of workspace names; never null */ public Set<String> getWorkspaces() { return requests.getWorkspaces().getAvailableWorkspaceNames(); }
/** * Index (or re-index) all of the content in all of the workspaces within the source. This method operates synchronously and * returns when the requested indexing is completed. * * @return this object for convenience in method chaining; never null * @throws RepositorySourceException if there is a problem accessing the content * @throws SearchEngineException if there is a problem updating the indexes * @throws IllegalArgumentException if the context is null, or if depth per read is not positive */ public SearchEngineIndexer indexAllWorkspaces() throws RepositorySourceException, SearchEngineException { // Get the names of all the workspaces ... GetWorkspacesRequest getWorkspaces = new GetWorkspacesRequest(); try { channel.addAndAwait(getWorkspaces); checkRequestForErrors(getWorkspaces); } catch (InterruptedException e) { // Clear the interrupted status of the thread and continue ... Thread.interrupted(); return this; } // Index all of the workspaces ... Path rootPath = context.getValueFactories().getPathFactory().createRootPath(); Location rootLocation = Location.create(rootPath); for (String workspaceName : getWorkspaces.getAvailableWorkspaceNames()) { index(workspaceName, rootLocation); } return this; }
@Test public void shouldMakeAvailablePredefinedWorkspaces() { RepositoryConnection connection = source.getConnection(); GetWorkspacesRequest request = new GetWorkspacesRequest(); connection.execute(context, request); Set<String> workspaces = request.getAvailableWorkspaceNames(); Set<String> graphWorkspaces = new HashSet<String>(Arrays.asList(predefinedWorkspaces)); assertThat(workspaces, is(graphWorkspaces)); // Use each workspace ... for (String workspaceName : predefinedWorkspaces) { ReadNodeRequest readRoot = new ReadNodeRequest(locationFor("/"), workspaceName); connection.execute(context, readRoot); assertThat(readRoot.getActualLocationOfNode().getPath(), is(pathFor("/"))); } }