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.exceptions.InsufficientPermissionsException;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
29 import com.google.gwt.core.client.GWT;
30 import com.google.gwt.http.client.Request;
31 import com.google.gwt.http.client.RequestCallback;
32 import com.google.gwt.http.client.Response;
37 public abstract class MultipleDeleteCommand extends RestCommand {
40 Map<String, Throwable> errors = new HashMap<String, Throwable>();
42 List<String> successPaths = new ArrayList<String>();
46 public MultipleDeleteCommand(String[] pathToDelete){
47 this(pathToDelete, true);
50 public MultipleDeleteCommand(String[] pathToDelete, boolean showLoading){
51 setShowLoadingIndicator(showLoading);
52 if(isShowLoadingIndicator())
53 GSS.get().showLoadingIndicator();
55 for (final String pathg : pathToDelete) {
56 GWT.log("[DEL]"+pathg, null);
57 RestRequestBuilder builder = new RestRequestBuilder("DELETE", pathg);
60 handleHeaders(builder, pathg);
61 builder.sendRequest("", new RequestCallback() {
63 public void onError(Request arg0, Throwable arg1) {
64 errors.put(pathg, arg1);
67 public void onResponseReceived(Request arg0, Response arg1) {
68 if (arg1.getStatusCode() == 204)
69 successPaths.add(pathg);
70 else if(arg1.getStatusCode() == 403)
72 else if (arg1.getStatusCode() == 405)
73 errors.put(pathg, new InsufficientPermissionsException("You don't have permissions to delete this resource"));
75 errors.put(pathg, new RestException(pathg, arg1.getStatusCode(), arg1.getStatusText(), arg1.getText()));
79 } catch (Exception ex) {
80 errors.put(pathg, ex);
85 public boolean isComplete() {
86 return errors.size() + successPaths.size() == paths.length;
89 public boolean execute() {
90 boolean com = isComplete();
93 for(String p : errors.keySet())
94 onError(p, errors.get(p));
96 if(isShowLoadingIndicator())
97 GSS.get().hideLoadingIndicator();
103 public boolean hasErrors(){
104 return errors.size() >0;
109 * Retrieve the errors.
113 public Map<String, Throwable> getErrors() {
118 GWT.log("-ERRORS-->"+getErrors().size(), null);
119 for(String p : getErrors().keySet())
120 GWT.log("error:"+p, getErrors().get(p));
123 public abstract void onError(String path, Throwable throwable);