@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 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); }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowCopyFromNullPathToNullPath() throws Exception { workspace.copy(null, null); }
@Test public void shouldCopyFromPathToAnotherPathInSameWorkspace() throws Exception { workspace.copy("/a/b", "/b/b-copy"); }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowCopyFromOtherWorkspaceWithNullWorkspace() throws Exception { workspace.copy(null, null, null); }
@Test( expected = RepositoryException.class ) @FixFor( "MODE-1972" ) public void shouldNotCopyPartialWorkspaceIntoWorkspaceRoot() throws Exception { otherWorkspace.copy(workspaceName, "/a/b", "/"); }
@Test @FixFor( "MODE-2115" ) public void copiedNodesShouldReplaceAutoCreatedChildren() throws Exception { tools.registerNodeTypes(session, "cnd/autocreated-child-nodes.cnd"); Node parent = session.getRootNode().addNode("parent", "test:autocreatedFolders"); session.save(); long folder1CreatedTs = parent.getNode("folder1").getProperty("jcr:created").getDate().getTimeInMillis(); long folder2CreatedTs = parent.getNode("folder2").getProperty("jcr:created").getDate().getTimeInMillis(); workspace.copy("/parent", "/new_parent"); AbstractJcrNode newParent = session.getNode("/new_parent"); assertEquals(2, newParent.getNodes().getSize()); Node folder1Copy = assertNode("/new_parent/folder1", "nt:folder"); assertEquals(folder1CreatedTs, folder1Copy.getProperty("jcr:created").getDate().getTimeInMillis()); Node folder2Copy = assertNode("/new_parent/folder2", "nt:folder"); assertEquals(folder2CreatedTs, folder2Copy.getProperty("jcr:created").getDate().getTimeInMillis()); }
@Test @FixFor("MODE-2637") public void copyNodeWithEmptyMultiValueProperty() throws Exception { // start a repository with some indexes startRepositoryWithConfigurationFrom("config/repo-config-local-provider-and-nodetype-index.json"); session.getRootNode().addNode("a"); Node node = session.getNode("/a"); node.addMixin("mix:referenceable"); session.save(); node.removeMixin("mix:referenceable"); session.save(); assertTrue(node.hasProperty("jcr:mixinTypes")); assertThat(node.getProperty("jcr:mixinTypes").getValues().length, is(0)); session.getWorkspace().copy(session.getNode("/a").getPath(), "/a2"); session.save(); }
@Test @FixFor( "MODE-2115" ) public void copiedNodesShouldReplaceReferenceableAutoCreatedChildren() throws Exception { tools.registerNodeTypes(session, "cnd/autocreated-child-nodes.cnd"); session.getRootNode().addNode("parent", "test:autocreatedReferenceableChildren"); session.save(); session.getNode("/parent/child1").addNode("child1_1"); session.save(); workspace.copy("/parent", "/new_parent"); AbstractJcrNode newParent = session.getNode("/new_parent"); assertEquals(2, newParent.getNodes().getSize()); // validate that the jcr:uuid is the same as the identifier of the node Node child1 = assertNode("/new_parent/child1", "test:subnodeReferenceable"); assertEquals(child1.getIdentifier(), child1.getProperty("jcr:uuid").getString()); Node child2 = assertNode("/new_parent/child2", "test:subnodeReferenceable"); assertEquals(child2.getIdentifier(), child2.getProperty("jcr:uuid").getString()); assertNode("/new_parent/child1/child1_1"); }
@Test @FixFor( "MODE-1972" ) public void shouldCopyEntireWorkspaces() throws Exception { otherWorkspace.copy(workspaceName, "/", "/"); assertNotNull(otherSession.getNode("/a")); assertNotNull(otherSession.getNode("/a/b")); assertNotNull(otherSession.getNode("/a/b/c")); assertNotNull(otherSession.getNode("/b")); }
@Test @FixFor( "MODE-2114" ) public void copiedReferencesShouldHaveUpdatedUUIDs() throws Exception { tools.registerNodeTypes(session, "cnd/references.cnd"); Node parent = session.getRootNode().addNode("parent"); Node nodeA = parent.addNode("A", "test:node"); Node nodeB = parent.addNode("B", "test:node"); Node nodeC = parent.addNode("C", "test:node"); Node nodeD = parent.addNode("D", "test:node"); nodeA.setProperty("test:strongReference", session.getValueFactory().createValue(nodeB)); nodeA.setProperty("test:weakReference", session.getValueFactory().createValue(nodeC, true)); nodeA.setProperty("test:simpleReference", session.getValueFactory().createSimpleReference(nodeD)); session.save(); workspace.copy("/parent", "/new_parent"); AbstractJcrNode otherA = session.getNode("/new_parent/A"); AbstractJcrNode otherB = session.getNode("/new_parent/B"); AbstractJcrNode otherC = session.getNode("/new_parent/C"); AbstractJcrNode otherD = session.getNode("/new_parent/D"); assertEquals(otherB.getIdentifier(), otherA.getProperty("test:strongReference").getNode().getIdentifier()); assertEquals(otherC.getIdentifier(), otherA.getProperty("test:weakReference").getNode().getIdentifier()); assertEquals(otherD.getIdentifier(), otherA.getProperty("test:simpleReference").getNode().getIdentifier()); }
session.getWorkspace().copy(originalNode.getPath(), "/uploads/copiedNode");
workspace.copy("/col1", "/col3"); fail("Should not allow copying"); } catch (ConstraintViolationException e) { workspace.copy("/regular", "/col1/regular"); NodeIterator nodes = session.getNode("/col1").getNodes(); assertEquals(1, nodes.getSize()); otherSession.getWorkspace().copy(workspace.getName(), "/regular", "/col2/regular"); nodes = otherSession.getNode("/col2").getNodes(); assertEquals(2, nodes.getSize());
@Test @FixFor( "MODE-2457") public void onlyOwningSessionShouldCopyLockedNode() throws Exception { Node node = session.getRootNode().addNode("lockable"); node.addMixin("mix:lockable"); session.save(); JcrLockManager lockManager = session.lockManager(); lockManager.lock("/lockable", true, true, Long.MAX_VALUE, null); // this should succeed because this is the lock owning session session.getWorkspace().copy("/lockable", "/lockable_copy"); assertNotNull(session.getNode("/lockable_copy")); assertTrue("Original node should still be locked", lockManager.isLocked("/lockable")); assertFalse("Copied node should not be locked", lockManager.isLocked("/lockable_copy")); JcrSession session1 = repository().login(); try { session1.getWorkspace().copy("/lockable", "/lockable_copy1"); fail("Copy should not succeed because the session does not own the lock"); } catch (LockException e) { //expected } finally { session1.logout(); lockManager.unlock("/lockable"); } }
@Test @FixFor( "MODE-2012" ) public void copiedUUIDsShouldNotBeTheSame() throws Exception { tools.registerNodeTypes(session, "cnd/references.cnd"); Node nodeA = session.getRootNode().addNode("A", "test:node"); Node nodeB = session.getRootNode().addNode("B", "test:node"); session.save(); otherWorkspace.copy("default", "/", "/"); assertNotEquals(nodeA.getIdentifier(), otherSession.getNode("/A").getIdentifier()); assertNotEquals(nodeB.getIdentifier(), otherSession.getNode("/B").getIdentifier()); }
@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()); } }
session.getWorkspace().copy("/NewArea", "/OtherNewArea"); Node baseVersion3 = findBaseVersion(originalPath); assertNotNull(baseVersion3);
@Test @FixFor( "MODE-2012" ) public void copiedReferencesShouldPointToTargetWorkspace() throws Exception { tools.registerNodeTypes(session, "cnd/references.cnd"); Node nodeA = session.getRootNode().addNode("A", "test:node"); Node nodeB = session.getRootNode().addNode("B", "test:node"); Node nodeC = session.getRootNode().addNode("C", "test:node"); Node nodeD = session.getRootNode().addNode("D", "test:node"); nodeA.setProperty("test:strongReference", session.getValueFactory().createValue(nodeB)); nodeA.setProperty("test:weakReference", session.getValueFactory().createValue(nodeC, true)); nodeA.setProperty("test:simpleReference", session.getValueFactory().createSimpleReference(nodeD)); session.save(); otherWorkspace.copy("default", "/", "/"); nodeD.remove(); nodeC.remove(); nodeB.remove(); nodeA.remove(); session.save(); AbstractJcrNode otherA = otherSession.getNode("/A"); AbstractJcrNode otherB = otherSession.getNode("/B"); AbstractJcrNode otherC = otherSession.getNode("/C"); AbstractJcrNode otherD = otherSession.getNode("/D"); assertEquals(otherB.getIdentifier(), otherA.getProperty("test:strongReference").getNode().getIdentifier()); assertEquals(otherC.getIdentifier(), otherA.getProperty("test:weakReference").getNode().getIdentifier()); assertEquals(otherD.getIdentifier(), otherA.getProperty("test:simpleReference").getNode().getIdentifier()); }
session.getWorkspace().copy("/aclNode", "/aclNodeCopy"); assertEquals(1, accessControlManager.getPolicies("/aclNodeCopy").length); Privilege[] privileges = accessControlManager.getPrivileges("/aclNodeCopy");