コード例 #1
0
ファイル: RosterManager.java プロジェクト: nihed/magnetism
  Collection<String> getSharedUsersForRoster(Group group, Roster roster) {
    String showInRoster = group.getProperties().get("sharedRoster.showInRoster");
    String groupNames = group.getProperties().get("sharedRoster.groupList");

    // Answer an empty collection if the group is not being shown in users' rosters
    if (!"onlyGroup".equals(showInRoster) && !"everybody".equals(showInRoster)) {
      return new ArrayList<String>();
    }

    // Add the users of the group
    Collection<String> users = new HashSet<String>(group.getMembers());
    users.addAll(group.getAdmins());

    // Check if anyone can see this shared group
    if ("everybody".equals(showInRoster)) {
      // If the user of the roster belongs to the public group then we should return all users
      // in the system since they all need to be in the roster with subscription "from"
      if (group.isUser(roster.getUsername())) {
        // Add all users in the system
        for (User user : UserManager.getInstance().getUsers()) {
          users.add(user.getUsername());
        }
      }
    } else {
      // Add the users that may see the group
      Collection<Group> groupList = parseGroups(groupNames);
      for (Group groupInList : groupList) {
        users.addAll(groupInList.getMembers());
        users.addAll(groupInList.getAdmins());
      }
    }
    return users;
  }
コード例 #2
0
ファイル: RosterManager.java プロジェクト: nihed/magnetism
 /**
  * This method is similar to {@link #getAffectedUsers(Group)} except that it receives some group
  * properties. The group properties are passed as parameters since the called of this method may
  * want to obtain the related users of the group based in some properties values.
  *
  * <p>This is useful when the group is being edited and some properties has changed and we need to
  * obtain the related users of the group based on the previous group state.
  */
 private Collection<String> getAffectedUsers(Group group, String showInRoster, String groupNames) {
   // Answer an empty collection if the group is not being shown in users' rosters
   if (!"onlyGroup".equals(showInRoster) && !"everybody".equals(showInRoster)) {
     return new ArrayList<String>();
   }
   // Add the users of the group
   Collection<String> users = new HashSet<String>(group.getMembers());
   users.addAll(group.getAdmins());
   // Check if anyone can see this shared group
   if ("everybody".equals(showInRoster)) {
     // Add all users in the system
     for (User user : UserManager.getInstance().getUsers()) {
       users.add(user.getUsername());
     }
     // Add all logged users. We don't need to add all users in the system since only the
     // logged ones will be affected.
     // users.addAll(SessionManager.getInstance().getSessionUsers());
   } else {
     // Add the users that may see the group
     Collection<Group> groupList = parseGroups(groupNames);
     for (Group groupInList : groupList) {
       users.addAll(groupInList.getMembers());
       users.addAll(groupInList.getAdmins());
     }
   }
   return users;
 }
コード例 #3
0
ファイル: RosterManager.java プロジェクト: nihed/magnetism
  private void removeSharedGroupFromRoster(Group group, String username) {
    // Get the group users to remove from the user's roster
    Collection<String> users = new HashSet<String>(group.getMembers());
    users.addAll(group.getAdmins());

    // Get the roster of the user from which we need to remove the shared group users
    Roster userRoster = (Roster) CacheManager.getCache("username2roster").get(username);

    // Iterate on all the group users and update their rosters
    for (String userToRemove : users) {
      // Get the roster to update
      Roster roster = (Roster) CacheManager.getCache("username2roster").get(userToRemove);
      // Only update rosters in memory
      if (roster != null) {
        roster.deleteSharedUser(group, username);
      }
      // Update the roster of the user
      if (userRoster != null) {
        try {
          User user = UserManager.getInstance().getUser(userToRemove);
          Collection<Group> groups = GroupManager.getInstance().getGroups(user);
          userRoster.deleteSharedUser(userToRemove, groups, group);
        } catch (UserNotFoundException e) {
        }
      }
    }
  }
コード例 #4
0
ファイル: RosterManager.java プロジェクト: nihed/magnetism
  /**
   * Notification that a Group user has been added. Update the group users' roster accordingly.
   *
   * @param group the group where the user was added.
   * @param addedUser the username of the user that has been added to the group.
   */
  private void groupUserAdded(Group group, String addedUser) {
    // Get all the affected users
    Collection<String> users = getAffectedUsers(group);
    // Get the roster of the added user.
    Roster addedUserRoster = (Roster) CacheManager.getCache("username2roster").get(addedUser);

    // Iterate on all the affected users and update their rosters
    for (String userToUpdate : users) {
      if (!addedUser.equals(userToUpdate)) {
        // Get the roster to update
        Roster roster = (Roster) CacheManager.getCache("username2roster").get(userToUpdate);
        // Only update rosters in memory
        if (roster != null) {
          roster.addSharedUser(group, addedUser);
        }
        // Update the roster of the newly added group user.
        if (addedUserRoster != null) {
          try {
            User user = UserManager.getInstance().getUser(userToUpdate);
            Collection<Group> groups = GroupManager.getInstance().getGroups(user);
            addedUserRoster.addSharedUser(userToUpdate, groups, group);
          } catch (UserNotFoundException e) {
          }
        }
      }
    }
  }
コード例 #5
0
ファイル: RosterManager.java プロジェクト: nihed/magnetism
  /**
   * Notification that a Group user has been deleted. Update the group users' roster accordingly.
   *
   * @param group the group from where the user was deleted.
   * @param users the users to update their rosters
   * @param deletedUser the username of the user that has been deleted from the group.
   */
  private void groupUserDeleted(Group group, Collection<String> users, String deletedUser) {
    // Get the roster of the deleted user.
    Roster deletedUserRoster = (Roster) CacheManager.getCache("username2roster").get(deletedUser);

    // Iterate on all the affected users and update their rosters
    for (String userToUpdate : users) {
      // Get the roster to update
      Roster roster = (Roster) CacheManager.getCache("username2roster").get(userToUpdate);
      // Only update rosters in memory
      if (roster != null) {
        roster.deleteSharedUser(group, deletedUser);
      }
      // Update the roster of the newly deleted group user.
      if (deletedUserRoster != null) {
        try {
          User user = UserManager.getInstance().getUser(userToUpdate);
          Collection<Group> groups = GroupManager.getInstance().getGroups(user);
          deletedUserRoster.deleteSharedUser(userToUpdate, groups, group);
        } catch (UserNotFoundException e) {
        }
      }
    }
  }