@Test public void testRemoveMembers() throws Exception { Set<String> members = new HashSet<String>(); String[] users = new String[NUM_USERS]; Group grp = createGroup(); for (int i = 0; i < NUM_USERS; i++) { User usr = createUser(); grp.addMember(usr); members.add(usr.getID()); users[i] = usr.getID(); } root.commit(); for (int i = 0; i < SIZE_TH; i++) { Authorizable auth = userMgr.getAuthorizable(users[i]); members.remove(users[i]); grp.removeMember(auth); } root.commit(); assertMembers(grp, members); Tree tree = getTree(grp); assertNull( "rep:members property not exist", tree.getProperty(REP_MEMBERS) ); for (int i = 0; i < SIZE_TH / 2; i++) { Authorizable auth = userMgr.getAuthorizable(users[i]); members.add(users[i]); grp.addMember(auth); } root.commit(); assertEquals( "rep:members property must have correct number of references", SIZE_TH / 2, tree.getProperty(REP_MEMBERS).count() ); assertMembers(grp, members); for (int i = 2 * SIZE_TH; i < (3 * SIZE_TH); i++) { Authorizable auth = userMgr.getAuthorizable(users[i]); members.remove(users[i]); grp.removeMember(auth); } root.commit(); assertMembers(grp, members); Tree membersList = tree.getChild(REP_MEMBERS_LIST); assertFalse( "the first overflow node must not exist", membersList.getChild("1").exists() ); for (int i = 2 * SIZE_TH; i < (3 * SIZE_TH); i++) { Authorizable auth = userMgr.getAuthorizable(users[i]); members.add(users[i]); grp.addMember(auth); } root.commit(); assertMembers(grp, members); membersList = tree.getChild(REP_MEMBERS_LIST); assertTrue("the first overflow node must not exist", membersList.getChild("1").exists() ); }
@NotNull Set<String> removeMembers(@NotNull Tree groupTree, @NotNull Map<String, String> memberIds) { Tree membersList = groupTree.getChild(UserConstants.REP_MEMBERS_LIST); Iterator<Tree> trees = Iterators.concat( Iterators.singletonIterator(groupTree), membersList.getChildren().iterator() ); while (trees.hasNext() && !memberIds.isEmpty()) { Tree t = trees.next(); PropertyState refs = t.getProperty(UserConstants.REP_MEMBERS); if (refs != null) { PropertyBuilder<String> prop = PropertyBuilder.copy(Type.WEAKREFERENCE, refs); Iterator<Map.Entry<String,String>> it = memberIds.entrySet().iterator(); while (it.hasNext() && !prop.isEmpty()) { String memberContentId = it.next().getKey(); if (prop.hasValue(memberContentId)) { prop.removeValue(memberContentId); it.remove(); } } if (prop.isEmpty()) { if (t == groupTree) { t.removeProperty(UserConstants.REP_MEMBERS); } else { t.remove(); } } else { t.setProperty(prop.getPropertyState()); } } } return Sets.newHashSet(memberIds.values()); }
MembershipWriter { @NotNull Set<String> removeMembers(@NotNull Tree groupTree, @NotNull Map<String, String> memberIds) { Tree membersList = groupTree.getChild(UserConstants.REP_MEMBERS_LIST); Iterator<Tree> trees = Iterators.concat( Iterators.singletonIterator(groupTree), membersList.getChildren().iterator() ); while (trees.hasNext() && !memberIds.isEmpty()) { Tree t = trees.next(); PropertyState refs = t.getProperty(UserConstants.REP_MEMBERS); if (refs != null) { PropertyBuilder<String> prop = PropertyBuilder.copy(Type.WEAKREFERENCE, refs); Iterator<Map.Entry<String,String>> it = memberIds.entrySet().iterator(); while (it.hasNext() && !prop.isEmpty()) { String memberContentId = it.next().getKey(); if (prop.hasValue(memberContentId)) { prop.removeValue(memberContentId); it.remove(); } } if (prop.isEmpty()) { if (t == groupTree) { t.removeProperty(UserConstants.REP_MEMBERS); } else { t.remove(); } } else { t.setProperty(prop.getPropertyState()); } } } return Sets.newHashSet(memberIds.values()); } }
MembershipWriter { @NotNull Set<String> removeMembers(@NotNull Tree groupTree, @NotNull Map<String, String> memberIds) { Tree membersList = groupTree.getChild(UserConstants.REP_MEMBERS_LIST); Iterator<Tree> trees = Iterators.concat( Iterators.singletonIterator(groupTree), membersList.getChildren().iterator() ); while (trees.hasNext() && !memberIds.isEmpty()) { Tree t = trees.next(); PropertyState refs = t.getProperty(UserConstants.REP_MEMBERS); if (refs != null) { PropertyBuilder<String> prop = PropertyBuilder.copy(Type.WEAKREFERENCE, refs); Iterator<Map.Entry<String,String>> it = memberIds.entrySet().iterator(); while (it.hasNext() && !prop.isEmpty()) { String memberContentId = it.next().getKey(); if (prop.hasValue(memberContentId)) { prop.removeValue(memberContentId); it.remove(); } } if (prop.isEmpty()) { if (t == groupTree) { t.removeProperty(UserConstants.REP_MEMBERS); } else { t.remove(); } } else { t.setProperty(prop.getPropertyState()); } } } return Sets.newHashSet(memberIds.values()); }  }
MembershipWriter { @NotNull Set<String> removeMembers(@NotNull Tree groupTree, @NotNull Map<String, String> memberIds) { Tree membersList = groupTree.getChild(UserConstants.REP_MEMBERS_LIST); Iterator<Tree> trees = Iterators.concat( Iterators.singletonIterator(groupTree), membersList.getChildren().iterator() ); while (trees.hasNext() && !memberIds.isEmpty()) { Tree t = trees.next(); PropertyState refs = t.getProperty(UserConstants.REP_MEMBERS); if (refs != null) { PropertyBuilder<String> prop = PropertyBuilder.copy(Type.WEAKREFERENCE, refs); Iterator<Map.Entry<String,String>> it = memberIds.entrySet().iterator(); while (it.hasNext() && !prop.isEmpty()) { String memberContentId = it.next().getKey(); if (prop.hasValue(memberContentId)) { prop.removeValue(memberContentId); it.remove(); } } if (prop.isEmpty()) { if (t == groupTree) { t.removeProperty(UserConstants.REP_MEMBERS); } else { t.remove(); } } else { t.setProperty(prop.getPropertyState()); } } } return Sets.newHashSet(memberIds.values()); }   }
MembershipWriter { @NotNull Set<String> removeMembers(@NotNull Tree groupTree, @NotNull Map<String, String> memberIds) { Tree membersList = groupTree.getChild(UserConstants.REP_MEMBERS_LIST); Iterator<Tree> trees = Iterators.concat( Iterators.singletonIterator(groupTree), membersList.getChildren().iterator() ); while (trees.hasNext() && !memberIds.isEmpty()) { Tree t = trees.next(); PropertyState refs = t.getProperty(UserConstants.REP_MEMBERS); if (refs != null) { PropertyBuilder<String> prop = PropertyBuilder.copy(Type.WEAKREFERENCE, refs); Iterator<Map.Entry<String,String>> it = memberIds.entrySet().iterator(); while (it.hasNext() && !prop.isEmpty()) { String memberContentId = it.next().getKey(); if (prop.hasValue(memberContentId)) { prop.removeValue(memberContentId); it.remove(); } } if (prop.isEmpty()) { if (t == groupTree) { t.removeProperty(UserConstants.REP_MEMBERS); } else { t.remove(); } } else { t.setProperty(prop.getPropertyState()); } } } return Sets.newHashSet(memberIds.values()); }   static final int DEFAULT_MEMBERSHIP_THRESHOLD; }