1 package gr.grnet.pithos.web.client.catalog;
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;
10 import java.util.Iterator;
11 import java.util.List;
15 * This is a wrapper around GetUserCatalogs that takes care of updating
16 * the application-wide user catalogs.
18 public class UpdateUserCatalogs implements Scheduler.ScheduledCommand {
19 private final GetUserCatalogs getUserCatalogs;
20 private final Pithos app;
22 public UpdateUserCatalogs(Pithos app) {
23 this(app, null, null);
26 public UpdateUserCatalogs(Pithos app, String userID) {
27 this(app, Helpers.toList(userID), null);
30 public UpdateUserCatalogs(Pithos app, List<String> ids) {
34 public void onSuccess(UserCatalogs requestedUserCatalogs, UserCatalogs updatedUserCatalogs) {
35 for(Map.Entry<String, String> uc : requestedUserCatalogs) {
36 // app.LOG("New displayName ", uc.getValue());
40 public void onError(Request request, Throwable t) {
41 getUserCatalogs.onError(request, t);
44 public UpdateUserCatalogs(Pithos app, List<String> ids, List<String> names) {
46 this.getUserCatalogs = new GetUserCatalogs(app, ids, names) {
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());
54 public void onError(Request request, Throwable t) {
55 UpdateUserCatalogs.this.onError(request, t);
61 public void execute() {
62 this.getUserCatalogs.execute();
65 public void scheduleDeferred() {
66 Scheduler.get().scheduleDeferred(this);
69 public void scheduleEntry() {
70 Scheduler.get().scheduleEntry(this);