Package org.jivesoftware.openfire.group
Class GroupManager
- java.lang.Object
-
- org.jivesoftware.openfire.group.GroupManager
-
-
Field Summary
Fields Modifier and Type Field Description static SystemProperty<Class>
GROUP_PROVIDER
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
adminAddedPostProcess(Group group, org.xmpp.packet.JID admin, boolean wasMember)
Updates the caches maintained by this manager and dispatches events that reflect an admin user having been added to a group.void
adminRemovedPostProcess(Group group, org.xmpp.packet.JID admin)
Updates the caches maintained by this manager and dispatches events that reflect an admin user having been removed from a group.Group
createGroup(String name)
Factory method for creating a new Group.void
createGroupPostProcess(Group group)
Updates the caches maintained by this manager and dispatches events that reflect a new group having been created.void
deleteGroup(Group group)
Deletes a group from the system.void
deleteGroupPostProcess(Group group)
Updates the caches maintained by this manager to reflect an existing group having been deleted.void
deleteGroupPreProcess(Group group)
Dispatches events that reflect an existing group having been deleted.void
deleteUser(User user)
Deletes a user from all the groups where he/she belongs.Group
getGroup(String name)
Returns a Group by name.Group
getGroup(String name, boolean forceLookup)
Returns a Group by name.Group
getGroup(org.xmpp.packet.JID jid)
Returns the corresponding group if the given JID represents a group.int
getGroupCount()
Returns the total number of groups in the system.Collection<Group>
getGroups()
Returns an unmodifiable Collection of all groups in the system.Collection<Group>
getGroups(int startIndex, int numResults)
Returns all groups given a start index and desired number of results.Collection<Group>
getGroups(User user)
Returns an iterator for all groups that the User is a member of.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.static GroupManager
getInstance()
Returns a singleton instance of GroupManager.GroupProvider
getProvider()
Returns the configured group provider.Collection<Group>
getPublicSharedGroups()
Returns an unmodifiable Collection of all public shared groups in the system.Collection<Group>
getSharedGroups()
Returns an unmodifiable Collection of all shared groups in the system.Collection<Group>
getSharedGroups(String userName)
Returns an unmodifiable Collection of all shared groups in the system for a given userName.Collection<Group>
getVisibleGroups(Group groupToCheck)
Returns an unmodifiable Collection of all shared groups in the system for a given group name.boolean
isReadOnly()
Returns true if groups are read-only.boolean
isSearchSupported()
Returns true if searching for groups is supported.void
memberAddedPostProcess(Group group, org.xmpp.packet.JID member, boolean wasAdmin)
Updates the caches maintained by this manager and dispatches events that reflect a member user having been added to a group.void
memberRemovedPostProcess(Group group, org.xmpp.packet.JID member)
Updates the caches maintained by this manager and dispatches events that reflect a member user having been removed from a group.void
propertiesDeletedPostProcess(Group group, Map<String,String> originalProperties)
Updates the caches maintained by this manager and dispatches events that reflect a group having all of its properties removed.void
propertyAddedPostProcess(Group group, String key)
Updates the caches maintained by this manager and dispatches events that reflect a group having received a new property.void
propertyDeletedPostProcess(Group group, String key, String originalValue)
Updates the caches maintained by this manager and dispatches events that reflect a group having one of its properties removed.void
propertyModifiedPostProcess(Group group, String key, String originalValue)
Updates the caches maintained by this manager and dispatches events that reflect a group having received a modification to one of its properties.void
redescribeGroupPostProcess(Group group, String originalDescription)
Updates the caches maintained by this manager and dispatches events that reflect a group having received a new description.void
renameGroupPostProcess(Group group, String originalName)
Updates the caches maintained by this manager and dispatches events that reflect a group having received a new name.Collection<Group>
search(String query)
Returns the groups that match the search.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.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.protected static Set<String>
splitGroupList(String csv)
Splits a comma-separated string of group name in a set of group names.
-
-
-
Field Detail
-
GROUP_PROVIDER
public static final SystemProperty<Class> GROUP_PROVIDER
-
-
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, GroupNameInvalidException
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.GroupNameInvalidException
-
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) throws GroupNotFoundException
Returns a Group by name.- Parameters:
name
- The name of the group to retrieve- Returns:
- The group corresponding to that name
- Throws:
GroupNotFoundException
- if the group 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 retrieveforceLookup
- 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) throws GroupNotFoundException
Deletes a group from the system.- Parameters:
group
- the group to delete.- Throws:
GroupNotFoundException
-
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 group name.- Parameters:
groupToCheck
- The group to check- Returns:
- an unmodifiable Collection of all shared groups for the given group name.
-
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 forpropValue
- the property value to search for- Returns:
- an unmodifiable Collection of all matching 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 fromnumResults
- 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.
-
createGroupPostProcess
public void createGroupPostProcess(@Nonnull Group group)
Updates the caches maintained by this manager and dispatches events that reflect a new group having been created. This method is intended to be invoked to update the internal state of GroupManager after a group has been created. It should rarely be invoked by code that is not part of the GroupManager implementation.- Parameters:
group
- The group that has been created.
-
deleteGroupPreProcess
public void deleteGroupPreProcess(@Nonnull Group group)
Dispatches events that reflect an existing group having been deleted. This method is intended to be invoked to update the internal state of GroupManager just before a group will be deleted. It should rarely be invoked by code that is not part of the GroupManager implementation.- Parameters:
group
- The group that is about to be removed.
-
deleteGroupPostProcess
public void deleteGroupPostProcess(@Nonnull Group group)
Updates the caches maintained by this manager to reflect an existing group having been deleted. This method is intended to be invoked to update the internal state of GroupManager after a group has been deleted. It should rarely be invoked by code that is not part of the GroupManager implementation.- Parameters:
group
- The group that has been deleted. Care should be taken to not apply changes to this instance, as it no longer refers to a valid, existing group.
-
adminAddedPostProcess
public void adminAddedPostProcess(@Nonnull Group group, @Nonnull org.xmpp.packet.JID admin, boolean wasMember)
Updates the caches maintained by this manager and dispatches events that reflect an admin user having been added to a group. This method is intended to be invoked to update the internal state of GroupManager after a group has been updated. It should rarely be invoked by code that is not part of the GroupManager implementation.- Parameters:
group
- The group that was modified.admin
- The address of the admin that was added to the group.wasMember
- Whether the admin was a member of the group (which are mutually exclusive roles) before the update.
-
adminRemovedPostProcess
public void adminRemovedPostProcess(@Nonnull Group group, @Nonnull org.xmpp.packet.JID admin)
Updates the caches maintained by this manager and dispatches events that reflect an admin user having been removed from a group. This method is intended to be invoked to update the internal state of GroupManager after a group has been updated. It should rarely be invoked by code that is not part of the GroupManager implementation.- Parameters:
group
- The group that was modified.admin
- The address of the admin that was removed from the group.
-
memberAddedPostProcess
public void memberAddedPostProcess(@Nonnull Group group, @Nonnull org.xmpp.packet.JID member, boolean wasAdmin)
Updates the caches maintained by this manager and dispatches events that reflect a member user having been added to a group. This method is intended to be invoked to update the internal state of GroupManager after a group has been updated. It should rarely be invoked by code that is not part of the GroupManager implementation.- Parameters:
group
- The group that was modified.member
- The address of the member that was added to the group.wasAdmin
- Whether the member was an admin of the group (which are mutually exclusive roles) before the update.
-
memberRemovedPostProcess
public void memberRemovedPostProcess(@Nonnull Group group, @Nonnull org.xmpp.packet.JID member)
Updates the caches maintained by this manager and dispatches events that reflect a member user having been removed from a group. This method is intended to be invoked to update the internal state of GroupManager after a group has been updated. It should rarely be invoked by code that is not part of the GroupManager implementation.- Parameters:
group
- The group that was modified.member
- The address of the member that was removed from the group.
-
renameGroupPostProcess
public void renameGroupPostProcess(@Nonnull Group group, @Nullable String originalName)
Updates the caches maintained by this manager and dispatches events that reflect a group having received a new name. This method is intended to be invoked to update the internal state of GroupManager after a group has been updated. It should rarely be invoked by code that is not part of the GroupManager implementation.- Parameters:
group
- The group that was modified.originalName
- The name of the group prior to the change.
-
redescribeGroupPostProcess
public void redescribeGroupPostProcess(@Nonnull Group group, @Nullable String originalDescription)
Updates the caches maintained by this manager and dispatches events that reflect a group having received a new description. This method is intended to be invoked to update the internal state of GroupManager after a group has been updated. It should rarely be invoked by code that is not part of the GroupManager implementation.- Parameters:
group
- The group that was modified.originalDescription
- The description of the group prior to the change.
-
propertyAddedPostProcess
public void propertyAddedPostProcess(@Nonnull Group group, @Nonnull String key)
Updates the caches maintained by this manager and dispatches events that reflect a group having received a new property. This method is intended to be invoked to update the internal state of GroupManager after a group has been updated. It should rarely be invoked by code that is not part of the GroupManager implementation.- Parameters:
group
- The group that was modified.key
- The key of the property that was added.
-
propertyModifiedPostProcess
public void propertyModifiedPostProcess(@Nonnull Group group, @Nonnull String key, @Nonnull String originalValue)
Updates the caches maintained by this manager and dispatches events that reflect a group having received a modification to one of its properties. This method is intended to be invoked to update the internal state of GroupManager after a group has been updated. It should rarely be invoked by code that is not part of the GroupManager implementation.- Parameters:
group
- The group that was modified.key
- The key of the property that was modified.originalValue
- The value of the property prior to the modification.
-
propertyDeletedPostProcess
public void propertyDeletedPostProcess(@Nonnull Group group, @Nonnull String key, @Nonnull String originalValue)
Updates the caches maintained by this manager and dispatches events that reflect a group having one of its properties removed. This method is intended to be invoked to update the internal state of GroupManager after a group has been updated. It should rarely be invoked by code that is not part of the GroupManager implementation.- Parameters:
group
- The group that was modified.key
- The key of the property that was removed.originalValue
- The value of the property prior to the removal.
-
propertiesDeletedPostProcess
public void propertiesDeletedPostProcess(@Nonnull Group group, @Nonnull Map<String,String> originalProperties)
Updates the caches maintained by this manager and dispatches events that reflect a group having all of its properties removed. This method is intended to be invoked to update the internal state of GroupManager after a group has been updated. It should rarely be invoked by code that is not part of the GroupManager implementation.- Parameters:
group
- The group that was modified.originalProperties
- The properties of the group prior to the removal.
-
-