root / src / gr / grnet / pithos / web / client / commands / RemoveUserCommand.java @ ee77dbf1
History | View | Annotate | Download (4.6 kB)
1 | 4baffab1 | Christos Stathis | /*
|
---|---|---|---|
2 | cae2a8db | Christos Stathis | * Copyright 2011-2012 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 com.google.gwt.core.client.GWT; |
38 | 4baffab1 | Christos Stathis | import com.google.gwt.core.client.Scheduler; |
39 | 9539e23d | Christos Stathis | import com.google.gwt.http.client.Response; |
40 | ea94470a | Christos Stathis | import com.google.gwt.http.client.URL; |
41 | 4baffab1 | Christos Stathis | import com.google.gwt.user.client.Command; |
42 | 4baffab1 | Christos Stathis | import com.google.gwt.user.client.ui.PopupPanel; |
43 | ee77dbf1 | Christos KK Loverdos | import gr.grnet.pithos.web.client.Const; |
44 | ee77dbf1 | Christos KK Loverdos | import gr.grnet.pithos.web.client.Pithos; |
45 | ee77dbf1 | Christos KK Loverdos | import gr.grnet.pithos.web.client.Resource; |
46 | ee77dbf1 | Christos KK Loverdos | import gr.grnet.pithos.web.client.grouptree.Group; |
47 | ee77dbf1 | Christos KK Loverdos | import gr.grnet.pithos.web.client.grouptree.User; |
48 | ee77dbf1 | Christos KK Loverdos | import gr.grnet.pithos.web.client.rest.PostRequest; |
49 | ee77dbf1 | Christos KK Loverdos | import gr.grnet.pithos.web.client.rest.RestException; |
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 | public class RemoveUserCommand implements Command { |
55 | ee77dbf1 | Christos KK Loverdos | private PopupPanel containerPanel;
|
56 | 4baffab1 | Christos Stathis | |
57 | 4baffab1 | Christos Stathis | User user; |
58 | 4baffab1 | Christos Stathis | |
59 | 4baffab1 | Christos Stathis | Pithos app; |
60 | 4baffab1 | Christos Stathis | |
61 | ee77dbf1 | Christos KK Loverdos | /**
|
62 | ee77dbf1 | Christos KK Loverdos | * @param aContainerPanel
|
63 | ee77dbf1 | Christos KK Loverdos | */
|
64 | ee77dbf1 | Christos KK Loverdos | public RemoveUserCommand(Pithos _app, PopupPanel aContainerPanel, User _user) {
|
65 | 4baffab1 | Christos Stathis | app = _app; |
66 | ee77dbf1 | Christos KK Loverdos | containerPanel = aContainerPanel; |
67 | ee77dbf1 | Christos KK Loverdos | user = _user; |
68 | ee77dbf1 | Christos KK Loverdos | } |
69 | ee77dbf1 | Christos KK Loverdos | |
70 | ee77dbf1 | Christos KK Loverdos | @Override
|
71 | ee77dbf1 | Christos KK Loverdos | public void execute() { |
72 | ee77dbf1 | Christos KK Loverdos | if(containerPanel != null) { |
73 | ee77dbf1 | Christos KK Loverdos | containerPanel.hide(); |
74 | ee77dbf1 | Christos KK Loverdos | } |
75 | ee77dbf1 | Christos KK Loverdos | final String groupName = user.getGroup(); |
76 | ee77dbf1 | Christos KK Loverdos | final Group group = app.getAccount().getGroup(groupName); |
77 | ee77dbf1 | Christos KK Loverdos | if(group == null) { |
78 | ee77dbf1 | Christos KK Loverdos | return;
|
79 | ee77dbf1 | Christos KK Loverdos | } |
80 | ee77dbf1 | Christos KK Loverdos | group.removeUser(user); |
81 | ee77dbf1 | Christos KK Loverdos | String path = "?update="; |
82 | ee77dbf1 | Christos KK Loverdos | PostRequest updateGroup = new PostRequest(app, app.getApiPath(), app.getUserID(), path) {
|
83 | ee77dbf1 | Christos KK Loverdos | |
84 | ee77dbf1 | Christos KK Loverdos | @Override
|
85 | ee77dbf1 | Christos KK Loverdos | public void onSuccess(Resource result) { |
86 | ee77dbf1 | Christos KK Loverdos | app.fetchAccount(new Command() {
|
87 | ee77dbf1 | Christos KK Loverdos | |
88 | ee77dbf1 | Christos KK Loverdos | @Override
|
89 | ee77dbf1 | Christos KK Loverdos | public void execute() { |
90 | ee77dbf1 | Christos KK Loverdos | Group updatedGroup2 = app.getAccount().getGroup(groupName);
|
91 | ee77dbf1 | Christos KK Loverdos | if(updatedGroup2 != null) { |
92 | ee77dbf1 | Christos KK Loverdos | app.updateGroupNode(updatedGroup2); |
93 | ee77dbf1 | Christos KK Loverdos | } |
94 | ee77dbf1 | Christos KK Loverdos | else {
|
95 | ee77dbf1 | Christos KK Loverdos | app.updateGroupNode(null);
|
96 | ee77dbf1 | Christos KK Loverdos | } |
97 | ee77dbf1 | Christos KK Loverdos | } |
98 | ee77dbf1 | Christos KK Loverdos | }); |
99 | ee77dbf1 | Christos KK Loverdos | } |
100 | 4baffab1 | Christos Stathis | |
101 | ee77dbf1 | Christos KK Loverdos | @Override
|
102 | ee77dbf1 | Christos KK Loverdos | public void onError(Throwable t) { |
103 | ee77dbf1 | Christos KK Loverdos | GWT.log("", t);
|
104 | ee77dbf1 | Christos KK Loverdos | app.setError(t); |
105 | ee77dbf1 | Christos KK Loverdos | if(t instanceof RestException) { |
106 | ee77dbf1 | Christos KK Loverdos | app.displayError("Unable to update group:" + ((RestException) t).getHttpStatusText());
|
107 | ee77dbf1 | Christos KK Loverdos | } |
108 | ee77dbf1 | Christos KK Loverdos | else {
|
109 | ee77dbf1 | Christos KK Loverdos | app.displayError("System error updating group:" + t.getMessage());
|
110 | ee77dbf1 | Christos KK Loverdos | } |
111 | ee77dbf1 | Christos KK Loverdos | } |
112 | 9539e23d | Christos Stathis | |
113 | ee77dbf1 | Christos KK Loverdos | @Override
|
114 | ee77dbf1 | Christos KK Loverdos | protected void onUnauthorized(Response response) { |
115 | ee77dbf1 | Christos KK Loverdos | app.sessionExpired(); |
116 | ee77dbf1 | Christos KK Loverdos | } |
117 | ee77dbf1 | Christos KK Loverdos | }; |
118 | ee77dbf1 | Christos KK Loverdos | updateGroup.setHeader(Const.X_AUTH_TOKEN, app.getUserToken()); |
119 | ee77dbf1 | Christos KK Loverdos | final String groupMembers; |
120 | ee77dbf1 | Christos KK Loverdos | if(!group.getUsers().isEmpty()) {
|
121 | ee77dbf1 | Christos KK Loverdos | groupMembers = group.encodeUserIDsForXAccountGroup(); |
122 | ee77dbf1 | Christos KK Loverdos | } |
123 | ee77dbf1 | Christos KK Loverdos | else {
|
124 | ee77dbf1 | Christos KK Loverdos | groupMembers = "~";
|
125 | ee77dbf1 | Christos KK Loverdos | } |
126 | ee77dbf1 | Christos KK Loverdos | updateGroup.setHeader(Const.X_ACCOUNT_GROUP_ + URL.encodePathSegment(group.getName()), groupMembers);
|
127 | ee77dbf1 | Christos KK Loverdos | Scheduler.get().scheduleDeferred(updateGroup); |
128 | ee77dbf1 | Christos KK Loverdos | } |
129 | 4baffab1 | Christos Stathis | } |