2 * Copyright 2011 GRNET S.A. All rights reserved.
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the following
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
30 * The views and conclusions contained in the software and
31 * documentation are those of the authors and should not be
32 * interpreted as representing official policies, either expressed
33 * or implied, of GRNET S.A.
35 package gr.grnet.pithos.web.client.commands;
37 import gr.grnet.pithos.web.client.Pithos;
38 import gr.grnet.pithos.web.client.rest.MultiplePostCommand;
39 import gr.grnet.pithos.web.client.rest.PostCommand;
40 import gr.grnet.pithos.web.client.rest.RestException;
41 import gr.grnet.pithos.web.client.rest.resource.FileResource;
42 import gr.grnet.pithos.web.client.rest.resource.FolderResource;
43 import gr.grnet.pithos.web.client.rest.resource.TrashFolderResource;
44 import gr.grnet.pithos.web.client.rest.resource.TrashResource;
46 import java.util.ArrayList;
47 import java.util.List;
49 import com.google.gwt.core.client.GWT;
50 import com.google.gwt.user.client.Command;
51 import com.google.gwt.user.client.DeferredCommand;
52 import com.google.gwt.user.client.ui.PopupPanel;
57 * Restore trashed files and folders.
60 public class RestoreTrashCommand implements Command{
61 private PopupPanel containerPanel;
63 public RestoreTrashCommand(PopupPanel _containerPanel){
64 containerPanel = _containerPanel;
68 public void execute() {
69 containerPanel.hide();
70 Object selection = Pithos.get().getCurrentSelection();
71 if (selection == null){
72 // Check to see if Trash Node is selected.
73 List folderList = new ArrayList();
74 TrashResource trashItem = Pithos.get().getTreeView().getTrash();
75 for(int i=0 ; i < trashItem.getFolders().size() ; i++)
76 folderList.add(trashItem.getFolders().get(i));
79 GWT.log("selection: " + selection.toString(), null);
80 if (selection instanceof FileResource) {
81 final FileResource resource = (FileResource)selection;
82 PostCommand rt = new PostCommand(resource.getUri()+"?restore=","", 200){
85 public void onComplete() {
87 //Pithos.get().getFolders().update(Pithos.get().getFolders().getTrashItem());
89 Pithos.get().showFileList(true);
93 public void onError(Throwable t) {
95 if(t instanceof RestException){
96 int statusCode = ((RestException)t).getHttpStatusCode();
98 Pithos.get().displayError("You don't have the necessary permissions");
99 else if(statusCode == 404)
100 Pithos.get().displayError("File does not exist");
101 else if(statusCode == 409)
102 Pithos.get().displayError("A file with the same name already exists");
103 else if(statusCode == 413)
104 Pithos.get().displayError("Your quota has been exceeded");
106 Pithos.get().displayError("Unable to restore file:"+((RestException)t).getHttpStatusText());
109 Pithos.get().displayError("System error restoring file:"+t.getMessage());
112 DeferredCommand.addCommand(rt);
114 else if (selection instanceof List) {
115 final List<FileResource> fdtos = (List<FileResource>) selection;
116 final List<String> fileIds = new ArrayList<String>();
117 for(FileResource f : fdtos)
118 fileIds.add(f.getUri()+"?restore=");
119 MultiplePostCommand rt = new MultiplePostCommand(fileIds.toArray(new String[0]), 200){
122 public void onComplete() {
124 //Pithos.get().getFolders().update(Pithos.get().getFolders().getTrashItem());
125 Pithos.get().showFileList(true);
129 public void onError(String p, Throwable t) {
131 if(t instanceof RestException){
132 int statusCode = ((RestException)t).getHttpStatusCode();
133 if(statusCode == 405)
134 Pithos.get().displayError("You don't have the necessary permissions");
135 else if(statusCode == 404)
136 Pithos.get().displayError("File does not exist");
137 else if(statusCode == 409)
138 Pithos.get().displayError("A file with the same name already exists");
139 else if(statusCode == 413)
140 Pithos.get().displayError("Your quota has been exceeded");
142 Pithos.get().displayError("Unable to restore file::"+((RestException)t).getHttpStatusText());
145 Pithos.get().displayError("System error restoring file:"+t.getMessage());
148 DeferredCommand.addCommand(rt);
150 else if (selection instanceof TrashFolderResource) {
151 final FolderResource resource = ((TrashFolderResource)selection).getResource();
152 PostCommand rt = new PostCommand(resource.getUri()+"?restore=","", 200){
155 public void onComplete() {
158 Pithos.get().getFolders().updateFolder((DnDTreeItem) Pithos.get().getFolders().getRootItem());
160 Pithos.get().getFolders().update(Pithos.get().getFolders().getTrashItem());
163 Pithos.get().getTreeView().updateTrashNode();
164 Pithos.get().getTreeView().updateRootNode();
168 public void onError(Throwable t) {
170 if(t instanceof RestException){
171 int statusCode = ((RestException)t).getHttpStatusCode();
172 if(statusCode == 405)
173 Pithos.get().displayError("You don't have the necessary permissions");
174 else if(statusCode == 404)
175 Pithos.get().displayError("Folder does not exist");
176 else if(statusCode == 409)
177 Pithos.get().displayError("A folder with the same name already exists");
178 else if(statusCode == 413)
179 Pithos.get().displayError("Your quota has been exceeded");
181 Pithos.get().displayError("Unable to restore folder::"+((RestException)t).getHttpStatusText());
184 Pithos.get().displayError("System error restoring folder:"+t.getMessage());
187 DeferredCommand.addCommand(rt);