Class GroupMultiProvider

java.lang.Object
org.jivesoftware.openfire.group.GroupMultiProvider
All Implemented Interfaces:
GroupProvider
Direct Known Subclasses:
HybridGroupProvider, MappedGroupProvider

public abstract class GroupMultiProvider extends Object implements GroupProvider
A GroupProvider that delegates to one or more 'backing' GroupProvider.
Author:
Guus der Kinderen, guus@goodbytes.nl
  • Constructor Details

    • GroupMultiProvider

      public GroupMultiProvider()
  • Method Details

    • instantiate

      public static GroupProvider instantiate(@Nonnull SystemProperty<Class> implementationProperty)
      Instantiates a GroupProvider based on Class-based system property. When the property is not set, this method returns null. When the property is set, but an exception occurs while instantiating the class, this method logs the error and returns null. GroupProvider classes are required to have a public, no-argument constructor.
      Parameters:
      implementationProperty - A property that defines the class of the instance to be returned.
      Returns:
      A group provider (can be null).
    • instantiate

      public static GroupProvider instantiate(@Nonnull SystemProperty<Class> implementationProperty, @Nullable SystemProperty<String> configProperty)
      Instantiates a GroupProvider based on Class-based system property. When the property is not set, this method returns null. When the property is set, but an exception occurs while instantiating the class, this method logs the error and returns null. GroupProvider classes are required to have a public, no-argument constructor, but can have an optional additional constructor that takes a single String argument. If such constructor is defined, then it is invoked with the value of the second argument of this method. This is typically used to (but needs not) identify a property (by name) that holds additional configuration for the to be instantiated GroupProvider. This implementation will pass on any non-empty value to the constructor. When a configuration argument is provided, but no constructor exists in the implementation that accepts a single String value, this method will log a warning and attempt to return an instance based on the no-arg constructor of the class.
      Parameters:
      implementationProperty - A property that defines the class of the instance to be returned.
      configProperty - an opaque string value passed to the constructor.
      Returns:
      A group provider (can be null).
    • getGroupCount

      public int getGroupCount()
      Returns the number of groups in the system, calculated as the sum of groups in each provider.
      Specified by:
      getGroupCount in interface GroupProvider
      Returns:
      the number of groups in the system.
    • getGroupNames

      public Collection<String> getGroupNames()
      Returns the Collection of all group names in each of the providers.
      Specified by:
      getGroupNames in interface GroupProvider
      Returns:
      the Collection of all groups.
    • isSharingSupported

      public boolean isSharingSupported()
      Returns true if at least one provider allows group sharing. Shared groups enable roster sharing.
      Specified by:
      isSharingSupported in interface GroupProvider
      Returns:
      true if group sharing is supported.
    • getSharedGroupNames

      public Collection<String> getSharedGroupNames()
      Returns an unmodifiable Collection of all shared groups from each provider that supports group sharing.
      Specified by:
      getSharedGroupNames in interface GroupProvider
      Returns:
      unmodifiable Collection of all shared groups in the system.
    • getSharedGroupNames

      public Collection<String> getSharedGroupNames(org.xmpp.packet.JID user)
      Returns an unmodifiable Collection of all shared groups in the system for a given user. Implementations should use the bare JID representation of the JID passed as an argument to this method.
      Specified by:
      getSharedGroupNames in interface GroupProvider
      Parameters:
      user - The bare JID for the user (node@domain)
      Returns:
      unmodifiable Collection of all shared groups in the system for a given user.
    • getPublicSharedGroupNames

      public Collection<String> getPublicSharedGroupNames()
      Returns an unmodifiable Collection of all public shared groups by each of the providers that support sharing.
      Specified by:
      getPublicSharedGroupNames in interface GroupProvider
      Returns:
      unmodifiable Collection of all public shared groups in the system.
    • getVisibleGroupNames

      public Collection<String> getVisibleGroupNames(String userGroup)
      Returns an unmodifiable Collection of groups that are visible to the members of the given group.
      Specified by:
      getVisibleGroupNames in interface GroupProvider
      Parameters:
      userGroup - The given group
      Returns:
      unmodifiable Collection of group names that are visible to the given group.
    • getGroupNames

      public Collection<String> getGroupNames(int startIndex, int numResults)
      Returns the Collection of all groups provided by each of the providers, ordered by provider-order.
      Specified by:
      getGroupNames in interface GroupProvider
      Parameters:
      startIndex - start index in results.
      numResults - number of results to return.
      Returns:
      the Collection of all group names given the startIndex and numResults.
    • getGroupNames

      public Collection<String> getGroupNames(org.xmpp.packet.JID user)
      Returns the Collection of group names that an entity belongs to. Implementations should use the bare JID representation of the JID passed as an argument to this method.
      Specified by:
      getGroupNames in interface GroupProvider
      Parameters:
      user - the (bare) JID of the entity.
      Returns:
      the Collection of group names that the user belongs to.
    • isReadOnly

      public boolean isReadOnly()
      Returns whether all backing providers are read-only. When read-only, groups can not be created, deleted, or modified. If at least one provider is not read-only, this method returns false.
      Specified by:
      isReadOnly in interface GroupProvider
      Returns:
      true when all backing providers are read-only, otherwise false.
    • search

      public Collection<String> search(String query)
      Description copied from interface: GroupProvider
      Returns the group names that match a 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 GroupProvider.isSearchSupported() method to ensure that searching is supported.

      Specified by:
      search in interface GroupProvider
      Parameters:
      query - the search string for group names.
      Returns:
      all groups that match the search.
    • search

      public Collection<String> search(String query, int startIndex, int numResults)
      Returns the group names that match a 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. This method throws an UnsupportedOperationException when none of the backing providers support search.

      Specified by:
      search in interface GroupProvider
      Parameters:
      query - the search string for group names.
      startIndex - start index in results.
      numResults - number of results to return.
      Returns:
      all groups that match the search.
      Throws:
      UnsupportedOperationException - When none of the providers support search.
    • search

      public Collection<String> search(String key, String value)
      Returns the names of groups that have a property matching the given key/value pair. This provides a simple extensible search mechanism for providers with differing property sets and storage models. The semantics of the key/value matching (wildcard support, scoping, etc.) are unspecified by the interface and may vary for each implementation. When a key/value combination ia provided that are not supported by a particular provider, this is ignored by that provider (but can still be used by other providers). Before searching or showing a search UI, use the isSearchSupported() method to ensure that searching is supported.
      Specified by:
      search in interface GroupProvider
      Parameters:
      key - The name of a group property (e.g. "sharedRoster.showInRoster")
      value - The value to match for the given property
      Returns:
      unmodifiable Collection of group names that match the given key/value pair.
      Throws:
      UnsupportedOperationException - When none of the providers support search.
    • isSearchSupported

      public boolean isSearchSupported()
      Returns true if group searching is supported by at least one of the providers.
      Specified by:
      isSearchSupported in interface GroupProvider
      Returns:
      true if searching is supported.
    • getGroup

      public Group getGroup(String name) throws GroupNotFoundException
      Loads a group from the first provider that contains the group.
      Specified by:
      getGroup in interface GroupProvider
      Parameters:
      name - the name of the group (cannot be null or empty).
      Returns:
      The group (never null).
      Throws:
      GroupNotFoundException - When none of the providers contains the group.
    • createGroup

      Creates a group with the given name in the first provider that is not read-only.
      Specified by:
      createGroup in interface GroupProvider
      Parameters:
      name - name of the group.
      Returns:
      the newly created group.
      Throws:
      GroupAlreadyExistsException - if a group with the same name already exists.
      UnsupportedOperationException - if the provider does not support the operation.
      GroupNameInvalidException - if the provided new name is an unacceptable value.
    • deleteGroup

      public void deleteGroup(String name) throws GroupNotFoundException
      Removes a group from all non-read-only providers.
      Specified by:
      deleteGroup in interface GroupProvider
      Parameters:
      name - the name of the group to delete.
      Throws:
      GroupNotFoundException
    • setName

      Sets the name of a group to a new name in the provider that is used for this group.
      Specified by:
      setName in interface GroupProvider
      Parameters:
      oldName - the current name of the group.
      newName - the desired new name of the group.
      Throws:
      GroupAlreadyExistsException - if a group with the same name already exists.
      UnsupportedOperationException - if the provider does not support the operation.
      GroupNotFoundException - if the provided old name does not refer to an existing group.
      GroupNameInvalidException - if the provided new name is an unacceptable value.
    • setDescription

      public void setDescription(String name, String description) throws GroupNotFoundException
      Updates the group's description in the provider that is used for this group.
      Specified by:
      setDescription in interface GroupProvider
      Parameters:
      name - the group name.
      description - the group description.
      Throws:
      GroupNotFoundException - if no existing group could be found to update.
    • addMember

      public void addMember(String groupName, org.xmpp.packet.JID user, boolean administrator) throws GroupNotFoundException
      Adds an entity to a group (optional operation). Implementations should use the bare JID representation of the JID passed as an argument to this method.
      Specified by:
      addMember in interface GroupProvider
      Parameters:
      groupName - the group to add the member to
      user - the (bare) JID of the entity to add
      administrator - True if the member is an administrator of the group
      Throws:
      UnsupportedOperationException - if the provider does not support the operation.
      GroupNotFoundException - if the provided group name does not refer to an existing group.
    • updateMember

      public void updateMember(String groupName, org.xmpp.packet.JID user, boolean administrator) throws GroupNotFoundException
      Updates the privileges of an entity in a group. Implementations should use the bare JID representation of the JID passed as an argument to this method.
      Specified by:
      updateMember in interface GroupProvider
      Parameters:
      groupName - the group where the change happened
      user - the (bare) JID of the entity with new privileges
      administrator - True if the member is an administrator of the group
      Throws:
      UnsupportedOperationException - if the provider does not support the operation.
      GroupNotFoundException - if the provided group name does not refer to an existing group.
    • deleteMember

      public void deleteMember(String groupName, org.xmpp.packet.JID user)
      Deletes an entity from a group (optional operation). Implementations should use the bare JID representation of the JID passed as an argument to this method.
      Specified by:
      deleteMember in interface GroupProvider
      Parameters:
      groupName - the group name.
      user - the (bare) JID of the entity to delete.
      Throws:
      UnsupportedOperationException - if the provider does not support the operation.
    • loadProperties

      public PersistableMap<String,String> loadProperties(Group group)
      Loads the group properties (if any) from the backend data store. If the properties can be changed, the provider implementation must ensure that updates to the resulting Map are persisted to the backend data store. Otherwise, if a mutator method is called, the implementation should throw an UnsupportedOperationException. If there are no corresponding properties for the given group, or if the provider does not support group properties, this method should return an empty Map rather than null.
      Specified by:
      loadProperties in interface GroupProvider
      Parameters:
      group - The target group
      Returns:
      The properties for the given group