Statistics
| Branch: | Tag: | Revision:

root / web_client / src / gr / grnet / pithos / web / client / rest / GetCommand.java @ fa5600f7

History | View | Annotate | Download (10.2 kB)

1 ab1eb3f8 Christos Stathis
/*
2 58777026 Christos Stathis
 * Copyright 2011 GRNET S.A. All rights reserved.
3 58777026 Christos Stathis
 *
4 58777026 Christos Stathis
 * Redistribution and use in source and binary forms, with or
5 58777026 Christos Stathis
 * without modification, are permitted provided that the following
6 58777026 Christos Stathis
 * conditions are met:
7 58777026 Christos Stathis
 *
8 58777026 Christos Stathis
 *   1. Redistributions of source code must retain the above
9 58777026 Christos Stathis
 *      copyright notice, this list of conditions and the following
10 58777026 Christos Stathis
 *      disclaimer.
11 58777026 Christos Stathis
 *
12 58777026 Christos Stathis
 *   2. Redistributions in binary form must reproduce the above
13 58777026 Christos Stathis
 *      copyright notice, this list of conditions and the following
14 58777026 Christos Stathis
 *      disclaimer in the documentation and/or other materials
15 58777026 Christos Stathis
 *      provided with the distribution.
16 58777026 Christos Stathis
 *
17 58777026 Christos Stathis
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 58777026 Christos Stathis
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 58777026 Christos Stathis
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 58777026 Christos Stathis
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 58777026 Christos Stathis
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 58777026 Christos Stathis
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 58777026 Christos Stathis
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 58777026 Christos Stathis
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 58777026 Christos Stathis
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 58777026 Christos Stathis
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 58777026 Christos Stathis
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 58777026 Christos Stathis
 * POSSIBILITY OF SUCH DAMAGE.
29 58777026 Christos Stathis
 *
30 58777026 Christos Stathis
 * The views and conclusions contained in the software and
31 58777026 Christos Stathis
 * documentation are those of the authors and should not be
32 58777026 Christos Stathis
 * interpreted as representing official policies, either expressed
33 58777026 Christos Stathis
 * or implied, of GRNET S.A.
34 ab1eb3f8 Christos Stathis
 */
35 ab1eb3f8 Christos Stathis
package gr.grnet.pithos.web.client.rest;
36 ab1eb3f8 Christos Stathis
37 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.GSS;
38 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.FileResource;
39 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.FolderResource;
40 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.GroupResource;
41 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.GroupUserResource;
42 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.GroupsResource;
43 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.OtherUserResource;
44 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.OthersResource;
45 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.RestResource;
46 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.SearchResource;
47 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.SharedResource;
48 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.TagsResource;
49 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.TrashResource;
50 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.UploadStatusResource;
51 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.UserResource;
52 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.UserSearchResource;
53 ab1eb3f8 Christos Stathis
54 ab1eb3f8 Christos Stathis
import java.util.HashMap;
55 ab1eb3f8 Christos Stathis
import java.util.Map;
56 ab1eb3f8 Christos Stathis
57 ab1eb3f8 Christos Stathis
import com.google.gwt.core.client.GWT;
58 ab1eb3f8 Christos Stathis
import com.google.gwt.http.client.Request;
59 ab1eb3f8 Christos Stathis
import com.google.gwt.http.client.RequestBuilder;
60 ab1eb3f8 Christos Stathis
import com.google.gwt.http.client.Response;
61 ab1eb3f8 Christos Stathis
62 ab1eb3f8 Christos Stathis
public abstract class GetCommand<T extends RestResource> extends RestCommand{
63 ab1eb3f8 Christos Stathis
64 ab1eb3f8 Christos Stathis
        boolean complete = false;
65 ab1eb3f8 Christos Stathis
        T result = null;
66 ab1eb3f8 Christos Stathis
        Throwable exception = null;
67 ab1eb3f8 Christos Stathis
        Class<T> aclass;
68 ab1eb3f8 Christos Stathis
        private final String path;
69 ab1eb3f8 Christos Stathis
        private String username;
70 ab1eb3f8 Christos Stathis
        private boolean requestSent = false;
71 ab1eb3f8 Christos Stathis
        T cached;
72 ab1eb3f8 Christos Stathis
        
73 ab1eb3f8 Christos Stathis
        private static final long MAX_CACHE_AGE = 1000;
74 ab1eb3f8 Christos Stathis
        
75 ab1eb3f8 Christos Stathis
        private static class RequestData {
76 ab1eb3f8 Christos Stathis
                public String path;
77 ab1eb3f8 Christos Stathis
                public String username;
78 ab1eb3f8 Christos Stathis
                
79 ab1eb3f8 Christos Stathis
                public RequestData(String _path, String _username) {
80 ab1eb3f8 Christos Stathis
                        path = _path;
81 ab1eb3f8 Christos Stathis
                        username = _username;
82 ab1eb3f8 Christos Stathis
                }
83 ab1eb3f8 Christos Stathis
84 ab1eb3f8 Christos Stathis
                @Override
85 ab1eb3f8 Christos Stathis
                public int hashCode() {
86 ab1eb3f8 Christos Stathis
                        final int prime = 31;
87 ab1eb3f8 Christos Stathis
                        int result = 1;
88 ab1eb3f8 Christos Stathis
                        result = prime * result + ((path == null) ? 0 : path.hashCode());
89 ab1eb3f8 Christos Stathis
                        result = prime * result + ((username == null) ? 0 : username.hashCode());
90 ab1eb3f8 Christos Stathis
                        return result;
91 ab1eb3f8 Christos Stathis
                }
92 ab1eb3f8 Christos Stathis
93 ab1eb3f8 Christos Stathis
                @Override
94 ab1eb3f8 Christos Stathis
                public boolean equals(Object obj) {
95 ab1eb3f8 Christos Stathis
                        if (this == obj)
96 ab1eb3f8 Christos Stathis
                                return true;
97 ab1eb3f8 Christos Stathis
                        if (obj == null)
98 ab1eb3f8 Christos Stathis
                                return false;
99 ab1eb3f8 Christos Stathis
                        if (getClass() != obj.getClass())
100 ab1eb3f8 Christos Stathis
                                return false;
101 ab1eb3f8 Christos Stathis
                        RequestData other = (RequestData) obj;
102 ab1eb3f8 Christos Stathis
                        if (path == null) {
103 ab1eb3f8 Christos Stathis
                                if (other.path != null)
104 ab1eb3f8 Christos Stathis
                                        return false;
105 ab1eb3f8 Christos Stathis
                        } else if (!path.equals(other.path))
106 ab1eb3f8 Christos Stathis
                                return false;
107 ab1eb3f8 Christos Stathis
                        if (username == null) {
108 ab1eb3f8 Christos Stathis
                                if (other.username != null)
109 ab1eb3f8 Christos Stathis
                                        return false;
110 ab1eb3f8 Christos Stathis
                        } else if (!username.equals(other.username))
111 ab1eb3f8 Christos Stathis
                                return false;
112 ab1eb3f8 Christos Stathis
                        return true;
113 ab1eb3f8 Christos Stathis
                }
114 ab1eb3f8 Christos Stathis
        }
115 ab1eb3f8 Christos Stathis
        
116 ab1eb3f8 Christos Stathis
        private static class ResponseData {
117 ab1eb3f8 Christos Stathis
                public long timestamp;
118 ab1eb3f8 Christos Stathis
                public Object result;
119 ab1eb3f8 Christos Stathis
                public ResponseData(long _timestamp, Object _result) {
120 ab1eb3f8 Christos Stathis
                        timestamp = _timestamp;
121 ab1eb3f8 Christos Stathis
                        result = _result;
122 ab1eb3f8 Christos Stathis
                }
123 ab1eb3f8 Christos Stathis
        }
124 ab1eb3f8 Christos Stathis
        
125 ab1eb3f8 Christos Stathis
        private static Map<RequestData, ResponseData> cache = new HashMap<RequestData, ResponseData>();
126 ab1eb3f8 Christos Stathis
        
127 ab1eb3f8 Christos Stathis
128 ab1eb3f8 Christos Stathis
        public GetCommand(Class<T> theclass, String pathToGet, T theCached){
129 ab1eb3f8 Christos Stathis
                this(theclass, pathToGet, true, theCached);
130 ab1eb3f8 Christos Stathis
        }
131 ab1eb3f8 Christos Stathis
132 ab1eb3f8 Christos Stathis
        public GetCommand(Class<T> theclass, String pathToGet, boolean showLoading, T theCached){
133 ab1eb3f8 Christos Stathis
                setShowLoadingIndicator(showLoading);
134 ab1eb3f8 Christos Stathis
                if(isShowLoadingIndicator())
135 ab1eb3f8 Christos Stathis
                        GSS.get().showLoadingIndicator("Getting ",pathToGet);
136 ab1eb3f8 Christos Stathis
                this.aclass = theclass;
137 ab1eb3f8 Christos Stathis
                if(pathToGet.indexOf("?") != -1)
138 ab1eb3f8 Christos Stathis
                        path = pathToGet;
139 ab1eb3f8 Christos Stathis
                else
140 ab1eb3f8 Christos Stathis
                        path =fixPath(pathToGet);
141 ab1eb3f8 Christos Stathis
                this.cached = theCached;
142 ab1eb3f8 Christos Stathis
        }
143 ab1eb3f8 Christos Stathis
144 ab1eb3f8 Christos Stathis
        public GetCommand(Class<T> theclass, String aUsername , String pathToGet, T theCached){
145 ab1eb3f8 Christos Stathis
                this(theclass, aUsername, pathToGet, true, theCached);
146 ab1eb3f8 Christos Stathis
        }
147 ab1eb3f8 Christos Stathis
148 ab1eb3f8 Christos Stathis
        public GetCommand(Class<T> theclass, String aUsername , String pathToGet, boolean showLoading, T theCached){
149 ab1eb3f8 Christos Stathis
                setShowLoadingIndicator(showLoading);
150 ab1eb3f8 Christos Stathis
                if(isShowLoadingIndicator())
151 ab1eb3f8 Christos Stathis
                        GSS.get().showLoadingIndicator("Getting ",pathToGet);
152 ab1eb3f8 Christos Stathis
                this.aclass = theclass;
153 ab1eb3f8 Christos Stathis
                path = fixPath(pathToGet);
154 ab1eb3f8 Christos Stathis
                this.username = aUsername;
155 ab1eb3f8 Christos Stathis
                this.cached = theCached;
156 ab1eb3f8 Christos Stathis
        }
157 ab1eb3f8 Christos Stathis
158 ab1eb3f8 Christos Stathis
        private void sendRequest(){
159 ab1eb3f8 Christos Stathis
                if(requestSent)
160 ab1eb3f8 Christos Stathis
                        return;
161 ab1eb3f8 Christos Stathis
                requestSent=true;
162 ab1eb3f8 Christos Stathis
                RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
163 ab1eb3f8 Christos Stathis
                if(cached!=null && cached.getLastModifiedSince() != null)
164 ab1eb3f8 Christos Stathis
                        builder.setHeader("If-Modified-Since", cached.getLastModifiedSince());
165 ab1eb3f8 Christos Stathis
                try {
166 ab1eb3f8 Christos Stathis
                        if(username == null)
167 ab1eb3f8 Christos Stathis
                                handleHeaders(builder, path);
168 ab1eb3f8 Christos Stathis
                        else
169 ab1eb3f8 Christos Stathis
                                handleHeaders(username, builder, path);
170 ab1eb3f8 Christos Stathis
                        builder.sendRequest("", new RestCallback(path) {
171 ab1eb3f8 Christos Stathis
172 ab1eb3f8 Christos Stathis
                                @Override
173 ab1eb3f8 Christos Stathis
                                public Object deserialize(Response response) {
174 ab1eb3f8 Christos Stathis
                                        return deserializeResponse(path, response);
175 ab1eb3f8 Christos Stathis
                                }
176 ab1eb3f8 Christos Stathis
177 ab1eb3f8 Christos Stathis
                                @Override
178 ab1eb3f8 Christos Stathis
                                public void handleError(Request request, Throwable _exception) {
179 ab1eb3f8 Christos Stathis
                                        result = null;
180 ab1eb3f8 Christos Stathis
                                        complete = true;
181 ab1eb3f8 Christos Stathis
                                        exception = _exception;
182 ab1eb3f8 Christos Stathis
                                        if(_exception instanceof RestException)
183 ab1eb3f8 Christos Stathis
                                                if(((RestException)_exception).getHttpStatusCode() == 304 && cached != null){
184 ab1eb3f8 Christos Stathis
                                                        GWT.log("Using cache:"+cached.getUri(), null);
185 ab1eb3f8 Christos Stathis
                                                        handleSuccess(cached);
186 ab1eb3f8 Christos Stathis
                                                        return;
187 ab1eb3f8 Christos Stathis
                                                }
188 ab1eb3f8 Christos Stathis
                                        
189 ab1eb3f8 Christos Stathis
                                }
190 ab1eb3f8 Christos Stathis
191 ab1eb3f8 Christos Stathis
                                @Override
192 ab1eb3f8 Christos Stathis
                                public void handleSuccess(Object object) {
193 ab1eb3f8 Christos Stathis
                                        result = (T) object;
194 ab1eb3f8 Christos Stathis
                                        complete = true;
195 ab1eb3f8 Christos Stathis
                                }
196 ab1eb3f8 Christos Stathis
197 ab1eb3f8 Christos Stathis
                        });
198 ab1eb3f8 Christos Stathis
                } catch (Exception ex) {
199 ab1eb3f8 Christos Stathis
                        complete = true;
200 ab1eb3f8 Christos Stathis
                        exception = ex;
201 ab1eb3f8 Christos Stathis
                }
202 ab1eb3f8 Christos Stathis
        }
203 ab1eb3f8 Christos Stathis
        public boolean isComplete() {
204 ab1eb3f8 Christos Stathis
                return complete;
205 ab1eb3f8 Christos Stathis
        }
206 ab1eb3f8 Christos Stathis
207 ab1eb3f8 Christos Stathis
        public T getResult(){
208 ab1eb3f8 Christos Stathis
                return result;
209 ab1eb3f8 Christos Stathis
        }
210 ab1eb3f8 Christos Stathis
211 ab1eb3f8 Christos Stathis
        @Override
212 ab1eb3f8 Christos Stathis
        public boolean execute() {
213 ab1eb3f8 Christos Stathis
                boolean com = isComplete();
214 ab1eb3f8 Christos Stathis
                RequestData key = new RequestData(path, username);
215 ab1eb3f8 Christos Stathis
                if (!com) {
216 ab1eb3f8 Christos Stathis
                        if (cache.containsKey(key)) {
217 ab1eb3f8 Christos Stathis
                                ResponseData resp = cache.get(key);
218 ab1eb3f8 Christos Stathis
                                if (resp==null) {
219 ab1eb3f8 Christos Stathis
                                        return true;
220 ab1eb3f8 Christos Stathis
                                }
221 ab1eb3f8 Christos Stathis
                                
222 ab1eb3f8 Christos Stathis
                                // Cache hit
223 ab1eb3f8 Christos Stathis
                                if (System.currentTimeMillis()-resp.timestamp>MAX_CACHE_AGE) {
224 ab1eb3f8 Christos Stathis
                                        // Cache stale, remove
225 ab1eb3f8 Christos Stathis
                                        cache.put(key,null);
226 ab1eb3f8 Christos Stathis
                                }
227 ab1eb3f8 Christos Stathis
                                else {
228 ab1eb3f8 Christos Stathis
                                        // Use cache data
229 ab1eb3f8 Christos Stathis
                                        if(isShowLoadingIndicator())
230 ab1eb3f8 Christos Stathis
                                                GSS.get().hideLoadingIndicator();
231 ab1eb3f8 Christos Stathis
                                        if (resp.result instanceof Throwable) {
232 ab1eb3f8 Christos Stathis
                                                // Error to be handled
233 ab1eb3f8 Christos Stathis
                                                Throwable ex = (Throwable) resp.result;
234 ab1eb3f8 Christos Stathis
                                                onError(ex);
235 ab1eb3f8 Christos Stathis
                                                return false;
236 ab1eb3f8 Christos Stathis
                                        }
237 ab1eb3f8 Christos Stathis
                                        result = (T) resp.result;
238 ab1eb3f8 Christos Stathis
                                        if (result != null) {
239 ab1eb3f8 Christos Stathis
                                                onComplete();
240 ab1eb3f8 Christos Stathis
                                        }
241 ab1eb3f8 Christos Stathis
                                        complete = true;
242 ab1eb3f8 Christos Stathis
                                        return false;
243 ab1eb3f8 Christos Stathis
                                }
244 ab1eb3f8 Christos Stathis
                        }
245 ab1eb3f8 Christos Stathis
                
246 ab1eb3f8 Christos Stathis
                        if(!requestSent) {
247 ab1eb3f8 Christos Stathis
                                cache.put(key,null);
248 ab1eb3f8 Christos Stathis
                                sendRequest();
249 ab1eb3f8 Christos Stathis
                        }
250 ab1eb3f8 Christos Stathis
                }
251 ab1eb3f8 Christos Stathis
                
252 ab1eb3f8 Christos Stathis
                if(com){
253 ab1eb3f8 Christos Stathis
                        if(isShowLoadingIndicator())
254 ab1eb3f8 Christos Stathis
                                GSS.get().hideLoadingIndicator();
255 ab1eb3f8 Christos Stathis
                        if(getResult() != null) {
256 ab1eb3f8 Christos Stathis
                                // Add to cache
257 ab1eb3f8 Christos Stathis
                                cache.put(key, new ResponseData(System.currentTimeMillis(), getResult()));
258 ab1eb3f8 Christos Stathis
                                onComplete();
259 ab1eb3f8 Christos Stathis
                        }
260 ab1eb3f8 Christos Stathis
                        else {
261 ab1eb3f8 Christos Stathis
                                cache.put(key, new ResponseData(System.currentTimeMillis(), exception));
262 ab1eb3f8 Christos Stathis
                                onError(exception);
263 ab1eb3f8 Christos Stathis
                        }
264 ab1eb3f8 Christos Stathis
                        return false;
265 ab1eb3f8 Christos Stathis
                }
266 ab1eb3f8 Christos Stathis
                return true;
267 ab1eb3f8 Christos Stathis
        }
268 ab1eb3f8 Christos Stathis
269 ab1eb3f8 Christos Stathis
        public Object deserializeResponse(String aPath, Response response) {
270 ab1eb3f8 Christos Stathis
                RestResource result1 = null;
271 ab1eb3f8 Christos Stathis
                if(aclass.equals(FolderResource.class)){
272 ab1eb3f8 Christos Stathis
                        result1 = new FolderResource(aPath);
273 ab1eb3f8 Christos Stathis
                        result1.createFromJSON(response.getText());
274 ab1eb3f8 Christos Stathis
                }
275 ab1eb3f8 Christos Stathis
                else if(aclass.equals(FileResource.class)){
276 ab1eb3f8 Christos Stathis
                        result1 = new FileResource(aPath);
277 ab1eb3f8 Christos Stathis
                        result1.createFromJSON(response.getHeader("X-GSS-Metadata"));
278 ab1eb3f8 Christos Stathis
                }
279 ab1eb3f8 Christos Stathis
                else if(aclass.equals(GroupsResource.class)){
280 ab1eb3f8 Christos Stathis
                        result1 = new GroupsResource(aPath);
281 ab1eb3f8 Christos Stathis
                        result1.createFromJSON(response.getText());
282 ab1eb3f8 Christos Stathis
                }
283 ab1eb3f8 Christos Stathis
                else if(aclass.equals(TrashResource.class)){
284 ab1eb3f8 Christos Stathis
                        result1 = new TrashResource(aPath);
285 ab1eb3f8 Christos Stathis
                        result1.createFromJSON(response.getText());
286 ab1eb3f8 Christos Stathis
                }
287 ab1eb3f8 Christos Stathis
                else if(aclass.equals(SharedResource.class)){
288 ab1eb3f8 Christos Stathis
                        result1 = new SharedResource(aPath);
289 ab1eb3f8 Christos Stathis
                        result1.createFromJSON(response.getText());
290 ab1eb3f8 Christos Stathis
                }
291 ab1eb3f8 Christos Stathis
                else if(aclass.equals(OthersResource.class)){
292 ab1eb3f8 Christos Stathis
                        result1 = new OthersResource(aPath);
293 ab1eb3f8 Christos Stathis
                        result1.createFromJSON(response.getText());
294 ab1eb3f8 Christos Stathis
                }
295 ab1eb3f8 Christos Stathis
                else if(aclass.equals(OtherUserResource.class)){
296 ab1eb3f8 Christos Stathis
                        result1 = new OtherUserResource(aPath);
297 ab1eb3f8 Christos Stathis
                        result1.createFromJSON(response.getText());
298 ab1eb3f8 Christos Stathis
                }
299 ab1eb3f8 Christos Stathis
                else if(aclass.equals(GroupResource.class)){
300 ab1eb3f8 Christos Stathis
                        result1 = new GroupResource(aPath);
301 ab1eb3f8 Christos Stathis
                        result1.createFromJSON(response.getText());
302 ab1eb3f8 Christos Stathis
                }
303 ab1eb3f8 Christos Stathis
                else if(aclass.equals(GroupUserResource.class)){
304 ab1eb3f8 Christos Stathis
                        result1 = new GroupUserResource(aPath);
305 ab1eb3f8 Christos Stathis
                        result1.createFromJSON(response.getText());
306 ab1eb3f8 Christos Stathis
                }
307 ab1eb3f8 Christos Stathis
                else if(aclass.equals(UserResource.class)){
308 ab1eb3f8 Christos Stathis
                        result1 = new UserResource(aPath);
309 ab1eb3f8 Christos Stathis
                        result1.createFromJSON(response.getText());
310 ab1eb3f8 Christos Stathis
                }
311 ab1eb3f8 Christos Stathis
                else if(aclass.equals(TagsResource.class)){
312 ab1eb3f8 Christos Stathis
                        result1 = new TagsResource(aPath);
313 ab1eb3f8 Christos Stathis
                        result1.createFromJSON(response.getText());
314 ab1eb3f8 Christos Stathis
                }
315 ab1eb3f8 Christos Stathis
                else if(aclass.equals(SearchResource.class)){
316 ab1eb3f8 Christos Stathis
                        result1 = new SearchResource(aPath);
317 ab1eb3f8 Christos Stathis
                        result1.createFromJSON(response.getText());
318 ab1eb3f8 Christos Stathis
                }
319 ab1eb3f8 Christos Stathis
                else if(aclass.equals(UserSearchResource.class)){
320 ab1eb3f8 Christos Stathis
                        result1 = new UserSearchResource(aPath);
321 ab1eb3f8 Christos Stathis
                        result1.createFromJSON(response.getText());
322 ab1eb3f8 Christos Stathis
                }
323 ab1eb3f8 Christos Stathis
                else if(aclass.equals(UploadStatusResource.class)){
324 ab1eb3f8 Christos Stathis
                        result1 = new UploadStatusResource(aPath);
325 ab1eb3f8 Christos Stathis
                        result1.createFromJSON(response.getText());
326 ab1eb3f8 Christos Stathis
                }
327 ab1eb3f8 Christos Stathis
                return result1;
328 ab1eb3f8 Christos Stathis
        }
329 ab1eb3f8 Christos Stathis
330 ab1eb3f8 Christos Stathis
        public T getCached() {
331 ab1eb3f8 Christos Stathis
                return cached;
332 ab1eb3f8 Christos Stathis
        }
333 ab1eb3f8 Christos Stathis
334 ab1eb3f8 Christos Stathis
        public void setCached(T theCached) {
335 ab1eb3f8 Christos Stathis
                this.cached = theCached;
336 ab1eb3f8 Christos Stathis
        }
337 ab1eb3f8 Christos Stathis
        
338 ab1eb3f8 Christos Stathis
        public boolean usedCachedVersion(){
339 ab1eb3f8 Christos Stathis
                if(exception !=null && exception instanceof RestException)
340 ab1eb3f8 Christos Stathis
                        if(((RestException)exception).getHttpStatusCode() == 304){
341 ab1eb3f8 Christos Stathis
                                return true;
342 ab1eb3f8 Christos Stathis
                        }
343 ab1eb3f8 Christos Stathis
                return false;
344 ab1eb3f8 Christos Stathis
        }
345 ab1eb3f8 Christos Stathis
}