@Override public void move( String srcAbsPath, String destAbsPath ) throws ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException { session.checkLive(); CheckArg.isNotEmpty(srcAbsPath, "srcAbsPath"); CheckArg.isNotEmpty(destAbsPath, "destAbsPath"); // Create a new JCR session, perform the move, and then save the session ... JcrSession moveSession = this.session.spawnSession(false); moveSession.move(srcAbsPath, destAbsPath); moveSession.save(); }
@Override public void move( String srcAbsPath, String destAbsPath ) throws ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException { session.checkLive(); CheckArg.isNotEmpty(srcAbsPath, "srcAbsPath"); CheckArg.isNotEmpty(destAbsPath, "destAbsPath"); // Create a new JCR session, perform the move, and then save the session ... JcrSession moveSession = this.session.spawnSession(false); moveSession.move(srcAbsPath, destAbsPath); moveSession.save(); }
private void moveDocument(String nodeName) throws Exception { Node section = session.getRootNode().addNode(nodeName); section.setProperty("name", nodeName); section.addNode("temppath"); session.save(); String srcAbsPath = "/" + nodeName + "/temppath"; String destAbsPath = "/" + nodeName + "/20130104"; session.move(srcAbsPath, destAbsPath); session.save(); NodeIterator nitr = section.getNodes(); if (print) { System.err.println("Child Nodes of " + nodeName + " are:"); while (nitr.hasNext()) { Node n = nitr.nextNode(); System.err.println(" Node: " + n.getName()); } } } }
@Override public String call() throws Exception { JcrSession session = repository.login(); final Node item = session.getNodeByIdentifier(sourceId); String destAbsPath = destinationPath + "/" + item.getName(); String sourceAbsPath = item.getPath(); try { if (print) { System.out.println(Thread.currentThread().getName() + String.format(" Moving node from '%s' to '%s'", sourceAbsPath, destAbsPath)); } session.move(item.getPath(), destAbsPath); session.save(); session.save(); return item.getIdentifier(); } catch (Exception e) { if (print) { System.out.println(Thread.currentThread().getName() + String.format(" Exception moving node from '%s' to '%s'", sourceAbsPath, destAbsPath)); } throw e; } finally { session.logout(); } } }
@Test @FixFor( "MODE-1978" ) public void shouldAllowRemovingArtifact() throws Exception { // Register the node types ... registerNodeTypes("cnd/sramp.cnd"); UUID uuid = UUID.randomUUID(); Node sramp = session.getRootNode().addNode("sramp"); Node artifacts = sramp.addNode("artifacts"); Node trash = sramp.addNode("trash"); session.save(); Node artifact = artifacts.addNode(uuid.toString()); artifact.addMixin("sramp:xsdDocument"); artifact.setProperty("sramp:uuid", uuid.toString()); Node artifactChild = artifact.addNode("child"); artifactChild.addMixin("sramp:elementDeclaration"); artifactChild.setProperty("sramp:uuid", UUID.randomUUID().toString()); session.save(); // Now "remove" it by removing the doc type mixins, adding the "deleted" mixin, and moving it to a different area ... artifact.removeMixin("sramp:xsdDocument"); artifact.addMixin("sramp:deletedArtifact"); artifactChild.removeMixin("sramp:elementDeclaration"); artifactChild.addMixin("sramp:deletedArtifact"); session.move(artifact.getPath(), trash.getPath()); session.save(); }
@Test @FixFor( "MODE-1977" ) public void shouldAllowMoveIfSourceIsNotFederatedAndTargetIsNotFederated() throws Exception { federationManager.createProjection("/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "fed1"); ((Node)session.getRootNode()).addNode("testRoot2").addNode("a"); session.save(); session.move("/testRoot2", "/testRoot"); session.save(); assertNodeFound("/testRoot[1]/fed1"); assertNodeFound("/testRoot[2]/a"); }
@Test @FixFor( "MODE-2104" ) public void shouldRestoreMovedNode() throws Exception { registerNodeTypes("cnd/jj.cnd"); Node parent = session.getRootNode().addNode("parent", "jj:page"); parent.addNode("child", "jj:content"); session.save(); versionManager.checkpoint(parent.getPath()); parent.addNode("_context", "jj:context"); // move to a location under a new parent session.move("/parent/child", "/parent/_context/child"); session.save(); // restore versionManager.restore(parent.getPath(), "1.0", true); //the default OPV is COPY, so we expect the restore to have removed _context assertNoNode("/parent/_context"); assertNode("/parent/child"); }
@Test @FixFor( "MODE-1977" ) public void shouldNotAllowMoveIfSourceIsFederatedAndTargetIsNot() throws Exception { federationManager.createProjection("/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "fed1"); ((Node)session.getRootNode()).addNode("testRoot2"); session.save(); try { session.move("/testRoot", "/testRoot2"); fail("Should not allow move is source is federated is target is not."); } catch (RepositoryException e) { // expected if (print) { e.printStackTrace(); } } try { session.move("/testRoot/fed1", "/testRoot2"); fail("Should not allow move is source is federated is target is not."); } catch (RepositoryException e) { // expected if (print) { e.printStackTrace(); } } }
@Test @FixFor( "MODE-2112" ) public void shouldRestoreMovedNode2() throws Exception { registerNodeTypes("cnd/jj.cnd"); Node parent = session.getRootNode().addNode("parent", "jj:page"); parent.addNode("_context", "jj:context"); parent.addNode("child", "jj:content"); session.save(); versionManager.checkpoint(parent.getPath()); // move to a location under a new parent session.move("/parent/child", "/parent/_context/child"); session.save(); // restore versionManager.restore(parent.getPath(), "1.0", true); assertNoNode("/parent/_context/child"); assertNode("/parent/child"); }
@Test @FixFor( "MODE-1977" ) public void shouldNotAllowMoveIfSourceOrTargetIsProjection() throws Exception { federationManager.createProjection("/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "fed1"); federationManager.createProjection("/testRoot", SOURCE_NAME, MockConnector.DOC2_LOCATION, "fed2"); try { session.move("/testRoot/fed2/federated3", "/testRoot/fed1"); fail("Should not allow move if target is projection"); } catch (RepositoryException e) { // expected if (print) { e.printStackTrace(); } } try { session.move("/testRoot/fed2", "/testRoot/fed1"); fail("Should not allow move if source is projection"); } catch (RepositoryException e) { // expected if (print) { e.printStackTrace(); } } }
@Test @FixFor( "MODE-1977" ) public void shouldNotAllowMoveIfSourceIsNotFederatedAndTargetIs() throws Exception { federationManager.createProjection("/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "fed1"); ((Node)session.getRootNode()).addNode("testRoot2"); session.save(); try { session.move("/testRoot2", "/testRoot/fed1"); fail("Should not allow move is source is not federated and target is"); } catch (RepositoryException e) { // expected if (print) { e.printStackTrace(); } } }
@Test @FixFor( "MODE-2109 ") public void shouldNotSupportRenamingsButShouldSupportMove() throws Exception { Node col1 = session.getRootNode().addNode("col1", "test:smallCollection"); session.getRootNode().addNode("col2", "test:smallCollection"); col1.addNode("child1"); col1.addNode("child2"); session.save(); try { // reject renamings session.move("/col1/child1", "/col1/child3"); fail("Renamings should not be supported for large collections"); } catch (ConstraintViolationException e) { // expected } // but allow a normal move session.move("/col1/child1", "/col2/child1"); session.save(); NodeIterator nodes = session.getNode("/col1").getNodes(); assertEquals(1, nodes.getSize()); assertEquals("/col1/child2", nodes.nextNode().getPath()); nodes = session.getNode("/col2").getNodes(); assertEquals(1, nodes.getSize()); assertEquals("/col2/child1", nodes.nextNode().getPath()); }
@Test @FixFor( "MODE-1977" ) public void shouldNotAllowMoveIfSourceAndTargetBelongToDifferentSources() throws Exception { federationManager.createProjection("/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "fed1"); federationManager.createProjection("/testRoot", "mock-source-non-queryable", MockConnector.DOC2_LOCATION, "fed2"); try { session.move("/testRoot/fed1", "/testRoot/fed2"); fail("Should not allow move if source and target don't belong to the same source"); } catch (RepositoryException e) { // expected if (print) { e.printStackTrace(); } } }
@Test @FixFor( "MODE-2112" ) public void shouldRestoreMovedNode3() throws Exception { registerNodeTypes("cnd/jj.cnd"); Node parent = session.getRootNode().addNode("parent", "jj:page"); parent.addNode("child1", "jj:content"); parent.addNode("_context", "jj:context"); parent.addNode("child2", "jj:content"); session.save(); versionManager.checkpoint(parent.getPath()); // move to a location under a new parent session.move("/parent/child1", "/parent/_context/child1"); session.save(); // restore versionManager.restore(parent.getPath(), "1.0", true); assertNoNode("/parent/_context/child1"); assertNoNode("/parent/_context/child2"); assertNode("/parent/child1"); assertNode("/parent/child2"); assertNode("/parent/_context"); }
private void moveSNSWhileCachingPaths( String srcId, String destId, String destNodeName ) throws Exception { Node targetNode = session.getNodeByIdentifier(destId); String targetNodePath = targetNode.getPath(); targetNode = session.getNode(targetNodePath); Node sourceNode = session.getNodeByIdentifier(srcId); String sourceNodePath = sourceNode.getPath(); sourceNode = session.getNode(sourceNodePath); Node sourceParent = sourceNode.getParent(); // the next calls will load all the children (sns) and store them in the ws cache loadChildrenByPaths(session, sourceParent); loadChildrenByPaths(session, targetNode); session.move(sourceNodePath, targetNodePath + "/" + destNodeName); session.save(); // this will expose the problem of the cached paths loadChildrenByPaths(session, sourceParent); loadChildrenByPaths(session, targetNode); }
@Test @FixFor( "MODE-2206" ) public void shouldMoveOverNodesRemovedInTheSameSession() throws Exception { try { // add 2 nodes under a parent that doesn't allow SNS final Node root = session.getRootNode(); final Node parent = root.addNode("parent", "nt:folder"); parent.addNode("name1", "nt:folder"); parent.addNode("name2", "nt:folder"); session.save(); // overwrite 2 with 1 session.removeItem("/parent/name2"); assertFalse("Added node 2 doest not exist after remove", session.nodeExists("/parent/name2")); assertTrue("Added node 1 still exists", session.nodeExists("/parent/name1")); session.move("/parent/name1", "/parent/name2"); session.save(); assertTrue("Added node 2 doest not exist after move", session.nodeExists("/parent/name2")); assertFalse("Added node 1 still exists", session.nodeExists("/parent/name1")); } finally { session.logout(); } }
@Test @FixFor( "MODE-1977" ) public void shouldAllowMoveWithSameSource() throws Exception { federationManager.createProjection("/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "fed1"); ((Node)session.getNode("/testRoot/fed1")).addNode("federated1"); session.save(); assertNodeFound("/testRoot/fed1/federated1"); federationManager.createProjection("/testRoot", SOURCE_NAME, MockConnector.DOC2_LOCATION, "fed2"); assertNodeFound("/testRoot/fed2/federated3"); session.move("/testRoot/fed1/federated1", "/testRoot/fed2/federated3"); session.save(); assertNodeFound("/testRoot/fed2/federated3[1]"); assertNodeFound("/testRoot/fed2/federated3[2]"); assertNodeNotFound("/testRoot/fed1/federated1"); }
@Test public void shouldMoveToNewName() throws Exception { initializeData(); session.move("/a/b/c", "/a/b/d"); session.getRootNode().getNode("a").getNode("b").getNode("d"); try { session.getRootNode().getNode("a").getNode("b").getNode("c"); fail("Node still exists at /a/b/c after move"); } catch (PathNotFoundException e) { // Expected } }
@Test @FixFor( "MODE-1799" ) public void shouldMoveNodesUnderRoot() throws Exception { initializeData(); session.getRootNode().addNode("d"); session.save(); session.move("/a", "/d"); session.save(); assertNotNull(session.getNode("/d")); assertNotNull(session.getNode("/d/b")); assertNotNull(session.getNode("/d/b/c")); }
/** * Verify that it is possible to move a (proxy) node in a shared set. * * @throws RepositoryException */ @Test public void shouldAllowingMovingSharedNode() throws RepositoryException { String originalPath = "/Cars/Utility"; String sharedPath = "/NewArea/SharedUtility"; // Make the original a shareable node ... Node original = makeShareable(originalPath); session.save(); // Now create the share ... Node sharedNode = makeShare(originalPath, sharedPath); assertSharedSetIncludes(original, originalPath, sharedPath); assertSharedSetIncludes(sharedNode, originalPath, sharedPath); // Now move the new shared node ... String newPath = "/NewSecondArea/SharedUtility"; // no index session.move(sharedPath, newPath); session.save(); // Verify ... Node newSharedNode = session.getNode(newPath); assertSharedSetIs(original, originalPath, newPath); assertSharedSetIs(newSharedNode, originalPath, newPath); verifyShare(original, newSharedNode); }