Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / catalog / UpdateUserCatalogs.java @ ee77dbf1

History | View | Annotate | Download (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.List;
11

    
12
/**
13
 * This is a wrapper around GetUserCatalogs that takes care of updating
14
 * the application-wide user catalogs.
15
 */
16
public class UpdateUserCatalogs implements Scheduler.ScheduledCommand {
17
    private final GetUserCatalogs getUserCatalogs;
18
    private final Pithos app;
19

    
20
    public UpdateUserCatalogs(Pithos app) {
21
        this(app, null, null);
22
    }
23

    
24
    public UpdateUserCatalogs(Pithos app, String userID) {
25
        this(app, Helpers.toList(userID), null);
26
    }
27

    
28
    public UpdateUserCatalogs(Pithos app, List<String> ids) {
29
        this(app, ids, null);
30
    }
31

    
32
    public void onSuccess(UserCatalogs requestedUserCatalogs, UserCatalogs updatedUserCatalogs) {
33
    }
34

    
35
    public void onError(Request request, Throwable t) {
36
        getUserCatalogs.onError(request, t);
37
    }
38

    
39
    public UpdateUserCatalogs(Pithos app, List<String> ids, List<String> names) {
40
        this.app = app;
41
        this.getUserCatalogs = new GetUserCatalogs(app, ids, names) {
42
            @Override
43
            public void onSuccess(Request request, Response response, JSONObject result, UserCatalogs userCatalogs) {
44
                UpdateUserCatalogs.this.app.getUserCatalogs().updateFrom(userCatalogs);
45
                UpdateUserCatalogs.this.onSuccess(userCatalogs, UpdateUserCatalogs.this.app.getUserCatalogs());
46
            }
47

    
48
            @Override
49
            public void onError(Request request, Throwable t) {
50
                UpdateUserCatalogs.this.onError(request, t);
51
            }
52
        };
53
    }
54

    
55
    @Override
56
    public void execute() {
57
        this.getUserCatalogs.execute();
58
    }
59

    
60
    public void scheduleDeferred() {
61
        Scheduler.get().scheduleDeferred(this);
62
    }
63

    
64
    public void scheduleEntry() {
65
        Scheduler.get().scheduleEntry(this);
66
    }
67
}