test_class.declarator: writer
test_class.modifier: private
test_class.original_string: private MembershipWriter writer;
test_class.type: MembershipWriter
test_class.var_name: writer
test_class.file: oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/MembershipWriterTest.java
test_class.identifier: MembershipWriterTest
test_class.superclass: extends MembershipBaseTest
test_case.body: @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();
  
          // remove the first TH users, this should remove all references from rep:members in the group node and remove
          // the rep:members property
          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);
  
          // also check storage structure
          Tree tree = getTree(grp);
          assertNull(
                  "rep:members property not exist",
                  tree.getProperty(REP_MEMBERS)
          );
  
          // now add TH/2 again.
          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);
  
          // now remove the users 20-30, this should remove the 2nd overflow node
          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()
          );
  
          // now add 10 users and check if the "1" node exists again
          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()
          );
      }
test_case.class_method_signature: MembershipWriterTest.testRemoveMembers()
test_case.full_signature: @Test public void testRemoveMembers()
test_case.identifier: testRemoveMembers
test_case.invocations: createGroup createUser addMember add getID getID commit getAuthorizable remove removeMember commit assertMembers getTree assertNull getProperty getAuthorizable add addMember commit assertEquals count getProperty assertMembers getAuthorizable remove removeMember commit assertMembers getChild assertFalse exists getChild getAuthorizable add addMember commit assertMembers getChild assertTrue exists getChild
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testRemoveMembers()
focal_class.declarator: DEFAULT_MEMBERSHIP_THRESHOLD = 100
focal_class.modifier: public static final
focal_class.original_string: public static final int DEFAULT_MEMBERSHIP_THRESHOLD = 100;
focal_class.type: int
focal_class.var_name: DEFAULT_MEMBERSHIP_THRESHOLD
focal_class.declarator: membershipSizeThreshold = DEFAULT_MEMBERSHIP_THRESHOLD
focal_class.modifier: private
focal_class.original_string: private int membershipSizeThreshold = DEFAULT_MEMBERSHIP_THRESHOLD;
focal_class.type: int
focal_class.var_name: membershipSizeThreshold
focal_class.file: oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/MembershipWriter.java
focal_class.identifier: MembershipWriter
focal_class.class_method_signature: MembershipWriter.setMembershipSizeThreshold(int membershipSizeThreshold)
focal_class.full_signature:  void setMembershipSizeThreshold(int membershipSizeThreshold)
focal_class.identifier: setMembershipSizeThreshold
focal_class.parameters: (int membershipSizeThreshold)
focal_class.return: void
focal_class.signature: void setMembershipSizeThreshold(int membershipSizeThreshold)
focal_class.class_method_signature: MembershipWriter.addMember(@NotNull Tree groupTree, @NotNull String memberContentId)
focal_class.full_signature:  boolean addMember(@NotNull Tree groupTree, @NotNull String memberContentId)
focal_class.identifier: addMember
focal_class.parameters: (@NotNull Tree groupTree, @NotNull String memberContentId)
focal_class.return: boolean
focal_class.signature: boolean addMember(@NotNull Tree groupTree, @NotNull String memberContentId)
focal_class.class_method_signature: MembershipWriter.addMembers(@NotNull Tree groupTree, @NotNull Map<String, String> memberIds)
focal_class.full_signature: @NotNull Set<String> addMembers(@NotNull Tree groupTree, @NotNull Map<String, String> memberIds)
focal_class.identifier: addMembers
focal_class.modifiers: @NotNull
focal_class.parameters: (@NotNull Tree groupTree, @NotNull Map<String, String> memberIds)
focal_class.return: Set<String>
focal_class.signature: Set<String> addMembers(@NotNull Tree groupTree, @NotNull Map<String, String> memberIds)
focal_class.class_method_signature: MembershipWriter.createMemberRefTree(@NotNull Tree groupTree, @NotNull Tree membersList)
focal_class.full_signature: @NotNull private static Tree createMemberRefTree(@NotNull Tree groupTree, @NotNull Tree membersList)
focal_class.identifier: createMemberRefTree
focal_class.modifiers: @NotNull private static
focal_class.parameters: (@NotNull Tree groupTree, @NotNull Tree membersList)
focal_class.return: Tree
focal_class.signature: Tree createMemberRefTree(@NotNull Tree groupTree, @NotNull Tree membersList)
focal_class.class_method_signature: MembershipWriter.nextRefNodeName(@NotNull Tree membersList)
focal_class.full_signature: @NotNull private static String nextRefNodeName(@NotNull Tree membersList)
focal_class.identifier: nextRefNodeName
focal_class.modifiers: @NotNull private static
focal_class.parameters: (@NotNull Tree membersList)
focal_class.return: String
focal_class.signature: String nextRefNodeName(@NotNull Tree membersList)
focal_class.class_method_signature: MembershipWriter.removeMember(@NotNull Tree groupTree, @NotNull String memberContentId)
focal_class.full_signature:  boolean removeMember(@NotNull Tree groupTree, @NotNull String memberContentId)
focal_class.identifier: removeMember
focal_class.parameters: (@NotNull Tree groupTree, @NotNull String memberContentId)
focal_class.return: boolean
focal_class.signature: boolean removeMember(@NotNull Tree groupTree, @NotNull String memberContentId)
focal_class.class_method_signature: MembershipWriter.removeMembers(@NotNull Tree groupTree, @NotNull Map<String, String> memberIds)
focal_class.full_signature: @NotNull Set<String> removeMembers(@NotNull Tree groupTree, @NotNull Map<String, String> memberIds)
focal_class.identifier: removeMembers
focal_class.modifiers: @NotNull
focal_class.parameters: (@NotNull Tree groupTree, @NotNull Map<String, String> memberIds)
focal_class.return: Set<String>
focal_class.signature: Set<String> removeMembers(@NotNull Tree groupTree, @NotNull Map<String, String> memberIds)
focal_method.body: @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());
      }
focal_method.class_method_signature: MembershipWriter.removeMembers(@NotNull Tree groupTree, @NotNull Map<String, String> memberIds)
focal_method.full_signature: @NotNull Set<String> removeMembers(@NotNull Tree groupTree, @NotNull Map<String, String> memberIds)
focal_method.identifier: removeMembers
focal_method.invocations: getChild concat singletonIterator iterator getChildren hasNext isEmpty next getProperty copy iterator entrySet hasNext isEmpty getKey next hasValue removeValue remove isEmpty removeProperty remove setProperty getPropertyState newHashSet values
focal_method.modifiers: @NotNull
focal_method.parameters: (@NotNull Tree groupTree, @NotNull Map<String, String> memberIds)
focal_method.return: Set<String>
focal_method.signature: Set<String> removeMembers(@NotNull Tree groupTree, @NotNull Map<String, String> memberIds)