Class EPersonServiceImpl

All Implemented Interfaces:
DSpaceObjectLegacySupportService<EPerson>, DSpaceObjectService<EPerson>, EPersonService

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

  • Constructor Details

    • EPersonServiceImpl

      protected EPersonServiceImpl()
  • Method Details

    • find

      public EPerson 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<EPerson>
      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.
    • getSystemEPerson

      public EPerson getSystemEPerson(Context c) throws SQLException
      Create a fake EPerson which can receive email. Its address will be the value of "mail.admin", or "postmaster" if all else fails.
      Specified by:
      getSystemEPerson in interface EPersonService
      Parameters:
      c -
      Returns:
      Throws:
      SQLException
    • findByIdOrLegacyId

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

      public EPerson findByLegacyId(Context context, int legacyId) 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<EPerson>
      Parameters:
      context - - the context
      legacyId - - 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.
    • findByEmail

      public EPerson findByEmail(Context context, String email) throws SQLException
      Description copied from interface: EPersonService
      Find the eperson by their email address.
      Specified by:
      findByEmail in interface EPersonService
      Parameters:
      context - The relevant DSpace Context.
      email - EPerson's email to search by
      Returns:
      EPerson, or null if none such exists.
      Throws:
      SQLException - An exception that provides information on a database access error or other errors.
    • findByNetid

      public EPerson findByNetid(Context context, String netId) throws SQLException
      Description copied from interface: EPersonService
      Find the eperson by their netid.
      Specified by:
      findByNetid in interface EPersonService
      Parameters:
      context - The relevant DSpace Context.
      netId - Network ID
      Returns:
      corresponding EPerson, or null
      Throws:
      SQLException - An exception that provides information on a database access error or other errors.
    • search

      public List<EPerson> search(Context context, String query) throws SQLException
      Description copied from interface: EPersonService
      Find the epeople that match the search query across firstname, lastname or email.
      Specified by:
      search in interface EPersonService
      Parameters:
      context - The relevant DSpace Context.
      query - The search string
      Returns:
      array of EPerson objects
      Throws:
      SQLException - An exception that provides information on a database access error or other errors.
    • search

      public List<EPerson> search(Context context, String query, int offset, int limit) throws SQLException
      Description copied from interface: EPersonService
      Find the epeople that match the search query across firstname, lastname or email. This method also allows offsets and limits for pagination purposes.
      Specified by:
      search in interface EPersonService
      Parameters:
      context - The relevant DSpace Context.
      query - The search string
      offset - Inclusive offset (the position of the first result to return)
      limit - Maximum number of matches returned
      Returns:
      List of matching EPerson objects
      Throws:
      SQLException - An exception that provides information on a database access error or other errors.
    • searchResultCount

      public int searchResultCount(Context context, String query) throws SQLException
      Description copied from interface: EPersonService
      Returns the total number of epeople returned by a specific query, without the overhead of creating the EPerson objects to store the results.
      Specified by:
      searchResultCount in interface EPersonService
      Parameters:
      context - The relevant DSpace Context.
      query - The search string
      Returns:
      the number of epeople matching the query
      Throws:
      SQLException - An exception that provides information on a database access error or other errors.
    • searchNonMembers

      public List<EPerson> searchNonMembers(Context context, String query, Group excludeGroup, int offset, int limit) throws SQLException
      Description copied from interface: EPersonService
      Find the EPersons that match the search query which are NOT currently members of the given Group. The search query is run against firstname, lastname or email.
      Specified by:
      searchNonMembers in interface EPersonService
      Parameters:
      context - DSpace context
      query - The search string
      excludeGroup - Group to exclude results from. Members of this group will never be returned.
      offset - Inclusive offset (the position of the first result to return)
      limit - Maximum number of matches returned
      Returns:
      List of matching EPerson objects
      Throws:
      SQLException - if error
    • searchNonMembersCount

      public int searchNonMembersCount(Context context, String query, Group excludeGroup) throws SQLException
      Description copied from interface: EPersonService
      Returns the total number of EPersons that match the search query which are NOT currently members of the given Group. The search query is run against firstname, lastname or email. Can be used with searchNonMembers() to support pagination
      Specified by:
      searchNonMembersCount in interface EPersonService
      Parameters:
      context - DSpace context
      query - The search string
      excludeGroup - Group to exclude results from. Members of this group will never be returned.
      Returns:
      List of matching EPerson objects
      Throws:
      SQLException - if error
    • findAll

      public List<EPerson> findAll(Context context, int sortField) throws SQLException
      Description copied from interface: EPersonService
      Find all the EPersons in a specific order by field. The sortable fields are:
      • ID
      • LASTNAME
      • EMAIL
      • NETID
      Specified by:
      findAll in interface EPersonService
      Parameters:
      context - The relevant DSpace Context.
      sortField - which field to sort EPersons by
      Returns:
      list of EPerson objects
      Throws:
      SQLException - An exception that provides information on a database access error or other errors.
    • findAll

      public List<EPerson> findAll(Context context, int sortField, int pageSize, int offset) throws SQLException
      Description copied from interface: EPersonService
      Find all the EPersons in a specific order by field. The sortable fields are:
      • ID
      • LASTNAME
      • EMAIL
      • NETID
      Specified by:
      findAll in interface EPersonService
      Parameters:
      context - The relevant DSpace Context.
      sortField - which field to sort EPersons by
      pageSize - how many results return
      offset - the position of the first result to return
      Returns:
      list of EPerson objects
      Throws:
      SQLException - An exception that provides information on a database access error or other errors.
    • create

      public EPerson create(Context context) throws SQLException, AuthorizeException
      Description copied from interface: EPersonService
      Create a new eperson
      Specified by:
      create in interface EPersonService
      Parameters:
      context - The relevant DSpace Context.
      Returns:
      the created EPerson
      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.
    • delete

      public void delete(Context context, EPerson ePerson) throws SQLException, AuthorizeException
      Specified by:
      delete in interface DSpaceObjectService<EPerson>
      Throws:
      SQLException
      AuthorizeException
    • delete

      public void delete(Context context, EPerson ePerson, boolean cascade) throws SQLException, AuthorizeException, IOException, EPersonDeletionException
      Deletes an EPerson. The argument cascade defines whether all references on an EPerson should be deleted as well (by either deleting the referencing object - e.g. WorkspaceItem, ResourcePolicy - or by setting the foreign key null - e.g. archived Items). If cascade is set to false and the EPerson is referenced somewhere, this leads to an AuthorizeException. EPersons may be referenced by Items, ResourcePolicies and workflow tasks.
      Parameters:
      context - DSpace context
      ePerson - The EPerson to delete.
      cascade - Whether to delete references on the EPerson (cascade = true) or to abort the deletion (cascade = false) if the EPerson is referenced within DSpace.
      Throws:
      SQLException
      AuthorizeException
      IOException
      EPersonDeletionException
    • getSupportsTypeConstant

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

      public void setPassword(EPerson ePerson, String password)
      Description copied from interface: EPersonService
      Set the EPerson's password.
      Specified by:
      setPassword in interface EPersonService
      Parameters:
      ePerson - EPerson whose password we want to set.
      password - the new password.
    • setPasswordHash

      public void setPasswordHash(EPerson ePerson, PasswordHash password)
      Description copied from interface: EPersonService
      Set the EPerson's password hash.
      Specified by:
      setPasswordHash in interface EPersonService
      Parameters:
      ePerson - EPerson whose password hash we want to set.
      password - hashed password, or null to set row data to NULL.
    • getPasswordHash

      public PasswordHash getPasswordHash(EPerson ePerson)
      Description copied from interface: EPersonService
      Return the EPerson's password hash.
      Specified by:
      getPasswordHash in interface EPersonService
      Parameters:
      ePerson - EPerson whose password hash we want to get.
      Returns:
      hash of the password, or null on failure (such as no password).
    • checkPassword

      public boolean checkPassword(Context context, EPerson ePerson, String attempt)
      Description copied from interface: EPersonService
      Check EPerson's password. Side effect: original unsalted MD5 hashes are converted using the current algorithm.
      Specified by:
      checkPassword in interface EPersonService
      Parameters:
      context - The relevant DSpace Context.
      ePerson - EPerson whose password we want to check
      attempt - the password attempt
      Returns:
      boolean successful/unsuccessful
    • update

      public void update(Context context, EPerson ePerson) throws SQLException, AuthorizeException
      Specified by:
      update in interface DSpaceObjectService<EPerson>
      Overrides:
      update in class DSpaceObjectServiceImpl<EPerson>
      Throws:
      SQLException
      AuthorizeException
    • getDeleteConstraints

      public List<String> getDeleteConstraints(Context context, EPerson ePerson) throws SQLException
      Description copied from interface: EPersonService
      Check for presence of EPerson in tables that have constraints on EPersons. Called by delete() to determine whether the eperson can actually be deleted. An EPerson cannot be deleted if it exists in the item, resourcepolicy or workflow-related tables.
      Specified by:
      getDeleteConstraints in interface EPersonService
      Parameters:
      context - The relevant DSpace Context.
      ePerson - EPerson to find
      Returns:
      List of tables that contain a reference to the eperson.
      Throws:
      SQLException - An exception that provides information on a database access error or other errors.
    • findByGroups

      public List<EPerson> findByGroups(Context c, Set<Group> groups) throws SQLException
      Description copied from interface: EPersonService
      Retrieve all EPerson accounts which belong to at least one of the specified groups.

      WARNING: This method may have bad performance issues for Groups with a very large number of members, as it will load all member EPerson objects into memory.

      For better performance, use the paginated version of this method.

      Specified by:
      findByGroups in interface EPersonService
      Parameters:
      c - The relevant DSpace Context.
      groups - set of eperson groups
      Returns:
      a list of epeople
      Throws:
      SQLException - An exception that provides information on a database access error or other errors.
    • findByGroups

      public List<EPerson> findByGroups(Context c, Set<Group> groups, int pageSize, int offset) throws SQLException
      Description copied from interface: EPersonService
      Retrieve all EPerson accounts which belong to at least one of the specified groups, in a paginated fashion.
      Specified by:
      findByGroups in interface EPersonService
      Parameters:
      c - The relevant DSpace Context.
      groups - Set of group(s) to check membership in
      pageSize - number of EPerson objects to load at one time. Set to <=0 to disable pagination
      offset - number of page to load (starting with 1). Set to <=0 to disable pagination
      Returns:
      a list of epeople
      Throws:
      SQLException - An exception that provides information on a database access error or other errors.
    • countByGroups

      public int countByGroups(Context c, Set<Group> groups) throws SQLException
      Description copied from interface: EPersonService
      Count all EPerson accounts which belong to at least one of the specified groups. This provides the total number of results to expect from corresponding findByGroups() for pagination purposes.
      Specified by:
      countByGroups in interface EPersonService
      Parameters:
      c - The relevant DSpace Context.
      groups - Set of group(s) to check membership in
      Returns:
      total number of (unique) EPersons who are a member of one or more groups.
      Throws:
      SQLException - An exception that provides information on a database access error or other errors.
    • findEPeopleWithSubscription

      public List<EPerson> findEPeopleWithSubscription(Context context) throws SQLException
      Description copied from interface: EPersonService
      Retrieve all accounts which are subscribed to receive information about new items.
      Specified by:
      findEPeopleWithSubscription in interface EPersonService
      Parameters:
      context - The relevant DSpace Context.
      Returns:
      a list of epeople
      Throws:
      SQLException - An exception that provides information on a database access error or other errors.
    • updateLastModified

      public void updateLastModified(Context context, EPerson dso) throws SQLException
      Specified by:
      updateLastModified in interface DSpaceObjectService<EPerson>
      Throws:
      SQLException
    • getMetadata

      public String getMetadata(EPerson dso, String field)
      Description copied from interface: DSpaceObjectService
      Get the value of a metadata field
      Specified by:
      getMetadata in interface DSpaceObjectService<EPerson>
      Overrides:
      getMetadata in class DSpaceObjectServiceImpl<EPerson>
      Parameters:
      dso - DSpaceObject
      field - the name of the metadata field to get
      Returns:
      the value of the metadata field (or null if the column is an SQL NULL)
    • findUnsalted

      public List<EPerson> findUnsalted(Context context) throws SQLException
      Description copied from interface: EPersonService
      Retrieve all accounts which have a password but do not have a digest algorithm
      Specified by:
      findUnsalted in interface EPersonService
      Parameters:
      context - The relevant DSpace Context.
      Returns:
      a list of epeople
      Throws:
      SQLException - An exception that provides information on a database access error or other errors.
    • findNotActiveSince

      public List<EPerson> findNotActiveSince(Context context, Instant date) throws SQLException
      Description copied from interface: EPersonService
      Retrieve all accounts which have not logged in since the specified date
      Specified by:
      findNotActiveSince in interface EPersonService
      Parameters:
      context - The relevant DSpace Context.
      date - from which date
      Returns:
      a list of epeople
      Throws:
      SQLException - An exception that provides information on a database access error or other errors.
    • countTotal

      public int countTotal(Context context) throws SQLException
      Description copied from interface: EPersonService
      Count all accounts.
      Specified by:
      countTotal in interface EPersonService
      Parameters:
      context - The relevant DSpace Context.
      Returns:
      the total number of epeople
      Throws:
      SQLException - An exception that provides information on a database access error or other errors.
    • findByProfileItem

      public EPerson findByProfileItem(Context context, Item profile) throws SQLException
      Description copied from interface: EPersonService
      Find the EPerson related to the given profile item. If the given item is not a profile item, null is returned.
      Specified by:
      findByProfileItem in interface EPersonService
      Parameters:
      context - The relevant DSpace Context.
      profile - the profile item to search for
      Returns:
      the EPerson, if any
      Throws:
      SQLException - An exception that provides information on a database access error or other errors.
    • getName

      public String getName(EPerson 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<EPerson>
      Overrides:
      getName in class DSpaceObjectServiceImpl<EPerson>
      Parameters:
      dso - DSpaceObject
      Returns:
      Name for the object, or null if it doesn't have one