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.List;
13 * This is a wrapper around GetUserCatalogs that takes care of updating
14 * the application-wide user catalogs.
16 * @author Christos KK Loverdos <loverdos@gmail.com>
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) {
37 public void onError(Request request, Throwable t) {
38 getUserCatalogs.onError(request, t);
41 public UpdateUserCatalogs(Pithos app, List<String> ids, List<String> names) {
43 this.getUserCatalogs = new GetUserCatalogs(app, ids, names) {
45 public void onSuccess(Request request, Response response, JSONObject result, UserCatalogs userCatalogs) {
46 UpdateUserCatalogs.this.app.getUserCatalogs().updateFrom(userCatalogs);
47 UpdateUserCatalogs.this.onSuccess(userCatalogs, UpdateUserCatalogs.this.app.getUserCatalogs());
51 public void onError(Request request, Throwable t) {
52 UpdateUserCatalogs.this.onError(request, t);
58 public void execute() {
59 this.getUserCatalogs.execute();
62 public void scheduleDeferred() {
63 Scheduler.get().scheduleDeferred(this);