1 |
5211
|
jones
|
/**
|
2 |
|
|
* '$RCSfile$'
|
3 |
|
|
* Copyright: 2000 Regents of the University of California and the
|
4 |
|
|
* National Center for Ecological Analysis and Synthesis
|
5 |
|
|
*
|
6 |
|
|
* '$Author: Serhan AKIN $'
|
7 |
|
|
* '$Date: 2009-07-15 10:54:27 +0300 $'
|
8 |
|
|
*
|
9 |
|
|
* This program is free software; you can redistribute it and/or modify
|
10 |
|
|
* it under the terms of the GNU General Public License as published by
|
11 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
12 |
|
|
* (at your option) any later version.
|
13 |
|
|
*
|
14 |
|
|
* This program is distributed in the hope that it will be useful,
|
15 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
|
|
* GNU General Public License for more details.
|
18 |
|
|
*
|
19 |
|
|
* You should have received a copy of the GNU General Public License
|
20 |
|
|
* along with this program; if not, write to the Free Software
|
21 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
22 |
|
|
*/
|
23 |
|
|
|
24 |
|
|
package edu.ucsb.nceas.metacat.client.rest;
|
25 |
|
|
|
26 |
|
|
import java.io.IOException;
|
27 |
|
|
import java.io.Reader;
|
28 |
|
|
import java.util.Vector;
|
29 |
|
|
|
30 |
|
|
import edu.ucsb.nceas.metacat.client.DocumentNotFoundException;
|
31 |
|
|
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException;
|
32 |
|
|
import edu.ucsb.nceas.metacat.client.MetacatAuthException;
|
33 |
|
|
import edu.ucsb.nceas.metacat.client.MetacatException;
|
34 |
|
|
import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException;
|
35 |
|
|
|
36 |
|
|
/**
|
37 |
|
|
* This interface provides methods for initializing and logging in to a
|
38 |
|
|
* Metacat REST API, and then querying, reading, transforming, inserting,
|
39 |
|
|
* updating and deleting documents from that server.
|
40 |
|
|
*/
|
41 |
|
|
public interface MetacatRest
|
42 |
|
|
{
|
43 |
|
|
/** HTTP Verb GET*/
|
44 |
|
|
public static final String GET = "GET";
|
45 |
|
|
/** HTTP Verb POST*/
|
46 |
|
|
public static final String POST = "POST";
|
47 |
|
|
/** HTTP Verb PUT*/
|
48 |
|
|
public static final String PUT = "PUT";
|
49 |
|
|
/** HTTP Verb DELETE*/
|
50 |
|
|
public static final String DELETE = "DELETE";
|
51 |
|
|
|
52 |
|
|
/*
|
53 |
|
|
* API Resources
|
54 |
|
|
*/
|
55 |
|
|
|
56 |
|
|
/** API OBJECTS Resource which handles with document operations*/
|
57 |
5282
|
jones
|
public static final String RESOURCE_OBJECTS = "object";
|
58 |
5211
|
jones
|
/** API SESSION Resource which handles with user session operations*/
|
59 |
|
|
public static final String RESOURCE_SESSION = "session";
|
60 |
|
|
/** API IDENTIFIER Resource which controls object unique identifier operations*/
|
61 |
|
|
public static final String RESOURCE_IDENTIFIER = "identifier";
|
62 |
|
|
|
63 |
|
|
/*
|
64 |
|
|
* API Functions used as URL parameters
|
65 |
|
|
*/
|
66 |
|
|
/** Function keyword*/
|
67 |
|
|
public static final String FUNCTION_KEYWORD = "op";
|
68 |
|
|
/** Function name for login function*/
|
69 |
|
|
public static final String FUNCTION_NAME_LOGIN = "login";
|
70 |
|
|
/** Function name for logout function*/
|
71 |
|
|
public static final String FUNCTION_NAME_LOGOUT = "logout";
|
72 |
|
|
/** Function name for isregistered function*/
|
73 |
|
|
public static final String FUNCTION_NAME_ISREGISTERED = "isregistered";
|
74 |
|
|
/** Function name for getalldocids function*/
|
75 |
|
|
public static final String FUNCTION_NAME_GETALLDOCS = "getalldocids";
|
76 |
|
|
/** Function name for getnextrevision function*/
|
77 |
|
|
public static final String FUNCTION_NAME_GETNEXTREV = "getnextrevision";
|
78 |
|
|
/** Function name for getnextobject function*/
|
79 |
|
|
public static final String FUNCTION_NAME_GETNEXTOBJ = "getnextobject";
|
80 |
|
|
/** Function name for insert function*/
|
81 |
|
|
public static final String FUNCTION_NAME_INSERT = "insert";
|
82 |
|
|
/** Function name for update function*/
|
83 |
|
|
public static final String FUNCTION_NAME_UPDATE= "update";
|
84 |
|
|
|
85 |
|
|
/**
|
86 |
|
|
* Method used to log in to a metacat server through REST API
|
87 |
|
|
*
|
88 |
|
|
* @param username the username of the user, like an LDAP DN
|
89 |
|
|
* @param password the password for that user for authentication
|
90 |
|
|
* @return the response string from metacat in XML format
|
91 |
|
|
* @throws MetacatAuthException when the username/password could
|
92 |
|
|
* not be authenticated
|
93 |
|
|
*/
|
94 |
|
|
|
95 |
|
|
public String login(String username, String password)
|
96 |
|
|
throws MetacatAuthException, MetacatInaccessibleException;
|
97 |
|
|
|
98 |
|
|
/**
|
99 |
|
|
* Method used to log out a metacat server. The Metacat server will end
|
100 |
|
|
* the session when this call is invoked.
|
101 |
|
|
*
|
102 |
|
|
* @return the response string from metacat in XML format
|
103 |
|
|
* @throws MetacatInaccessibleException when the metacat server can not be
|
104 |
|
|
* reached or does not respond
|
105 |
|
|
*/
|
106 |
|
|
public String logout() throws MetacatInaccessibleException,
|
107 |
|
|
MetacatException;
|
108 |
|
|
|
109 |
|
|
/**
|
110 |
|
|
* Read a public XML document , accessed by docid, and returned as a Reader.
|
111 |
|
|
*
|
112 |
|
|
* @param docid the identifier of the document to be read
|
113 |
|
|
* @param outputFile name of the file to be written to local (optional)
|
114 |
|
|
* @return a Reader for accessing the document
|
115 |
|
|
* @throws InsufficientKarmaException when the user has insufficent rights
|
116 |
|
|
* for the operation
|
117 |
|
|
* @throws MetacatInaccessibleException when the metacat server can not be
|
118 |
|
|
* reached or does not respond
|
119 |
|
|
* @throws MetacatException when the metacat server generates another error
|
120 |
|
|
*/
|
121 |
|
|
public Reader getObject(String docid, String outputFile) throws InsufficientKarmaException,
|
122 |
|
|
MetacatInaccessibleException, DocumentNotFoundException, MetacatException;
|
123 |
|
|
|
124 |
|
|
/**
|
125 |
|
|
* Read XML document from server session, accessed by docid, and returned as a Reader.
|
126 |
|
|
*
|
127 |
|
|
* @param docid the identifier of the document to be read
|
128 |
|
|
* @param outputFile name of the file to be written to local (optional)
|
129 |
|
|
* @return a Reader for accessing the document
|
130 |
|
|
* @throws InsufficientKarmaException when the user has insufficent rights
|
131 |
|
|
* for the operation
|
132 |
|
|
* @throws MetacatInaccessibleException when the metacat server can not be
|
133 |
|
|
* reached or does not respond
|
134 |
|
|
* @throws MetacatException when the metacat server generates another error
|
135 |
|
|
*/
|
136 |
|
|
public Reader authenticatedGetObject(String docid, String outputFile) throws InsufficientKarmaException,
|
137 |
|
|
MetacatInaccessibleException, DocumentNotFoundException, MetacatException;
|
138 |
|
|
|
139 |
|
|
/**
|
140 |
|
|
* Query the metacat document store with the given metacat-compatible
|
141 |
|
|
* query document, and return the result set as a Reader.
|
142 |
|
|
*
|
143 |
|
|
* @param xmlQuery a Reader for accessing the XML version of the query
|
144 |
|
|
* @return a Reader for accessing the result set
|
145 |
|
|
*/
|
146 |
|
|
public Reader query(Reader xmlQuery) throws MetacatInaccessibleException,IOException;
|
147 |
|
|
|
148 |
|
|
public Reader authenticatedQuery(Reader xmlQuery) throws MetacatInaccessibleException,IOException;
|
149 |
|
|
|
150 |
|
|
/**
|
151 |
5291
|
jones
|
* Create an XML document into the repository, making it available for
|
152 |
5211
|
jones
|
* searching using the query() methods.
|
153 |
|
|
*
|
154 |
|
|
* @param docid the docid to insert the document
|
155 |
|
|
* @param xmlDocument a Reader for accessing the XML document to be inserted
|
156 |
|
|
*
|
157 |
|
|
* @return the metacat response message
|
158 |
|
|
* @throws InsufficientKarmaException when the user has insufficent rights
|
159 |
|
|
* for the operation
|
160 |
|
|
* @throws MetacatInaccessibleException when the metacat server can not be
|
161 |
|
|
* reached or does not respond
|
162 |
|
|
* @throws MetacatException when the metacat server generates another error
|
163 |
|
|
* @throws IOException when there is an error reading the xml document
|
164 |
|
|
*/
|
165 |
5291
|
jones
|
public String create(String docid, Reader xmlDocument)
|
166 |
5211
|
jones
|
throws InsufficientKarmaException, MetacatException, IOException,
|
167 |
|
|
MetacatInaccessibleException;
|
168 |
|
|
|
169 |
5291
|
jones
|
/**
|
170 |
|
|
* Update an XML document into the repository, making it available for
|
171 |
|
|
* searching using the query() methods.
|
172 |
|
|
*
|
173 |
|
|
* @param docid the docid to insert the document
|
174 |
|
|
* @param xmlDocument a Reader for accessing the XML document to be inserted
|
175 |
|
|
*
|
176 |
|
|
* @return the metacat response message
|
177 |
|
|
* @throws InsufficientKarmaException when the user has insufficent rights
|
178 |
|
|
* for the operation
|
179 |
|
|
* @throws MetacatInaccessibleException when the metacat server can not be
|
180 |
|
|
* reached or does not respond
|
181 |
|
|
* @throws MetacatException when the metacat server generates another error
|
182 |
|
|
* @throws IOException when there is an error reading the xml document
|
183 |
|
|
*/
|
184 |
|
|
public String update(String docid, Reader xmlDocument)
|
185 |
|
|
throws InsufficientKarmaException, MetacatException, IOException,
|
186 |
|
|
MetacatInaccessibleException;
|
187 |
|
|
|
188 |
5211
|
jones
|
|
189 |
|
|
/**
|
190 |
|
|
* Delete an XML document in the repository.
|
191 |
|
|
*
|
192 |
|
|
* @param docid the docid to delete
|
193 |
|
|
* @return the metacat response message
|
194 |
|
|
* @throws InsufficientKarmaException when the user has insufficent rights
|
195 |
|
|
* for the operation
|
196 |
|
|
* @throws MetacatInaccessibleException when the metacat server can not be
|
197 |
|
|
* reached or does not respond
|
198 |
|
|
* @throws MetacatException when the metacat server generates another error
|
199 |
|
|
*/
|
200 |
|
|
public String deleteObject(String docid)
|
201 |
|
|
throws InsufficientKarmaException, MetacatException,
|
202 |
|
|
MetacatInaccessibleException;
|
203 |
|
|
|
204 |
|
|
/**
|
205 |
|
|
* When the MetacatFactory creates an instance it needs to set the
|
206 |
|
|
* MetacatUrl to which connections should be made.
|
207 |
|
|
*
|
208 |
|
|
* @param metacatUrl the URL for the metacat server
|
209 |
|
|
*/
|
210 |
|
|
public void setContextRootUrl(String contextRootUrl) ;
|
211 |
|
|
|
212 |
|
|
/**
|
213 |
|
|
* Get the session identifier for this session.
|
214 |
|
|
*
|
215 |
|
|
* @returns the sessionId as a String, or null if the session is invalid
|
216 |
|
|
*/
|
217 |
|
|
public String getSessionId();
|
218 |
|
|
|
219 |
|
|
/**
|
220 |
|
|
* Set the session identifier for this session. This identifier was
|
221 |
|
|
* previously established with a call to login. To continue to use the
|
222 |
|
|
* same session, set the session id before making a call to one of the
|
223 |
|
|
* metacat access methods (e.g., read, query, insert, etc.).
|
224 |
|
|
*
|
225 |
|
|
* @param String the sessionId from a previously established session
|
226 |
|
|
*/
|
227 |
|
|
public void setSessionId(String sessionId);
|
228 |
|
|
|
229 |
|
|
|
230 |
|
|
/**
|
231 |
|
|
* Return the highest document id for a given scope. This is used by
|
232 |
|
|
* clients to make it easier to determine the next free identifier in a
|
233 |
|
|
* sequence for a given scope.
|
234 |
|
|
* @param scope String the scope to use for looking up the latest id
|
235 |
|
|
* @throws MetacatException when an error occurs
|
236 |
|
|
*/
|
237 |
|
|
public String getNextObject(String scope) throws MetacatException;
|
238 |
|
|
|
239 |
|
|
/**
|
240 |
|
|
* The method will return the latest revision in metacat server
|
241 |
|
|
* for a given document id. If some error happens, this method will throw
|
242 |
|
|
* an exception.
|
243 |
|
|
* @param identifierId String the given docid you want to use. the docid it self
|
244 |
|
|
* can have or haven't revision number
|
245 |
|
|
* @throws MetacatException
|
246 |
|
|
*/
|
247 |
|
|
public int getNextRevision(String identifierId) throws MetacatException;
|
248 |
|
|
|
249 |
|
|
/**
|
250 |
|
|
* return a list of all docids that match a given scope. if scope is null
|
251 |
|
|
* return all docids registered in the system
|
252 |
|
|
* @param scope String the scope to use to limit the docid query
|
253 |
|
|
* @throws MetacatException when an error occurs
|
254 |
|
|
*/
|
255 |
|
|
public Vector<String> getAllDocids(String scope) throws MetacatException;
|
256 |
|
|
|
257 |
|
|
/**
|
258 |
|
|
* return true of the given docid is registered, false if not
|
259 |
|
|
* @param scope String the scope to use to limit the docid query
|
260 |
|
|
* @throws MetacatException when an error occurs
|
261 |
|
|
*/
|
262 |
|
|
public boolean isRegistered(String identifierId) throws MetacatException;
|
263 |
|
|
|
264 |
|
|
/**
|
265 |
|
|
* Adds identifierId (Metacat Server does not support it!)
|
266 |
|
|
* @param identifierId String the given docid you want to use.
|
267 |
|
|
* @throws MetacatException when an error occurs
|
268 |
|
|
*/
|
269 |
|
|
public String addLSID(String identifierId) throws MetacatException;
|
270 |
|
|
}
|