コード例 #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
 public void memberRemoved(Group group, Map params) {
   String deletedUser = (String) params.get("member");
   // Do nothing if the user is still an admin
   if (group.getAdmins().contains(deletedUser)) {
     return;
   }
   if (!isSharedGroup(group)) {
     for (Group visibleGroup : getVisibleGroups(group)) {
       removeSharedGroupFromRoster(visibleGroup, deletedUser);
     }
   } else {
     groupUserDeleted(group, deletedUser);
   }
 }
コード例 #5
0
ファイル: RosterManager.java プロジェクト: nihed/magnetism
 public void memberAdded(Group group, Map params) {
   String addedUser = (String) params.get("member");
   // Do nothing if the user was an admin that became a member
   if (group.getAdmins().contains(addedUser)) {
     return;
   }
   if (!isSharedGroup(group)) {
     for (Group visibleGroup : getVisibleGroups(group)) {
       addSharedGroupToRoster(visibleGroup, addedUser);
     }
   } else {
     groupUserAdded(group, addedUser);
   }
 }
コード例 #6
0
ファイル: RosterManager.java プロジェクト: nihed/magnetism
  public void groupModified(Group group, Map params) {
    // Do nothing if no group property has been modified
    if (!"propertyModified".equals(params.get("type"))) {
      return;
    }
    String keyChanged = (String) params.get("propertyKey");
    String originalValue = (String) params.get("originalValue");

    if ("sharedRoster.showInRoster".equals(keyChanged)) {
      String currentValue = group.getProperties().get("sharedRoster.showInRoster");
      // Nothing has changed so do nothing.
      if (currentValue.equals(originalValue)) {
        return;
      }
      // Get the users of the group
      Collection<String> users = new HashSet<String>(group.getMembers());
      users.addAll(group.getAdmins());
      // Get the users whose roster will be affected
      Collection<String> affectedUsers =
          getAffectedUsers(
              group, originalValue, group.getProperties().get("sharedRoster.groupList"));
      // Remove the group members from the affected rosters
      for (String deletedUser : users) {
        groupUserDeleted(group, affectedUsers, deletedUser);
      }

      // Simulate that the group users has been added to the group. This will cause to push
      // roster items to the "affected" users for the group users
      // Collection<Group> visibleGroups = getVisibleGroups(group);
      for (String user : users) {
        groupUserAdded(group, user);
        /*for (Group visibleGroup : visibleGroups) {
            addSharedGroupToRoster(visibleGroup, user);
        }*/
      }
    } else if ("sharedRoster.groupList".equals(keyChanged)) {
      String currentValue = group.getProperties().get("sharedRoster.groupList");
      // Nothing has changed so do nothing.
      if (currentValue.equals(originalValue)) {
        return;
      }
      // Get the users of the group
      Collection<String> users = new HashSet<String>(group.getMembers());
      users.addAll(group.getAdmins());
      // Get the users whose roster will be affected
      Collection<String> affectedUsers =
          getAffectedUsers(
              group, group.getProperties().get("sharedRoster.showInRoster"), originalValue);
      // Remove the group members from the affected rosters
      for (String deletedUser : users) {
        groupUserDeleted(group, affectedUsers, deletedUser);
      }

      // Simulate that the group users has been added to the group. This will cause to push
      // roster items to the "affected" users for the group users
      // Collection<Group> visibleGroups = getVisibleGroups(group);
      for (String user : users) {
        groupUserAdded(group, user);
        /*for (Group visibleGroup : visibleGroups) {
            addSharedGroupToRoster(visibleGroup, user);
        }*/
      }
    } else if ("sharedRoster.displayName".equals(keyChanged)) {
      String currentValue = group.getProperties().get("sharedRoster.displayName");
      // Nothing has changed so do nothing.
      if (currentValue.equals(originalValue)) {
        return;
      }
      // Do nothing if the group is not being shown in users' rosters
      if (!isSharedGroup(group)) {
        return;
      }
      // Get all the affected users
      Collection<String> users = getAffectedUsers(group);
      // Iterate on all the affected users and update their rosters
      for (String updatedUser : users) {
        // Get the roster to update.
        Roster roster = (Roster) CacheManager.getCache("username2roster").get(updatedUser);
        if (roster != null) {
          // Update the roster with the new group display name
          roster.shareGroupRenamed(users);
        }
      }
    }
  }