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