static Tree createIndex(Tree index, String name, Set<String> propNames) { Tree def = index.addChild(INDEX_DEFINITIONS_NAME).addChild(name); def.setProperty(JcrConstants.JCR_PRIMARYTYPE, INDEX_DEFINITIONS_NODE_TYPE, Type.NAME); def.setProperty(TYPE_PROPERTY_NAME, LuceneIndexConstants.TYPE_LUCENE); def.setProperty(REINDEX_PROPERTY_NAME, true); def.setProperty(FulltextIndexConstants.FULL_TEXT_ENABLED, false); def.setProperty(PropertyStates.createProperty(FulltextIndexConstants.INCLUDE_PROPERTY_NAMES, propNames, Type.STRINGS)); def.setProperty(LuceneIndexConstants.SAVE_DIR_LISTING, true); return index.getChild(INDEX_DEFINITIONS_NAME).getChild(name); }
private static boolean hasRestrictionProperty(Tree aceTree, String name) { if (aceTree.hasProperty(name)) { return true; } Tree restrictionTree = aceTree.getChild(AccessControlConstants.REP_RESTRICTIONS); return restrictionTree.exists() && restrictionTree.hasProperty(name); }
private void copy(Tree source, Tree targetParent, String targetName) { Tree target = targetParent.addChild(targetName); for (PropertyState property : source.getProperties()) { target.setProperty(property); } for (Tree child : source.getChildren()) { copy(child, target, child.getName()); } }
private static Tree getOrCreateChild(Tree tree, String name){ if (tree.hasChild(name)){ return tree.getChild(name); } Tree child = tree.addChild(name); child.setOrderableChildren(true); child.setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, NAME); return child; }
/** * Remove the property */ @Override public boolean remove() { if (parent.hasProperty(name)) { parent.removeProperty(name); return true; } else { return false; } }
private static void checkEqual(Tree tree1, Tree tree2) { assertEquals(tree1.getChildrenCount(Long.MAX_VALUE), tree2.getChildrenCount(Long.MAX_VALUE)); assertEquals(tree1.getPropertyCount(), tree2.getPropertyCount()); for (PropertyState property1 : tree1.getProperties()) { assertEquals(property1, tree2.getProperty(property1.getName())); } for (Tree child1 : tree1.getChildren()) { checkEqual(child1, tree2.getChild(child1.getName())); } } }
@Before public void before() { existingTree = Mockito.mock(Tree.class); when(existingTree.exists()).thenReturn(true); when(existingTree.getName()).thenReturn(PathUtils.ROOT_NAME); when(existingTree.getPath()).thenReturn(PathUtils.ROOT_PATH); when(existingTree.hasProperty(JcrConstants.JCR_PRIMARYTYPE)).thenReturn(true); when(existingTree.getProperty(JcrConstants.JCR_PRIMARYTYPE)).thenReturn(PropertyStates.createProperty(JcrConstants.JCR_PRIMARYTYPE, "rep:root")); }
@Test public void testChangeDeletedNode() throws CommitFailedException { theirRoot.getTree("/x").remove(); ourRoot.getTree("/x").setProperty("p", OUR_VALUE); theirRoot.commit(); ourRoot.commit(); Tree n = ourRoot.getTree("/x"); assertTrue(n.exists()); assertEquals(OUR_VALUE, n.getProperty("p").getValue(STRING)); }
private String getOakName(Tree tree) { PropertyState property = tree.getProperty(JCR_NODETYPENAME); if (property != null) { return property.getValue(Type.NAME); } else { return tree.getName(); } }
static void assertMemberList(@NotNull Tree groupTree, int cntRefTrees, int cnt) { Tree list = groupTree.getChild(REP_MEMBERS_LIST); assertTrue(list.exists()); assertEquals(cntRefTrees, list.getChildrenCount(5)); for (Tree c : list.getChildren()) { PropertyState repMembers = c.getProperty(REP_MEMBERS); assertNotNull(repMembers); assertTrue(SIZE_TH == repMembers.count() || cnt == repMembers.count()); } }
@Test public void testVersionableWithUnsupportedType() throws Exception { Tree versionable = root.getTree("/content"); Tree vh = checkNotNull(versionManager.getVersionHistory(versionable)); Tree frozen = vh.getChild("1.0").getChild(JCR_FROZENNODE).getChild("a").getChild("b").getChild("c"); Tree invalidFrozen = frozen.addChild(REP_CUG_POLICY); invalidFrozen.setProperty(JCR_PRIMARYTYPE, NT_REP_CUG_POLICY); CugPermissionProvider pp = createCugPermissionProvider(ImmutableSet.of(SUPPORTED_PATH, SUPPORTED_PATH2)); TreePermission tp = getTreePermission(root, PathUtils.concat(vh.getPath(), "1.0", JCR_FROZENNODE, "a/b/c"), pp); TreePermission tpForUnsupportedType = pp.getTreePermission(invalidFrozen, TreeType.VERSION, tp); assertEquals(TreePermission.NO_RECOURSE, tpForUnsupportedType); }
private static TreeLocation createNonExistingTreeLocation(@NotNull String path) { String name = Text.getName(path); Tree nonExistingTree = Mockito.mock(Tree.class); when(nonExistingTree.exists()).thenReturn(false); when(nonExistingTree.getName()).thenReturn(name); when(nonExistingTree.getPath()).thenReturn(path); when(nonExistingTree.getChild(name)).thenReturn(nonExistingTree); return TreeLocation.create(nonExistingTree); }
private void enableIndexDefinitionIndex() throws CommitFailedException { Tree nodetype = root.getTree("/oak:index/nodetype"); assertTrue(nodetype.exists()); List<String> nodetypes = Lists.newArrayList(); if (nodetype.hasProperty(DECLARING_NODE_TYPES)){ nodetypes = Lists.newArrayList(nodetype.getProperty(DECLARING_NODE_TYPES).getValue(Type.STRINGS)); } nodetypes.add(INDEX_DEFINITIONS_NODE_TYPE); nodetype.setProperty(DECLARING_NODE_TYPES, nodetypes, Type.NAMES); nodetype.setProperty(IndexConstants.REINDEX_PROPERTY_NAME, true); root.commit(); }
private static Tree createMemberRefTree(@NotNull Tree groupTree, @NotNull Tree membersList) { if (!membersList.exists()) { membersList = groupTree.addChild(UserConstants.REP_MEMBERS_LIST); membersList.setProperty(JcrConstants.JCR_PRIMARYTYPE, UserConstants.NT_REP_MEMBER_REFERENCES_LIST, NAME); } Tree refTree = membersList.addChild(nextRefNodeName(membersList)); refTree.setProperty(JcrConstants.JCR_PRIMARYTYPE, UserConstants.NT_REP_MEMBER_REFERENCES, NAME); return refTree; }
@Test public void testAddExistingNode() throws CommitFailedException { theirRoot.getTree("/").addChild("n").setProperty("p", THEIR_VALUE); ourRoot.getTree("/").addChild("n").setProperty("p", OUR_VALUE); theirRoot.commit(); ourRoot.commit(); Tree n = ourRoot.getTree("/n"); assertTrue(n.exists()); assertEquals(OUR_VALUE, n.getProperty("p").getValue(STRING)); }
@Test public void testRemoveTokenRemovesNode() throws Exception { TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap()); Tree userTree = root.getTree(getUserManager(root).getAuthorizable(userId).getPath()); Tree tokens = userTree.getChild(TOKENS_NODE_NAME); String tokenNodePath = tokens.getChildren().iterator().next().getPath(); info.remove(); assertFalse(root.getTree(tokenNodePath).exists()); }
private static boolean isa(Tree types, String typeName, String superName) { if (typeName.equals(superName)) { return true; } Tree type = types.getChild(typeName); if (!type.exists()) { return false; } PropertyState supertypes = type.getProperty(REP_SUPERTYPES); return supertypes != null && contains(supertypes.getValue(Type.NAMES), superName); }
@Test public void testTokenizeCN() throws Exception { Tree t = root.getTree("/").addChild("containsCN"); Tree one = t.addChild("one"); one.setProperty("t", "美女衬衫"); root.commit(); assertQuery("//*[jcr:contains(., '美女')]", "xpath", ImmutableList.of(one.getPath())); }