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 TypeMethodDescriptionstatic InputStream
Read a document from metacat and return the InputStream.static InputStream
read
(org.dataone.service.types.v1.Identifier pid) Read the object input stream for a given pidprotected 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 void
sendNotSupportMessage
(javax.servlet.http.HttpServletResponse response) Send back the not-support messageprotected void
validateSciMeta
(org.dataone.service.types.v1.Identifier pid, org.dataone.service.types.v1.ObjectFormatIdentifier formatId) Validate a scientific metadata object.protected void
validateXmlSciMeta
(org.dataone.service.types.v1.Identifier pid, String formatId) Validate an XML object.
-
Constructor Details
-
MetacatHandler
public MetacatHandler()Default constructor.
-
-
Method Details
-
sendNotSupportMessage
protected void sendNotSupportMessage(javax.servlet.http.HttpServletResponse response) throws IOException Send back the not-support message- Parameters:
response
-- Throws:
IOException
-
read
public static InputStream read(String localId, String dataType) throws edu.ucsb.nceas.utilities.ParseLSIDException, edu.ucsb.nceas.utilities.PropertyNotFoundException, McdbDocNotFoundException, SQLException, ClassNotFoundException, IOException, IllegalArgumentException, NoSuchAlgorithmException, org.dataone.service.exceptions.ServiceFailure 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
McdbDocNotFoundException
SQLException
ClassNotFoundException
IOException
org.dataone.service.exceptions.ServiceFailure
NoSuchAlgorithmException
IllegalArgumentException
-
read
public static InputStream read(org.dataone.service.types.v1.Identifier pid) throws IllegalArgumentException, NoSuchAlgorithmException, org.dataone.service.exceptions.ServiceFailure, IOException, McdbDocNotFoundException Read the object input stream for a given pid- Parameters:
pid
- the pid which will be read- Returns:
- the input stream representation of the object
- Throws:
IllegalArgumentException
NoSuchAlgorithmException
org.dataone.service.exceptions.ServiceFailure
IOException
McdbDocNotFoundException
-
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, IllegalArgumentException, NoSuchAlgorithmException, McdbException, InvocationTargetException, IllegalAccessException 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
NoSuchAlgorithmException
IllegalArgumentException
McdbException
InvocationTargetException
IllegalAccessException
-
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(org.dataone.service.types.v1.Identifier pid, org.dataone.service.types.v1.ObjectFormatIdentifier formatId) throws org.dataone.service.exceptions.InvalidRequest, org.dataone.service.exceptions.ServiceFailure, IOException, IllegalArgumentException, NoSuchAlgorithmException, McdbException Validate a scientific metadata object. It will throw an InvalidRequest if it is invalid.- Parameters:
pid
- the identifier of the object which will be validate. The identifier can be used to get the content of the object.formatId
- format id of the object- Throws:
org.dataone.service.exceptions.InvalidRequest
org.dataone.service.exceptions.ServiceFailure
ServiceException
edu.ucsb.nceas.utilities.PropertyNotFoundException
IOException
NoSuchAlgorithmException
IllegalArgumentException
McdbException
SAXException
MetacatException
-
validateXmlSciMeta
protected void validateXmlSciMeta(org.dataone.service.types.v1.Identifier pid, String formatId) throws IOException, org.dataone.service.exceptions.ServiceFailure, org.dataone.service.exceptions.InvalidRequest, IllegalArgumentException, NoSuchAlgorithmException, McdbException Validate an XML object. If it is not valid, an InvalidRequest will be thrown.- Parameters:
pid
- the identifier of the object which will be validate. The identifier can be used to get the content of the object.formatId
- format id of the object- Throws:
IOException
org.dataone.service.exceptions.ServiceFailure
org.dataone.service.exceptions.InvalidRequest
NoSuchAlgorithmException
IllegalArgumentException
McdbException
-