Package edu.ucsb.nceas.metacat
Class MetacatHandler
java.lang.Object
edu.ucsb.nceas.metacat.MetacatHandler
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
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionGet the data object directoryGet the metadata object directoryprotected Path
initializeDir
(String path) Create a directory based on the given path if it is necessary.static InputStream
Read a document from metacat and return the InputStream.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) Register the dataone identifier into database (the xml_documents/revisions, identifier tables).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) Save the object into diskprotected Path
saveBytes
(InputStream object, String localId, org.dataone.service.types.v1.Checksum checksum, String docType, org.dataone.service.types.v1.Identifier pid) Save the bytes from a input stream into disk.protected void
sendNotSupportMessage
(javax.servlet.http.HttpServletResponse response) Send back the not-support messageprotected void
validateSciMeta
(byte[] object, org.dataone.service.types.v1.ObjectFormatIdentifier formatId) Validate a scientific metadata object.protected void
validateXmlSciMeta
(byte[] object, String formatId) Validate an XML object.
-
Constructor Details
-
MetacatHandler
public MetacatHandler()Default constructor.
-
-
Method Details
-
initializeDir
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
Get the metadata object directory- Returns:
- the metadata object directory
-
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 readdataType
- 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 identifierchangeModificationDate
- 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.UPDATEdocType
- the type of object - data (BIN) or metadataobject
- the input stream contains the content of the objectpreSys
- 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 objectlocalId
- the docid which serves as the file namechecksum
- checksum of the input stream from the system metadata declaration.docType
- the type of object. BIN means data; otherwise means metadatapid
- 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 identifieraction
- insert or updateconn
- the connection to dbuser
- the user who requests the actiondocType
- BIN for data objects; the format id for metadata objectsprePid
- 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
-