コード例 #1
0
ファイル: RosterManager.java プロジェクト: nihed/magnetism
 /**
  * Returns a collection with all the groups that the user may include in his roster. The following
  * criteria will be used to select the groups: 1) Groups that are configured so that everybody can
  * include in his roster, 2) Groups that are configured so that its users may include the group in
  * their rosters and the user is a group user of the group and 3) User belongs to a Group that may
  * see a Group that whose members may include the Group in their rosters.
  *
  * @param user the user to return his shared groups.
  * @return a collection with all the groups that the user may include in his roster.
  */
 public Collection<Group> getSharedGroups(User user) {
   Collection<Group> answer = new HashSet<Group>();
   Collection<Group> groups = GroupManager.getInstance().getGroups();
   for (Group group : groups) {
     String showInRoster = group.getProperties().get("sharedRoster.showInRoster");
     if ("onlyGroup".equals(showInRoster)) {
       if (group.isUser(user.getUsername())) {
         // The user belongs to the group so add the group to the answer
         answer.add(group);
       } else {
         // Check if the user belongs to a group that may see this group
         Collection<Group> groupList =
             parseGroups(group.getProperties().get("sharedRoster.groupList"));
         for (Group groupInList : groupList) {
           if (groupInList.isUser(user.getUsername())) {
             answer.add(group);
           }
         }
       }
     } else if ("everybody".equals(showInRoster)) {
       // Anyone can see this group so add the group to the answer
       answer.add(group);
     }
   }
   return answer;
 }
コード例 #2
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;
  }
コード例 #3
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;
 }