1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Copyright: 2000 Regents of the University of California and the
|
4
|
* National Center for Ecological Analysis and Synthesis
|
5
|
*
|
6
|
* '$Author: leinfelder $'
|
7
|
* '$Date: 2011-02-04 06:17:53 -0800 (Fri, 04 Feb 2011) $'
|
8
|
* '$Revision: 5914 $'
|
9
|
*
|
10
|
* This program is free software; you can redistribute it and/or modify
|
11
|
* it under the terms of the GNU General Public License as published by
|
12
|
* the Free Software Foundation; either version 2 of the License, or
|
13
|
* (at your option) any later version.
|
14
|
*
|
15
|
* This program is distributed in the hope that it will be useful,
|
16
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18
|
* GNU General Public License for more details.
|
19
|
*
|
20
|
* You should have received a copy of the GNU General Public License
|
21
|
* along with this program; if not, write to the Free Software
|
22
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23
|
*/
|
24
|
|
25
|
package edu.ucsb.nceas.metacat.client;
|
26
|
|
27
|
import java.io.Reader;
|
28
|
import java.io.IOException;
|
29
|
import java.io.File;
|
30
|
import java.io.InputStream;
|
31
|
import java.util.Vector;
|
32
|
|
33
|
/**
|
34
|
* This interface provides methods for initializing and logging in to a
|
35
|
* Metacat server, and then querying, reading, transforming, inserting,
|
36
|
* updating and deleting documents from that server.
|
37
|
*/
|
38
|
public interface Metacat
|
39
|
{
|
40
|
/**
|
41
|
* Method used to log in to a metacat server. Implementations will need
|
42
|
* to cache a cookie value to make the session persistent. Each time a
|
43
|
* call is made to one of the other methods (e.g., read), the cookie will
|
44
|
* need to be passed back to the metacat server along with the request.
|
45
|
*
|
46
|
* @param username the username of the user, like an LDAP DN
|
47
|
* @param password the password for that user for authentication
|
48
|
* @return the response string from metacat in XML format
|
49
|
* @throws MetacatAuthException when the username/password could
|
50
|
* not be authenticated
|
51
|
*/
|
52
|
public String login(String username, String password)
|
53
|
throws MetacatAuthException, MetacatInaccessibleException;
|
54
|
|
55
|
/**
|
56
|
* Method used to log out a metacat server. The Metacat server will end
|
57
|
* the session when this call is invoked.
|
58
|
*
|
59
|
* @return the response string from metacat in XML format
|
60
|
* @throws MetacatInaccessibleException when the metacat server can not be
|
61
|
* reached or does not respond
|
62
|
*/
|
63
|
public String logout() throws MetacatInaccessibleException,
|
64
|
MetacatException;
|
65
|
|
66
|
/**
|
67
|
* Read an XML document from the metacat server session, accessed by docid,
|
68
|
* and returned as a Reader.
|
69
|
*
|
70
|
* @param docid the identifier of the document to be read
|
71
|
* @return a Reader for accessing the document
|
72
|
* @throws InsufficientKarmaException when the user has insufficent rights
|
73
|
* for the operation
|
74
|
* @throws MetacatInaccessibleException when the metacat server can not be
|
75
|
* reached or does not respond
|
76
|
* @throws MetacatException when the metacat server generates another error
|
77
|
*/
|
78
|
public InputStream read(String docid) throws InsufficientKarmaException,
|
79
|
MetacatInaccessibleException, DocumentNotFoundException, MetacatException;
|
80
|
|
81
|
/**
|
82
|
* Read inline data from the metacat server session, accessed by
|
83
|
* inlinedataid, and returned as a Reader.
|
84
|
*
|
85
|
* @param inlinedataid the identifier of the document to be read
|
86
|
* @return a Reader for accessing the document
|
87
|
* @throws InsufficientKarmaException when the user has insufficent rights
|
88
|
* for the operation
|
89
|
* @throws MetacatInaccessibleException when the metacat server can not be
|
90
|
* reached or does not respond
|
91
|
* @throws MetacatException when the metacat server generates another error
|
92
|
*/
|
93
|
public InputStream readInlineData(String inlinedataid)
|
94
|
throws InsufficientKarmaException,
|
95
|
MetacatInaccessibleException, MetacatException;
|
96
|
|
97
|
/**
|
98
|
* Query the metacat document store with the given metacat-compatible
|
99
|
* query document, and return the result set as a Reader.
|
100
|
*
|
101
|
* @param xmlQuery a Reader for accessing the XML version of the query
|
102
|
* @return a Reader for accessing the result set
|
103
|
*/
|
104
|
public Reader query(Reader xmlQuery) throws MetacatInaccessibleException,
|
105
|
IOException;
|
106
|
|
107
|
|
108
|
/**
|
109
|
* Query the metacat document store with the given metacat-compatible
|
110
|
* query document and qformat, and return the result set as a Reader.
|
111
|
*
|
112
|
* @param xmlQuery a Reader for accessing the XML version of the query
|
113
|
* @param qformat the format of return doc. It can be xml, knb, lter and etal.
|
114
|
* @return a Reader for accessing the result set
|
115
|
*/
|
116
|
public Reader query(Reader xmlQuery, String qformat) throws MetacatInaccessibleException,
|
117
|
IOException;
|
118
|
|
119
|
/**
|
120
|
* Insert an XML document into the repository, making it available for
|
121
|
* searching using the query() methods.
|
122
|
*
|
123
|
* @param docid the docid to insert the document
|
124
|
* @param xmlDocument a Reader for accessing the XML document to be inserted
|
125
|
* @param schema a Reader for accessing the DTD or XML Schema for
|
126
|
* the document
|
127
|
* @return the metacat response message
|
128
|
* @throws InsufficientKarmaException when the user has insufficent rights
|
129
|
* for the operation
|
130
|
* @throws MetacatInaccessibleException when the metacat server can not be
|
131
|
* reached or does not respond
|
132
|
* @throws MetacatException when the metacat server generates another error
|
133
|
* @throws IOException when there is an error reading the xml document
|
134
|
*/
|
135
|
public String insert(String docid, Reader xmlDocument, Reader schema)
|
136
|
throws InsufficientKarmaException, MetacatException, IOException,
|
137
|
MetacatInaccessibleException;
|
138
|
|
139
|
/**
|
140
|
* Update an XML document in the repository by providing a new version of
|
141
|
* the XML document. The new version is placed in the search index,
|
142
|
* and older versions are archived (accessible by read(), but not in the
|
143
|
* search index).
|
144
|
*
|
145
|
* @param docid the docid to update
|
146
|
* @param xmlDocument a Reader for accessing the XML text to be updated
|
147
|
* @param schema a Reader for accessing the DTD or XML Schema for
|
148
|
* the document
|
149
|
* @return the metacat response message
|
150
|
* @throws InsufficientKarmaException when the user has insufficent rights
|
151
|
* for the operation
|
152
|
* @throws MetacatInaccessibleException when the metacat server can not be
|
153
|
* reached or does not respond
|
154
|
* @throws MetacatException when the metacat server generates another error
|
155
|
* @throws IOException when there is an error reading the xml document
|
156
|
*/
|
157
|
public String update(String docid, Reader xmlDocument, Reader schema)
|
158
|
throws InsufficientKarmaException, MetacatException, IOException,
|
159
|
MetacatInaccessibleException;
|
160
|
|
161
|
/**
|
162
|
* Upload a data document into the repository. Data files are stored on
|
163
|
* metacat and may be in any format (binary or text), but they are all
|
164
|
* treated as if they were binary. Data files are not searched by the
|
165
|
* query() methods because they are not loaded into the XML store because
|
166
|
* they are not XML documents. The File parameter is used to determine a
|
167
|
* name for the uploaded document.
|
168
|
*
|
169
|
* @param docid the identifier to be used for the document
|
170
|
* @param file the File to be uploaded
|
171
|
* @param document a InputStream containing the data to be uploaded
|
172
|
* @return the metacat response message
|
173
|
* @throws InsufficientKarmaException when the user has insufficent rights
|
174
|
* for the operation
|
175
|
* @throws MetacatInaccessibleException when the metacat server can not be
|
176
|
* reached or does not respond
|
177
|
* @throws MetacatException when the metacat server generates another error
|
178
|
* @throws IOException when there is an error reading the xml document
|
179
|
*/
|
180
|
public String upload(String docid, File file)
|
181
|
throws InsufficientKarmaException, MetacatException, IOException,
|
182
|
MetacatInaccessibleException;
|
183
|
|
184
|
/**
|
185
|
* Upload a data document into the repository. Data files are stored on
|
186
|
* metacat and may be in any format (binary or text), but they are all
|
187
|
* treated as if they were binary. Data files are not searched by the
|
188
|
* query() methods because they are not loaded into the XML store because
|
189
|
* they are not XML documents. The name for the document is set explicitly
|
190
|
* using the filename parameter.
|
191
|
*
|
192
|
* @param docid the identifier to be used for the document
|
193
|
* @param filename the name to be used in the MIME description of the uploaded file
|
194
|
* @param document a InputStream containing the data to be uploaded
|
195
|
* @return the metacat response message
|
196
|
* @throws InsufficientKarmaException when the user has insufficent rights
|
197
|
* for the operation
|
198
|
* @throws MetacatInaccessibleException when the metacat server can not be
|
199
|
* reached or does not respond
|
200
|
* @throws MetacatException when the metacat server generates another error
|
201
|
* @throws IOException when there is an error reading the xml document
|
202
|
*/
|
203
|
public String upload(String docid, String fileName,
|
204
|
InputStream fileData, int size)
|
205
|
throws InsufficientKarmaException, MetacatException, IOException,
|
206
|
MetacatInaccessibleException;
|
207
|
|
208
|
/**
|
209
|
* Delete an XML document in the repository.
|
210
|
*
|
211
|
* @param docid the docid to delete
|
212
|
* @return the metacat response message
|
213
|
* @throws InsufficientKarmaException when the user has insufficent rights
|
214
|
* for the operation
|
215
|
* @throws MetacatInaccessibleException when the metacat server can not be
|
216
|
* reached or does not respond
|
217
|
* @throws MetacatException when the metacat server generates another error
|
218
|
*/
|
219
|
public String delete(String docid)
|
220
|
throws InsufficientKarmaException, MetacatException,
|
221
|
MetacatInaccessibleException;
|
222
|
|
223
|
public String getAccessControl(String docid)
|
224
|
throws InsufficientKarmaException, MetacatException,MetacatInaccessibleException;
|
225
|
|
226
|
/**
|
227
|
* set the access on an XML document in the repository.
|
228
|
*
|
229
|
* @param _docid the docid of the document for which the access should be applied.
|
230
|
*
|
231
|
* @param _principal the document's principal
|
232
|
*
|
233
|
* @param _permission the access permission to be applied to the docid
|
234
|
* {e.g. read,write,all}
|
235
|
*
|
236
|
* @param _permType the permission type to be applied to the document
|
237
|
* {e.g. allow or deny}
|
238
|
*
|
239
|
* @param _permOrder the order that the document's permissions should be
|
240
|
* processed {e.g. denyFirst or allowFirst}
|
241
|
*
|
242
|
*
|
243
|
* @return the metacat response message
|
244
|
*
|
245
|
* @throws InsufficientKarmaException when the user has insufficent rights
|
246
|
* for the operation
|
247
|
* @throws MetacatInaccessibleException when the metacat server can not be
|
248
|
* reached or does not respond
|
249
|
* @throws MetacatException when the metacat server generates another error
|
250
|
*/
|
251
|
public String setAccess(String docid, String principal, String
|
252
|
permission, String permType, String permOrder )
|
253
|
throws InsufficientKarmaException, MetacatException, MetacatInaccessibleException;
|
254
|
|
255
|
public String setAccess(String docid, String accessBlock)
|
256
|
throws InsufficientKarmaException, MetacatException, MetacatInaccessibleException;
|
257
|
|
258
|
/**
|
259
|
* When the MetacatFactory creates an instance it needs to set the
|
260
|
* MetacatUrl to which connections should be made.
|
261
|
*
|
262
|
* @param metacatUrl the URL for the metacat server
|
263
|
*/
|
264
|
public void setMetacatUrl(String metacatUrl);
|
265
|
|
266
|
/**
|
267
|
* Get the session identifier for this session.
|
268
|
*
|
269
|
* @returns the sessionId as a String, or null if the session is invalid
|
270
|
*/
|
271
|
public String getSessionId();
|
272
|
|
273
|
/**
|
274
|
* Set the session identifier for this session. This identifier was
|
275
|
* previously established with a call to login. To continue to use the
|
276
|
* same session, set the session id before making a call to one of the
|
277
|
* metacat access methods (e.g., read, query, insert, etc.).
|
278
|
*
|
279
|
* @param String the sessionId from a previously established session
|
280
|
*/
|
281
|
public void setSessionId(String sessionId);
|
282
|
|
283
|
/**
|
284
|
* Get the logged in user for this session.
|
285
|
*
|
286
|
* @returns the response received from the server for action=getloggeduserinfo
|
287
|
*/
|
288
|
public String getloggedinuserinfo() throws MetacatInaccessibleException;
|
289
|
|
290
|
/**
|
291
|
* The method will return the latest revision in metacat server
|
292
|
* for a given document id. If some error happens, this method will throw
|
293
|
* an exception.
|
294
|
* @param docId String the given docid you want to use. the docid it self
|
295
|
* can have or haven't revision number
|
296
|
* @throws MetacatException
|
297
|
*/
|
298
|
public int getNewestDocRevision(String docId) throws MetacatException;
|
299
|
|
300
|
/**
|
301
|
* Return the highest document id for a given scope. This is used by
|
302
|
* clients to make it easier to determine the next free identifier in a
|
303
|
* sequence for a given scope.
|
304
|
* @param scope String the scope to use for looking up the latest id
|
305
|
* @throws MetacatException when an error occurs
|
306
|
*/
|
307
|
public String getLastDocid(String scope) throws MetacatException;
|
308
|
|
309
|
/**
|
310
|
* return a list of all docids that match a given scope. if scope is null
|
311
|
* return all docids registered in the system
|
312
|
* @param scope String the scope to use to limit the docid query
|
313
|
* @throws MetacatException when an error occurs
|
314
|
*/
|
315
|
public Vector getAllDocids(String scope) throws MetacatException;
|
316
|
|
317
|
/**
|
318
|
* return true of the given docid is registered, false if not
|
319
|
* @param scope String the scope to use to limit the docid query
|
320
|
* @throws MetacatException when an error occurs
|
321
|
*/
|
322
|
public boolean isRegistered(String docid) throws MetacatException;
|
323
|
|
324
|
/**
|
325
|
* Returns the character encoding used used when communicating with Metacat.
|
326
|
* @return character encoding name
|
327
|
*/
|
328
|
public String getEncoding();
|
329
|
|
330
|
/**
|
331
|
* Returns the character encoding used used when communicating with Metacat.
|
332
|
* @param encoding The encoding (i.e. "UTF-8")
|
333
|
*/
|
334
|
public void setEncoding(String encoding);
|
335
|
|
336
|
}
|