Statistics
| Branch: | Tag: | Revision:

root / src / gr / ebs / gss / client / rest / resource / SearchResource.java @ 44d84dc0

History | View | Annotate | Download (3.4 kB)

1 a52ea5e4 pastith
/*
2 a52ea5e4 pastith
 * Copyright 2009 Electronic Business Systems Ltd.
3 a52ea5e4 pastith
 *
4 a52ea5e4 pastith
 * This file is part of GSS.
5 a52ea5e4 pastith
 *
6 a52ea5e4 pastith
 * GSS is free software: you can redistribute it and/or modify
7 a52ea5e4 pastith
 * it under the terms of the GNU General Public License as published by
8 a52ea5e4 pastith
 * the Free Software Foundation, either version 3 of the License, or
9 a52ea5e4 pastith
 * (at your option) any later version.
10 a52ea5e4 pastith
 *
11 a52ea5e4 pastith
 * GSS is distributed in the hope that it will be useful,
12 a52ea5e4 pastith
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 a52ea5e4 pastith
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 a52ea5e4 pastith
 * GNU General Public License for more details.
15 a52ea5e4 pastith
 *
16 a52ea5e4 pastith
 * You should have received a copy of the GNU General Public License
17 a52ea5e4 pastith
 * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
18 a52ea5e4 pastith
 */
19 a52ea5e4 pastith
package gr.ebs.gss.client.rest.resource;
20 a52ea5e4 pastith
21 db55fcd2 pastith
import java.util.ArrayList;
22 db55fcd2 pastith
import java.util.Date;
23 a52ea5e4 pastith
import java.util.LinkedList;
24 a52ea5e4 pastith
import java.util.List;
25 a52ea5e4 pastith
26 d6ba3052 koutsoub
import com.google.gwt.http.client.URL;
27 a52ea5e4 pastith
import com.google.gwt.json.client.JSONArray;
28 db55fcd2 pastith
import com.google.gwt.json.client.JSONObject;
29 a52ea5e4 pastith
import com.google.gwt.json.client.JSONParser;
30 a52ea5e4 pastith
31 a52ea5e4 pastith
/**
32 a52ea5e4 pastith
 * @author kman
33 a52ea5e4 pastith
 */
34 a52ea5e4 pastith
public class SearchResource extends RestResource {
35 a52ea5e4 pastith
36 555e8e59 pastith
        public SearchResource(String aUri) {
37 555e8e59 pastith
                super(aUri);
38 a52ea5e4 pastith
        }
39 a52ea5e4 pastith
40 db55fcd2 pastith
        List<FileResource> files = new ArrayList<FileResource>();
41 db55fcd2 pastith
        List<String> filePaths = new LinkedList<String>();
42 a52ea5e4 pastith
43 a52ea5e4 pastith
        /**
44 a52ea5e4 pastith
         * Retrieve the files.
45 a52ea5e4 pastith
         *
46 a52ea5e4 pastith
         * @return the files
47 a52ea5e4 pastith
         */
48 db55fcd2 pastith
        public List<String> getFilePaths() {
49 db55fcd2 pastith
                return filePaths;
50 db55fcd2 pastith
        }
51 db55fcd2 pastith
52 db55fcd2 pastith
        /**
53 db55fcd2 pastith
         * Modify the files.
54 db55fcd2 pastith
         *
55 0e4865ee pastith
         * @param newFilePaths the files to set
56 db55fcd2 pastith
         */
57 0e4865ee pastith
        public void setFilePaths(List<String> newFilePaths) {
58 0e4865ee pastith
                filePaths = newFilePaths;
59 db55fcd2 pastith
        }
60 db55fcd2 pastith
61 db55fcd2 pastith
        /**
62 db55fcd2 pastith
         * Retrieve the files.
63 db55fcd2 pastith
         *
64 db55fcd2 pastith
         * @return the files
65 db55fcd2 pastith
         */
66 db55fcd2 pastith
        public List<FileResource> getFiles() {
67 a52ea5e4 pastith
                return files;
68 a52ea5e4 pastith
        }
69 a52ea5e4 pastith
70 a52ea5e4 pastith
        /**
71 a52ea5e4 pastith
         * Modify the files.
72 a52ea5e4 pastith
         *
73 0e4865ee pastith
         * @param newFiles the files to set
74 a52ea5e4 pastith
         */
75 0e4865ee pastith
        public void setFiles(List<FileResource> newFiles) {
76 0e4865ee pastith
                files = newFiles;
77 a52ea5e4 pastith
        }
78 a52ea5e4 pastith
79 0e4865ee pastith
        @Override
80 a52ea5e4 pastith
        public void createFromJSON(String text) {
81 a52ea5e4 pastith
                JSONArray subs = JSONParser.parse(text).isArray();
82 a52ea5e4 pastith
                if (subs != null)
83 db55fcd2 pastith
                        for (int i = 0; i < subs.size(); i++) {
84 db55fcd2 pastith
                                JSONObject fo = subs.get(i).isObject();
85 db55fcd2 pastith
                                if (fo != null) {
86 db55fcd2 pastith
                                        String fname = unmarshallString(fo, "name");
87 db55fcd2 pastith
                                        String fowner = unmarshallString(fo, "owner");
88 0e4865ee pastith
                                        String fcontent = unmarshallString(fo, "content");
89 d6ba3052 koutsoub
                                        String fpath = unmarshallString(fo, "path");
90 d6ba3052 koutsoub
                                        fpath = URL.decodeComponent(fpath);
91 db55fcd2 pastith
                                        Integer fversion = null;
92 db55fcd2 pastith
                                        if (fo.get("version") != null)
93 db55fcd2 pastith
                                                fversion = new Integer(fo.get("version").toString());
94 db55fcd2 pastith
                                        boolean fdeleted = unmarshallBoolean(fo, "deleted");
95 db55fcd2 pastith
                                        Date fcreationDate = null;
96 db55fcd2 pastith
                                        if (fo.get("creationDate") != null)
97 db55fcd2 pastith
                                                fcreationDate = new Date(new Long(fo.get("creationDate").toString()));
98 10786b3c Panagiotis Astithas
                                        Date fmodificationDate = null;
99 10786b3c Panagiotis Astithas
                                        if (fo.get("modificationDate") != null)
100 10786b3c Panagiotis Astithas
                                                fmodificationDate = new Date(new Long(fo.get("modificationDate").toString()));
101 db55fcd2 pastith
                                        String furi = unmarshallString(fo,"uri");
102 db55fcd2 pastith
                                        Long fsize = 0L;
103 db55fcd2 pastith
                                        if(fo.get("size") != null)
104 db55fcd2 pastith
                                                fsize = new Long(fo.get("size").toString());
105 db55fcd2 pastith
                                        filePaths.add(furi);
106 db55fcd2 pastith
                                        FileResource fs = new FileResource(furi);
107 db55fcd2 pastith
                                        fs.setName(fname);
108 db55fcd2 pastith
                                        fs.setOwner(fowner);
109 db55fcd2 pastith
                                        fs.setVersion(fversion);
110 db55fcd2 pastith
                                        fs.setContentLength(fsize);
111 db55fcd2 pastith
                                        fs.setDeleted(fdeleted);
112 db55fcd2 pastith
                                        fs.setCreationDate(fcreationDate);
113 10786b3c Panagiotis Astithas
                                        fs.setModificationDate(fmodificationDate);
114 0e4865ee pastith
                                        fs.setContentType(fcontent);
115 555e8e59 pastith
                                        fs.setPath(fpath);
116 db55fcd2 pastith
                                        files.add(fs);
117 db55fcd2 pastith
                                }
118 db55fcd2 pastith
                        }
119 a52ea5e4 pastith
        }
120 a52ea5e4 pastith
121 62f168b2 Giannis Koutsoubos
        @Override
122 62f168b2 Giannis Koutsoubos
        public String getLastModifiedSince() {
123 62f168b2 Giannis Koutsoubos
                return null;
124 62f168b2 Giannis Koutsoubos
        }
125 a52ea5e4 pastith
}