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: 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
	public static final String RESOURCE_OBJECTS = "object";
58
	/** 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
     * Insert / Update an XML document into the repository, making it available for 
152
     * 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
     * @param isInsert whether the operation is update or insert
157
     * 
158
     * @return the metacat response message
159
     * @throws InsufficientKarmaException when the user has insufficent rights
160
     *                                    for the operation
161
     * @throws MetacatInaccessibleException when the metacat server can not be
162
     *                                    reached or does not respond
163
     * @throws MetacatException when the metacat server generates another error
164
     * @throws IOException when there is an error reading the xml document
165
     */
166
    public String putObject(String docid, Reader xmlDocument,boolean isInsert)
167
        throws InsufficientKarmaException, MetacatException, IOException,
168
        MetacatInaccessibleException;
169

    
170
 
171

    
172
    /**
173
     * Delete an XML document in the repository.
174
     *
175
     * @param docid the docid to delete
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
     */
183
    public String deleteObject(String docid)
184
        throws InsufficientKarmaException, MetacatException,
185
        MetacatInaccessibleException;
186

    
187
    /**
188
     * When the MetacatFactory creates an instance it needs to set the
189
     * MetacatUrl to which connections should be made.
190
     *
191
     * @param metacatUrl the URL for the metacat server
192
     */
193
    public void setContextRootUrl(String contextRootUrl) ;
194

    
195
    /**
196
     * Get the session identifier for this session.
197
     *
198
     * @returns the sessionId as a String, or null if the session is invalid
199
     */
200
    public String getSessionId();
201

    
202
    /**
203
     * Set the session identifier for this session.  This identifier was
204
     * previously established with a call to login.  To continue to use the
205
     * same session, set the session id before making a call to one of the
206
     * metacat access methods (e.g., read, query, insert, etc.).
207
     *
208
     * @param String the sessionId from a previously established session
209
     */
210
    public void setSessionId(String sessionId);
211

    
212

    
213
    /**
214
     * Return the highest document id for a given scope.  This is used by
215
     * clients to make it easier to determine the next free identifier in a
216
     * sequence for a given scope.
217
     * @param scope String  the scope to use for looking up the latest id
218
     * @throws MetacatException when an error occurs
219
     */
220
    public String getNextObject(String scope) throws MetacatException;
221

    
222
    /**
223
     * The method will return the latest revision in metacat server
224
     * for a given document id. If some error happens, this method will throw
225
     * an exception.
226
     * @param identifierId String  the given docid you want to use. the docid it self
227
     *                      can have or haven't revision number
228
     * @throws MetacatException
229
     */
230
    public int getNextRevision(String identifierId) throws MetacatException;
231
    
232
    /**
233
     * return a list of all docids that match a given scope.  if scope is null
234
     * return all docids registered in the system
235
     * @param scope String  the scope to use to limit the docid query
236
     * @throws MetacatException when an error occurs
237
     */
238
    public Vector<String> getAllDocids(String scope) throws MetacatException;
239
    
240
    /**
241
     * return true of the given docid is registered, false if not
242
     * @param scope String  the scope to use to limit the docid query
243
     * @throws MetacatException when an error occurs
244
     */
245
    public boolean isRegistered(String identifierId) throws MetacatException;
246
    
247
    /**
248
     * Adds identifierId (Metacat Server does not support it!)
249
     * @param identifierId String  the given docid you want to use.
250
     * @throws MetacatException when an error occurs
251
     */
252
    public String addLSID(String identifierId) throws MetacatException;
253
}
(1-1/2)