root / src / gr / ebs / gss / client / rest / DeleteCommand.java @ 2147acc8
History | View | Annotate | Download (2.5 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2009 Electronic Business Systems Ltd.
|
3 |
*
|
4 |
* This file is part of GSS.
|
5 |
*
|
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.
|
10 |
*
|
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.
|
15 |
*
|
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/>.
|
18 |
*/
|
19 |
package gr.ebs.gss.client.rest; |
20 |
|
21 |
import gr.ebs.gss.client.GSS; |
22 |
import gr.ebs.gss.client.exceptions.InsufficientPermissionsException; |
23 |
|
24 |
import com.google.gwt.http.client.Request; |
25 |
import com.google.gwt.http.client.RequestCallback; |
26 |
import com.google.gwt.http.client.Response; |
27 |
|
28 |
|
29 |
/**
|
30 |
* @author kman
|
31 |
*
|
32 |
*/
|
33 |
public abstract class DeleteCommand extends RestCommand{ |
34 |
|
35 |
boolean complete = false; |
36 |
|
37 |
public DeleteCommand(String pathToDelete){ |
38 |
this(pathToDelete, true); |
39 |
} |
40 |
|
41 |
|
42 |
public DeleteCommand(String pathToDelete, boolean showLoading){ |
43 |
setShowLoadingIndicator(showLoading); |
44 |
if(isShowLoadingIndicator())
|
45 |
GSS.get().showLoadingIndicator(); |
46 |
final String path; |
47 |
if(pathToDelete.endsWith("/")) |
48 |
path = pathToDelete; |
49 |
else
|
50 |
path = pathToDelete+"/";
|
51 |
RestRequestBuilder builder = new RestRequestBuilder("DELETE", path); |
52 |
|
53 |
try {
|
54 |
handleHeaders(builder, path); |
55 |
builder.sendRequest("", new RequestCallback() { |
56 |
|
57 |
|
58 |
public void onError(Request arg0, Throwable arg1) { |
59 |
complete = true;
|
60 |
DeleteCommand.this.onError(arg1); |
61 |
} |
62 |
|
63 |
|
64 |
public void onResponseReceived(Request arg0, Response arg1) { |
65 |
complete=true;
|
66 |
if(arg1.getStatusCode() == 204) |
67 |
onComplete(); |
68 |
else if(arg1.getStatusCode() == 403) |
69 |
sessionExpired(); |
70 |
else if(arg1.getStatusCode() == 405) |
71 |
DeleteCommand.this.onError(new InsufficientPermissionsException("You don't have permissions to delete this resource")); |
72 |
else
|
73 |
DeleteCommand.this.onError(new RestException(path, arg1.getStatusCode(), arg1.getStatusText(), arg1.getText()));
|
74 |
} |
75 |
|
76 |
}); |
77 |
} catch (Exception ex) { |
78 |
complete=true;
|
79 |
onError(ex); |
80 |
} |
81 |
} |
82 |
|
83 |
public boolean isComplete() { |
84 |
return complete;
|
85 |
} |
86 |
|
87 |
public boolean execute() { |
88 |
boolean com = isComplete();
|
89 |
if(com){
|
90 |
if(isShowLoadingIndicator())
|
91 |
GSS.get().hideLoadingIndicator(); |
92 |
return false; |
93 |
} |
94 |
return true; |
95 |
} |
96 |
|
97 |
} |