org.apache.jackrabbit.oak.api.Root.move()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(11.2k)|赞(0)|评价(0)|浏览(222)

本文整理了Java中org.apache.jackrabbit.oak.api.Root.move方法的一些代码示例,展示了Root.move的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Root.move方法的具体详情如下:
包路径:org.apache.jackrabbit.oak.api.Root
类名称:Root
方法名:move

Root.move介绍

[英]Move the child located at sourcePath to a child at destPath. Both paths must be absolute and resolve to a child located beneath this root.
This method does nothing and returns false if

  • the tree at sourcePath does not exist or is not accessible,
  • the parent of the tree at destinationPath does not exist or is not accessible,
  • a tree already exists at destinationPath.
    If a tree at destinationPath exists but is not accessible to the editing content session this method succeeds but a subsequent #commit() will detect the violation and fail.
    [中]将位于sourcePath的子级移动到位于destPath的子级。这两条路径都必须是绝对路径,并解析为位于该根下的子路径。
    此方法不执行任何操作,如果
    *sourcePath上的树不存在或不可访问,
    *destinationPath上树的父级不存在或不可访问,
    *destinationPath上已存在一棵树。
    如果destinationPath上存在一棵树,但编辑内容会话无法访问该树,则此方法会成功,但后续的#commit()将检测到该冲突并失败。

代码示例

代码示例来源:origin: org.apache.jackrabbit/oak-remote

@Override
public void apply(Root root) throws RemoteCommitException {
  logger.debug("performing 'move' operation on source={}, target={}", source, target);
  boolean success = root.move(source, target);
  if (success) {
    return;
  }
  throw new RemoteCommitException("unable to move the tree");
}

代码示例来源:origin: apache/jackrabbit-oak

@Override
void apply(Root root) {
  root.move(source, destination);
}

代码示例来源:origin: apache/jackrabbit-oak

@Override
public boolean move(String srcAbsPath, String destAbsPath) {
  return base.move(srcAbsPath, destAbsPath);
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void moveToSelf() throws CommitFailedException {
  Root root = session.getLatestRoot();
  root.getTree("/").addChild("s");
  root.commit();
  assertTrue(root.move("/s", "/s"));
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void moveToDescendant() throws CommitFailedException {
  Root root = session.getLatestRoot();
  root.getTree("/").addChild("s");
  root.commit();
  assertFalse(root.move("/s", "/s/t"));
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void rebaseWithMove() throws CommitFailedException {
  Root root1 = session.getLatestRoot();
  Root root2 = session.getLatestRoot();
  checkEqual(root1.getTree("/"), root2.getTree("/"));
  root2.getTree("/").addChild("one").addChild("two").addChild("three")
      .setProperty("p1", "V1");
  root2.commit();
  root1.move("/x", "/y/x-moved");
  root1.rebase();
  root2.move("/x", "/y/x-moved");
  checkEqual(root1.getTree("/"), (root2.getTree("/")));
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void moveNew() {
  Root root = session.getLatestRoot();
  Tree tree = root.getTree("/");
  Tree t = tree.addChild("new");
  root.move("/new", "/y/new");
  assertEquals("/y/new", t.getPath());
  assertFalse(tree.getChild("new").exists());
}

代码示例来源:origin: apache/jackrabbit-oak

/**
 * Similar to {@code org.apache.jackrabbit.oak.jcr.security.authorization.SessionMoveTest.testMoveAndAddProperty2()}
 * without having a permission-entry cache.
 *
 * @throws Exception
 */
@Test
public void testMoveAndAddProperty2() throws Exception {
  setupPermission("/a/b", testPrincipal, true,
      PrivilegeConstants.JCR_REMOVE_NODE,
      PrivilegeConstants.JCR_REMOVE_CHILD_NODES,
      PrivilegeConstants.REP_ADD_PROPERTIES);
  setupPermission("/a/bb", testPrincipal, true,
      PrivilegeConstants.JCR_ADD_CHILD_NODES,
      PrivilegeConstants.JCR_NODE_TYPE_MANAGEMENT);
  String siblingDestPath = "/a/bb/destination";
  Root testRoot = getTestRoot();
  testRoot.move("/a/b/c", siblingDestPath);
  Tree destTree = testRoot.getTree(siblingDestPath);
  destTree.setProperty("newProp", "val");
  testRoot.commit();
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void testMoveToUnsupportedPath() throws Exception {
  createCug(root, SUPPORTED_PATH3, EveryonePrincipal.NAME);
  Tree newTree = TreeUtil.addChild(root.getTree(SUPPORTED_PATH3), "child", NT_OAK_UNSTRUCTURED);
  String path = newTree.getPath();
  createCug(path, getTestGroupPrincipal());
  root.commit();
  String destPath = PathUtils.concat(UNSUPPORTED_PATH, "moved");
  root.move(path, destPath);
  root.commit();
  assertNestedCugs(root, getRootProvider(), SUPPORTED_PATH3, true);
  assertNestedCugs(root, getRootProvider(), ROOT_PATH, false, SUPPORTED_PATH3, destPath);
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void testMoveToSupportedPath() throws Exception {
  createCug(root, SUPPORTED_PATH3, EveryonePrincipal.NAME);
  Tree newTree = TreeUtil.addChild(root.getTree(SUPPORTED_PATH3), "child", NT_OAK_UNSTRUCTURED);
  String path = newTree.getPath();
  createCug(path, getTestGroupPrincipal());
  root.commit();
  String destPath = PathUtils.concat(SUPPORTED_PATH, "moved");
  root.move(path, destPath);
  root.commit();
  assertNestedCugs(root, getRootProvider(), SUPPORTED_PATH3, true);
  assertNestedCugs(root, getRootProvider(), ROOT_PATH, false, SUPPORTED_PATH3, destPath);
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void oak962() throws CommitFailedException {
  Root root = session.getLatestRoot();
  Tree r = root.getTree("/").addChild("root");
  r.addChild("N3");
  r.addChild("N6");
  r.getChild("N6").addChild("N7");
  root.commit();
  root.move("/root/N6/N7", "/root/N3/N12");
  r.getChild("N3").getChild("N12").remove();
  r.getChild("N6").remove();
  root.commit();
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void moveExistingParent() throws CommitFailedException {
  Root root = session.getLatestRoot();
  root.getTree("/").addChild("parent").addChild("new");
  root.commit();
  Tree parent = root.getTree("/parent");
  Tree n = root.getTree("/parent/new");
  root.move("/parent", "/moved");
  assertEquals(Status.NEW, parent.getStatus());
  assertEquals(Status.NEW, n.getStatus());
  assertEquals("/moved", parent.getPath());
  assertEquals("/moved/new", n.getPath());
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void rename() throws CommitFailedException {
  Root root = session.getLatestRoot();
  Tree tree = root.getTree("/");
  Tree x = tree.getChild("x");
  assertTrue(x.exists());
  root.move("/x", "/xx");
  assertFalse(tree.hasChild("x"));
  assertTrue(tree.hasChild("xx"));
  assertEquals("/xx", x.getPath());
  
  root.commit();
  assertFalse(tree.hasChild("x"));
  assertTrue(tree.hasChild("xx"));
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
  public void testMoveToNested() throws Exception {
    createCug(root, SUPPORTED_PATH2, EveryonePrincipal.NAME);
    createCug(root, SUPPORTED_PATH3, EveryonePrincipal.NAME);

    Tree newTree = TreeUtil.addChild(root.getTree(SUPPORTED_PATH3), "child", NT_OAK_UNSTRUCTURED);
    String path = newTree.getPath();
    createCug(path, getTestGroupPrincipal());
    root.commit();

    String destPath = PathUtils.concat(SUPPORTED_PATH2, "moved");
    root.move(path, destPath);
    root.commit();

    assertNestedCugs(root, getRootProvider(), ROOT_PATH, false, SUPPORTED_PATH3, SUPPORTED_PATH2);
    assertNestedCugs(root, getRootProvider(), SUPPORTED_PATH3, true);
    assertNestedCugs(root, getRootProvider(), SUPPORTED_PATH2, true, destPath);
  }
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
  public void moveOrderableNodes() throws Exception {
    ContentSession s = repository.login(null, null);
    try {
      Root r = s.getLatestRoot();
      Tree t = r.getTree("/");
      Tree c = t.addChild("c");
      c.addChild("node1").orderBefore(null);
      c.addChild("node2");
      t.addChild("node3");
      r.commit();

      r.move("/node3", "/c/node3");
      assertSequence(c.getChildren(), "node1", "node2", "node3");
      r.commit();
      assertSequence(c.getChildren(), "node1", "node2", "node3");
    } finally {
      s.close();
    }
  }
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void moveRemoveAdd() {
  Root root = session.getLatestRoot();
  Tree x = root.getTree("/x");
  Tree z = root.getTree("/z");
  z.setProperty("p", "1");
  root.move("/z", "/x/z");
  root.getTree("/x/z").remove();
  assertFalse(z.exists());
  x.addChild("z");
  assertEquals(Status.NEW, z.getStatus());
  x.getChild("z").setProperty("p", "2");
  PropertyState p = z.getProperty("p");
  assertNotNull(p);
  assertEquals("2", p.getValue(Type.STRING));
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void testGetTokenInfoFromInvalidLocation4() throws Exception {
  TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
  Tree tokenTree = getTokenTree(info);
  assertNotNull(tokenProvider.getTokenInfo(info.getToken()));
  TokenInfo info2 = null;
  try {
    Tree adminTree = root.getTree(getUserManager(root).getAuthorizable(adminSession.getAuthInfo().getUserID()).getPath());
    NodeUtil node = new NodeUtil(adminTree).getOrAddChild(TOKENS_NODE_NAME, JcrConstants.NT_UNSTRUCTURED);
    assertTrue(root.move(tokenTree.getPath(), node.getTree().getPath() + '/' + tokenTree.getName()));
    info2 = tokenProvider.getTokenInfo(info.getToken());
    assertNotNull(info2);
    assertFalse(info2.matches(new TokenCredentials(info.getToken())));
  } finally {
    root.refresh();
  }
}

代码示例来源:origin: apache/jackrabbit-oak

/**
 * Regression test for OAK-208
 */
@Test
public void removeMoved() throws CommitFailedException {
  Root root = session.getLatestRoot();
  Tree r = root.getTree("/");
  r.addChild("a");
  r.addChild("b");
  root.move("/a", "/b/c");
  assertFalse(r.hasChild("a"));
  assertTrue(r.hasChild("b"));
  r.getChild("b").remove();
  assertFalse(r.hasChild("a"));
  assertFalse(r.hasChild("b"));
  root.commit();
  assertFalse(r.hasChild("a"));
  assertFalse(r.hasChild("b"));
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
  public void testPreserveHistoryAfterMovingVersionable() throws RepositoryException, CommitFailedException {
    NodeUtil node = new NodeUtil(root.getTree("/"));
    NodeUtil testVersionable = node.addChild("testVersionable", NodeTypeConstants.NT_OAK_UNSTRUCTURED);
    TreeUtil.addMixin(testVersionable.getTree(), JcrConstants.MIX_VERSIONABLE, root.getTree(NodeTypeConstants.NODE_TYPES_PATH), null);
    root.commit();

    Tree history = versionManager.getVersionHistory(testVersionable.getTree());
    assertTrue(history.exists());
    String historyUuid = history.getProperty(JCR_UUID).getValue(Type.STRING);

    assertTrue(root.move("/testVersionable", "/testVersionable2"));
    root.commit();

    history = versionManager.getVersionHistory(root.getTree("/testVersionable2"));
    assertTrue(history.exists());
    assertEquals(historyUuid, history.getProperty(JCR_UUID).getValue(Type.STRING));
  }
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void move() throws CommitFailedException {
  Root root = session.getLatestRoot();
  Tree tree = root.getTree("/");
  Tree y = tree.getChild("y");
  Tree x = tree.getChild("x");
  assertTrue(x.exists());
  assertFalse(root.hasPendingChanges());
  root.move("/x", "/y/xx");
  assertTrue(root.hasPendingChanges());
  assertFalse(tree.hasChild("x"));
  assertTrue(y.hasChild("xx"));
  assertEquals("/y/xx", x.getPath());
  root.commit();
  assertFalse(root.hasPendingChanges());
  assertFalse(tree.hasChild("x"));
  assertTrue(tree.hasChild("y"));
  assertTrue(tree.getChild("y").hasChild("xx"));
}

相关文章