root / src / org / gss_project / gss / web / client / commands / GetUserCommand.java @ 1206:292dec4eae08
History | View | Annotate | Download (2.2 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2010 Electronic Business Systems Ltd.
|
3 |
*
|
4 |
* This file is part of GSS.
|
5 |
*
|
6 |
* GSS is free software: you can redistribute it and/or modify
|
7 |
* it under the terms of the GNU General Public License as published by
|
8 |
* the Free Software Foundation, either version 3 of the License, or
|
9 |
* (at your option) any later version.
|
10 |
*
|
11 |
* GSS is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 |
*/
|
19 |
package org.gss_project.gss.web.client.commands; |
20 |
|
21 |
import org.gss_project.gss.web.client.GSS; |
22 |
import org.gss_project.gss.web.client.rest.GetCommand; |
23 |
import org.gss_project.gss.web.client.rest.resource.UserResource; |
24 |
import org.gss_project.gss.web.client.rest.resource.UserSearchResource; |
25 |
|
26 |
import com.google.gwt.core.client.GWT; |
27 |
import com.google.gwt.user.client.Command; |
28 |
import com.google.gwt.user.client.DeferredCommand; |
29 |
|
30 |
|
31 |
/**
|
32 |
* This command manages usernames and the corresponding user's Full Name
|
33 |
* along with the HashMap collection in the GSS.java class
|
34 |
*
|
35 |
* @author natasa
|
36 |
*
|
37 |
*/
|
38 |
public class GetUserCommand implements Command{ |
39 |
|
40 |
/**
|
41 |
* User's username e.g johndoe@somewhere.com
|
42 |
*/
|
43 |
private String userName; |
44 |
|
45 |
public GetUserCommand(String _userName){ |
46 |
userName = _userName; |
47 |
} |
48 |
|
49 |
@Override
|
50 |
public void execute() { |
51 |
String path = GSS.get().getApiPath() + "users/" + userName; |
52 |
GetCommand<UserSearchResource> gg = new GetCommand<UserSearchResource>(UserSearchResource.class,
|
53 |
path, false ,null) { |
54 |
@Override
|
55 |
public void onComplete() { |
56 |
final UserSearchResource result = getResult();
|
57 |
for (UserResource user : result.getUsers()){
|
58 |
String username = user.getUsername();
|
59 |
String _userFullName = user.getName();
|
60 |
GSS.get().putUserToMap(username, _userFullName); |
61 |
} |
62 |
} |
63 |
@Override
|
64 |
public void onError(Throwable t) { |
65 |
GWT.log("", t);
|
66 |
GSS.get().displayError("Unable to fetch user's full name from the given username " + userName);
|
67 |
} |
68 |
}; |
69 |
DeferredCommand.addCommand(gg); |
70 |
|
71 |
} |
72 |
|
73 |
} |