root / src / gr / ebs / gss / client / rest / DeleteCommand.java @ d0d4d0f5
History | View | Annotate | Download (2.5 kB)
1 | a52ea5e4 | pastith | /*
|
---|---|---|---|
2 | a52ea5e4 | pastith | * Copyright 2009 Electronic Business Systems Ltd.
|
3 | a52ea5e4 | pastith | *
|
4 | a52ea5e4 | pastith | * This file is part of GSS.
|
5 | a52ea5e4 | pastith | *
|
6 | a52ea5e4 | pastith | * GSS is free software: you can redistribute it and/or modify
|
7 | a52ea5e4 | pastith | * it under the terms of the GNU General Public License as published by
|
8 | a52ea5e4 | pastith | * the Free Software Foundation, either version 3 of the License, or
|
9 | a52ea5e4 | pastith | * (at your option) any later version.
|
10 | a52ea5e4 | pastith | *
|
11 | a52ea5e4 | pastith | * GSS is distributed in the hope that it will be useful,
|
12 | a52ea5e4 | pastith | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | a52ea5e4 | pastith | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | a52ea5e4 | pastith | * GNU General Public License for more details.
|
15 | a52ea5e4 | pastith | *
|
16 | a52ea5e4 | pastith | * You should have received a copy of the GNU General Public License
|
17 | a52ea5e4 | pastith | * along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 | a52ea5e4 | pastith | */
|
19 | a52ea5e4 | pastith | package gr.ebs.gss.client.rest; |
20 | a52ea5e4 | pastith | |
21 | a52ea5e4 | pastith | import gr.ebs.gss.client.GSS; |
22 | a52ea5e4 | pastith | import gr.ebs.gss.client.exceptions.InsufficientPermissionsException; |
23 | a52ea5e4 | pastith | |
24 | a52ea5e4 | pastith | import com.google.gwt.http.client.Request; |
25 | a52ea5e4 | pastith | import com.google.gwt.http.client.RequestCallback; |
26 | a52ea5e4 | pastith | import com.google.gwt.http.client.Response; |
27 | a52ea5e4 | pastith | |
28 | a52ea5e4 | pastith | |
29 | a52ea5e4 | pastith | /**
|
30 | a52ea5e4 | pastith | * @author kman
|
31 | a52ea5e4 | pastith | *
|
32 | a52ea5e4 | pastith | */
|
33 | 895035a2 | pastith | public abstract class DeleteCommand extends RestCommand{ |
34 | a52ea5e4 | pastith | |
35 | a52ea5e4 | pastith | boolean complete = false; |
36 | a52ea5e4 | pastith | |
37 | 895035a2 | pastith | public DeleteCommand(String pathToDelete){ |
38 | aa8608d3 | koutsoub | this(pathToDelete, true); |
39 | aa8608d3 | koutsoub | } |
40 | aa8608d3 | koutsoub | |
41 | aa8608d3 | koutsoub | |
42 | 895035a2 | pastith | public DeleteCommand(String pathToDelete, boolean showLoading){ |
43 | aa8608d3 | koutsoub | setShowLoadingIndicator(showLoading); |
44 | aa8608d3 | koutsoub | if(isShowLoadingIndicator())
|
45 | aa8608d3 | koutsoub | GSS.get().showLoadingIndicator(); |
46 | a52ea5e4 | pastith | final String path; |
47 | a52ea5e4 | pastith | if(pathToDelete.endsWith("/")) |
48 | a52ea5e4 | pastith | path = pathToDelete; |
49 | a52ea5e4 | pastith | else
|
50 | a52ea5e4 | pastith | path = pathToDelete+"/";
|
51 | a52ea5e4 | pastith | RestRequestBuilder builder = new RestRequestBuilder("DELETE", path); |
52 | a52ea5e4 | pastith | |
53 | a52ea5e4 | pastith | try {
|
54 | a52ea5e4 | pastith | handleHeaders(builder, path); |
55 | a52ea5e4 | pastith | builder.sendRequest("", new RequestCallback() { |
56 | a52ea5e4 | pastith | |
57 | a52ea5e4 | pastith | |
58 | a52ea5e4 | pastith | public void onError(Request arg0, Throwable arg1) { |
59 | a52ea5e4 | pastith | complete = true;
|
60 | 895035a2 | pastith | DeleteCommand.this.onError(arg1); |
61 | a52ea5e4 | pastith | } |
62 | a52ea5e4 | pastith | |
63 | a52ea5e4 | pastith | |
64 | a52ea5e4 | pastith | public void onResponseReceived(Request arg0, Response arg1) { |
65 | a52ea5e4 | pastith | complete=true;
|
66 | a52ea5e4 | pastith | if(arg1.getStatusCode() == 204) |
67 | a52ea5e4 | pastith | onComplete(); |
68 | 05f65955 | koutsoub | else if(arg1.getStatusCode() == 403) |
69 | 05f65955 | koutsoub | sessionExpired(); |
70 | a52ea5e4 | pastith | else if(arg1.getStatusCode() == 405) |
71 | 895035a2 | pastith | DeleteCommand.this.onError(new InsufficientPermissionsException("You don't have permissions to delete this resource")); |
72 | a52ea5e4 | pastith | else
|
73 | 895035a2 | pastith | DeleteCommand.this.onError(new RestException(path, arg1.getStatusCode(), arg1.getStatusText(), arg1.getText()));
|
74 | a52ea5e4 | pastith | } |
75 | a52ea5e4 | pastith | |
76 | a52ea5e4 | pastith | }); |
77 | a52ea5e4 | pastith | } catch (Exception ex) { |
78 | a52ea5e4 | pastith | complete=true;
|
79 | a52ea5e4 | pastith | onError(ex); |
80 | a52ea5e4 | pastith | } |
81 | a52ea5e4 | pastith | } |
82 | a52ea5e4 | pastith | |
83 | a52ea5e4 | pastith | public boolean isComplete() { |
84 | a52ea5e4 | pastith | return complete;
|
85 | a52ea5e4 | pastith | } |
86 | a52ea5e4 | pastith | |
87 | a52ea5e4 | pastith | public boolean execute() { |
88 | a52ea5e4 | pastith | boolean com = isComplete();
|
89 | a52ea5e4 | pastith | if(com){
|
90 | aa8608d3 | koutsoub | if(isShowLoadingIndicator())
|
91 | aa8608d3 | koutsoub | GSS.get().hideLoadingIndicator(); |
92 | a52ea5e4 | pastith | return false; |
93 | a52ea5e4 | pastith | } |
94 | a52ea5e4 | pastith | return true; |
95 | a52ea5e4 | pastith | } |
96 | a52ea5e4 | pastith | |
97 | a52ea5e4 | pastith | } |