Revision fa5600f7
b/web_client/src/gr/grnet/pithos/web/client/FolderPropertiesDialog.java | ||
---|---|---|
34 | 34 |
*/ |
35 | 35 |
package gr.grnet.pithos.web.client; |
36 | 36 |
|
37 |
import com.google.gwt.core.client.Scheduler; |
|
37 | 38 |
import com.google.gwt.event.dom.client.KeyDownEvent; |
38 | 39 |
import com.google.gwt.user.client.Event; |
39 | 40 |
import gr.grnet.pithos.web.client.foldertree.Folder; |
41 |
import gr.grnet.pithos.web.client.foldertree.Resource; |
|
40 | 42 |
import gr.grnet.pithos.web.client.rest.PostCommand; |
43 |
import gr.grnet.pithos.web.client.rest.PutRequest; |
|
41 | 44 |
import gr.grnet.pithos.web.client.rest.RestException; |
42 | 45 |
import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper; |
43 | 46 |
|
... | ... | |
67 | 70 |
*/ |
68 | 71 |
public class FolderPropertiesDialog extends DialogBox { |
69 | 72 |
|
73 |
private GSS app; |
|
74 |
|
|
70 | 75 |
private CheckBox readForAll; |
71 | 76 |
|
72 | 77 |
/** |
... | ... | |
86 | 91 |
|
87 | 92 |
/** |
88 | 93 |
* The widget's constructor. |
89 |
* |
|
90 |
* @param _create true if the dialog is displayed for creating a new |
|
91 |
* sub-folder of the selected folder, false if it is displayed |
|
92 |
* for modifying the selected folder |
|
93 | 94 |
*/ |
94 |
public FolderPropertiesDialog(boolean _create, Folder selected) { |
|
95 |
public FolderPropertiesDialog(GSS app, boolean _create, Folder selected) { |
|
96 |
this.app = app; |
|
95 | 97 |
setAnimationEnabled(true); |
96 | 98 |
|
97 | 99 |
// Enable IE selection for the dialog (must disable it upon closing it) |
98 |
GSS.enableIESelection();
|
|
100 |
app.enableIESelection();
|
|
99 | 101 |
|
100 | 102 |
create = _create; |
101 | 103 |
|
... | ... | |
227 | 229 |
* (we disable the prevention on creation of the dialog) |
228 | 230 |
*/ |
229 | 231 |
public void closeDialog() { |
230 |
GSS.preventIESelection();
|
|
232 |
app.preventIESelection();
|
|
231 | 233 |
hide(); |
232 | 234 |
} |
233 | 235 |
|
... | ... | |
236 | 238 |
*/ |
237 | 239 |
private void createFolder() { |
238 | 240 |
String name = folderName.getText(); |
239 |
|
|
240 |
// PostCommand ep = new PostCommand(folder.getUri() + "?new=" + |
|
241 |
// URL.encodeComponent(name), "", 201) { |
|
242 |
// |
|
243 |
// @Override |
|
244 |
// public void onComplete() { |
|
245 |
// //TODO:CELLTREE |
|
246 |
// if(folder.getUri().equals(GSS.get().getTreeView().getMyFolders().getUri())){ |
|
247 |
// GSS.get().getTreeView().updateRootNode(); |
|
248 |
// } |
|
249 |
// else |
|
250 |
// GSS.get().getTreeView().updateNodeChildren((RestResourceWrapper) GSS.get().getTreeView().getSelection()); |
|
251 |
// //GSS.get().getFolders().updateFolder((DnDTreeItem) GSS.get().getFolders().getCurrent()); |
|
252 |
// } |
|
253 |
// |
|
254 |
// @Override |
|
255 |
// public void onError(Throwable t) { |
|
256 |
// GWT.log("", t); |
|
257 |
// if(t instanceof RestException){ |
|
258 |
// int statusCode = ((RestException)t).getHttpStatusCode(); |
|
259 |
// if(statusCode == 405) |
|
260 |
// GSS.get().displayError("You don't have the necessary" + |
|
261 |
// " permissions or a folder with same name " + |
|
262 |
// "already exists"); |
|
263 |
// else if(statusCode == 404) |
|
264 |
// GSS.get().displayError("Resource not found"); |
|
265 |
// else |
|
266 |
// GSS.get().displayError("Unable to create folder:" + |
|
267 |
// ((RestException)t).getHttpStatusText()); |
|
268 |
// } |
|
269 |
// else |
|
270 |
// GSS.get().displayError("System error creating folder:" + |
|
271 |
// t.getMessage()); |
|
272 |
// } |
|
273 |
// }; |
|
274 |
// DeferredCommand.addCommand(ep); |
|
275 |
|
|
241 |
String prefix = folder.getPrefix(); |
|
242 |
String path = app.getApiPath() + app.getUsername() + "/" + folder.getContainer() + "/" + (prefix.length() == 0 ? "" : prefix + "/") + name; |
|
243 |
PutRequest createFolder = new PutRequest(path) { |
|
244 |
@Override |
|
245 |
public void onSuccess(Resource result) { |
|
246 |
app.updateFolder(folder); |
|
247 |
} |
|
248 |
|
|
249 |
@Override |
|
250 |
public void onError(Throwable t) { |
|
251 |
GWT.log("", t); |
|
252 |
if (t instanceof RestException) { |
|
253 |
app.displayError("Unable to create folder:" + ((RestException) t).getHttpStatusText()); |
|
254 |
} |
|
255 |
else |
|
256 |
app.displayError("System error creating folder:" + t.getMessage()); |
|
257 |
} |
|
258 |
}; |
|
259 |
createFolder.setHeader("X-Auth-Token", "0000"); |
|
260 |
createFolder.setHeader("Accept", "*/*"); |
|
261 |
createFolder.setHeader("Content-Length", "0"); |
|
262 |
createFolder.setHeader("Content-Type", "application/folder"); |
|
263 |
Scheduler.get().scheduleDeferred(createFolder); |
|
276 | 264 |
} |
277 | 265 |
|
278 | 266 |
/** |
... | ... | |
296 | 284 |
// json.put("name", new JSONString(folderName.getText())); |
297 | 285 |
// //only update the read for all perm if the user is the owner |
298 | 286 |
// if (readForAll.getValue() != folder.isReadForAll()) |
299 |
// if (folder.getOwner().equals(GSS.get().getCurrentUserResource().getUsername()))
|
|
287 |
// if (folder.getOwner().equals(app.getCurrentUserResource().getUsername()))
|
|
300 | 288 |
// json.put("readForAll", JSONBoolean.getInstance(readForAll.getValue())); |
301 | 289 |
// if (permList.hasChanges()) { |
302 | 290 |
// JSONArray perma = new JSONArray(); |
... | ... | |
325 | 313 |
// if(getPostBody() != null && !"".equals(getPostBody().trim())){ |
326 | 314 |
// |
327 | 315 |
// |
328 |
// FolderResource fres = ((RestResourceWrapper) GSS.get().getTreeView().getSelection()).getResource();
|
|
316 |
// FolderResource fres = ((RestResourceWrapper) app.getTreeView().getSelection()).getResource();
|
|
329 | 317 |
// String initialPath = fres.getUri(); |
330 | 318 |
// String newPath = getPostBody().trim(); |
331 | 319 |
// fres.setUri(newPath); |
332 |
// ((RestResourceWrapper) GSS.get().getTreeView().getSelection()).getResource().setUri(newPath);
|
|
333 |
// ((RestResourceWrapper) GSS.get().getTreeView().getSelection()).setUri(newPath);
|
|
334 |
// GSS.get().getTreeView().updateNodeChildren(fres.getParentURI());
|
|
320 |
// ((RestResourceWrapper) app.getTreeView().getSelection()).getResource().setUri(newPath);
|
|
321 |
// ((RestResourceWrapper) app.getTreeView().getSelection()).setUri(newPath);
|
|
322 |
// app.getTreeView().updateNodeChildren(fres.getParentURI());
|
|
335 | 323 |
// if (permList.hasChanges()) { |
336 |
// GSS.get().getTreeView().updateMySharedNode();
|
|
324 |
// app.getTreeView().updateMySharedNode();
|
|
337 | 325 |
// } |
338 | 326 |
// /* |
339 | 327 |
// if(folderItem.getParentItem() != null && ((DnDTreeItem)folderItem.getParentItem()).getFolderResource() != null){ |
... | ... | |
341 | 329 |
// ((DnDTreeItem)folderItem.getParentItem()).getFolderResource().getSubfolderPaths().add(newPath); |
342 | 330 |
// }*/ |
343 | 331 |
// } |
344 |
// //GSS.get().getFolders().updateFolder( (DnDTreeItem) GSS.get().getFolders().getCurrent());
|
|
332 |
// //app.getFolders().updateFolder( (DnDTreeItem) app.getFolders().getCurrent());
|
|
345 | 333 |
// |
346 |
// GSS.get().showFileList(true);
|
|
334 |
// app.get().showFileList(true);
|
|
347 | 335 |
// } |
348 | 336 |
// |
349 | 337 |
// @Override |
... | ... | |
352 | 340 |
// if(t instanceof RestException){ |
353 | 341 |
// int statusCode = ((RestException)t).getHttpStatusCode(); |
354 | 342 |
// if(statusCode == 405) |
355 |
// GSS.get().displayError("You don't have the necessary permissions or" +
|
|
343 |
// app.displayError("You don't have the necessary permissions or" +
|
|
356 | 344 |
// " a folder with same name already exists"); |
357 | 345 |
// else if(statusCode == 404) |
358 |
// GSS.get().displayError("Resource not found, or user specified in sharing does not exist");
|
|
346 |
// app.displayError("Resource not found, or user specified in sharing does not exist");
|
|
359 | 347 |
// else |
360 |
// GSS.get().displayError("Unable to update folder: "+((RestException)t).getHttpStatusText());
|
|
348 |
// app.displayError("Unable to update folder: "+((RestException)t).getHttpStatusText());
|
|
361 | 349 |
// } |
362 | 350 |
// else |
363 |
// GSS.get().displayError("System error moifying file: "+t.getMessage());
|
|
351 |
// app.displayError("System error moifying file: "+t.getMessage());
|
|
364 | 352 |
// //TODO:CELLTREE |
365 |
// //GSS.get().getFolders().updateFolder( (DnDTreeItem) GSS.get().getFolders().getCurrent());
|
|
353 |
// //app.getFolders().updateFolder( (DnDTreeItem) app.getFolders().getCurrent());
|
|
366 | 354 |
// } |
367 | 355 |
// }; |
368 | 356 |
// DeferredCommand.addCommand(ep); |
... | ... | |
371 | 359 |
public void selectTab(int _tab) { |
372 | 360 |
inner.selectTab(_tab); |
373 | 361 |
} |
374 |
|
|
375 | 362 |
} |
b/web_client/src/gr/grnet/pithos/web/client/GSS.java | ||
---|---|---|
120 | 120 |
return account; |
121 | 121 |
} |
122 | 122 |
|
123 |
public void updateFolder(Folder f) { |
|
124 |
folderTreeView.updateFolder(f); |
|
125 |
} |
|
126 |
|
|
123 | 127 |
/** |
124 | 128 |
* An aggregate image bundle that pulls together all the images for this |
125 | 129 |
* application into a single bundle. |
b/web_client/src/gr/grnet/pithos/web/client/commands/NewFolderCommand.java | ||
---|---|---|
86 | 86 |
|
87 | 87 |
void displayNewFolderDialog() { |
88 | 88 |
if (folder != null) { |
89 |
FolderPropertiesDialog dlg = new FolderPropertiesDialog(true, folder); |
|
89 |
FolderPropertiesDialog dlg = new FolderPropertiesDialog(GSS.get(), true, folder);
|
|
90 | 90 |
dlg.center(); |
91 | 91 |
} |
92 | 92 |
} |
b/web_client/src/gr/grnet/pithos/web/client/foldertree/Folder.java | ||
---|---|---|
191 | 191 |
public boolean equals(Object other) { |
192 | 192 |
if (other instanceof Folder) { |
193 | 193 |
Folder o = (Folder) other; |
194 |
if (container != null) |
|
195 |
return prefix.equals(o.getPrefix()) && container.equals(o.getContainer()); |
|
196 |
else |
|
197 |
return o.getContainer() == null && name.equals(o.getName()); |
|
194 |
return (container + prefix).equals(o.getContainer() + o.getPrefix()); |
|
198 | 195 |
} |
199 | 196 |
return false; |
200 | 197 |
} |
201 | 198 |
|
202 | 199 |
@Override |
203 | 200 |
public int hashCode() { |
204 |
return prefix.hashCode() + name.hashCode();
|
|
201 |
return (container + prefix).hashCode();
|
|
205 | 202 |
} |
206 | 203 |
|
207 | 204 |
public Set<File> getFiles() { |
b/web_client/src/gr/grnet/pithos/web/client/foldertree/FolderTreeView.java | ||
---|---|---|
106 | 106 |
public Folder getSelection() { |
107 | 107 |
return model.getSelection(); |
108 | 108 |
} |
109 |
|
|
110 |
public void updateFolder(Folder folder) { |
|
111 |
model.updateFolder(folder); |
|
112 |
} |
|
109 | 113 |
} |
b/web_client/src/gr/grnet/pithos/web/client/foldertree/FolderTreeViewModel.java | ||
---|---|---|
51 | 51 |
import gr.grnet.pithos.web.client.foldertree.FolderTreeView.Templates; |
52 | 52 |
import gr.grnet.pithos.web.client.rest.GetRequest; |
53 | 53 |
import gr.grnet.pithos.web.client.rest.RestException; |
54 |
import java.util.HashMap; |
|
54 | 55 |
import java.util.Iterator; |
56 |
import java.util.Map; |
|
55 | 57 |
import java.util.Set; |
56 | 58 |
|
57 | 59 |
public class FolderTreeViewModel implements TreeViewModel { |
... | ... | |
68 | 70 |
@Override |
69 | 71 |
public void onBrowserEvent(Cell.Context context, com.google.gwt.dom.client.Element parent, Folder folder, com.google.gwt.dom.client.NativeEvent event, com.google.gwt.cell.client.ValueUpdater<Folder> valueUpdater) { |
70 | 72 |
if (event.getType().equals(ContextMenuEvent.getType().getName())) { |
71 |
Folder target = (Folder) context.getKey(); |
|
72 |
FolderTreeViewModel.this.selectionModel.setSelected(target, true); |
|
73 |
FolderContextMenu menu = new FolderContextMenu(FolderTreeView.images, target); |
|
73 |
FolderTreeViewModel.this.selectionModel.setSelected(folder, true); |
|
74 |
FolderContextMenu menu = new FolderContextMenu(FolderTreeView.images, folder); |
|
74 | 75 |
menu.setPopupPosition(event.getClientX(), event.getClientY()); |
75 | 76 |
menu.show(); |
76 | 77 |
} |
... | ... | |
79 | 80 |
|
80 | 81 |
private ListDataProvider<Folder> rootDataProvider = new ListDataProvider<Folder>(); |
81 | 82 |
|
83 |
private Map<Folder, ListDataProvider<Folder>> dataProviderMap = new HashMap<Folder, ListDataProvider<Folder>>(); |
|
84 |
|
|
82 | 85 |
private SingleSelectionModel<Folder> selectionModel; |
83 | 86 |
|
84 | 87 |
public FolderTreeViewModel(SingleSelectionModel<Folder> selectionModel) { |
... | ... | |
94 | 97 |
} |
95 | 98 |
else { |
96 | 99 |
final Folder f = (Folder) value; |
97 |
final ListDataProvider<Folder> dataProvider = new ListDataProvider<Folder>(); |
|
98 |
dataProvider.flush(); |
|
99 |
Scheduler.get().scheduleDeferred(new ScheduledCommand() { |
|
100 |
@Override |
|
101 |
public void execute() { |
|
102 |
final GSS app = GSS.get(); |
|
103 |
String path = app.getApiPath() + app.getUsername() + "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + f.getPrefix(); |
|
104 |
GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, path, f) { |
|
105 |
@Override |
|
106 |
public void onSuccess(Folder result) { |
|
107 |
Iterator<Folder> iter = result.getSubfolders().iterator(); |
|
108 |
fetchFolder(iter, dataProvider, result.getSubfolders()); |
|
109 |
} |
|
110 |
|
|
111 |
@Override |
|
112 |
public void onError(Throwable t) { |
|
113 |
GWT.log("Error getting folder", t); |
|
114 |
if (t instanceof RestException) |
|
115 |
GSS.get().displayError("Error getting folder: " + ((RestException) t).getHttpStatusText()); |
|
116 |
else |
|
117 |
GSS.get().displayError("System error fetching folder: " + t.getMessage()); |
|
118 |
} |
|
119 |
}; |
|
120 |
getFolder.setHeader("X-Auth-Token", app.getToken()); |
|
121 |
Scheduler.get().scheduleDeferred(getFolder); |
|
122 |
} |
|
123 |
}); |
|
100 |
if (dataProviderMap.get(f) == null) { |
|
101 |
dataProviderMap.put(f, new ListDataProvider<Folder>()); |
|
102 |
} |
|
103 |
final ListDataProvider<Folder> dataProvider = dataProviderMap.get(f); |
|
104 |
fetchFolder(f, dataProvider); |
|
124 | 105 |
return new DefaultNodeInfo<Folder>(dataProvider, folderCell, selectionModel, null); |
125 | 106 |
} |
126 | 107 |
} |
... | ... | |
174 | 155 |
public Folder getSelection() { |
175 | 156 |
return selectionModel.getSelectedObject(); |
176 | 157 |
} |
158 |
|
|
159 |
public void updateFolder(Folder folder) { |
|
160 |
if (dataProviderMap.get(folder) == null) { |
|
161 |
dataProviderMap.put(folder, new ListDataProvider<Folder>()); |
|
162 |
} |
|
163 |
final ListDataProvider<Folder> dataProvider = dataProviderMap.get(folder); |
|
164 |
fetchFolder(folder, dataProvider); |
|
165 |
} |
|
166 |
|
|
167 |
public void fetchFolder(final Folder f, final ListDataProvider<Folder> dataProvider) { |
|
168 |
dataProvider.flush(); |
|
169 |
Scheduler.get().scheduleDeferred(new ScheduledCommand() { |
|
170 |
@Override |
|
171 |
public void execute() { |
|
172 |
final GSS app = GSS.get(); |
|
173 |
String path = app.getApiPath() + app.getUsername() + "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + f.getPrefix(); |
|
174 |
GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, path, f) { |
|
175 |
@Override |
|
176 |
public void onSuccess(Folder result) { |
|
177 |
Iterator<Folder> iter = result.getSubfolders().iterator(); |
|
178 |
fetchFolder(iter, dataProvider, result.getSubfolders()); |
|
179 |
} |
|
180 |
|
|
181 |
@Override |
|
182 |
public void onError(Throwable t) { |
|
183 |
GWT.log("Error getting folder", t); |
|
184 |
if (t instanceof RestException) |
|
185 |
GSS.get().displayError("Error getting folder: " + ((RestException) t).getHttpStatusText()); |
|
186 |
else |
|
187 |
GSS.get().displayError("System error fetching folder: " + t.getMessage()); |
|
188 |
} |
|
189 |
}; |
|
190 |
getFolder.setHeader("X-Auth-Token", app.getToken()); |
|
191 |
Scheduler.get().scheduleDeferred(getFolder); |
|
192 |
} |
|
193 |
}); |
|
194 |
} |
|
177 | 195 |
} |
b/web_client/src/gr/grnet/pithos/web/client/rest/GetRequest.java | ||
---|---|---|
53 | 53 |
|
54 | 54 |
private int okCode; |
55 | 55 |
|
56 |
private String username; |
|
57 |
|
|
58 | 56 |
private T cached; |
59 | 57 |
|
60 | 58 |
private T result; |
... | ... | |
83 | 81 |
@Override |
84 | 82 |
public void execute() { |
85 | 83 |
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path); |
84 |
builder.setHeader("If-Modified-Since", "0"); |
|
86 | 85 |
for (String header : headers.keySet()) { |
87 |
builder.setHeader("If-Modified-Since", "0"); |
|
88 | 86 |
builder.setHeader(header, headers.get(header)); |
89 | 87 |
} |
90 | 88 |
try { |
b/web_client/src/gr/grnet/pithos/web/client/rest/PutRequest.java | ||
---|---|---|
1 |
/* |
|
2 |
* Copyright 2011 GRNET S.A. All rights reserved. |
|
3 |
* |
|
4 |
* Redistribution and use in source and binary forms, with or |
|
5 |
* without modification, are permitted provided that the following |
|
6 |
* conditions are met: |
|
7 |
* |
|
8 |
* 1. Redistributions of source code must retain the above |
|
9 |
* copyright notice, this list of conditions and the following |
|
10 |
* disclaimer. |
|
11 |
* |
|
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. |
|
16 |
* |
|
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. |
|
29 |
* |
|
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. |
|
34 |
*/ |
|
35 |
|
|
36 |
/* |
|
37 |
* Copyright 2011 GRNET S.A. All rights reserved. |
|
38 |
* |
|
39 |
* Redistribution and use in source and binary forms, with or |
|
40 |
* without modification, are permitted provided that the following |
|
41 |
* conditions are met: |
|
42 |
* |
|
43 |
* 1. Redistributions of source code must retain the above |
|
44 |
* copyright notice, this list of conditions and the following |
|
45 |
* disclaimer. |
|
46 |
* |
|
47 |
* 2. Redistributions in binary form must reproduce the above |
|
48 |
* copyright notice, this list of conditions and the following |
|
49 |
* disclaimer in the documentation and/or other materials |
|
50 |
* provided with the distribution. |
|
51 |
* |
|
52 |
* THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
53 |
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
54 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
55 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
56 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
57 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
58 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
59 |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
60 |
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
61 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
62 |
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
63 |
* POSSIBILITY OF SUCH DAMAGE. |
|
64 |
* |
|
65 |
* The views and conclusions contained in the software and |
|
66 |
* documentation are those of the authors and should not be |
|
67 |
* interpreted as representing official policies, either expressed |
|
68 |
* or implied, of GRNET S.A. |
|
69 |
*/ |
|
70 |
|
|
71 |
package gr.grnet.pithos.web.client.rest; |
|
72 |
|
|
73 |
import com.google.gwt.core.client.Scheduler.ScheduledCommand; |
|
74 |
import com.google.gwt.http.client.Request; |
|
75 |
import com.google.gwt.http.client.RequestBuilder; |
|
76 |
import com.google.gwt.http.client.RequestException; |
|
77 |
import com.google.gwt.http.client.Response; |
|
78 |
import gr.grnet.pithos.web.client.foldertree.Resource; |
|
79 |
import java.util.HashMap; |
|
80 |
import java.util.Map; |
|
81 |
|
|
82 |
public abstract class PutRequest implements ScheduledCommand { |
|
83 |
|
|
84 |
private String path; |
|
85 |
|
|
86 |
private String username; |
|
87 |
|
|
88 |
private Map<String, String> headers = new HashMap<String, String>(); |
|
89 |
|
|
90 |
public abstract void onSuccess(Resource result); |
|
91 |
|
|
92 |
public abstract void onError(Throwable t); |
|
93 |
|
|
94 |
public PutRequest(String path) { |
|
95 |
this.path = path; |
|
96 |
} |
|
97 |
|
|
98 |
@Override |
|
99 |
public void execute() { |
|
100 |
RequestBuilder builder = new RequestBuilder(RequestBuilder.PUT, path); |
|
101 |
for (String header : headers.keySet()) { |
|
102 |
builder.setHeader(header, headers.get(header)); |
|
103 |
} |
|
104 |
try { |
|
105 |
builder.sendRequest("", new RestRequestCallback(path, Response.SC_CREATED) { |
|
106 |
@Override |
|
107 |
public void onSuccess(Resource object) { |
|
108 |
PutRequest.this.onSuccess(object); |
|
109 |
} |
|
110 |
|
|
111 |
@Override |
|
112 |
public Resource deserialize(Response response) { |
|
113 |
return Resource.createFromResponse(Resource.class, response, null); |
|
114 |
} |
|
115 |
|
|
116 |
@Override |
|
117 |
public void onError(Request request, Throwable throwable) { |
|
118 |
PutRequest.this.onError(throwable); |
|
119 |
} |
|
120 |
}); |
|
121 |
} |
|
122 |
catch (RequestException e) { |
|
123 |
} |
|
124 |
} |
|
125 |
|
|
126 |
public void setHeader(String header, String value) { |
|
127 |
headers.put(header, value); |
|
128 |
} |
|
129 |
} |
Also available in: Unified diff