*/
package gr.grnet.pithos.web.client.commands;
-import com.google.gwt.core.client.Scheduler;
import gr.grnet.pithos.web.client.Pithos;
import gr.grnet.pithos.web.client.foldertree.File;
import gr.grnet.pithos.web.client.foldertree.Folder;
import gr.grnet.pithos.web.client.foldertree.Resource;
-import gr.grnet.pithos.web.client.rest.PostRequest;
+import gr.grnet.pithos.web.client.rest.DeleteRequest;
+import gr.grnet.pithos.web.client.rest.GetRequest;
+import gr.grnet.pithos.web.client.rest.PutRequest;
import gr.grnet.pithos.web.client.rest.RestException;
import java.util.Iterator;
import java.util.List;
-
import com.google.gwt.core.client.GWT;
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.http.client.Response;
+import com.google.gwt.http.client.URL;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.PopupPanel;
@SuppressWarnings("unchecked")
@Override
public void execute() {
- app.updateFolder(((List<File>) resource).get(0).getParent(), true);
+ app.updateFolder(((List<File>) resource).get(0).getParent(), true, null);
}
});
}
trashFolder(toBeTrashed, new Command() {
@Override
public void execute() {
- app.updateFolder(toBeTrashed.getParent(), true);
+ app.updateFolder(toBeTrashed.getParent(), true, null);
}
});
}
private void trashFolder(final Folder f, final Command callback) {
- String path = f.getUri() + "?update=";
- PostRequest trashFolder = new PostRequest(app.getApiPath(), app.getUsername(), path) {
+ String path = "/" + Pithos.TRASH_CONTAINER + "/" + f.getPrefix();
+ PutRequest createFolder = new PutRequest(app.getApiPath(), app.getUsername(), path) {
@Override
public void onSuccess(@SuppressWarnings("unused") Resource result) {
- Iterator<File> iter = f.getFiles().iterator();
- trashFiles(iter, new Command() {
- @Override
- public void execute() {
- Iterator<Folder> iterf = f.getSubfolders().iterator();
- trashSubfolders(iterf, new Command() {
- @Override
- public void execute() {
- callback.execute();
- }
- });
- }
- });
+ GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, app.getApiPath(), f.getOwner(), "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix()), f) {
+
+ @Override
+ public void onSuccess(final Folder _f) {
+ Iterator<File> iter = _f.getFiles().iterator();
+ trashFiles(iter, new Command() {
+ @Override
+ public void execute() {
+ Iterator<Folder> iterf = _f.getSubfolders().iterator();
+ trashSubfolders(iterf, new Command() {
+
+ @Override
+ public void execute() {
+ DeleteRequest deleteFolder = new DeleteRequest(app.getApiPath(), _f.getOwner(), _f.getUri()) {
+
+ @Override
+ public void onSuccess(@SuppressWarnings("unused") Resource _result) {
+ if (callback != null)
+ callback.execute();
+ }
+
+ @Override
+ public void onError(Throwable t) {
+ GWT.log("", t);
+ if (t instanceof RestException) {
+ if (((RestException) t).getHttpStatusCode() == Response.SC_NOT_FOUND)
+ onSuccess(null);
+ else
+ app.displayError("Unable to delete folder: " + ((RestException) t).getHttpStatusText());
+ }
+ else
+ app.displayError("System error unable to delete folder: "+t.getMessage());
+ }
+
+ @Override
+ protected void onUnauthorized(Response response) {
+ app.sessionExpired();
+ }
+ };
+ deleteFolder.setHeader("X-Auth-Token", app.getToken());
+ Scheduler.get().scheduleDeferred(deleteFolder);
+ }
+ });
+ }
+ });
+ }
+
+ @Override
+ public void onError(Throwable t) {
+ GWT.log("", t);
+ if (t instanceof RestException) {
+ app.displayError("Unable to get folder: " + ((RestException) t).getHttpStatusText());
+ }
+ else
+ app.displayError("System error getting folder: " + t.getMessage());
+ }
+
+ @Override
+ protected void onUnauthorized(Response response) {
+ app.sessionExpired();
+ }
+ };
+ getFolder.setHeader("X-Auth-Token", app.getToken());
+ Scheduler.get().scheduleDeferred(getFolder);
}
@Override
else
app.displayError("System error creating folder:" + t.getMessage());
}
+
+ @Override
+ protected void onUnauthorized(Response response) {
+ app.sessionExpired();
+ }
};
- trashFolder.setHeader("X-Auth-Token", app.getToken());
- trashFolder.setHeader("X-Object-Meta-Trash", "true");
- Scheduler.get().scheduleDeferred(trashFolder);
+ createFolder.setHeader("X-Auth-Token", app.getToken());
+ createFolder.setHeader("Accept", "*/*");
+ createFolder.setHeader("Content-Length", "0");
+ createFolder.setHeader("Content-Type", "application/folder");
+ Scheduler.get().scheduleDeferred(createFolder);
}
+
+
protected void trashFiles(final Iterator<File> iter, final Command callback) {
if (iter.hasNext()) {
File file = iter.next();
- String path = file.getUri() + "?update=";
- PostRequest trashFile = new PostRequest(app.getApiPath(), app.getUsername(), path) {
+ String path = "/" + Pithos.TRASH_CONTAINER + "/" + file.getPath();
+ PutRequest trashFile = new PutRequest(app.getApiPath(), app.getUsername(), path) {
@Override
public void onSuccess(@SuppressWarnings("unused") Resource result) {
trashFiles(iter, callback);
else
app.displayError("System error unable to copy file: "+t.getMessage());
}
+
+ @Override
+ protected void onUnauthorized(Response response) {
+ app.sessionExpired();
+ }
};
trashFile.setHeader("X-Auth-Token", app.getToken());
- trashFile.setHeader("X-Object-Meta-Trash", "true");
+ trashFile.setHeader("X-Move-From", file.getUri());
Scheduler.get().scheduleDeferred(trashFile);
}
- else if (callback != null) {
+ else if (callback != null) {
callback.execute();
}
}
protected void trashSubfolders(final Iterator<Folder> iter, final Command callback) {
if (iter.hasNext()) {
final Folder f = iter.next();
- trashFolder(f, callback);
+ trashFolder(f, new Command() {
+
+ @Override
+ public void execute() {
+ trashSubfolders(iter, callback);
+ }
+ });
}
- else if (callback != null) {
- callback.execute();
+ else {
+ app.updateTrash(false, callback);
}
}
}