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
ConstructorsConstructorDescriptionMetacatRestClient(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.intgetNextRevision(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.booleanisRegistered(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.voidsetContextRootUrl(String contextRootUrl) When the MetacatFactory creates an instance it needs to set the MetacatUrl to which connections should be made.voidsetSessionId(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:
loginin 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:
logoutin 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:
getObjectin 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:
authenticatedGetObjectin 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:
queryin interfaceMetacatRest- Parameters:
xmlQuery- a Reader for accessing the XML version of the query- Returns:
- a Reader for accessing the result set
- Throws:
MetacatInaccessibleExceptionIOException
-
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:
authenticatedQueryin interfaceMetacatRest- Parameters:
xmlQuery- a Reader for accessing the XML version of the query- Returns:
- a Reader for accessing the result set
- Throws:
MetacatInaccessibleExceptionIOException
-
create
public String create(String docid, Reader xmlDocument) throws InsufficientKarmaException, MetacatException, IOException, MetacatInaccessibleException Create an XML document in the repository.- Specified by:
createin 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:
updatein 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:
deleteObjectin 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:
getNextObjectin 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:
getNextRevisionin 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:
getAllDocidsin 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:
isRegisteredin interfaceMetacatRest- Parameters:
scope- String the scope to use to limit the docid query- Throws:
MetacatException- when an error occurs
-
addLSID
Adds identifierId- Specified by:
addLSIDin interfaceMetacatRest- Parameters:
identifierId- String the given docid you want to use.- Throws:
MetacatException- when an error occurs
-
setContextRootUrl
Description copied from interface:MetacatRestWhen the MetacatFactory creates an instance it needs to set the MetacatUrl to which connections should be made.- Specified by:
setContextRootUrlin interfaceMetacatRest
-
getSessionId
Description copied from interface:MetacatRestGet the session identifier for this session.- Specified by:
getSessionIdin interfaceMetacatRest
-
setSessionId
Description copied from interface:MetacatRestSet 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:
setSessionIdin interfaceMetacatRest
-