Class GroupManager


  • public class GroupManager
    extends Object
    Manages groups.
    Author:
    Matt Tucker
    See Also:
    Group
    • Method Detail

      • getInstance

        public static GroupManager getInstance()
        Returns a singleton instance of GroupManager.
        Returns:
        a GroupManager instance.
      • createGroup

        public Group createGroup​(String name)
                          throws GroupAlreadyExistsException
        Factory method for creating a new Group. A unique name is the only required field.
        Parameters:
        name - the new and unique name for the group.
        Returns:
        a new Group.
        Throws:
        GroupAlreadyExistsException - if the group name already exists in the system.
      • getGroup

        public Group getGroup​(org.xmpp.packet.JID jid)
                       throws GroupNotFoundException
        Returns the corresponding group if the given JID represents a group.
        Parameters:
        jid - The JID for the group to retrieve
        Returns:
        The group corresponding to the JID, or null if the JID does not represent a group
        Throws:
        GroupNotFoundException - if the JID represents a group that does not exist
      • getGroup

        public Group getGroup​(String name,
                              boolean forceLookup)
                       throws GroupNotFoundException
        Returns a Group by name.
        Parameters:
        name - The name of the group to retrieve
        forceLookup - Invalidate the group cache for this group
        Returns:
        The group corresponding to that name
        Throws:
        GroupNotFoundException - if the group does not exist.
      • deleteGroup

        public void deleteGroup​(Group group)
        Deletes a group from the system.
        Parameters:
        group - the group to delete.
      • deleteUser

        public void deleteUser​(User user)
        Deletes a user from all the groups where he/she belongs. The most probable cause for this request is that the user has been deleted from the system.
        Parameters:
        user - the deleted user from the system.
      • getGroupCount

        public int getGroupCount()
        Returns the total number of groups in the system.
        Returns:
        the total number of groups.
      • getGroups

        public Collection<Group> getGroups()
        Returns an unmodifiable Collection of all groups in the system. NOTE: Iterating through the resulting collection has the effect of loading every group into memory. This may be an issue for large deployments. You may call the size() method on the resulting collection to determine the best approach to take before iterating over (and thus instantiating) the groups.
        Returns:
        an unmodifiable Collection of all groups.
      • getSharedGroups

        public Collection<Group> getSharedGroups()
        Returns an unmodifiable Collection of all shared groups in the system. NOTE: Iterating through the resulting collection has the effect of loading all shared groups into memory. This may be an issue for large deployments. You may call the size() method on the resulting collection to determine the best approach to take before iterating over (and thus instantiating) the groups.
        Returns:
        an unmodifiable Collection of all shared groups.
      • getSharedGroups

        public Collection<Group> getSharedGroups​(String userName)
        Returns an unmodifiable Collection of all shared groups in the system for a given userName.
        Parameters:
        userName - the user to check
        Returns:
        an unmodifiable Collection of all shared groups for the given userName.
      • getVisibleGroups

        public Collection<Group> getVisibleGroups​(Group groupToCheck)
        Returns an unmodifiable Collection of all shared groups in the system for a given userName.
        Parameters:
        groupToCheck - The group to check
        Returns:
        an unmodifiable Collection of all shared groups for the given userName.
      • getPublicSharedGroups

        public Collection<Group> getPublicSharedGroups()
        Returns an unmodifiable Collection of all public shared groups in the system.
        Returns:
        an unmodifiable Collection of all shared groups.
      • search

        public Collection<Group> search​(String propName,
                                        String propValue)
        Returns an unmodifiable Collection of all groups in the system that match given propValue for the specified propName.
        Parameters:
        propName - the property name to search for
        propValue - the property value to search for
        Returns:
        an unmodifiable Collection of all shared groups.
      • getGroups

        public Collection<Group> getGroups​(int startIndex,
                                           int numResults)
        Returns all groups given a start index and desired number of results. This is useful to support pagination in a GUI where you may only want to display a certain number of results per page. It is possible that the number of results returned will be less than that specified by numResults if numResults is greater than the number of records left in the system to display.
        Parameters:
        startIndex - start index in results.
        numResults - number of results to return.
        Returns:
        an Iterator for all groups in the specified range.
      • getGroups

        public Collection<Group> getGroups​(User user)
        Returns an iterator for all groups that the User is a member of.
        Parameters:
        user - the user.
        Returns:
        all groups the user belongs to.
      • getGroups

        public Collection<Group> getGroups​(org.xmpp.packet.JID user)
        Returns an iterator for all groups that the entity with the specified JID is a member of.
        Parameters:
        user - the JID of the entity to get a list of groups for.
        Returns:
        all groups that an entity belongs to.
      • isReadOnly

        public boolean isReadOnly()
        Returns true if groups are read-only.
        Returns:
        true if groups are read-only.
      • isSearchSupported

        public boolean isSearchSupported()
        Returns true if searching for groups is supported.
        Returns:
        true if searching for groups are supported.
      • search

        public Collection<Group> search​(String query)
        Returns the groups that match the search. The search is over group names and implicitly uses wildcard matching (although the exact search semantics are left up to each provider implementation). For example, a search for "HR" should match the groups "HR", "HR Department", and "The HR People".

        Before searching or showing a search UI, use the isSearchSupported() method to ensure that searching is supported.

        Parameters:
        query - the search string for group names.
        Returns:
        all groups that match the search.
      • search

        public Collection<Group> search​(String query,
                                        int startIndex,
                                        int numResults)
        Returns the groups that match the search given a start index and desired number of results. The search is over group names and implicitly uses wildcard matching (although the exact search semantics are left up to each provider implementation). For example, a search for "HR" should match the groups "HR", "HR Department", and "The HR People".

        Before searching or showing a search UI, use the isSearchSupported() method to ensure that searching is supported.

        Parameters:
        query - the search string for group names.
        startIndex - the start index to retrieve the group list from
        numResults - the maximum number of results to return
        Returns:
        all groups that match the search.
      • getProvider

        public GroupProvider getProvider()
        Returns the configured group provider. Note that this method has special access privileges since only a few certain classes need to access the provider directly.
        Returns:
        the group provider.
      • splitGroupList

        protected static Set<String> splitGroupList​(String csv)
        Splits a comma-separated string of group name in a set of group names.
        Parameters:
        csv - The comma-separated list. Cannot be null.
        Returns:
        A set of group names.