root / src / gr / grnet / pithos / web / client / commands / AddUserCommand.java @ ea94470a
History | View | Annotate | Download (3.7 kB)
1 | 4baffab1 | Christos Stathis | /*
|
---|---|---|---|
2 | 4baffab1 | Christos Stathis | * Copyright 2011 GRNET S.A. All rights reserved.
|
3 | 4baffab1 | Christos Stathis | *
|
4 | 4baffab1 | Christos Stathis | * Redistribution and use in source and binary forms, with or
|
5 | 4baffab1 | Christos Stathis | * without modification, are permitted provided that the following
|
6 | 4baffab1 | Christos Stathis | * conditions are met:
|
7 | 4baffab1 | Christos Stathis | *
|
8 | 4baffab1 | Christos Stathis | * 1. Redistributions of source code must retain the above
|
9 | 4baffab1 | Christos Stathis | * copyright notice, this list of conditions and the following
|
10 | 4baffab1 | Christos Stathis | * disclaimer.
|
11 | 4baffab1 | Christos Stathis | *
|
12 | 4baffab1 | Christos Stathis | * 2. Redistributions in binary form must reproduce the above
|
13 | 4baffab1 | Christos Stathis | * copyright notice, this list of conditions and the following
|
14 | 4baffab1 | Christos Stathis | * disclaimer in the documentation and/or other materials
|
15 | 4baffab1 | Christos Stathis | * provided with the distribution.
|
16 | 4baffab1 | Christos Stathis | *
|
17 | 4baffab1 | Christos Stathis | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 | 4baffab1 | Christos Stathis | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 | 4baffab1 | Christos Stathis | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 | 4baffab1 | Christos Stathis | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 | 4baffab1 | Christos Stathis | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | 4baffab1 | Christos Stathis | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 | 4baffab1 | Christos Stathis | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 | 4baffab1 | Christos Stathis | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 | 4baffab1 | Christos Stathis | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 | 4baffab1 | Christos Stathis | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 | 4baffab1 | Christos Stathis | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 | 4baffab1 | Christos Stathis | * POSSIBILITY OF SUCH DAMAGE.
|
29 | 4baffab1 | Christos Stathis | *
|
30 | 4baffab1 | Christos Stathis | * The views and conclusions contained in the software and
|
31 | 4baffab1 | Christos Stathis | * documentation are those of the authors and should not be
|
32 | 4baffab1 | Christos Stathis | * interpreted as representing official policies, either expressed
|
33 | 4baffab1 | Christos Stathis | * or implied, of GRNET S.A.
|
34 | 4baffab1 | Christos Stathis | */
|
35 | 4baffab1 | Christos Stathis | package gr.grnet.pithos.web.client.commands; |
36 | 4baffab1 | Christos Stathis | |
37 | 4baffab1 | Christos Stathis | import gr.grnet.pithos.web.client.Pithos; |
38 | 4baffab1 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Resource; |
39 | 4baffab1 | Christos Stathis | import gr.grnet.pithos.web.client.grouptree.Group; |
40 | 4baffab1 | Christos Stathis | import gr.grnet.pithos.web.client.rest.PostRequest; |
41 | 4baffab1 | Christos Stathis | import gr.grnet.pithos.web.client.rest.RestException; |
42 | 4baffab1 | Christos Stathis | |
43 | 4baffab1 | Christos Stathis | import com.google.gwt.core.client.GWT; |
44 | 4baffab1 | Christos Stathis | import com.google.gwt.core.client.Scheduler; |
45 | 9539e23d | Christos Stathis | import com.google.gwt.http.client.Response; |
46 | ea94470a | Christos Stathis | import com.google.gwt.http.client.URL; |
47 | 4baffab1 | Christos Stathis | import com.google.gwt.user.client.Command; |
48 | 4baffab1 | Christos Stathis | import com.google.gwt.user.client.Window; |
49 | 4baffab1 | Christos Stathis | import com.google.gwt.user.client.ui.PopupPanel; |
50 | 4baffab1 | Christos Stathis | |
51 | 4baffab1 | Christos Stathis | /**
|
52 | 4baffab1 | Christos Stathis | * Display the 'new folder' dialog for creating a new folder.
|
53 | 4baffab1 | Christos Stathis | *
|
54 | 4baffab1 | Christos Stathis | */
|
55 | 4baffab1 | Christos Stathis | public class AddUserCommand implements Command { |
56 | 4baffab1 | Christos Stathis | private PopupPanel containerPanel;
|
57 | 4baffab1 | Christos Stathis | |
58 | 4baffab1 | Christos Stathis | Group group;
|
59 | 4baffab1 | Christos Stathis | |
60 | 4baffab1 | Christos Stathis | Pithos app; |
61 | 4baffab1 | Christos Stathis | |
62 | 4baffab1 | Christos Stathis | /**
|
63 | 4baffab1 | Christos Stathis | * @param aContainerPanel
|
64 | 4baffab1 | Christos Stathis | */
|
65 | 4baffab1 | Christos Stathis | public AddUserCommand(Pithos _app, PopupPanel aContainerPanel, Group _group){ |
66 | 4baffab1 | Christos Stathis | app = _app; |
67 | 4baffab1 | Christos Stathis | containerPanel = aContainerPanel; |
68 | 4baffab1 | Christos Stathis | group = _group; |
69 | 4baffab1 | Christos Stathis | } |
70 | 4baffab1 | Christos Stathis | |
71 | 4baffab1 | Christos Stathis | @Override
|
72 | 4baffab1 | Christos Stathis | public void execute() { |
73 | 4baffab1 | Christos Stathis | if (containerPanel != null) |
74 | 4baffab1 | Christos Stathis | containerPanel.hide(); |
75 | 4baffab1 | Christos Stathis | String username = Window.prompt("Enter username:", ""); |
76 | 4baffab1 | Christos Stathis | if (username != null && username.length() > 0) { |
77 | 4baffab1 | Christos Stathis | group.addMember(username); |
78 | 4baffab1 | Christos Stathis | String path = "?update="; |
79 | 4baffab1 | Christos Stathis | PostRequest updateGroup = new PostRequest(app.getApiPath(), app.getUsername(), path) {
|
80 | 4baffab1 | Christos Stathis | |
81 | 4baffab1 | Christos Stathis | @Override
|
82 | abd8738f | Christos Stathis | public void onSuccess(@SuppressWarnings("unused") Resource result) { |
83 | 4baffab1 | Christos Stathis | app.updateGroupNode(group); |
84 | 4baffab1 | Christos Stathis | } |
85 | 4baffab1 | Christos Stathis | |
86 | 4baffab1 | Christos Stathis | @Override
|
87 | 4baffab1 | Christos Stathis | public void onError(Throwable t) { |
88 | 4baffab1 | Christos Stathis | GWT.log("", t);
|
89 | 4baffab1 | Christos Stathis | if (t instanceof RestException) { |
90 | 4baffab1 | Christos Stathis | app.displayError("Unable to update group:" + ((RestException) t).getHttpStatusText());
|
91 | 4baffab1 | Christos Stathis | } |
92 | 4baffab1 | Christos Stathis | else
|
93 | 4baffab1 | Christos Stathis | app.displayError("System error updating group:" + t.getMessage());
|
94 | 4baffab1 | Christos Stathis | } |
95 | 9539e23d | Christos Stathis | |
96 | 9539e23d | Christos Stathis | @Override
|
97 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
98 | 9539e23d | Christos Stathis | app.sessionExpired(); |
99 | 9539e23d | Christos Stathis | } |
100 | 4baffab1 | Christos Stathis | }; |
101 | 4baffab1 | Christos Stathis | updateGroup.setHeader("X-Auth-Token", app.getToken());
|
102 | 4baffab1 | Christos Stathis | String groupMembers = ""; |
103 | 4baffab1 | Christos Stathis | for (String u : group.getMembers()) |
104 | 4baffab1 | Christos Stathis | groupMembers += (u + ",");
|
105 | ea94470a | Christos Stathis | updateGroup.setHeader("X-Account-Group-" + URL.encodePathSegment(group.getName()), groupMembers); |
106 | 4baffab1 | Christos Stathis | Scheduler.get().scheduleDeferred(updateGroup); |
107 | 4baffab1 | Christos Stathis | } |
108 | 4baffab1 | Christos Stathis | } |
109 | 4baffab1 | Christos Stathis | } |