Class MetacatHandler

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

public class MetacatHandler extends Object
General entry point for the Metacat server which is called from various mechanisms such as the standard MetacatServlet class and the various web service servlets such as RestServlet class. All application logic should be encapsulated in this class, and the calling classes should only contain parameter marshaling and unmarshalling code, delegating all else to this MetacatHandler instance.
Author:
Matthew Jones
  • Constructor Details

    • MetacatHandler

      public MetacatHandler()
      Default constructor.
  • Method Details

    • initializeDir

      protected Path initializeDir(String path)
      Create a directory based on the given path if it is necessary. If Metacat can't read/write/exectue an exiting directory or create a new directory, null will be return. The return value is an indicator if we can use the given path as the storage path.
      Parameters:
      path - the path of the directory
      Returns:
      the path of the created directory or existing directory with proper permissions. Return null if bad things happen.
    • sendNotSupportMessage

      protected void sendNotSupportMessage(javax.servlet.http.HttpServletResponse response) throws IOException
      Send back the not-support message
      Parameters:
      response -
      Throws:
      IOException
    • getMetadataDir

      public String getMetadataDir()
      Get the metadata object directory
      Returns:
      the metadata object directory
    • getDataDir

      public String getDataDir()
      Get the data object directory
      Returns:
      the data object directory
    • read

      public static InputStream read(String localId, String dataType) throws edu.ucsb.nceas.utilities.ParseLSIDException, edu.ucsb.nceas.utilities.PropertyNotFoundException, McdbException, SQLException, ClassNotFoundException, IOException
      Read a document from metacat and return the InputStream.
      Parameters:
      localId - the metacat docid to read
      dataType - the type of the object associated with docid
      Returns:
      objectStream the document as an InputStream
      Throws:
      InsufficientKarmaException
      edu.ucsb.nceas.utilities.ParseLSIDException
      edu.ucsb.nceas.utilities.PropertyNotFoundException
      McdbException
      SQLException
      ClassNotFoundException
      IOException
    • save

      public String save(org.dataone.service.types.v2.SystemMetadata sysmeta, boolean changeModificationDate, MetacatHandler.Action action, String docType, InputStream object, org.dataone.service.types.v2.SystemMetadata preSys, String user) throws org.dataone.service.exceptions.InvalidRequest, org.dataone.service.exceptions.ServiceFailure, org.dataone.service.exceptions.InvalidSystemMetadata, IOException
      Save the object into disk
      Parameters:
      sysmeta - the system metadata of the object, which contains the identifier
      changeModificationDate - if Metacat needs to update the modification date of the system metadata when Metacat stores it.
      action - the action of the request: Action.INSERT (new) or Action.UPDATE
      docType - the type of object - data (BIN) or metadata
      object - the input stream contains the content of the object
      preSys - the system metadata of the obsoleted object in the update action. It will be ignored in the insert action.
      user - the user initializing the request
      Returns:
      the local Metacat docid for this object. It also serves as its file name.
      Throws:
      org.dataone.service.exceptions.InvalidRequest
      org.dataone.service.exceptions.ServiceFailure
      org.dataone.service.exceptions.InvalidSystemMetadata
      IOException
    • saveBytes

      protected Path saveBytes(InputStream object, String localId, org.dataone.service.types.v1.Checksum checksum, String docType, org.dataone.service.types.v1.Identifier pid) throws org.dataone.service.exceptions.ServiceFailure, org.dataone.service.exceptions.InvalidSystemMetadata, org.dataone.service.exceptions.InvalidRequest
      Save the bytes from a input stream into disk.
      Parameters:
      object - the input stream of the object
      localId - the docid which serves as the file name
      checksum - checksum of the input stream from the system metadata declaration.
      docType - the type of object. BIN means data; otherwise means metadata
      pid - the identifier of object. It is only used for debug information.
      Returns:
      the file which has the input stream content
      Throws:
      org.dataone.service.exceptions.ServiceFailure
      org.dataone.service.exceptions.InvalidSystemMetadata
      org.dataone.service.exceptions.InvalidRequest
    • registerToDB

      protected String registerToDB(org.dataone.service.types.v1.Identifier pid, MetacatHandler.Action action, DBConnection conn, String user, String docType, org.dataone.service.types.v1.Identifier prePid) throws org.dataone.service.exceptions.ServiceFailure, org.dataone.service.exceptions.InvalidRequest
      Register the dataone identifier into database (the xml_documents/revisions, identifier tables). It also generate a local Metacat doc id.
      Parameters:
      pid - the dataone identifier
      action - insert or update
      conn - the connection to db
      user - the user who requests the action
      docType - BIN for data objects; the format id for metadata objects
      prePid - the old identifier which will be updated. If this is an update action, you should specify it. For the insert action, it is ignored and can be null.
      Returns:
      the generated Metacat local docid
      Throws:
      org.dataone.service.exceptions.ServiceFailure
      org.dataone.service.exceptions.InvalidRequest
    • validateSciMeta

      protected void validateSciMeta(byte[] object, org.dataone.service.types.v1.ObjectFormatIdentifier formatId) throws org.dataone.service.exceptions.InvalidRequest, org.dataone.service.exceptions.ServiceFailure, IOException
      Validate a scientific metadata object. It will throw an InvalidRequest if it is invalid.
      Parameters:
      object - the content of the object. This is a byte array and so far it has not caused the memory issue. In 3.1.0 release, it will be replaced.
      formatId - format id of the object
      Throws:
      org.dataone.service.exceptions.InvalidRequest
      org.dataone.service.exceptions.ServiceFailure
      ServiceException
      edu.ucsb.nceas.utilities.PropertyNotFoundException
      IOException
      SAXException
      MetacatException
    • validateXmlSciMeta

      protected void validateXmlSciMeta(byte[] object, String formatId) throws IOException, org.dataone.service.exceptions.ServiceFailure, org.dataone.service.exceptions.InvalidRequest
      Validate an XML object. If it is not valid, an InvalidRequest will be thrown.
      Parameters:
      object - the content of the object. This is a byte array and so far it has not caused the memory issue. In 3.1.0 release, it will be replaced.
      formatId - format id of the object
      Throws:
      IOException
      org.dataone.service.exceptions.ServiceFailure
      org.dataone.service.exceptions.InvalidRequest