root / web_client / src / gr / grnet / pithos / web / client / rest / resource / UserSearchResource.java @ 9e8e14e4
History | View | Annotate | Download (1.4 kB)
1 | ab1eb3f8 | Christos Stathis | /*
|
---|---|---|---|
2 | 6dd67d1c | Christos Stathis | * Copyright (c) 2011 Greek Research and Technology Network
|
3 | ab1eb3f8 | Christos Stathis | */
|
4 | ab1eb3f8 | Christos Stathis | package gr.grnet.pithos.web.client.rest.resource; |
5 | ab1eb3f8 | Christos Stathis | |
6 | ab1eb3f8 | Christos Stathis | import java.util.ArrayList; |
7 | ab1eb3f8 | Christos Stathis | import java.util.List; |
8 | ab1eb3f8 | Christos Stathis | |
9 | ab1eb3f8 | Christos Stathis | import com.google.gwt.json.client.JSONArray; |
10 | ab1eb3f8 | Christos Stathis | import com.google.gwt.json.client.JSONObject; |
11 | ab1eb3f8 | Christos Stathis | import com.google.gwt.json.client.JSONParser; |
12 | ab1eb3f8 | Christos Stathis | |
13 | ab1eb3f8 | Christos Stathis | /**
|
14 | ab1eb3f8 | Christos Stathis | * A container for the results of a search query for users.
|
15 | ab1eb3f8 | Christos Stathis | *
|
16 | ab1eb3f8 | Christos Stathis | */
|
17 | ab1eb3f8 | Christos Stathis | public class UserSearchResource extends RestResource { |
18 | ab1eb3f8 | Christos Stathis | |
19 | ab1eb3f8 | Christos Stathis | public UserSearchResource(String aUri) { |
20 | ab1eb3f8 | Christos Stathis | super(aUri);
|
21 | ab1eb3f8 | Christos Stathis | } |
22 | ab1eb3f8 | Christos Stathis | |
23 | ab1eb3f8 | Christos Stathis | List<UserResource> users = new ArrayList<UserResource>(); |
24 | ab1eb3f8 | Christos Stathis | |
25 | ab1eb3f8 | Christos Stathis | @Override
|
26 | ab1eb3f8 | Christos Stathis | public void createFromJSON(String text) { |
27 | ab1eb3f8 | Christos Stathis | JSONArray json = JSONParser.parse(text).isArray(); |
28 | ab1eb3f8 | Christos Stathis | if (json != null) |
29 | ab1eb3f8 | Christos Stathis | for (int i = 0; i < json.size(); i++) { |
30 | ab1eb3f8 | Christos Stathis | JSONObject j = json.get(i).isObject(); |
31 | ab1eb3f8 | Christos Stathis | if (j != null) { |
32 | ab1eb3f8 | Christos Stathis | String username = unmarshallString(j, "username"); |
33 | ab1eb3f8 | Christos Stathis | String name = unmarshallString(j, "name"); |
34 | ab1eb3f8 | Christos Stathis | String home = unmarshallString(j, "home"); |
35 | ab1eb3f8 | Christos Stathis | UserResource user = new UserResource(home);
|
36 | ab1eb3f8 | Christos Stathis | user.setName(name); |
37 | ab1eb3f8 | Christos Stathis | user.setUsername(username); |
38 | ab1eb3f8 | Christos Stathis | users.add(user); |
39 | ab1eb3f8 | Christos Stathis | } |
40 | ab1eb3f8 | Christos Stathis | } |
41 | ab1eb3f8 | Christos Stathis | } |
42 | ab1eb3f8 | Christos Stathis | |
43 | ab1eb3f8 | Christos Stathis | /**
|
44 | ab1eb3f8 | Christos Stathis | * Retrieve the users.
|
45 | ab1eb3f8 | Christos Stathis | *
|
46 | ab1eb3f8 | Christos Stathis | * @return the users
|
47 | ab1eb3f8 | Christos Stathis | */
|
48 | ab1eb3f8 | Christos Stathis | public List<UserResource> getUsers() { |
49 | ab1eb3f8 | Christos Stathis | return users;
|
50 | ab1eb3f8 | Christos Stathis | } |
51 | ab1eb3f8 | Christos Stathis | |
52 | ab1eb3f8 | Christos Stathis | /**
|
53 | ab1eb3f8 | Christos Stathis | * Modify the users.
|
54 | ab1eb3f8 | Christos Stathis | *
|
55 | ab1eb3f8 | Christos Stathis | * @param newUsers the users to set
|
56 | ab1eb3f8 | Christos Stathis | */
|
57 | ab1eb3f8 | Christos Stathis | public void setUsers(List<UserResource> newUsers) { |
58 | ab1eb3f8 | Christos Stathis | users = newUsers; |
59 | ab1eb3f8 | Christos Stathis | } |
60 | ab1eb3f8 | Christos Stathis | |
61 | ab1eb3f8 | Christos Stathis | @Override
|
62 | ab1eb3f8 | Christos Stathis | public String getLastModifiedSince() { |
63 | ab1eb3f8 | Christos Stathis | return null; |
64 | ab1eb3f8 | Christos Stathis | } |
65 | ab1eb3f8 | Christos Stathis | } |