Class IdentifierManager

java.lang.Object
edu.ucsb.nceas.metacat.IdentifierManager

public class IdentifierManager extends Object
Manage the relationship between Metacat local identifiers (LocalIDs) that are codified as the (docid, rev) pair with globally unique string identifiers (GUIDs) that are opaque strings. This class provides methods to manage these identifiers, and to search for and look up LocalIDs based on their GUID and vice versa. IdentifierManager is a singleton.
Author:
Matthew Jones
  • Field Details

  • Method Details

    • getInstance

      public static IdentifierManager getInstance()
      Return the single instance of the manager after initializing it if it wasn't previously initialized.
      Returns:
      the single IdentifierManager instance
    • getSystemMetadata

      public org.dataone.service.types.v2.SystemMetadata getSystemMetadata(String guid) throws McdbDocNotFoundException
      return a hash of all of the info that is in the systemmetadata table
      Parameters:
      guid -
      Returns:
      Throws:
      McdbDocNotFoundException
    • getLatestRevForLocalId

      public int getLatestRevForLocalId(String localId) throws McdbDocNotFoundException
      return the newest rev for a given localId
      Parameters:
      localId -
      Returns:
      Throws:
      McdbDocNotFoundException
    • getLocalIdsWithNoSystemMetadata

      public List<String> getLocalIdsWithNoSystemMetadata(boolean includeRevisions, int serverLocation)
      return all local ids in the object store that do not have associated system metadata
    • getAllLocalIds

      public List<String> getAllLocalIds()
      return a listing of all local ids in the object store
      Returns:
      a list of all local ids in metacat
    • getAllSystemMetadataGUIDs

      public List<String> getAllSystemMetadataGUIDs()
      return a listing of all guids in the object store
      Returns:
      a list of all GUIDs in metacat
    • getAllPidsInChain

      public List<String> getAllPidsInChain(String sid) throws SQLException
      Get all pids in the series chain
      Parameters:
      sid - the id of the series chain
      Returns:
      a list of pid in the chain
      Throws:
      SQLException
    • getUpdatedSystemMetadataIds

      public List<String> getUpdatedSystemMetadataIds(Date since) throws Exception
      returns a list of system metadata-only guids since the given date
      Returns:
      a list of system ids in metacat that do not correspond to objects TODO: need to check which server they are on
      Throws:
      Exception
    • getLastModifiedDate

      public Date getLastModifiedDate() throws Exception
      returns a list of system metadata-only guids since the given date
      Returns:
      a list of system ids in metacat that do not correspond to objects TODO: need to check which server they are on
      Throws:
      Exception
    • identifierExists

      public boolean identifierExists(String guid) throws SQLException
      Determine if an identifier exists already, returning true if so. NOTE: looks in the identifier and system metadata table for a match (in that order) Can return true for both PIDs and SIDs.
      Parameters:
      guid - the global identifier to look up
      Returns:
      boolean true if the identifier exists
      Throws:
      SQLException
    • mappingExists

      public boolean mappingExists(String guid) throws SQLException
      Determine if an identifier mapping exists already, returning true if so.
      Parameters:
      guid - the global identifier to look up
      Returns:
      boolean true if the identifier exists
      Throws:
      SQLException
    • generateLocalId

      public String generateLocalId(String guid, int rev)
      Parameters:
      guid -
      rev -
      Returns:
    • generateLocalId

      public String generateLocalId(String guid, int rev, boolean isSystemMetadata)
      Given a global identifier (guid), create a suitable local identifier that follows Metacat's docid semantics and format (scope.id.rev), and create a mapping between these two identifiers. This effectively reserves both the global and the local identifier, as they will now be present in the identifier mapping table. REMOVED feature: If the incoming guid has the syntax of a Metacat docid (scope.id.rev), then simply use it. WHY: because "test.1.001" becomes "test.1.1" which is not correct for DataONE identifier use (those revision numbers are just chartacters and should not be interpreted)
      Parameters:
      guid - the global string identifier
      rev - the revision number to be used in the localId
      Returns:
      String containing the localId to be used for Metacat operations
    • getGUID

      public String getGUID(String docid, int rev) throws McdbDocNotFoundException
      given a local identifer, look up the guid. Throw McdbDocNotFoundException if the docid, rev is not found in the identifiers or systemmetadata tables
      Parameters:
      docid - the docid to look up
      rev - the revision of the docid to look up
      Returns:
      String containing the mapped guid
      Throws:
      McdbDocNotFoundException - if the docid, rev is not found
    • getGUIDs

      public List<String> getGUIDs(String formatId, String nodeId, String scheme)
      Get the list of identifiers which system metadata matches the given format id and original member node id and guid or series id start with the scheme (doi for example).
      Parameters:
      formatId - the format id of the identifier must match the given formatId.
      nodeId - the original member node of the identifier must match the given nodeId.
      scheme - the guid or series id must start with the given scheme (doi for exampe)
      Returns:
      the list of identifier string. An empty list will be returned if nothing was found.
    • getHeadPID

      public org.dataone.service.types.v1.Identifier getHeadPID(org.dataone.service.types.v1.Identifier sid) throws SQLException
      Get the pid of the head (current) version of objects match the specified sid. 1. locate all candidate chain-ends for S1: determined by: seriesId == S1 AND (obsoletedBy == null OR obsoletedBy.seriesId != S1) these are the type1 and type2 ends If obsoletedBy is missing, we generally consider it a type 2 end except: there is another object in the chain (has the same series id) that obsoletes the missing object. 2. if only 1 candidate chain-end, return it as the HEAD 3. otherwise return the one in the chain with the latest dateUploaded value. However, we find that dateUpload doesn't refect the obsoletes information (espically on the cn), so we will check osoletes information as well. https://redmine.dataone.org/issues/7624
      Parameters:
      sid - specified sid which should match.
      Returns:
      the pid of the head version. The null will be returned if there is no pid found.
      Throws:
      SQLException
    • systemMetadataSIDExists

      public boolean systemMetadataSIDExists(org.dataone.service.types.v1.Identifier sid) throws SQLException
      Check if the specified sid object exists on the serial id field on the system metadata table
      Parameters:
      sid -
      Returns:
      true if it exists; false otherwise.
      Throws:
      SQLException
    • systemMetadataSIDExists

      public boolean systemMetadataSIDExists(String sid) throws SQLException
      Check if the specified sid exists on the serial id field on the system metadata table
      Parameters:
      id -
      Returns:
      true if it exists; false otherwise.
      Throws:
      SQLException
    • systemMetadataPIDExists

      public boolean systemMetadataPIDExists(org.dataone.service.types.v1.Identifier pid) throws SQLException
      Determine if the specified identifier object exists or not.
      Parameters:
      pid - - the specified identifier
      Returns:
      true if it is exists.
      Throws:
      SQLException
      NullPointerException
    • systemMetadataPIDExists

      public boolean systemMetadataPIDExists(String guid) throws SQLException
      Throws:
      SQLException
    • updateMapping

      public void updateMapping(String guid, String localId)
      update a mapping
      Parameters:
      guid -
      localId -
    • getAccessPolicy

      public org.dataone.service.types.v1.AccessPolicy getAccessPolicy(String guid) throws McdbDocNotFoundException, AccessException
      Lookup access policy from Metacat
      Parameters:
      guid -
      Returns:
      Throws:
      McdbDocNotFoundException
      AccessException
    • convertPermission

      public List<org.dataone.service.types.v1.Permission> convertPermission(int permission)
    • getLocalId

      public String getLocalId(String guid) throws McdbDocNotFoundException, SQLException
      Lookup a localId given the GUID. If the identifier is not found, throw an exception.
      Parameters:
      guid - the global identifier to look up
      Returns:
      String containing the corresponding LocalId
      Throws:
      McdbDocNotFoundException - if the identifier is not found
      SQLException
    • querySystemMetadata

      public org.dataone.service.types.v1.ObjectList querySystemMetadata(Date startTime, Date endTime, org.dataone.service.types.v1.ObjectFormatIdentifier objectFormatId, org.dataone.service.types.v1.NodeReference nodeId, int start, int count, org.dataone.service.types.v1.Identifier identifier, boolean isSID) throws SQLException, edu.ucsb.nceas.utilities.PropertyNotFoundException, ServiceException
      query the systemmetadata table based on the given parameters
      Parameters:
      startTime -
      endTime -
      objectFormat -
      nodeId -
      start -
      count -
      Returns:
      ObjectList
      Throws:
      SQLException
      ServiceException
      edu.ucsb.nceas.utilities.PropertyNotFoundException
    • createMapping

      public void createMapping(String guid, String localId)
      Create a mapping between the dataone identifier and local docid in the identifier table
      Parameters:
      guid - the dataone identifier
      localId - the local docid
      Throws:
      SQLException
      AccessionNumberException
      NumberFormatException
    • createMapping

      public void createMapping(String guid, String localId, DBConnection dbConn) throws NumberFormatException, AccessionNumberException, SQLException
      Create a mapping between the dataone identifier and local docid in the identifier table
      Parameters:
      guid - the dataone identifier
      localId - the local metacat docid
      Throws:
      SQLException
      AccessionNumberException
      NumberFormatException
    • removeMapping

      public void removeMapping(String guid, String localId)
      remove a mapping in the identifier table
      Parameters:
      guid -
      localId -
    • getObjectFilePath

      public String getObjectFilePath(String localId, boolean isScienceMetadata) throws edu.ucsb.nceas.utilities.PropertyNotFoundException
      Get the the file path for the given object local id
      Parameters:
      localId -
      isScienceMetadata -
      Returns:
      Throws:
      edu.ucsb.nceas.utilities.PropertyNotFoundException
    • existsInXmlLRevisionTable

      public boolean existsInXmlLRevisionTable(String docid, int rev) throws SQLException
      IF the given localId exists on the xml_revisions table
      Parameters:
      localId -
      Returns:
      Throws:
      SQLException
    • existsInIdentifierTable

      public boolean existsInIdentifierTable(org.dataone.service.types.v1.Identifier pid) throws SQLException
      Determine if the given pid exists on the identifier table.
      Parameters:
      pid - must be a PID
      Returns:
      true if it exists; false otherwise.
      Throws:
      SQLException
    • getGUIDsByTimeRange

      public List<String> getGUIDsByTimeRange(Date start, Date end)
      Get the list of guids whose modification dates are in the range of the given start and end times.
      Parameters:
      start - the start time of the range
      end - the end time of the range
      Returns:
      list of guids whose modification dates are in the range