Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / foldertree / FileVersions.java @ 8474a42a

History | View | Annotate | Download (3.3 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 611de529 Christos Stathis
package gr.grnet.pithos.web.client.foldertree;
36 611de529 Christos Stathis
37 611de529 Christos Stathis
import java.util.ArrayList;
38 611de529 Christos Stathis
import java.util.Date;
39 611de529 Christos Stathis
import java.util.List;
40 611de529 Christos Stathis
41 611de529 Christos Stathis
import com.google.gwt.http.client.Response;
42 611de529 Christos Stathis
import com.google.gwt.json.client.JSONArray;
43 7228fda0 Christos Stathis
import com.google.gwt.json.client.JSONNumber;
44 611de529 Christos Stathis
import com.google.gwt.json.client.JSONParser;
45 7228fda0 Christos Stathis
import com.google.gwt.json.client.JSONString;
46 611de529 Christos Stathis
import com.google.gwt.json.client.JSONValue;
47 cc0120ab Christos KK Loverdos
import gr.grnet.pithos.web.client.Resource;
48 611de529 Christos Stathis
49 611de529 Christos Stathis
public class FileVersions extends Resource {
50 611de529 Christos Stathis
        private List<Version> versions;
51 611de529 Christos Stathis
        
52 611de529 Christos Stathis
        public List<Version> getVersions() {
53 611de529 Christos Stathis
                return versions;
54 611de529 Christos Stathis
        }
55 611de529 Christos Stathis
56 611de529 Christos Stathis
        public static FileVersions createFromResponse(Response response) {
57 611de529 Christos Stathis
                FileVersions res =  new FileVersions();
58 611de529 Christos Stathis
                res.populate(response);
59 611de529 Christos Stathis
                return res;
60 611de529 Christos Stathis
        }
61 611de529 Christos Stathis
62 611de529 Christos Stathis
        private void populate(Response response) {
63 611de529 Christos Stathis
                versions = new ArrayList<Version>();
64 611de529 Christos Stathis
        JSONValue json = JSONParser.parseStrict(response.getText());
65 611de529 Christos Stathis
        JSONArray array = json.isObject().get("versions").isArray();
66 611de529 Christos Stathis
        if (array != null) {
67 611de529 Christos Stathis
            for (int i=0; i<array.size(); i++) {
68 611de529 Christos Stathis
                JSONArray o = array.get(i).isArray();
69 611de529 Christos Stathis
                if (o != null) {
70 611de529 Christos Stathis
                        int num = (int) o.get(0).isNumber().doubleValue();
71 7228fda0 Christos Stathis
                        Date date = null;
72 7228fda0 Christos Stathis
                        JSONNumber n = o.get(1).isNumber();
73 7228fda0 Christos Stathis
                        if (n != null)
74 7228fda0 Christos Stathis
                                date = new Date((long) (n.doubleValue() * 1000)); //Convert to millis
75 7228fda0 Christos Stathis
                        else {
76 7228fda0 Christos Stathis
                                JSONString s = o.get(1).isString();
77 7228fda0 Christos Stathis
                                if (s != null)
78 7228fda0 Christos Stathis
                                        date = new Date((long) (Double.parseDouble(s.stringValue()) * 1000));
79 7228fda0 Christos Stathis
                        }
80 611de529 Christos Stathis
                        Version v = new Version(num, date);
81 611de529 Christos Stathis
                        versions.add(v);
82 611de529 Christos Stathis
                }
83 611de529 Christos Stathis
            }
84 611de529 Christos Stathis
        }
85 611de529 Christos Stathis
        }
86 f5023f13 Christos Stathis
87 f5023f13 Christos Stathis
        @Override
88 f5023f13 Christos Stathis
        public Date getLastModified() {
89 f5023f13 Christos Stathis
                return null;
90 f5023f13 Christos Stathis
        }
91 611de529 Christos Stathis
}