Esempio n. 1
0
  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);
        }
      }
    }
  }