2 * Copyright 2009 Electronic Business Systems Ltd.
4 * This file is part of GSS.
6 * GSS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
19 package gr.ebs.gss.client.rest;
21 import gr.ebs.gss.client.GSS;
22 import gr.ebs.gss.client.rest.resource.FileResource;
23 import gr.ebs.gss.client.rest.resource.FolderResource;
24 import gr.ebs.gss.client.rest.resource.GroupResource;
25 import gr.ebs.gss.client.rest.resource.GroupUserResource;
26 import gr.ebs.gss.client.rest.resource.GroupsResource;
27 import gr.ebs.gss.client.rest.resource.OtherUserResource;
28 import gr.ebs.gss.client.rest.resource.OthersResource;
29 import gr.ebs.gss.client.rest.resource.RestResource;
30 import gr.ebs.gss.client.rest.resource.SearchResource;
31 import gr.ebs.gss.client.rest.resource.SharedResource;
32 import gr.ebs.gss.client.rest.resource.TagsResource;
33 import gr.ebs.gss.client.rest.resource.TrashResource;
34 import gr.ebs.gss.client.rest.resource.UploadStatusResource;
35 import gr.ebs.gss.client.rest.resource.UserResource;
36 import gr.ebs.gss.client.rest.resource.UserSearchResource;
38 import com.google.gwt.http.client.Request;
39 import com.google.gwt.http.client.Response;
44 public abstract class GetCommand<T extends RestResource> extends RestCommand{
46 boolean complete = false;
50 public GetCommand(Class<T> theclass, String pathToGet){
51 this(theclass,pathToGet,true);
54 public GetCommand(Class<T> theclass, String pathToGet, boolean showLoading){
55 setShowLoadingIndicator(showLoading);
56 if(isShowLoadingIndicator())
57 GSS.get().showLoadingIndicator();
58 this.aclass = theclass;
60 if(pathToGet.indexOf("?") != -1)
63 path =fixPath(pathToGet);
64 RestRequestBuilder builder = new RestRequestBuilder("GET", path);
67 handleHeaders(builder, path);
68 builder.sendRequest("", new RestCallback(path) {
71 public Object deserialize(Response response) {
72 return deserializeResponse(path, response);
76 public void handleError(Request request, Throwable exception) {
78 GetCommand.this.onError(exception);
82 public void handleSuccess(Object object) {
88 } catch (Exception ex) {
94 public GetCommand(Class<T> theclass, String username , String pathToGet){
95 this(theclass,username, pathToGet, true);
98 public GetCommand(Class<T> theclass, String username , String pathToGet, boolean showLoading){
99 setShowLoadingIndicator(showLoading);
100 if(isShowLoadingIndicator())
101 GSS.get().showLoadingIndicator();
102 this.aclass = theclass;
103 final String path = fixPath(pathToGet);
104 RestRequestBuilder builder = new RestRequestBuilder("GET", path);
107 handleHeaders(username, builder, path);
108 builder.sendRequest("", new RestCallback(path) {
111 public Object deserialize(Response response) {
112 return deserializeResponse(path, response);
116 public void handleError(Request request, Throwable exception) {
118 GetCommand.this.onError(exception);
122 public void handleSuccess(Object object) {
128 } catch (Exception ex) {
134 public boolean isComplete() {
138 public T getResult(){
142 public boolean execute() {
143 boolean com = isComplete();
145 if(isShowLoadingIndicator())
146 GSS.get().hideLoadingIndicator();
147 if(getResult() != null)
154 public Object deserializeResponse(String path, Response response) {
155 RestResource result1 = null;
156 if(aclass.equals(FolderResource.class)){
157 result1 = new FolderResource(path);
158 result1.createFromJSON(response.getText());
160 else if(aclass.equals(FileResource.class)){
161 result1 = new FileResource(path);
162 result1.createFromJSON(response.getHeader("X-GSS-Metadata"));
164 else if(aclass.equals(GroupsResource.class)){
165 result1 = new GroupsResource(path);
166 result1.createFromJSON(response.getText());
168 else if(aclass.equals(TrashResource.class)){
169 result1 = new TrashResource(path);
170 result1.createFromJSON(response.getText());
172 else if(aclass.equals(SharedResource.class)){
173 result1 = new SharedResource(path);
174 result1.createFromJSON(response.getText());
176 else if(aclass.equals(OthersResource.class)){
177 result1 = new OthersResource(path);
178 result1.createFromJSON(response.getText());
180 else if(aclass.equals(OtherUserResource.class)){
181 result1 = new OtherUserResource(path);
182 result1.createFromJSON(response.getText());
184 else if(aclass.equals(GroupResource.class)){
185 result1 = new GroupResource(path);
186 result1.createFromJSON(response.getText());
188 else if(aclass.equals(GroupUserResource.class)){
189 result1 = new GroupUserResource(path);
190 result1.createFromJSON(response.getText());
192 else if(aclass.equals(UserResource.class)){
193 result1 = new UserResource(path);
194 result1.createFromJSON(response.getText());
196 else if(aclass.equals(TagsResource.class)){
197 result1 = new TagsResource(path);
198 result1.createFromJSON(response.getText());
200 else if(aclass.equals(SearchResource.class)){
201 result1 = new SearchResource(path);
202 result1.createFromJSON(response.getText());
204 else if(aclass.equals(UserSearchResource.class)){
205 result1 = new UserSearchResource(path);
206 result1.createFromJSON(response.getText());
208 else if(aclass.equals(UploadStatusResource.class)){
209 result1 = new UploadStatusResource(path);
210 result1.createFromJSON(response.getText());