root / src / gr / grnet / pithos / web / client / catalog / UpdateUserCatalogs.java @ c8f8690d
History | View | Annotate | Download (2.2 kB)
1 |
package gr.grnet.pithos.web.client.catalog; |
---|---|
2 |
|
3 |
import com.google.gwt.core.client.Scheduler; |
4 |
import com.google.gwt.http.client.Request; |
5 |
import com.google.gwt.http.client.Response; |
6 |
import com.google.gwt.json.client.JSONObject; |
7 |
import gr.grnet.pithos.web.client.Helpers; |
8 |
import gr.grnet.pithos.web.client.Pithos; |
9 |
|
10 |
import java.util.Iterator; |
11 |
import java.util.List; |
12 |
import java.util.Map; |
13 |
|
14 |
/**
|
15 |
* This is a wrapper around GetUserCatalogs that takes care of updating
|
16 |
* the application-wide user catalogs.
|
17 |
*/
|
18 |
public class UpdateUserCatalogs implements Scheduler.ScheduledCommand { |
19 |
private final GetUserCatalogs getUserCatalogs; |
20 |
private final Pithos app; |
21 |
|
22 |
public UpdateUserCatalogs(Pithos app) {
|
23 |
this(app, null, null); |
24 |
} |
25 |
|
26 |
public UpdateUserCatalogs(Pithos app, String userID) { |
27 |
this(app, Helpers.toList(userID), null); |
28 |
} |
29 |
|
30 |
public UpdateUserCatalogs(Pithos app, List<String> ids) { |
31 |
this(app, ids, null); |
32 |
} |
33 |
|
34 |
public void onSuccess(UserCatalogs requestedUserCatalogs, UserCatalogs updatedUserCatalogs) { |
35 |
for(Map.Entry<String, String> uc : requestedUserCatalogs) { |
36 |
app.LOG("New displayName ", uc.getValue());
|
37 |
} |
38 |
} |
39 |
|
40 |
public void onError(Request request, Throwable t) { |
41 |
getUserCatalogs.onError(request, t); |
42 |
} |
43 |
|
44 |
public UpdateUserCatalogs(Pithos app, List<String> ids, List<String> names) { |
45 |
this.app = app;
|
46 |
this.getUserCatalogs = new GetUserCatalogs(app, ids, names) { |
47 |
@Override
|
48 |
public void onSuccess(Request request, Response response, JSONObject result, UserCatalogs userCatalogs) { |
49 |
UpdateUserCatalogs.this.app.getUserCatalogs().updateFrom(userCatalogs); |
50 |
UpdateUserCatalogs.this.onSuccess(userCatalogs, UpdateUserCatalogs.this.app.getUserCatalogs()); |
51 |
} |
52 |
|
53 |
@Override
|
54 |
public void onError(Request request, Throwable t) { |
55 |
UpdateUserCatalogs.this.onError(request, t); |
56 |
} |
57 |
}; |
58 |
} |
59 |
|
60 |
@Override
|
61 |
public void execute() { |
62 |
this.getUserCatalogs.execute();
|
63 |
} |
64 |
|
65 |
public void scheduleDeferred() { |
66 |
Scheduler.get().scheduleDeferred(this);
|
67 |
} |
68 |
|
69 |
public void scheduleEntry() { |
70 |
Scheduler.get().scheduleEntry(this);
|
71 |
} |
72 |
} |