Package org.dspace.handle
Class HandleServiceImpl
- java.lang.Object
-
- org.dspace.handle.HandleServiceImpl
-
- All Implemented Interfaces:
HandleService
public class HandleServiceImpl extends Object implements HandleService
Interface to the CNRI Handle System .Currently, this class simply maps handles to local facilities; handles which are owned by other sites (including other DSpaces) are treated as non-existent.
- Version:
- $Revision$
- Author:
- Peter Breton
-
-
Field Summary
Fields Modifier and Type Field Description protected ConfigurationServiceconfigurationServiceprotected HandleDAOhandleDAOprotected SiteServicesiteService
-
Constructor Summary
Constructors Modifier Constructor Description protectedHandleServiceImpl()Public Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longcountHandlesByPrefix(Context context, String prefix)intcountTotal(Context context)StringcreateHandle(Context context, DSpaceObject dso)Creates a new handle in the database.StringcreateHandle(Context context, DSpaceObject dso, String suppliedHandle)Creates a handle entry, but with a handle supplied by the caller (new Handle not generated)StringcreateHandle(Context context, DSpaceObject dso, String suppliedHandle, boolean force)Creates a handle entry, but with a handle supplied by the caller (new Handle not generated)protected StringcreateId(Context context)Create/mint a new handle id.StringfindHandle(Context context, DSpaceObject dso)Return the handle for an Object, or null if the Object has no handle.protected HandlefindHandleInternal(Context context, String handle)Find the database row corresponding to handle.StringgetCanonicalForm(String handle)Transforms handle into a URI using http://hdl.handle.net if not overridden by the configuration property handle.canonical.prefix.StringgetCanonicalPrefix()Provides handle canonical prefix using http://hdl.handle.net if not overridden by the configuration property handle.canonical.prefix.List<String>getHandlesForPrefix(Context context, String prefix)Return all the handles which start with prefix.protected List<Handle>getInternalHandles(Context context, DSpaceObject dso)Return the handle for an Object, or null if the Object has no handle.StringgetPrefix()Get the configured Handle prefix string, or a defaultvoidmodifyHandleDSpaceObject(Context context, String handle, DSpaceObject newOwner)StringparseHandle(String identifier)Format a handle ~ - hdl:123456789/1 -> 123456789/1 - info:hdl/123456789/1 -> 123456789/1 - https://hdl.handle.net/123456789/1 -> 123456789/1DSpaceObjectresolveToObject(Context context, String handle)Return the object which handle maps to, or null.StringresolveToURL(Context context, String handle)Return the local URL for handle, or null if handle cannot be found.StringresolveUrlToHandle(Context context, String url)Try to detect a handle in a URL.voidunbindHandle(Context context, DSpaceObject dso)Removes binding of Handle to a DSpace object, while leaving the Handle in the table so it doesn't get reallocated.intupdateHandlesWithNewPrefix(Context context, String newPrefix, String oldPrefix)
-
-
-
Field Detail
-
handleDAO
@Autowired(required=true) protected HandleDAO handleDAO
-
configurationService
@Autowired(required=true) protected ConfigurationService configurationService
-
siteService
@Autowired protected SiteService siteService
-
-
Method Detail
-
resolveToURL
public String resolveToURL(Context context, String handle) throws SQLException
Description copied from interface:HandleServiceReturn the local URL for handle, or null if handle cannot be found. The returned URL is a (non-handle-based) location where a dissemination of the object referred to by handle can be obtained.- Specified by:
resolveToURLin interfaceHandleService- Parameters:
context- DSpace contexthandle- The handle- Returns:
- The local URL
- Throws:
SQLException- If a database error occurs
-
resolveUrlToHandle
public String resolveUrlToHandle(Context context, String url) throws SQLException
Description copied from interface:HandleServiceTry to detect a handle in a URL.- Specified by:
resolveUrlToHandlein interfaceHandleService- Parameters:
context- DSpace contexturl- The URL- Returns:
- The handle or null if the handle couldn't be extracted of a URL or if the extracted handle couldn't be found.
- Throws:
SQLException- If a database error occurs
-
getCanonicalPrefix
public String getCanonicalPrefix()
Description copied from interface:HandleServiceProvides handle canonical prefix using http://hdl.handle.net if not overridden by the configuration property handle.canonical.prefix. No attempt is made to verify that handle is in fact valid.- Specified by:
getCanonicalPrefixin interfaceHandleService- Returns:
- The canonical form
-
getCanonicalForm
public String getCanonicalForm(String handle)
Description copied from interface:HandleServiceTransforms handle into a URI using http://hdl.handle.net if not overridden by the configuration property handle.canonical.prefix. No attempt is made to verify that handle is in fact valid.- Specified by:
getCanonicalFormin interfaceHandleService- Parameters:
handle- The handle- Returns:
- The canonical form
-
createHandle
public String createHandle(Context context, DSpaceObject dso) throws SQLException
Description copied from interface:HandleServiceCreates a new handle in the database.- Specified by:
createHandlein interfaceHandleService- Parameters:
context- DSpace contextdso- The DSpaceObject to create a handle for- Returns:
- The newly created handle
- Throws:
SQLException- If a database error occurs
-
createHandle
public String createHandle(Context context, DSpaceObject dso, String suppliedHandle) throws SQLException, IllegalStateException
Description copied from interface:HandleServiceCreates a handle entry, but with a handle supplied by the caller (new Handle not generated)- Specified by:
createHandlein interfaceHandleService- Parameters:
context- DSpace contextdso- DSpaceObjectsuppliedHandle- existing handle value- Returns:
- the Handle
- Throws:
SQLException- An exception that provides information on a database access error or other errors.IllegalStateException- if specified handle is already in use by another object
-
createHandle
public String createHandle(Context context, DSpaceObject dso, String suppliedHandle, boolean force) throws SQLException, IllegalStateException
Description copied from interface:HandleServiceCreates a handle entry, but with a handle supplied by the caller (new Handle not generated)- Specified by:
createHandlein interfaceHandleService- Parameters:
context- DSpace contextdso- DSpaceObjectsuppliedHandle- existing handle valueforce- FIXME: currently unused- Returns:
- the Handle
- Throws:
SQLException- An exception that provides information on a database access error or other errors.IllegalStateException- if specified handle is already in use by another object
-
unbindHandle
public void unbindHandle(Context context, DSpaceObject dso) throws SQLException
Description copied from interface:HandleServiceRemoves binding of Handle to a DSpace object, while leaving the Handle in the table so it doesn't get reallocated. The AIP implementation also needs it there for foreign key references.- Specified by:
unbindHandlein interfaceHandleService- Parameters:
context- DSpace contextdso- DSpaceObject whose Handle to unbind.- Throws:
SQLException- An exception that provides information on a database access error or other errors.
-
resolveToObject
public DSpaceObject resolveToObject(Context context, String handle) throws IllegalStateException, SQLException
Description copied from interface:HandleServiceReturn the object which handle maps to, or null. This is the object itself, not a URL which points to it.- Specified by:
resolveToObjectin interfaceHandleService- Parameters:
context- DSpace contexthandle- The handle to resolve- Returns:
- The object which handle maps to, or null if handle is not mapped to any object.
- Throws:
IllegalStateException- If handle was found but is not bound to an objectSQLException- If a database error occurs
-
findHandle
public String findHandle(Context context, DSpaceObject dso) throws SQLException
Description copied from interface:HandleServiceReturn the handle for an Object, or null if the Object has no handle.- Specified by:
findHandlein interfaceHandleService- Parameters:
context- DSpace contextdso- The object to obtain a handle for- Returns:
- The handle for object, or null if the object has no handle.
- Throws:
SQLException- If a database error occurs
-
getHandlesForPrefix
public List<String> getHandlesForPrefix(Context context, String prefix) throws SQLException
Description copied from interface:HandleServiceReturn all the handles which start with prefix.- Specified by:
getHandlesForPrefixin interfaceHandleService- Parameters:
context- DSpace contextprefix- The handle prefix- Returns:
- A list of the handles starting with prefix. The list is guaranteed to be non-null. Each element of the list is a String.
- Throws:
SQLException- If a database error occurs
-
getPrefix
public String getPrefix()
Description copied from interface:HandleServiceGet the configured Handle prefix string, or a default- Specified by:
getPrefixin interfaceHandleService- Returns:
- configured prefix or "123456789"
-
countHandlesByPrefix
public long countHandlesByPrefix(Context context, String prefix) throws SQLException
- Specified by:
countHandlesByPrefixin interfaceHandleService- Throws:
SQLException
-
updateHandlesWithNewPrefix
public int updateHandlesWithNewPrefix(Context context, String newPrefix, String oldPrefix) throws SQLException
- Specified by:
updateHandlesWithNewPrefixin interfaceHandleService- Throws:
SQLException
-
modifyHandleDSpaceObject
public void modifyHandleDSpaceObject(Context context, String handle, DSpaceObject newOwner) throws SQLException
- Specified by:
modifyHandleDSpaceObjectin interfaceHandleService- Throws:
SQLException
-
getInternalHandles
protected List<Handle> getInternalHandles(Context context, DSpaceObject dso) throws SQLException
Return the handle for an Object, or null if the Object has no handle.- Parameters:
context- DSpace contextdso- DSpaceObject for which we require our handles- Returns:
- The handle for object, or null if the object has no handle.
- Throws:
SQLException- If a database error occurs
-
findHandleInternal
protected Handle findHandleInternal(Context context, String handle) throws SQLException
Find the database row corresponding to handle.- Parameters:
context- DSpace contexthandle- The handle to resolve- Returns:
- The database row corresponding to the handle
- Throws:
SQLException- If a database error occurs
-
createId
protected String createId(Context context) throws SQLException
Create/mint a new handle id.- Parameters:
context- DSpace Context- Returns:
- A new handle id
- Throws:
SQLException- If a database error occurs
-
countTotal
public int countTotal(Context context) throws SQLException
- Specified by:
countTotalin interfaceHandleService- Throws:
SQLException
-
parseHandle
public String parseHandle(String identifier)
Description copied from interface:HandleServiceFormat a handle ~ - hdl:123456789/1 -> 123456789/1 - info:hdl/123456789/1 -> 123456789/1 - https://hdl.handle.net/123456789/1 -> 123456789/1- Specified by:
parseHandlein interfaceHandleService- Returns:
-
-