Refine search
public void testMoveNode() throws Exception { Node n = (Node) readOnlySession.getItem(testNodePath); String destPath = testRootNode.getPath() + "/" + nodeName2; try { readOnlySession.move(n.getPath(), destPath); readOnlySession.save(); fail("A read only session must not be allowed to move a node"); } catch (AccessDeniedException e) { // expected log.debug(e.getMessage()); } }
private void moveToHistory(final Node node) { try { // the updater node was modified externally by the executor session.refresh(false); final String srcPath = node.getPath(); final Node history = session.getNode(UPDATE_HISTORY_PATH); String name = node.getName(); int count = 2; while (history.hasNode(name)) { name = node.getName() + "-" + count++; } final String destPath = UPDATE_HISTORY_PATH + "/" + name; session.move(srcPath, destPath); session.save(); } catch (RepositoryException e) { log.error("Failed to remove updater from queue", e); } }
/** * Tries to move a node using {@link javax.jcr.Session#move(String, String)} * where the destination parent is checked in. This should throw an {@link * javax.jcr.version.VersionException}. */ public void testSessionMoveDestCheckedInVersionException() throws RepositoryException { // make sure versionable node is checked in versionableNode.checkin(); try { // try to move the sub node this should throw an VersionException either instantly or upon save() superuser.move(nonVersionableNode.getPath(), versionableNode.getPath() + "/" + nodeName1); superuser.save(); fail("Moving a node using Session.save() where destination parent " + "node is versionable and checked in should throw a VersionException!"); } catch (VersionException e) { // ok, works as expected } } }
public static Node moveNode(Node node, Path newPath) { try { Session session = node.getSession(); String path = newPath.toAbsolutePath().toString(); session.move(node.getPath(), path); session.save(); // save required for the move to take effect. return session.getNode(path); } catch (AccessDeniedException e) { log.debug("Access denied", e); throw new AccessControlException(e.getMessage()); } catch (RepositoryException e) { throw new MetadataRepositoryException("Failed to move node to path: " + newPath, e); } }
/** * Test if the removeExisting-flag removes an existing node in case of uuid conflict. */ @SuppressWarnings("deprecation") public void testWorkspaceRestoreWithRemoveExisting() throws NotExecutableException, RepositoryException { // create version for parentNode of childNode superuser.getWorkspace().clone(workspaceName, wVersionableChildNode.getPath(), wVersionableChildNode.getPath(), false); Version parentV = versionableNode.checkin(); // move child node in order to produce the uuid conflict String newChildPath = wVersionableNode2.getPath() + "/" + wVersionableChildNode.getName(); wSuperuser.move(wVersionableChildNode.getPath(), newChildPath); wSuperuser.save(); // restore the parent with removeExisting == true >> moved child node // must be removed. wSuperuser.getWorkspace().restore(new Version[]{parentV}, true); if (wSuperuser.itemExists(newChildPath)) { fail("Workspace.restore(Version[], boolean) with the boolean flag set to true, must remove the existing node in case of Uuid conflict."); } }
/** * {@inheritDoc} */ @Override public void doMoveNode(Node parentNode, Node node, String nodeName, JcrNode jcrNode, Object entity) throws JcrMappingException, RepositoryException { if (parentNode.getPath().equals("/")) { // special case: moving a root node node.getSession().move(node.getPath(), parentNode.getPath() + nodeName); } else { node.getSession().move(node.getPath(), parentNode.getPath() + "/" + nodeName); } } }
/** * Test if the removeExisting-flag removes an existing node in case of uuid conflict. */ public void testWorkspaceRestoreWithRemoveExistingJcr2() throws NotExecutableException, RepositoryException { // create version for parentNode of childNode superuser.getWorkspace().clone(workspaceName, wVersionableChildNode.getPath(), wVersionableChildNode.getPath(), false); Version parentV = versionableNode.getSession().getWorkspace().getVersionManager().checkin(versionableNode.getPath()); // move child node in order to produce the uuid conflict String newChildPath = wVersionableNode2.getPath() + "/" + wVersionableChildNode.getName(); wSuperuser.move(wVersionableChildNode.getPath(), newChildPath); wSuperuser.save(); // restore the parent with removeExisting == true >> moved child node // must be removed. wSuperuser.getWorkspace().getVersionManager().restore(new Version[]{parentV}, true); if (wSuperuser.itemExists(newChildPath)) { fail("Workspace.restore(Version[], boolean) with the boolean flag set to true, must remove the existing node in case of Uuid conflict."); } }
private void moveContainerItems(final Node from, final Node to) throws RepositoryException { Session session = from.getSession(); for (Node fromChild : new NodeIterable(from.getNodes())) { String newName = fromChild.getName(); int counter = 0; while (to.hasNode(newName)) { newName = fromChild.getName() + ++counter; } session.move(fromChild.getPath(), to.getPath() + "/" + newName); } }
public void testRemoveWithMoveFrom() throws Exception { Node d = testRootNode.getNode("A").addNode("D"); superuser.save(); d.remove(); session.move(testRoot + "/A/B", testRoot + "/C/B"); superuser.save(); try { session.save(); } catch (InvalidItemStateException e) { fail("must not throw exception"); } }
public void beforeScanning(Node node) throws RepositoryException { String path = node.getPath(); if (path.startsWith("/node")) { log("Traversing: " + node.getPath()); } if ("/node1".equals(node.getPath())) { String from = "/node2/node3"; String to = "/node0/node3"; log("Moving " + from + " -> " + to); sessionMover.move(from, to); sessionMover.save(); sleepForFile(); } } });
private void migrateBlueprint(final Node blueprintNode) throws RepositoryException { if (!blueprintNode.hasNode("hst:channel")) { getLogger().info("No need to migrate blueprint '{}' because does not have an hst:channel node.", blueprintNode.getPath()); return; } final Node blueprintConfigurationNode; if (blueprintNode.hasNode("hst:configuration")) { blueprintConfigurationNode = blueprintNode.getNode("hst:configuration"); } else { blueprintConfigurationNode = blueprintNode.addNode("hst:configuration", "hst:configuration"); } blueprintNode.getSession().move(blueprintNode.getPath() + "/hst:channel", blueprintConfigurationNode.getPath() + "/hst:channel"); }