Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / Invitations.java @ b551f85b

History | View | Annotate | Download (3.2 kB)

1 cae2a8db Christos Stathis
/*
2 e6e9f6e6 Christos KK Loverdos
 * Copyright 2011-2013 GRNET S.A. All rights reserved.
3 cae2a8db Christos Stathis
 *
4 cae2a8db Christos Stathis
 * Redistribution and use in source and binary forms, with or
5 cae2a8db Christos Stathis
 * without modification, are permitted provided that the following
6 cae2a8db Christos Stathis
 * conditions are met:
7 cae2a8db Christos Stathis
 *
8 cae2a8db Christos Stathis
 *   1. Redistributions of source code must retain the above
9 cae2a8db Christos Stathis
 *      copyright notice, this list of conditions and the following
10 cae2a8db Christos Stathis
 *      disclaimer.
11 cae2a8db Christos Stathis
 *
12 cae2a8db Christos Stathis
 *   2. Redistributions in binary form must reproduce the above
13 cae2a8db Christos Stathis
 *      copyright notice, this list of conditions and the following
14 cae2a8db Christos Stathis
 *      disclaimer in the documentation and/or other materials
15 cae2a8db Christos Stathis
 *      provided with the distribution.
16 cae2a8db Christos Stathis
 *
17 cae2a8db Christos Stathis
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 cae2a8db Christos Stathis
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 cae2a8db Christos Stathis
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 cae2a8db Christos Stathis
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 cae2a8db Christos Stathis
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 cae2a8db Christos Stathis
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 cae2a8db Christos Stathis
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 cae2a8db Christos Stathis
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 cae2a8db Christos Stathis
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 cae2a8db Christos Stathis
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 cae2a8db Christos Stathis
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 cae2a8db Christos Stathis
 * POSSIBILITY OF SUCH DAMAGE.
29 cae2a8db Christos Stathis
 *
30 cae2a8db Christos Stathis
 * The views and conclusions contained in the software and
31 cae2a8db Christos Stathis
 * documentation are those of the authors and should not be
32 cae2a8db Christos Stathis
 * interpreted as representing official policies, either expressed
33 cae2a8db Christos Stathis
 * or implied, of GRNET S.A.
34 cae2a8db Christos Stathis
 */
35 fd1da2eb Christos Stathis
package gr.grnet.pithos.web.client;
36 fd1da2eb Christos Stathis
37 6b48912a Christos Stathis
import java.util.ArrayList;
38 fd1da2eb Christos Stathis
import java.util.Date;
39 6b48912a Christos Stathis
import java.util.List;
40 fd1da2eb Christos Stathis
41 5300a16e Christos Stathis
import com.google.gwt.http.client.Response;
42 6b48912a Christos Stathis
import com.google.gwt.json.client.JSONArray;
43 5300a16e Christos Stathis
import com.google.gwt.json.client.JSONObject;
44 5300a16e Christos Stathis
import com.google.gwt.json.client.JSONParser;
45 5300a16e Christos Stathis
import com.google.gwt.json.client.JSONValue;
46 5300a16e Christos Stathis
47 fd1da2eb Christos Stathis
public class Invitations extends Resource {
48 fd1da2eb Christos Stathis
49 5300a16e Christos Stathis
        private int invitationsLeft = 0;
50 fd1da2eb Christos Stathis
        
51 6b48912a Christos Stathis
        private List<Invitation> sentInvitations = new ArrayList<Invitation>();
52 6b48912a Christos Stathis
        
53 fd1da2eb Christos Stathis
        @Override
54 fd1da2eb Christos Stathis
        public Date getLastModified() {
55 fd1da2eb Christos Stathis
                return null;
56 fd1da2eb Christos Stathis
        }
57 fd1da2eb Christos Stathis
58 fd1da2eb Christos Stathis
        public int getInvitationsLeft() {
59 fd1da2eb Christos Stathis
                return invitationsLeft;
60 fd1da2eb Christos Stathis
        }
61 fd1da2eb Christos Stathis
62 5300a16e Christos Stathis
        public static Invitations createFromResponse(Response response) {
63 5300a16e Christos Stathis
                Invitations result = new Invitations();
64 5300a16e Christos Stathis
                result.populate(response);
65 5300a16e Christos Stathis
                return result;
66 5300a16e Christos Stathis
        }
67 5300a16e Christos Stathis
68 5300a16e Christos Stathis
        private void populate(Response response) {
69 5300a16e Christos Stathis
        JSONValue json = JSONParser.parseStrict(response.getText());
70 5300a16e Christos Stathis
        JSONObject o = json.isObject();
71 6b48912a Christos Stathis
        if (o != null) {
72 5300a16e Christos Stathis
                invitationsLeft = unmarshallInt(o, "invitations");
73 6b48912a Christos Stathis
                JSONArray sent = o.get("sent").isArray();
74 6b48912a Christos Stathis
                if (sent != null) {
75 6b48912a Christos Stathis
                        for (int i=0; i<sent.size(); i++) {
76 6b48912a Christos Stathis
                                JSONObject ob = sent.get(i).isObject();
77 6b48912a Christos Stathis
                                if (ob != null) {
78 6b48912a Christos Stathis
                                        boolean accepted = unmarshallBoolean(ob, "is_accepted");
79 6b48912a Christos Stathis
                                        String email = unmarshallString(ob, "email");
80 6b48912a Christos Stathis
                                        String realname = unmarshallString(ob, "realname");
81 6b48912a Christos Stathis
                                        Invitation inv = new Invitation(accepted, realname, email);
82 6b48912a Christos Stathis
                                        sentInvitations.add(inv);
83 6b48912a Christos Stathis
                                }
84 6b48912a Christos Stathis
                        }
85 6b48912a Christos Stathis
                }
86 6b48912a Christos Stathis
        }
87 6b48912a Christos Stathis
        }
88 6b48912a Christos Stathis
89 6b48912a Christos Stathis
        public List<Invitation> getSentInvitations() {
90 6b48912a Christos Stathis
                return sentInvitations;
91 5300a16e Christos Stathis
        }
92 5300a16e Christos Stathis
93 fd1da2eb Christos Stathis
}