Class GroupServiceImpl

All Implemented Interfaces:
DSpaceObjectLegacySupportService<Group>, DSpaceObjectService<Group>, GroupService

public class GroupServiceImpl extends DSpaceObjectServiceImpl<Group> implements GroupService
Service implementation for the Group object. This class is responsible for all business logic calls for the Group object and is autowired by spring. This class should never be accessed directly.
Author:
kevinvandevelde at atmire.com
  • Field Details

  • Constructor Details

    • GroupServiceImpl

      protected GroupServiceImpl()
  • Method Details

    • create

      public Group create(Context context) throws SQLException, AuthorizeException
      Description copied from interface: GroupService
      Create a new group
      Specified by:
      create in interface GroupService
      Parameters:
      context - DSpace context object
      Returns:
      group
      Throws:
      SQLException - if database error
      AuthorizeException - if authorization error
    • setName

      public void setName(Group group, String name) throws SQLException
      Description copied from interface: GroupService
      set name of group
      Specified by:
      setName in interface GroupService
      Parameters:
      group - DSpace group
      name - new group name
      Throws:
      SQLException - if database error
    • addMember

      public void addMember(Context context, Group group, EPerson e)
      Description copied from interface: GroupService
      add an eperson member
      Specified by:
      addMember in interface GroupService
      Parameters:
      context - DSpace context object
      group - DSpace group
      e - eperson
    • addMember

      public void addMember(Context context, Group groupParent, Group groupChild) throws SQLException
      Description copied from interface: GroupService
      add group to this group. Be sure to call the #update(Context, Group) method once that all the membership are set to trigger the rebuild of the group2group cache table
      Specified by:
      addMember in interface GroupService
      Parameters:
      context - DSpace context object
      groupParent - parent group
      groupChild - child group
      Throws:
      SQLException - if database error
    • removeMember

      public void removeMember(Context context, Group group, EPerson ePerson) throws SQLException
      Removes a member of a group. The removal will be refused if the group is linked to a workflow step which has claimed tasks or pool tasks and no other member is present in the group to handle these.
      Specified by:
      removeMember in interface GroupService
      Parameters:
      context - DSpace context object
      group - DSpace group
      ePerson - eperson
      Throws:
      SQLException
    • removeMember

      public void removeMember(Context context, Group groupParent, Group childGroup) throws SQLException
      Description copied from interface: GroupService
      remove group from this group. Be sure to call the #update(Context, Group) method once that all the membership are set to trigger the rebuild of the group2group cache table
      Specified by:
      removeMember in interface GroupService
      Parameters:
      context - DSpace context object
      groupParent - parent group
      childGroup - child group
      Throws:
      SQLException - if database error
    • isDirectMember

      public boolean isDirectMember(Group group, EPerson ePerson)
      Description copied from interface: GroupService
      check to see if an eperson is a direct member. If the eperson is a member via a subgroup will be returned false
      Specified by:
      isDirectMember in interface GroupService
      Parameters:
      group - DSpace group
      ePerson - eperson to check membership
      Returns:
      true or false
    • isMember

      public boolean isMember(Group owningGroup, Group childGroup)
      Description copied from interface: GroupService
      Check to see if childGroup is a direct group member of owningGroup. If childGroup is a subgroup via another group will be returned false
      Specified by:
      isMember in interface GroupService
      Parameters:
      owningGroup - parent group
      childGroup - child group
      Returns:
      true or false
    • isParentOf

      public boolean isParentOf(Context context, Group parentGroup, Group childGroup) throws SQLException
      Description copied from interface: GroupService
      Check to see if parentGroup is a direct or in-direct parent of a childGroup.
      Specified by:
      isParentOf in interface GroupService
      Parameters:
      context - current DSpace session.
      parentGroup - parent group
      childGroup - child group
      Returns:
      true or false
      Throws:
      SQLException
    • isMember

      public boolean isMember(Context context, Group group) throws SQLException
      Description copied from interface: GroupService
      fast check to see if an eperson is a member called with eperson id. Does database lookup without instantiating all of the eperson objects and is thus a static method
      Specified by:
      isMember in interface GroupService
      Parameters:
      context - context
      group - group to check
      Returns:
      true or false
      Throws:
      SQLException - if database error
    • isMember

      public boolean isMember(Context context, EPerson ePerson, Group group) throws SQLException
      Description copied from interface: GroupService
      fast check to see if an eperson is a member called with eperson id. Does database lookup without instantiating all of the eperson objects and is thus a static method.
      Specified by:
      isMember in interface GroupService
      Parameters:
      context - DSpace context object.
      ePerson - EPerson whose membership should be checked.
      group - The group to check against.
      Returns:
      true or false
      Throws:
      SQLException - if database error
    • isMember

      public boolean isMember(Context context, String groupName) throws SQLException
      Description copied from interface: GroupService
      fast check to see if an eperson is a member called with eperson id. Does database lookup without instantiating all of the eperson objects and is thus a static method. This method uses context.getCurrentUser() as eperson whose membership should be checked.
      Specified by:
      isMember in interface GroupService
      Parameters:
      context - context
      groupName - the name of the group to check
      Returns:
      true or false
      Throws:
      SQLException - if database error
    • isMember

      public boolean isMember(Context context, EPerson eperson, String groupName) throws SQLException
      Description copied from interface: GroupService
      fast check to see if an eperson is a member called with eperson id. Does database lookup without instantiating all of the eperson objects and is thus a static method. The eperson whose membership should be checked must be defined as method attribute.
      Specified by:
      isMember in interface GroupService
      Parameters:
      context - context
      eperson - is this EPerson a member of the group?
      groupName - the name of the group to check
      Returns:
      true or false
      Throws:
      SQLException - if database error
    • allMemberGroups

      public List<Group> allMemberGroups(Context context, EPerson ePerson) throws SQLException
      Description copied from interface: GroupService
      Get all of the groups that an eperson is a member of.
      Specified by:
      allMemberGroups in interface GroupService
      Parameters:
      context - DSpace context
      ePerson - ePerson object
      Returns:
      list of Group objects
      Throws:
      SQLException - if database error
    • allMemberGroupsSet

      public Set<Group> allMemberGroupsSet(Context context, EPerson ePerson) throws SQLException
      Specified by:
      allMemberGroupsSet in interface GroupService
      Throws:
      SQLException
    • allMembers

      public List<EPerson> allMembers(Context c, Group g) throws SQLException
      Description copied from interface: GroupService
      Get all of the EPerson objects who are a member of the specified group, or a member of a subgroup of the specified group, etc.

      WARNING: This method may have bad performance for Groups with a very large number of members, as it will load all member EPerson objects into memory. Only use if you need access to *every* EPerson object at once.

      Specified by:
      allMembers in interface GroupService
      Parameters:
      c - The relevant DSpace Context.
      g - Group object
      Returns:
      List of EPerson objects
      Throws:
      SQLException - if error
    • countAllMembers

      public int countAllMembers(Context context, Group group) throws SQLException
      Description copied from interface: GroupService
      Count all of the EPerson objects who are a member of the specified group, or a member of a subgroup of the specified group, etc. In other words, this will return the size of "allMembers()" without having to load all EPerson objects into memory.
      Specified by:
      countAllMembers in interface GroupService
      Parameters:
      context - current DSpace context
      group - Group object
      Returns:
      count of EPerson object members
      Throws:
      SQLException - if error
    • find

      public Group find(Context context, UUID id) throws SQLException
      Description copied from interface: DSpaceObjectService
      Generic find for when the precise type of an Entity is not known
      Specified by:
      find in interface DSpaceObjectService<Group>
      Parameters:
      context - - the context
      id - - uuid within table of typed dspace objects
      Returns:
      the dspace object found, or null if it does not exist.
      Throws:
      SQLException - only upon failure accessing the database.
    • findByName

      public Group findByName(Context context, String name) throws SQLException
      Description copied from interface: GroupService
      Find the group by its name - assumes name is unique
      Specified by:
      findByName in interface GroupService
      Parameters:
      context - The relevant DSpace Context.
      name - Group name to search for
      Returns:
      the named Group, or null if not found
      Throws:
      SQLException - if error
    • findAll

      @Deprecated public List<Group> findAll(Context context, int sortField) throws SQLException
      Deprecated.
      DEPRECATED: Please use findAll(Context context, List<MetadataField> metadataSortFields) instead
      Specified by:
      findAll in interface GroupService
      Parameters:
      context - DSpace context
      sortField - sort field index
      Returns:
      List of all groups in the site
      Throws:
      SQLException - if error
    • findAll

      public List<Group> findAll(Context context, List<MetadataField> metadataSortFields) throws SQLException
      Specified by:
      findAll in interface GroupService
      Parameters:
      context - The relevant DSpace Context.
      metadataSortFields - metadata fields to sort by, leave empty to sort by Name
      Returns:
      List of all groups in the site
      Throws:
      SQLException - if error
    • findAll

      public List<Group> findAll(Context context, List<MetadataField> metadataSortFields, int pageSize, int offset) throws SQLException
      Description copied from interface: GroupService
      Finds all groups in the site
      Specified by:
      findAll in interface GroupService
      Parameters:
      context - The relevant DSpace Context.
      metadataSortFields - metadata fields to sort by, leave empty to sort by Name
      pageSize - how many results return
      offset - the position of the first result to return
      Returns:
      List of all groups in the site
      Throws:
      SQLException - if error
    • search

      public List<Group> search(Context context, String query) throws SQLException
      Description copied from interface: GroupService
      Find the Groups that match the query across both Group name and Group ID. This is an unpaginated search, which means it will load all matching groups into memory at once. This may provide POOR PERFORMANCE when a large number of groups are matched.
      Specified by:
      search in interface GroupService
      Parameters:
      context - DSpace context
      query - The search string used to search across group name or group ID
      Returns:
      List of matching Group objects
      Throws:
      SQLException - if error
    • search

      public List<Group> search(Context context, String query, int offset, int limit) throws SQLException
      Description copied from interface: GroupService
      Find the Groups that match the query across both Group name and Group ID. This method supports pagination, which provides better performance than the above non-paginated search() method.
      Specified by:
      search in interface GroupService
      Parameters:
      context - DSpace context
      query - The search string used to search across group name or group ID
      offset - Inclusive offset (the position of the first result to return)
      limit - Maximum number of matches returned
      Returns:
      List of matching Group objects
      Throws:
      SQLException - if error
    • searchResultCount

      public int searchResultCount(Context context, String query) throws SQLException
      Description copied from interface: GroupService
      Returns the total number of Groups returned by a specific query. Search is performed based on Group name and Group ID. May be used with search() above to support pagination of matching Groups.
      Specified by:
      searchResultCount in interface GroupService
      Parameters:
      context - DSpace context
      query - The search string used to search across group name or group ID
      Returns:
      the number of groups matching the query
      Throws:
      SQLException - if error
    • searchNonMembers

      public List<Group> searchNonMembers(Context context, String query, Group excludeParentGroup, int offset, int limit) throws SQLException
      Description copied from interface: GroupService
      Find the groups that match the search query which are NOT currently members (subgroups) of the given parentGroup
      Specified by:
      searchNonMembers in interface GroupService
      Parameters:
      context - DSpace context
      query - The search string used to search across group name or group ID
      excludeParentGroup - Parent group to exclude results from
      offset - Inclusive offset (the position of the first result to return)
      limit - Maximum number of matches returned
      Returns:
      List of matching Group objects
      Throws:
      SQLException - if error
    • searchNonMembersCount

      public int searchNonMembersCount(Context context, String query, Group excludeParentGroup) throws SQLException
      Description copied from interface: GroupService
      Returns the total number of groups that match the search query which are NOT currently members (subgroups) of the given parentGroup. Can be used with searchNonMembers() to support pagination.
      Specified by:
      searchNonMembersCount in interface GroupService
      Parameters:
      context - DSpace context
      query - The search string used to search across group name or group ID
      excludeParentGroup - Parent group to exclude results from
      Returns:
      the number of Groups matching the query
      Throws:
      SQLException - if error
    • delete

      public void delete(Context context, Group group) throws SQLException
      Specified by:
      delete in interface DSpaceObjectService<Group>
      Throws:
      SQLException
    • getSupportsTypeConstant

      public int getSupportsTypeConstant()
      Description copied from interface: DSpaceObjectService
      Returns the Constants which this service supports
      Specified by:
      getSupportsTypeConstant in interface DSpaceObjectLegacySupportService<Group>
      Specified by:
      getSupportsTypeConstant in interface DSpaceObjectService<Group>
      Returns:
      a org.dspace.core.Constants that represents a IndexableObject type
    • isEmpty

      public boolean isEmpty(Group group)
      Return true if group has no direct or indirect members
      Specified by:
      isEmpty in interface GroupService
      Parameters:
      group - DSpace group
      Returns:
      true or false
    • initDefaultGroupNames

      public void initDefaultGroupNames(Context context) throws SQLException, AuthorizeException
      Description copied from interface: GroupService
      Initializes the group names for anonymous and administrator, and marks them "permanent".
      Specified by:
      initDefaultGroupNames in interface GroupService
      Parameters:
      context - the DSpace context
      Throws:
      SQLException - database exception
      AuthorizeException - authorization error
    • getEmptyGroups

      public List<Group> getEmptyGroups(Context context) throws SQLException
      Get a list of groups with no members.
      Specified by:
      getEmptyGroups in interface GroupService
      Parameters:
      context - The relevant DSpace Context.
      Returns:
      list of groups with no members
      Throws:
      SQLException - An exception that provides information on a database access error or other errors.
    • update

      public void update(Context context, Group group) throws SQLException, AuthorizeException
      Update the group - writing out group object and EPerson list if necessary
      Specified by:
      update in interface DSpaceObjectService<Group>
      Overrides:
      update in class DSpaceObjectServiceImpl<Group>
      Parameters:
      context - The relevant DSpace Context.
      group - Group to update
      Throws:
      SQLException - An exception that provides information on a database access error or other errors.
      AuthorizeException - Exception indicating the current user of the context does not have permission to perform a particular action.
    • isEPersonInGroup

      protected boolean isEPersonInGroup(Context context, Group group, EPerson ePerson) throws SQLException
      Throws:
      SQLException
    • rethinkGroupCache

      protected void rethinkGroupCache(Context context, boolean flushQueries) throws SQLException
      Regenerate the group cache AKA the group2groupcache table in the database - meant to be called when a group is added or removed from another group
      Parameters:
      context - The relevant DSpace Context.
      flushQueries - flushQueries Flush all pending queries
      Throws:
      SQLException - An exception that provides information on a database access error or other errors.
    • getParentObject

      public DSpaceObject getParentObject(Context context, Group group) throws SQLException
      Description copied from interface: DSpaceObjectService
      Return the dspace object that "own" the current object in the hierarchy. Note that this method has a meaning slightly different from the getAdminObject because it is independent of the action but it is in a way related to it. It defines the "first" dspace object OTHER then the current one, where allowed ADMIN actions imply allowed ADMIN actions on the object self.
      Specified by:
      getParentObject in interface DSpaceObjectService<Group>
      Overrides:
      getParentObject in class DSpaceObjectServiceImpl<Group>
      Parameters:
      context - DSpace context
      group - DSpaceObject
      Returns:
      the dspace object that "own" the current object in the hierarchy
      Throws:
      SQLException - if database error
    • updateLastModified

      public void updateLastModified(Context context, Group dso)
      Specified by:
      updateLastModified in interface DSpaceObjectService<Group>
    • getChildren

      protected Set<UUID> getChildren(Map<UUID,Set<UUID>> parents, UUID parent)
      Used recursively to generate a map of ALL of the children of the given parent
      Parameters:
      parents - Map of parent,child relationships
      parent - the parent you're interested in
      Returns:
      Map whose keys are all of the children of a parent
    • findByIdOrLegacyId

      public Group findByIdOrLegacyId(Context context, String id) throws SQLException
      Specified by:
      findByIdOrLegacyId in interface DSpaceObjectLegacySupportService<Group>
      Throws:
      SQLException
    • findByLegacyId

      public Group findByLegacyId(Context context, int id) throws SQLException
      Description copied from interface: DSpaceObjectLegacySupportService
      Generic find for when the precise type of a DSO is not known, just the a pair of type number and database ID.
      Specified by:
      findByLegacyId in interface DSpaceObjectLegacySupportService<Group>
      Parameters:
      context - - the context
      id - - the legacy id within table of type'd objects
      Returns:
      the object found, or null if it does not exist.
      Throws:
      SQLException - only upon failure accessing the database.
    • countTotal

      public int countTotal(Context context) throws SQLException
      Description copied from interface: GroupService
      Count the total number of groups in DSpace
      Specified by:
      countTotal in interface GroupService
      Parameters:
      context - The DSpace context
      Returns:
      The total number of groups
      Throws:
      SQLException - database exception
    • findByMetadataField

      public List<Group> findByMetadataField(Context context, String searchValue, MetadataField metadataField) throws SQLException
      Description copied from interface: GroupService
      Look up groups based on their value for a certain metadata field (NOTE: name is not stored as metadata)
      Specified by:
      findByMetadataField in interface GroupService
      Parameters:
      context - The DSpace context
      searchValue - The value to match
      metadataField - The metadata field to search in
      Returns:
      The groups that have a matching value for specified metadata field
      Throws:
      SQLException - database exception
    • getName

      public String getName(Group dso)
      Description copied from interface: DSpaceObjectService
      Get a proper name for the object. This may return null. Name should be suitable for display in a user interface.
      Specified by:
      getName in interface DSpaceObjectService<Group>
      Overrides:
      getName in class DSpaceObjectServiceImpl<Group>
      Parameters:
      dso - DSpaceObject
      Returns:
      Name for the object, or null if it doesn't have one
    • findByParent

      public List<Group> findByParent(Context context, Group parent, int pageSize, int offset) throws SQLException
      Description copied from interface: GroupService
      Find all groups which are a member of the given Parent group
      Specified by:
      findByParent in interface GroupService
      Parameters:
      context - The relevant DSpace Context.
      parent - The parent Group to search on
      pageSize - how many results return
      offset - the position of the first result to return
      Returns:
      List of all groups which are members of the parent group
      Throws:
      SQLException - database exception if error
    • countByParent

      public int countByParent(Context context, Group parent) throws SQLException
      Description copied from interface: GroupService
      Return number of groups which are a member of the given Parent group. Can be used with findByParent() for pagination of all groups within a given Parent group.
      Specified by:
      countByParent in interface GroupService
      Parameters:
      context - The relevant DSpace Context.
      parent - The parent Group to search on
      Returns:
      number of groups which are members of the parent group
      Throws:
      SQLException - database exception if error