Revision bb160e3a

b/src/gr/grnet/pithos/web/client/Pithos.java
1423 1423
			selectedUrls.add(urls.get(i));
1424 1424
		fileList.selectByUrl(selectedUrls);
1425 1425
	}
1426
	
1427
	public void deleteAndCreateTrash() {
1428
		DeleteRequest delete = new DeleteRequest(getApiPath(), getUsername(), "/trash") {
1429
			
1430
			@Override
1431
			protected void onUnauthorized(Response response) {
1432
				if (retries >= MAX_RETRIES)
1433
					sessionExpired();
1434
            	else //retry
1435
            		Scheduler.get().scheduleDeferred(this);
1436
			}
1437
			
1438
			@Override
1439
			public void onSuccess(Resource result) {
1440
				createTrashContainer(null);
1441
			}
1442
			
1443
			@Override
1444
			public void onError(Throwable t) {
1445
            	if (retries >= MAX_RETRIES) {
1446
	                GWT.log("Error deleting trash", t);
1447
					setError(t);
1448
	                if (t instanceof RestException)
1449
	                    displayError("Error deleting trash: " + ((RestException) t).getHttpStatusText());
1450
	                else
1451
	                    displayError("System error deleting trash: " + t.getMessage());
1452
            	}
1453
            	else {//retry
1454
            		GWT.log("Retry " + retries);
1455
            		Scheduler.get().scheduleDeferred(this);
1456
            	}
1457
			}
1458
		};
1459
		delete.setHeader("X-Auth-Token", getToken());
1460
		Scheduler.get().scheduleDeferred(delete);
1461
	}
1426 1462
}
b/src/gr/grnet/pithos/web/client/commands/EmptyTrashCommand.java
70 70
		if (containerPanel != null)
71 71
			containerPanel.hide();
72 72
		
73
		final Folder trash = app.getAccount().getTrash();
74
		if (trash != null) {
75
			app.deleteFolder(trash, null); //deleteFolder will not delete the folder itself if it is a container
76
		}
77
	}
78

  
79
	protected void deleteSubfolder(final Iterator<Folder> iter2, final Command callback) {
80
		if (iter2.hasNext()) {
81
			final Folder f = iter2.next();
82
			GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, app.getApiPath(), f.getOwner(), "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix()), f) {
83
				
84
				@Override
85
				public void onSuccess(final Folder _f) {
86
					Iterator<File> iter3 = _f.getFiles().iterator();
87
					deleteFile(iter3, new Command() {
88
				
89
						@Override
90
						public void execute() {
91
							Iterator<Folder> iter4 = _f.getSubfolders().iterator();
92
							deleteSubfolder(iter4, new Command() {
93
								
94
								@Override
95
								public void execute() {
96
									String path = _f.getUri();
97
									DeleteRequest deleteF = new DeleteRequest(app.getApiPath(), _f.getOwner(), URL.encode(path)) {
98
										
99
										@Override
100
										public void onSuccess(Resource _result) {
101
											deleteSubfolder(iter2, callback);
102
										}
103
										
104
										@Override
105
										public void onError(Throwable t) {
106
											GWT.log("", t);
107
											app.setError(t);
108
											if (t instanceof RestException) {
109
												app.displayError("Unable to delete file:" + ((RestException) t).getHttpStatusText());
110
											}
111
											else
112
												app.displayError("System error deleting file:" + t.getMessage());
113
										}
114
		
115
										@Override
116
										protected void onUnauthorized(Response response) {
117
											app.sessionExpired();
118
										}
119
									};
120
									deleteF.setHeader("X-Auth-Token", app.getToken());
121
									Scheduler.get().scheduleDeferred(deleteF);
122
								}
123
							});
124
						}
125
					});
126
				}
127

  
128
				@Override
129
				public void onError(Throwable t) {
130
	                GWT.log("", t);
131
					app.setError(t);
132
	                if (t instanceof RestException) {
133
	                    app.displayError("Unable to get folder: " + ((RestException) t).getHttpStatusText());
134
	                }
135
	                else
136
	                	app.displayError("System error getting folder: " + t.getMessage());
137
				}
138

  
139
				@Override
140
				protected void onUnauthorized(Response response) {
141
					app.sessionExpired();
142
				}
143
			};
144
			getFolder.setHeader("X-Auth-Token", app.getToken());
145
			Scheduler.get().scheduleDeferred(getFolder);
146
		}
147
		else {
148
			if (callback != null)
149
				callback.execute();
150
		}
151
	}
152

  
153
	void deleteFile(final Iterator<File> iter, final Command callback) {
154
		if (iter.hasNext()) {
155
			File f = iter.next();
156
			String path = f.getUri();
157
			DeleteRequest deleteF = new DeleteRequest(app.getApiPath(), f.getOwner(), URL.encode(path)) {
158
				
159
				@Override
160
				public void onSuccess(Resource result) {
161
					deleteFile(iter, callback);
162
				}
163
				
164
				@Override
165
				public void onError(Throwable t) {
166
					GWT.log("", t);
167
					app.setError(t);
168
					if (t instanceof RestException) {
169
						app.displayError("Unable to delete file:" + ((RestException) t).getHttpStatusText());
170
					}
171
					else
172
						app.displayError("System error deleting file:" + t.getMessage());
173
				}
174

  
175
				@Override
176
				protected void onUnauthorized(Response response) {
177
					app.sessionExpired();
178
				}
179
			};
180
			deleteF.setHeader("X-Auth-Token", app.getToken());
181
			Scheduler.get().scheduleDeferred(deleteF);
182
		}
183
		else {
184
			if (callback != null)
185
				callback.execute();
186
		}
73
		app.deleteAndCreateTrash();
187 74
	}
188 75
}
b/src/gr/grnet/pithos/web/client/rest/DeleteRequest.java
51 51
 * Templates.
52 52
 */
53 53
public abstract class DeleteRequest implements ScheduledCommand {
54
    private String api;
54
	
55
	protected static final int MAX_RETRIES = 3; 
56

  
57
	protected int retries = 0; 
58

  
59
	private String api;
55 60

  
56 61
    protected String owner;
57 62

  

Also available in: Unified diff