/** * A ConstraintViolationException is thrown if the operation would violate a * node-type or other implementation-specific constraint. */ public void testMoveNodesConstraintViolationException() throws RepositoryException { // if parent node is nt:base then no sub nodes can be created String nodetype = testNodeTypeNoChildren == null ? ntBase : testNodeTypeNoChildren; Node subNodesNotAllowedNode = testRootNode.addNode(nodeName3, nodetype); testRootNode.getSession().save(); try { String dstAbsPath = subNodesNotAllowedNode.getPath() + "/" + node2.getName(); workspace.move(node2.getPath(), dstAbsPath); fail("Moving a node below a node which can not have any sub nodes should throw a ConstraintViolationException."); } catch (ConstraintViolationException e) { // successful } }
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); } }
@Test public void findPrincipalNodes() throws Exception { // GIVEN final String otherTestUser = "Dagobert"; final Node folder = root.addNode("folder", NodeTypes.Folder.NAME); folder.addNode(otherTestUser, NodeTypes.User.NAME); session.save(); // WHEN final NodeIterator iterator = securityManager.findPrincipalNodes(root, NodeTypes.User.NAME); // THEN final List<String> users = new ArrayList<>(); while (iterator.hasNext()) { users.add(iterator.nextNode().getName()); } assertThat(users, hasItem(TEST_USER_NAME)); assertThat(users, hasItem(otherTestUser)); }
/** * OAK-612 */ @Test public void testAddNode() throws Exception { new TestContentLoader().loadTestContent(getAdminSession()); Session session = getAdminSession(); Node test = session.getRootNode().addNode("test", "test:orderableFolder"); assertTrue(test.getPrimaryNodeType().hasOrderableChildNodes()); test.addNode("a"); test.addNode("b"); session.save(); NodeIterator it = test.getNodes(); assertEquals("a", it.nextNode().getName()); assertEquals("b", it.nextNode().getName()); }
/** * Orders the node first among its siblings. */ public static void orderFirst(Node node) throws RepositoryException { Node parent = node.getParent(); NodeIterator siblings = parent.getNodes(); Node firstSibling = siblings.nextNode(); if (!firstSibling.isSame(node)) { parent.orderBefore(node.getName(), firstSibling.getName()); } }
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); } }
private void markMissingInitializeItems(final Session session, final Set<String> itemNames) throws RepositoryException { final Node initializeFolder = session.getNode(INIT_FOLDER_PATH); for (Node item : new NodeIterable(initializeFolder.getNodes())) { if (!itemNames.contains(item.getName()) && !item.getName().equals(HIPPO_LOCK)) { log.info("Marking missing initialize item {}", item.getName()); InitializeItem.markMissing(item); } } session.save(); }
@Override public void afterEach() throws Exception { NodeIterator nodeIterator = session.getRootNode().getNodes(); while (nodeIterator.hasNext()) { Node node = nodeIterator.nextNode(); if (!JcrLexicon.SYSTEM.getString().equals(node.getName())) { node.remove(); } } session.save(); super.afterEach(); }
private Node getLastChild(Node parent, Collection<String> childNames) throws RepositoryException { Node lastMatch = null; NodeIterator nodes = parent.getNodes(); while (nodes.hasNext()) { Node child = nodes.nextNode(); if (childNames.contains(child.getName())) { lastMatch = child; } } return lastMatch; }
/** * A ConstraintViolationException is thrown if the operation would violate a * node-type or other implementation-specific constraint. */ public void testCopyNodesConstraintViolationException() throws RepositoryException { // if parent node is nt:base then no sub nodes can be created String nodetype = testNodeTypeNoChildren == null ? ntBase : testNodeTypeNoChildren; Node subNodesNotAllowedNode = testRootNode.addNode(nodeName3, nodetype); testRootNode.getSession().save(); try { String dstAbsPath = subNodesNotAllowedNode.getPath() + "/" + node2.getName(); workspace.copy(node2.getPath(), dstAbsPath); fail("Copying a node below a node which can not have any sub nodes should throw a ConstraintViolationException."); } catch (ConstraintViolationException e) { // successful } }
/** * 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."); } }
/** * Take action on a sibling node.<br> * In this case, simply display in the install screen the sibling node name and path. */ protected void handleNode(Node node, InstallContext installContext) throws RepositoryException { installContext.warn("Found same name sibling of '" + node.getName() + "' at '" + node.getPath() + "'"); }
@Override public MgnlGroup doExec(Session session) throws RepositoryException { String parentPath = StringUtils.defaultString(path, "/"); Node groupNode = session.getNode(parentPath).addNode(name, NodeTypes.Group.NAME); session.save(); return new MgnlGroup(groupNode.getIdentifier(), groupNode.getName(), Collections.EMPTY_LIST, Collections.EMPTY_LIST); }
@Test public void findPrincipalNodesIgnoresNodesUnderDifferentRoot() throws Exception { // GIVEN final String otherTestUser = "Dagobert"; final Node folder = root.addNode("folder", NodeTypes.Folder.NAME); folder.addNode(otherTestUser, NodeTypes.User.NAME); session.save(); // WHEN final NodeIterator iterator = securityManager.findPrincipalNodes(folder, NodeTypes.User.NAME); // THEN final List<String> users = new ArrayList<>(); while (iterator.hasNext()) { users.add(iterator.nextNode().getName()); } assertThat(users, not(hasItem(TEST_USER_NAME))); assertThat(users, hasItem(otherTestUser)); }
@SuppressWarnings("deprecation") public void testRestoreRemoved() throws RepositoryException { Node parent = versionableNode.getParent(); String oldName = versionableNode.getName(); Version v1 = versionableNode.checkin(); versionableNode.remove(); versionableNode = null; parent.getSession().save(); parent.restore(v1, oldName, true); versionableNode = parent.getNode(oldName); String value = versionableNode.getProperty(propertyName1).getString(); assertEquals("Restoring a node must set the correct property.", propertyValue2, value); }
private void assertNodeOrder(Node node, String[] names) throws RepositoryException { NodeIterator nodes = node.getNodes(); for (String name : names) { Node childNode = nodes.nextNode(); if (!childNode.getName().equals(name)) { fail("Expected [" + name + "] was [" + childNode.getName() + "]"); } } } }