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: 2006-04-17 14:59:20 -0700 (Mon, 17 Apr 2006) $'
8
 * '$Revision: 2989 $'
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

    
32
/**
33
 *  This interface provides methods for initializing and logging in to a
34
 *  Metacat server, and then querying, reading, transforming, inserting,
35
 *  updating and deleting documents from that server.
36
 */
37
public interface Metacat
38
{
39
    /**
40
     *  Method used to log in to a metacat server. Implementations will need
41
     *  to cache a cookie value to make the session persistent.  Each time a
42
     *  call is made to one of the other methods (e.g., read), the cookie will
43
     *  need to be passed back to the metacat server along with the request.
44
     *
45
     *  @param username   the username of the user, like an LDAP DN
46
     *  @param password   the password for that user for authentication
47
     *  @return the response string from metacat in XML format
48
     *  @throws MetacatAuthException when the username/password could
49
     *                    not be authenticated
50
     */
51
    public String login(String username, String password)
52
           throws MetacatAuthException, MetacatInaccessibleException;
53

    
54
    /**
55
     *  Method used to log out a metacat server. The Metacat server will end
56
     *  the session when this call is invoked.
57
     *
58
     *  @return the response string from metacat in XML format
59
     *  @throws MetacatInaccessibleException when the metacat server can not be
60
     *                                    reached or does not respond
61
     */
62
    public String logout() throws MetacatInaccessibleException,
63
        MetacatException;
64

    
65
    /**
66
     * Read an XML document from the metacat server session, accessed by docid,
67
     * and returned as a Reader.
68
     *
69
     * @param docid the identifier of the document to be read
70
     * @return a Reader for accessing the document
71
     * @throws InsufficientKarmaException when the user has insufficent rights
72
     *                                    for the operation
73
     * @throws MetacatInaccessibleException when the metacat server can not be
74
     *                                    reached or does not respond
75
     * @throws MetacatException when the metacat server generates another error
76
     */
77
    public Reader read(String docid) throws InsufficientKarmaException,
78
        MetacatInaccessibleException, DocumentNotFoundException, MetacatException;
79

    
80
    /**
81
     * Read inline data from the metacat server session, accessed by
82
     * inlinedataid, and returned as a Reader.
83
     *
84
     * @param inlinedataid the identifier of the document to be read
85
     * @return a Reader for accessing the document
86
     * @throws InsufficientKarmaException when the user has insufficent rights
87
     *                                    for the operation
88
     * @throws MetacatInaccessibleException when the metacat server can not be
89
     *                                    reached or does not respond
90
     * @throws MetacatException when the metacat server generates another error
91
     */
92
    public Reader readInlineData(String inlinedataid)
93
        throws InsufficientKarmaException,
94
        MetacatInaccessibleException, MetacatException;
95

    
96
    /**
97
     * Query the metacat document store with the given metacat-compatible
98
     * query document, and return the result set as a Reader.
99
     *
100
     * @param xmlQuery a Reader for accessing the XML version of the query
101
     * @return a Reader for accessing the result set
102
     */
103
    public Reader query(Reader xmlQuery) throws MetacatInaccessibleException,
104
                                                IOException;
105

    
106
    /**
107
     * Insert an XML document into the repository.
108
     *
109
     * @param docid the docid to insert the document
110
     * @param xmlDocument a Reader for accessing the XML document to be inserted
111
     * @param schema a Reader for accessing the DTD or XML Schema for
112
     *               the document
113
     * @return the metacat response message
114
     * @throws InsufficientKarmaException when the user has insufficent rights
115
     *                                    for the operation
116
     * @throws MetacatInaccessibleException when the metacat server can not be
117
     *                                    reached or does not respond
118
     * @throws MetacatException when the metacat server generates another error
119
     * @throws IOException when there is an error reading the xml document
120
     */
121
    public String insert(String docid, Reader xmlDocument, Reader schema)
122
        throws InsufficientKarmaException, MetacatException, IOException,
123
        MetacatInaccessibleException;
124

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

    
144
    /**
145
     * Upload an XML document into the repository.
146
     *
147
     * @param docid the docid to insert the document
148
     * @param xmlDocument a Reader for accessing the document to be inserted
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 upload(String docid, File file)
158
        throws InsufficientKarmaException, MetacatException, IOException,
159
        MetacatInaccessibleException;
160

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

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

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

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

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

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

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

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

    
269
    /**
270
     * Return the highest document id for a given scope.  This is used by
271
     * clients to make it easier to determine the next free identifier in a
272
     * sequence for a given scope.  
273
     * @param scope String  the scope to use for looking up the latest id
274
     * @throws MetacatException when an error occurs
275
     */
276
    public String getLastDocid(String scope) throws MetacatException;
277
}
(3-3/8)