Project

General

Profile

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: berkley $'
7
 *     '$Date: 2007-01-18 10:36:49 -0800 (Thu, 18 Jan 2007) $'
8
 * '$Revision: 3143 $'
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 Reader 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 Reader 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
     * Insert an XML document into the repository.
109
     *
110
     * @param docid the docid to insert the document
111
     * @param xmlDocument a Reader for accessing the XML document to be inserted
112
     * @param schema a Reader for accessing the DTD or XML Schema for
113
     *               the document
114
     * @return the metacat response message
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
     * @throws IOException when there is an error reading the xml document
121
     */
122
    public String insert(String docid, Reader xmlDocument, Reader schema)
123
        throws InsufficientKarmaException, MetacatException, IOException,
124
        MetacatInaccessibleException;
125

    
126
    /**
127
     * Update an XML document in the repository.
128
     *
129
     * @param docid the docid to update
130
     * @param xmlDocument a Reader for accessing the XML text to be updated
131
     * @param schema a Reader for accessing the DTD or XML Schema for
132
     *               the document
133
     * @return the metacat response message
134
     * @throws InsufficientKarmaException when the user has insufficent rights
135
     *                                    for the operation
136
     * @throws MetacatInaccessibleException when the metacat server can not be
137
     *                                    reached or does not respond
138
     * @throws MetacatException when the metacat server generates another error
139
     * @throws IOException when there is an error reading the xml document
140
     */
141
    public String update(String docid, Reader xmlDocument, Reader schema)
142
        throws InsufficientKarmaException, MetacatException, IOException,
143
        MetacatInaccessibleException;
144

    
145
    /**
146
     * Upload an XML document into the repository.
147
     *
148
     * @param docid the docid to insert the document
149
     * @param xmlDocument a Reader for accessing the document to be inserted
150
     * @return the metacat response message
151
     * @throws InsufficientKarmaException when the user has insufficent rights
152
     *                                    for the operation
153
     * @throws MetacatInaccessibleException when the metacat server can not be
154
     *                                    reached or does not respond
155
     * @throws MetacatException when the metacat server generates another error
156
     * @throws IOException when there is an error reading the xml document
157
     */
158
    public String upload(String docid, File file)
159
        throws InsufficientKarmaException, MetacatException, IOException,
160
        MetacatInaccessibleException;
161

    
162
    /**
163
     * Upload an XML document into the repository.
164
     *
165
     * @param docid the docid to insert the document
166
     * @param fileName the name of the document
167
     * @param fileData InputStream of the document that has to be inserted
168
     * @param size size of the data being sent. If more data is
169
     *             found in the InputStream, an error would be reported.
170
     * @return the metacat response message
171
     * @throws InsufficientKarmaException when the user has insufficent rights
172
     *                                    for the operation
173
     * @throws MetacatInaccessibleException when the metacat server can not be
174
     *                                    reached or does not respond
175
     * @throws MetacatException when the metacat server generates another error
176
     * @throws IOException when there is an error reading the xml document
177
     */
178
    public String upload(String docid, String fileName,
179
                         InputStream fileData, int size)
180
        throws InsufficientKarmaException, MetacatException, IOException,
181
        MetacatInaccessibleException;
182

    
183
    /**
184
     * Delete an XML document in the repository.
185
     *
186
     * @param docid the docid to delete
187
     * @return the metacat response message
188
     * @throws InsufficientKarmaException when the user has insufficent rights
189
     *                                    for the operation
190
     * @throws MetacatInaccessibleException when the metacat server can not be
191
     *                                    reached or does not respond
192
     * @throws MetacatException when the metacat server generates another error
193
     */
194
    public String delete(String docid)
195
        throws InsufficientKarmaException, MetacatException,
196
        MetacatInaccessibleException;
197

    
198
    /**
199
     * set the access on an XML document in the repository.
200
     *
201
     * @param _docid the docid of the document for which the access should be applied.
202
     *
203
     * @param _principal the document's principal
204
     *
205
     * @param _permission the access permission to be applied to the docid
206
     *  {e.g. read,write,all}
207
     *
208
     * @param _permType the permission type to be applied to the document
209
     *  {e.g. allow or deny}
210
     *
211
     * @param _permOrder the order that the document's permissions should be
212
     *  processed {e.g. denyFirst or allowFirst}
213
     *
214
     *
215
     * @return the metacat response message
216
     *
217
     * @throws InsufficientKarmaException when the user has insufficent rights
218
     *                                    for the operation
219
     * @throws MetacatInaccessibleException when the metacat server can not be
220
     *                                    reached or does not respond
221
     * @throws MetacatException when the metacat server generates another error
222
     */
223
    public String setAccess(String _docid, String _principal, String
224
                            _permission, String _permType, String _permOrder )
225
        throws InsufficientKarmaException, MetacatException,
226
        MetacatInaccessibleException;
227

    
228
    /**
229
     * When the MetacatFactory creates an instance it needs to set the
230
     * MetacatUrl to which connections should be made.
231
     *
232
     * @param metacatUrl the URL for the metacat server
233
     */
234
    public void setMetacatUrl(String metacatUrl);
235

    
236
    /**
237
     * Get the session identifier for this session.
238
     *
239
     * @returns the sessionId as a String, or null if the session is invalid
240
     */
241
    public String getSessionId();
242

    
243
    /**
244
     * Set the session identifier for this session.  This identifier was
245
     * previously established with a call to login.  To continue to use the
246
     * same session, set the session id before making a call to one of the
247
     * metacat access methods (e.g., read, query, insert, etc.).
248
     *
249
     * @param String the sessionId from a previously established session
250
     */
251
    public void setSessionId(String sessionId);
252

    
253
    /**
254
     * Get the logged in user for this session.
255
     *
256
     * @returns the response received from the server for action=getloggeduserinfo 
257
     */
258
    public String getloggedinuserinfo() throws MetacatInaccessibleException;
259

    
260
    /**
261
     * The method will return the latest revision in metacat server 
262
     * for a given document id. If some error happens, this method will throw
263
     * an exception.   
264
     * @param docId String  the given docid you want to use. the docid it self
265
     *                      can have or haven't revision number
266
     * @throws MetacatException
267
     */
268
    public int getNewestDocRevision(String docId) throws MetacatException;
269

    
270
    /**
271
     * Return the highest document id for a given scope.  This is used by
272
     * clients to make it easier to determine the next free identifier in a
273
     * sequence for a given scope.  
274
     * @param scope String  the scope to use for looking up the latest id
275
     * @throws MetacatException when an error occurs
276
     */
277
    public String getLastDocid(String scope) throws MetacatException;
278
    
279
    /**
280
     * return a list of all docids that match a given scope.  if scope is null
281
     * return all docids registered in the system
282
     * @param scope String  the scope to use to limit the docid query
283
     * @throws MetacatException when an error occurs
284
     */
285
    public Vector getAllDocids(String scope) throws MetacatException;
286
    
287
    /**
288
     * return true of the given docid is registered, false if not
289
     * @param scope String  the scope to use to limit the docid query
290
     * @throws MetacatException when an error occurs
291
     */
292
    public boolean isRegistered(String docid) throws MetacatException;
293
}
(3-3/8)