@Override public void copy( String srcAbsPath, String destAbsPath ) throws ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException { CheckArg.isNotEmpty(srcAbsPath, "srcAbsPath"); CheckArg.isNotEmpty(destAbsPath, "destAbsPath"); session.checkLive(); this.copy(this.workspaceName, srcAbsPath, destAbsPath); }
@Override public void createWorkspace( String name, String srcWorkspace ) throws AccessDeniedException, UnsupportedRepositoryOperationException, NoSuchWorkspaceException, RepositoryException { validateCrossWorkspaceAction(srcWorkspace); createWorkspace(name); JcrSession newWorkspaceSession = session.spawnSession(name, false); JcrSession srcWorkspaceSession = session.spawnSession(srcWorkspace, true); deepClone(srcWorkspaceSession, srcWorkspaceSession.getRootNode().key(), newWorkspaceSession, newWorkspaceSession.getRootNode().key()); }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowImportContentHandlerWithNullPath() throws Exception { workspace.getImportContentHandler(null, 0); }
protected void validateCrossWorkspaceAction( String srcWorkspace ) throws RepositoryException { CheckArg.isNotEmpty(srcWorkspace, "srcWorkspace"); session.checkLive(); session.checkWorkspacePermission(srcWorkspace, ModeShapePermissions.READ); session.checkWorkspacePermission(getName(), ModeShapePermissions.READ); JcrRepository repository = repository(); if (!repository.hasWorkspace(srcWorkspace)) { throw new NoSuchWorkspaceException(JcrI18n.workspaceNameIsInvalid.text(repository.getName(), srcWorkspace)); } }
@Test @FixFor( "MODE-2109 ") public void shouldOnlyAllowCloningInSomeCases() throws Exception { session.getWorkspace().createWorkspace("other"); workspace.clone(workspace.getName(), "/col1", "/regular", false); fail("Should not allow cloning"); } catch (ConstraintViolationException e) { otherSession.save(); otherSession.getWorkspace().clone(workspace.getName(), "/regular", "/col2/regular", false); NodeIterator nodes = otherSession.getNode("/col2").getNodes(); assertEquals(2, nodes.getSize()); } finally { session.getWorkspace().deleteWorkspace("other");
protected void assertNoRepositoryNamespace( String uri, String prefix ) throws RepositoryException { NamespaceRegistry registry = session.getWorkspace().getNamespaceRegistry(); for (String existingPrefix : registry.getPrefixes()) { assertThat(existingPrefix.equals(prefix), is(false)); } for (String existingUri : registry.getURIs()) { assertThat(existingUri.equals(uri), is(false)); } }
@Test public void shouldAccessCustomNodeTypeManagerViaCasting() throws Exception { NodeTypeManager nodeTypeMgr = session.getWorkspace().getNodeTypeManager(); assertThat(nodeTypeMgr, is(notNullValue())); }
private void executeQueryWithSingleResult( String sql ) throws RepositoryException { Query query = session.getWorkspace().getQueryManager().createQuery(sql, JcrRepository.QueryLanguage.JCR_SQL2); QueryResult result = query.execute(); validateQuery().rowCount(1).hasColumns("jcr:path").validate(query, result); }
protected void lock( Node node, boolean isDeep, boolean isSessionScoped ) throws RepositoryException { session.getWorkspace().getLockManager().lock(node.getPath(), isDeep, isSessionScoped, 1L, "owner"); } }
final String workspaceName() { return workspace.getName(); }
private final JcrSession session() { return workspace.getSession(); }
protected void importIntoWorkspace( String workspaceName, String resourcePath ) throws IOException, RepositoryException { Session session = null; try { session = repository().login(workspaceName); } catch (NoSuchWorkspaceException e) { // Create the workspace ... session().getWorkspace().createWorkspace(workspaceName); // Create a new session ... session = repository().login(workspaceName); } try { importContent(session.getRootNode(), resourcePath, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW); } finally { session.logout(); } } }
JcrSession session = workspace.getSession(); NodeCache cache = session.cache().getWorkspace(); String workspaceName = workspace.getName();
@Override @Before public void beforeEach() throws Exception { super.beforeEach(); Node root = session.getRootNode(); Node a = root.addNode("a"); Node ab = a.addNode("b", "nt:unstructured"); Node abc = ab.addNode("c"); Node b = root.addNode("b"); abc.setProperty("stringProperty", "value"); session.save(); assertThat(b, is(notNullValue())); workspace = session.getWorkspace(); workspaceName = workspace.getName(); otherWorkspaceName = "anotherWs"; workspace.createWorkspace(otherWorkspaceName); otherSession = repository.login(otherWorkspaceName); otherWorkspace = otherSession.getWorkspace(); }
@SuppressWarnings( "deprecation" ) @Test public void shouldBeAbleToExecuteXPathQueryWithNewlyRegisteredNamespace() throws RepositoryException { NamespaceRegistry namespaceRegistry = session.getWorkspace().getNamespaceRegistry(); namespaceRegistry.registerNamespace("newPrefix", "newUri"); try { // We don't have any elements that use this yet, but let's at least verify that it can execute. Query query = session.getWorkspace().getQueryManager() .createQuery("//*[@newPrefix:someColumn = 'someValue']", Query.XPATH); query.execute(); } finally { namespaceRegistry.unregisterNamespace("newPrefix"); } }
@Test public void shouldFindBuiltInNodeTypes() throws Exception { String queryString = "select [jcr:path] from [nt:base] where ischildnode('/jcr:system/jcr:nodeTypes')"; QueryManager queryManager = session.getWorkspace().getQueryManager(); Query query = queryManager.createQuery(queryString, Query.JCR_SQL2); QueryResult result = query.execute(); long numNodetypes = session.getWorkspace().getNodeTypeManager().getAllNodeTypes().getSize(); validateQuery().rowCount(numNodetypes).validate(query, result); }
@Test @FixFor("MODE-2654") public void shouldNotCopyLocks()throws Exception { Node parentNode = session.getRootNode().addNode("node"); Node childNode = parentNode.addNode("child"); childNode.addMixin("mix:lockable"); session.save(); JcrWorkspace workspace = session.getWorkspace(); JcrLockManager lockManager = workspace.getLockManager(); lockManager.lock("/node/child", false, false, Long.MAX_VALUE, null); assertTrue(session.getNode("/node/child").isLocked()); workspace.copy("/node", "/newPath"); assertFalse(session.getNode("/newPath").isLocked()); assertFalse(session.getNode("/newPath/child").isLocked()); lockManager.lock("/newPath/child", false, false, Long.MAX_VALUE, null); assertTrue(session.getNode("/newPath/child").isLocked()); } }
@Test(expected = ConstraintViolationException.class) @FixFor( "MODE-2109" ) public void shouldNotAllowProjections() throws Exception { session.getRootNode().addNode("col", "test:smallCollection"); session.save(); session.getWorkspace().getFederationManager().createProjection("/col", "dummy", "/", "dummy"); }
@Test public void shouldProvideNamespaceRegistry() throws Exception { NamespaceRegistry registry = workspace.getNamespaceRegistry(); assertThat(registry, is(notNullValue())); assertThat(registry.getURI(JcrLexicon.Namespace.PREFIX), is(JcrLexicon.Namespace.URI)); }
protected static void registerNodeTypes( JcrSession session, String pathToClasspathResource ) throws RepositoryException, IOException { URL url = resourceUrl(pathToClasspathResource); session.getWorkspace().getNodeTypeManager().registerNodeTypes(url, true); }