Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / SharingUsers.java @ f7c37cc8

History | View | Annotate | Download (2.8 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 6d8e0f58 Christos Stathis
package gr.grnet.pithos.web.client;
36 6d8e0f58 Christos Stathis
37 6d8e0f58 Christos Stathis
import java.util.ArrayList;
38 b9a1049a Christos KK Loverdos
import java.util.Collections;
39 f5023f13 Christos Stathis
import java.util.Date;
40 6d8e0f58 Christos Stathis
import java.util.List;
41 6d8e0f58 Christos Stathis
42 6d8e0f58 Christos Stathis
import com.google.gwt.http.client.Response;
43 6d8e0f58 Christos Stathis
import com.google.gwt.json.client.JSONArray;
44 6d8e0f58 Christos Stathis
import com.google.gwt.json.client.JSONObject;
45 6d8e0f58 Christos Stathis
import com.google.gwt.json.client.JSONParser;
46 6d8e0f58 Christos Stathis
import com.google.gwt.json.client.JSONValue;
47 6d8e0f58 Christos Stathis
48 6d8e0f58 Christos Stathis
public class SharingUsers extends Resource {
49 b9a1049a Christos KK Loverdos
        private List<String> userIDs;
50 6d8e0f58 Christos Stathis
51 6d8e0f58 Christos Stathis
        public static SharingUsers createFromResponse(Response response, SharingUsers result) {
52 6d8e0f58 Christos Stathis
                SharingUsers u;
53 6d8e0f58 Christos Stathis
                if (result == null)
54 6d8e0f58 Christos Stathis
                        u = new SharingUsers();
55 6d8e0f58 Christos Stathis
                else
56 6d8e0f58 Christos Stathis
                        u = result;
57 6d8e0f58 Christos Stathis
                u.populate(response);
58 6d8e0f58 Christos Stathis
                return u;
59 6d8e0f58 Christos Stathis
        }
60 6d8e0f58 Christos Stathis
61 6d8e0f58 Christos Stathis
        private void populate(Response response) {
62 b9a1049a Christos KK Loverdos
                userIDs = new ArrayList<String>();
63 6d8e0f58 Christos Stathis
        JSONValue json = JSONParser.parseStrict(response.getText());
64 6d8e0f58 Christos Stathis
        JSONArray array = json.isArray();
65 6d8e0f58 Christos Stathis
        if (array != null) {
66 6d8e0f58 Christos Stathis
            for (int i=0; i<array.size(); i++) {
67 6d8e0f58 Christos Stathis
                JSONObject o = array.get(i).isObject();
68 6d8e0f58 Christos Stathis
                if (o != null) {
69 b9a1049a Christos KK Loverdos
                        userIDs.add(unmarshallString(o, "name"));
70 6d8e0f58 Christos Stathis
                }
71 6d8e0f58 Christos Stathis
            }
72 6d8e0f58 Christos Stathis
        }
73 6d8e0f58 Christos Stathis
        }
74 6d8e0f58 Christos Stathis
75 b9a1049a Christos KK Loverdos
        public List<String> getUserIDs() {
76 b9a1049a Christos KK Loverdos
                return Collections.unmodifiableList(userIDs);
77 6d8e0f58 Christos Stathis
        }
78 f5023f13 Christos Stathis
79 f5023f13 Christos Stathis
        @Override
80 f5023f13 Christos Stathis
        public Date getLastModified() {
81 f5023f13 Christos Stathis
                return null;
82 f5023f13 Christos Stathis
        }
83 6d8e0f58 Christos Stathis
}