Class MetacatRestClient
java.lang.Object
edu.ucsb.nceas.metacat.client.rest.MetacatRestClient
- All Implemented Interfaces:
MetacatRest
-
Field Summary
Fields inherited from interface edu.ucsb.nceas.metacat.client.rest.MetacatRest
DELETE, FUNCTION_KEYWORD, FUNCTION_NAME_GETALLDOCS, FUNCTION_NAME_GETNEXTOBJ, FUNCTION_NAME_GETNEXTREV, FUNCTION_NAME_INSERT, FUNCTION_NAME_ISREGISTERED, FUNCTION_NAME_LOGIN, FUNCTION_NAME_LOGOUT, FUNCTION_NAME_UPDATE, GET, POST, PUT, RESOURCE_IDENTIFIER, RESOURCE_OBJECTS, RESOURCE_SESSION
-
Constructor Summary
ConstructorDescriptionMetacatRestClient
(String contextRootUrl) Constructor to create a new instance. -
Method Summary
Modifier and TypeMethodDescriptionAdds identifierIdauthenticatedGetObject
(String docid, String outFile) Read XML document from server session, accessed by docid, and returned as a Reader.authenticatedQuery
(Reader xmlQuery) Query (as an authenticated user) the metacat document store with the given Ecogrid-compatible query document and return the Ecogrid result set as a Reader.Create an XML document in the repository.deleteObject
(String docid) Delete an XML document in the repository.getAllDocids
(String scope) return a list of all docids that match a given scope.getNextObject
(String scope) Return the highest document id for a given scope.int
getNextRevision
(String identifierId) The method will return the latest revision in metacat server for a given document id.Read a public XML document , accessed by docid, and returned as a Reader.Get the session identifier for this session.boolean
isRegistered
(String identifierId) return true of the given docid is registered, false if notMethod used to log in to a metacat server through REST API.logout()
Method used to log out a metacat server.Query the metacat document store with the given Ecogrid-compatible query document and return the Ecogrid result set as a Reader.void
setContextRootUrl
(String contextRootUrl) When the MetacatFactory creates an instance it needs to set the MetacatUrl to which connections should be made.void
setSessionId
(String sessionId) Set the session identifier for this session.Update an XML document in the repository, replacing an existing document.
-
Constructor Details
-
MetacatRestClient
Constructor to create a new instance.
-
-
Method Details
-
login
public String login(String username, String password) throws MetacatAuthException, MetacatInaccessibleException Method used to log in to a metacat server through REST API. Implementations will need to cache a cookie value to make the session persistent. Each time a call is made to one of the other methods (e.g., read), the cookie will need to be passed back to the metacat server along with the request.- Specified by:
login
in interfaceMetacatRest
- Parameters:
username
- the username of the user, like an LDAP DNpassword
- the password for that user for authentication- Returns:
- the response string from metacat in XML format
- Throws:
MetacatAuthException
- when the username/password could not be authenticatedMetacatInaccessibleException
-
logout
Method used to log out a metacat server. The Metacat server will end the session when this call is invoked.- Specified by:
logout
in interfaceMetacatRest
- Returns:
- the response string from metacat in XML format
- Throws:
MetacatInaccessibleException
- when the metacat server can not be reached or does not respondMetacatException
-
getObject
public Reader getObject(String docid, String outFile) throws InsufficientKarmaException, MetacatInaccessibleException, DocumentNotFoundException, MetacatException Read a public XML document , accessed by docid, and returned as a Reader.- Specified by:
getObject
in interfaceMetacatRest
- Parameters:
docid
- the identifier of the document to be readoutputFile
- name of the file to be written to local (optional)- Returns:
- a Reader for accessing the document
- Throws:
InsufficientKarmaException
- when the user has insufficent rights for the operationMetacatInaccessibleException
- when the metacat server can not be reached or does not respondMetacatException
- when the metacat server generates another errorDocumentNotFoundException
-
authenticatedGetObject
public Reader authenticatedGetObject(String docid, String outFile) throws InsufficientKarmaException, MetacatInaccessibleException, DocumentNotFoundException, MetacatException Read XML document from server session, accessed by docid, and returned as a Reader.- Specified by:
authenticatedGetObject
in interfaceMetacatRest
- Parameters:
docid
- the identifier of the document to be readoutputFile
- name of the file to be written to local (optional)- Returns:
- a Reader for accessing the document
- Throws:
InsufficientKarmaException
- when the user has insufficent rights for the operationMetacatInaccessibleException
- when the metacat server can not be reached or does not respondMetacatException
- when the metacat server generates another errorDocumentNotFoundException
-
query
Query the metacat document store with the given Ecogrid-compatible query document and return the Ecogrid result set as a Reader.- Specified by:
query
in interfaceMetacatRest
- Parameters:
xmlQuery
- a Reader for accessing the XML version of the query- Returns:
- a Reader for accessing the result set
- Throws:
MetacatInaccessibleException
IOException
-
authenticatedQuery
Query (as an authenticated user) the metacat document store with the given Ecogrid-compatible query document and return the Ecogrid result set as a Reader.- Specified by:
authenticatedQuery
in interfaceMetacatRest
- Parameters:
xmlQuery
- a Reader for accessing the XML version of the query- Returns:
- a Reader for accessing the result set
- Throws:
MetacatInaccessibleException
IOException
-
create
public String create(String docid, Reader xmlDocument) throws InsufficientKarmaException, MetacatException, IOException, MetacatInaccessibleException Create an XML document in the repository.- Specified by:
create
in interfaceMetacatRest
- Parameters:
docid
- the docid to insert the documentxmlDocument
- a Reader for accessing the XML document to be insertedisInsert
- whether the operation is update or insert- Returns:
- the metacat response message
- Throws:
InsufficientKarmaException
- when the user has insufficent rights for the operationMetacatInaccessibleException
- when the metacat server can not be reached or does not respondMetacatException
- when the metacat server generates another errorIOException
- when there is an error reading the xml document
-
update
public String update(String docid, Reader xmlDocument) throws InsufficientKarmaException, MetacatException, IOException, MetacatInaccessibleException Update an XML document in the repository, replacing an existing document.- Specified by:
update
in interfaceMetacatRest
- Parameters:
docid
- the docid to insert the documentxmlDocument
- a Reader for accessing the XML document to be insertedisInsert
- whether the operation is update or insert- Returns:
- the metacat response message
- Throws:
InsufficientKarmaException
- when the user has insufficent rights for the operationMetacatInaccessibleException
- when the metacat server can not be reached or does not respondMetacatException
- when the metacat server generates another errorIOException
- when there is an error reading the xml document
-
deleteObject
public String deleteObject(String docid) throws InsufficientKarmaException, MetacatException, MetacatInaccessibleException Delete an XML document in the repository.- Specified by:
deleteObject
in interfaceMetacatRest
- Parameters:
docid
- the docid to delete- Returns:
- the metacat response message
- Throws:
InsufficientKarmaException
- when the user has insufficent rights for the operationMetacatInaccessibleException
- when the metacat server can not be reached or does not respondMetacatException
- when the metacat server generates another error
-
getNextObject
Return the highest document id for a given scope. This is used by clients to make it easier to determine the next free identifier in a sequence for a given scope.- Specified by:
getNextObject
in interfaceMetacatRest
- Parameters:
scope
- String the scope to use for looking up the latest id- Throws:
MetacatException
- when an error occurs
-
getNextRevision
The method will return the latest revision in metacat server for a given document id. If some error happens, this method will throw an exception.- Specified by:
getNextRevision
in interfaceMetacatRest
- Parameters:
identifierId
- String the given docid you want to use. the docid it self can have or haven't revision number- Throws:
MetacatException
-
getAllDocids
return a list of all docids that match a given scope. if scope is null return all docids registered in the system- Specified by:
getAllDocids
in interfaceMetacatRest
- Parameters:
scope
- String the scope to use to limit the docid query- Throws:
MetacatException
- when an error occurs
-
isRegistered
return true of the given docid is registered, false if not- Specified by:
isRegistered
in interfaceMetacatRest
- Parameters:
scope
- String the scope to use to limit the docid query- Throws:
MetacatException
- when an error occurs
-
addLSID
Adds identifierId- Specified by:
addLSID
in interfaceMetacatRest
- Parameters:
identifierId
- String the given docid you want to use.- Throws:
MetacatException
- when an error occurs
-
setContextRootUrl
Description copied from interface:MetacatRest
When the MetacatFactory creates an instance it needs to set the MetacatUrl to which connections should be made.- Specified by:
setContextRootUrl
in interfaceMetacatRest
-
getSessionId
Description copied from interface:MetacatRest
Get the session identifier for this session.- Specified by:
getSessionId
in interfaceMetacatRest
-
setSessionId
Description copied from interface:MetacatRest
Set the session identifier for this session. This identifier was previously established with a call to login. To continue to use the same session, set the session id before making a call to one of the metacat access methods (e.g., read, query, insert, etc.).- Specified by:
setSessionId
in interfaceMetacatRest
-