Statistics
| Branch: | Tag: | Revision:

root / src / gr / ebs / gss / client / rest / resource / FolderResource.java @ c5070ebe

History | View | Annotate | Download (13.3 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
20 a52ea5e4 pastith
package gr.ebs.gss.client.rest.resource;
21 a52ea5e4 pastith
22 c5070ebe Natasa Kapravelou
import gr.ebs.gss.client.GSS;
23 62f168b2 Giannis Koutsoubos
import gr.ebs.gss.client.rest.MultipleGetCommand;
24 62f168b2 Giannis Koutsoubos
import gr.ebs.gss.client.rest.MultipleGetCommand.Cached;
25 62f168b2 Giannis Koutsoubos
26 a52ea5e4 pastith
import java.util.ArrayList;
27 a52ea5e4 pastith
import java.util.Date;
28 a52ea5e4 pastith
import java.util.HashSet;
29 a52ea5e4 pastith
import java.util.LinkedList;
30 a52ea5e4 pastith
import java.util.List;
31 a52ea5e4 pastith
import java.util.Set;
32 a52ea5e4 pastith
33 a52ea5e4 pastith
import com.google.gwt.core.client.GWT;
34 b2bc76a3 koutsoub
import com.google.gwt.http.client.URL;
35 a52ea5e4 pastith
import com.google.gwt.json.client.JSONArray;
36 a52ea5e4 pastith
import com.google.gwt.json.client.JSONObject;
37 a52ea5e4 pastith
import com.google.gwt.json.client.JSONParser;
38 c5070ebe Natasa Kapravelou
import com.google.gwt.user.client.ui.TreeItem;
39 a52ea5e4 pastith
40 a52ea5e4 pastith
/**
41 a52ea5e4 pastith
 * @author kman
42 a52ea5e4 pastith
 */
43 a52ea5e4 pastith
public class FolderResource extends RestResource {
44 a52ea5e4 pastith
45 555e8e59 pastith
        public FolderResource(String aUri) {
46 555e8e59 pastith
                super(aUri);
47 a52ea5e4 pastith
        }
48 a52ea5e4 pastith
49 a52ea5e4 pastith
        String name;
50 a52ea5e4 pastith
51 a52ea5e4 pastith
        String owner;
52 a52ea5e4 pastith
53 a52ea5e4 pastith
        String createdBy;
54 a52ea5e4 pastith
55 a52ea5e4 pastith
        String modifiedBy;
56 a52ea5e4 pastith
57 a52ea5e4 pastith
        Date creationDate;
58 a52ea5e4 pastith
59 a52ea5e4 pastith
        Date modificationDate;
60 a52ea5e4 pastith
61 a52ea5e4 pastith
        List<String> filePaths = new LinkedList<String>();
62 a52ea5e4 pastith
63 a52ea5e4 pastith
        List<String> subfolderPaths = new LinkedList<String>();
64 a52ea5e4 pastith
65 a52ea5e4 pastith
        Set<PermissionHolder> permissions = new HashSet<PermissionHolder>();
66 a52ea5e4 pastith
67 a52ea5e4 pastith
        List<FolderResource> folders = new ArrayList<FolderResource>();
68 a52ea5e4 pastith
69 a52ea5e4 pastith
        List<FileResource> files = new ArrayList<FileResource>();
70 a52ea5e4 pastith
71 a52ea5e4 pastith
        String parentURI;
72 a52ea5e4 pastith
73 a52ea5e4 pastith
        boolean deleted = false;
74 a52ea5e4 pastith
75 a52ea5e4 pastith
        boolean needsExpanding = false;
76 a52ea5e4 pastith
77 d6ba3052 koutsoub
        String parentName;
78 d6ba3052 koutsoub
79 62f168b2 Giannis Koutsoubos
        private boolean filesExpanded=false;
80 62f168b2 Giannis Koutsoubos
81 d6ba3052 koutsoub
        /**
82 d6ba3052 koutsoub
         * Modify the parentName.
83 d6ba3052 koutsoub
         *
84 555e8e59 pastith
         * @param aParentName the parentName to set
85 d6ba3052 koutsoub
         */
86 555e8e59 pastith
        public void setParentName(String aParentName) {
87 555e8e59 pastith
                parentName = aParentName;
88 d6ba3052 koutsoub
        }
89 d6ba3052 koutsoub
90 a52ea5e4 pastith
        /**
91 a52ea5e4 pastith
         * Retrieve the name.
92 a52ea5e4 pastith
         *
93 a52ea5e4 pastith
         * @return the name
94 a52ea5e4 pastith
         */
95 a52ea5e4 pastith
        public String getName() {
96 a52ea5e4 pastith
                return name;
97 a52ea5e4 pastith
        }
98 a52ea5e4 pastith
99 a52ea5e4 pastith
        /**
100 a52ea5e4 pastith
         * Modify the name.
101 a52ea5e4 pastith
         *
102 0e4865ee pastith
         * @param aName the name to set
103 a52ea5e4 pastith
         */
104 0e4865ee pastith
        public void setName(String aName) {
105 0e4865ee pastith
                name = aName;
106 a52ea5e4 pastith
        }
107 a52ea5e4 pastith
108 a52ea5e4 pastith
        /**
109 a52ea5e4 pastith
         * Retrieve the owner.
110 a52ea5e4 pastith
         *
111 a52ea5e4 pastith
         * @return the owner
112 a52ea5e4 pastith
         */
113 a52ea5e4 pastith
        public String getOwner() {
114 a52ea5e4 pastith
                return owner;
115 a52ea5e4 pastith
        }
116 a52ea5e4 pastith
117 a52ea5e4 pastith
        /**
118 a52ea5e4 pastith
         * Modify the owner.
119 a52ea5e4 pastith
         *
120 0e4865ee pastith
         * @param anOwner the owner to set
121 a52ea5e4 pastith
         */
122 0e4865ee pastith
        public void setOwner(String anOwner) {
123 0e4865ee pastith
                owner = anOwner;
124 a52ea5e4 pastith
        }
125 a52ea5e4 pastith
126 a52ea5e4 pastith
        /**
127 a52ea5e4 pastith
         * Retrieve the createdBy.
128 a52ea5e4 pastith
         *
129 a52ea5e4 pastith
         * @return the createdBy
130 a52ea5e4 pastith
         */
131 a52ea5e4 pastith
        public String getCreatedBy() {
132 a52ea5e4 pastith
                return createdBy;
133 a52ea5e4 pastith
        }
134 a52ea5e4 pastith
135 a52ea5e4 pastith
        /**
136 a52ea5e4 pastith
         * Modify the createdBy.
137 a52ea5e4 pastith
         *
138 0e4865ee pastith
         * @param aCreatedBy the createdBy to set
139 a52ea5e4 pastith
         */
140 0e4865ee pastith
        public void setCreatedBy(String aCreatedBy) {
141 0e4865ee pastith
                createdBy = aCreatedBy;
142 a52ea5e4 pastith
        }
143 a52ea5e4 pastith
144 a52ea5e4 pastith
        /**
145 a52ea5e4 pastith
         * Retrieve the modifiedBy.
146 a52ea5e4 pastith
         *
147 a52ea5e4 pastith
         * @return the modifiedBy
148 a52ea5e4 pastith
         */
149 a52ea5e4 pastith
        public String getModifiedBy() {
150 a52ea5e4 pastith
                return modifiedBy;
151 a52ea5e4 pastith
        }
152 a52ea5e4 pastith
153 a52ea5e4 pastith
        /**
154 a52ea5e4 pastith
         * Modify the modifiedBy.
155 a52ea5e4 pastith
         *
156 0e4865ee pastith
         * @param aModifiedBy the modifiedBy to set
157 a52ea5e4 pastith
         */
158 0e4865ee pastith
        public void setModifiedBy(String aModifiedBy) {
159 0e4865ee pastith
                modifiedBy = aModifiedBy;
160 a52ea5e4 pastith
        }
161 a52ea5e4 pastith
162 a52ea5e4 pastith
        /**
163 a52ea5e4 pastith
         * Retrieve the creationDate.
164 a52ea5e4 pastith
         *
165 a52ea5e4 pastith
         * @return the creationDate
166 a52ea5e4 pastith
         */
167 a52ea5e4 pastith
        public Date getCreationDate() {
168 a52ea5e4 pastith
                return creationDate;
169 a52ea5e4 pastith
        }
170 a52ea5e4 pastith
171 a52ea5e4 pastith
        /**
172 a52ea5e4 pastith
         * Modify the creationDate.
173 a52ea5e4 pastith
         *
174 0e4865ee pastith
         * @param aCreationDate the creationDate to set
175 a52ea5e4 pastith
         */
176 0e4865ee pastith
        public void setCreationDate(Date aCreationDate) {
177 0e4865ee pastith
                creationDate = aCreationDate;
178 a52ea5e4 pastith
        }
179 a52ea5e4 pastith
180 a52ea5e4 pastith
        /**
181 a52ea5e4 pastith
         * Retrieve the modificationDate.
182 a52ea5e4 pastith
         *
183 a52ea5e4 pastith
         * @return the modificationDate
184 a52ea5e4 pastith
         */
185 a52ea5e4 pastith
        public Date getModificationDate() {
186 a52ea5e4 pastith
                return modificationDate;
187 a52ea5e4 pastith
        }
188 a52ea5e4 pastith
189 a52ea5e4 pastith
        /**
190 a52ea5e4 pastith
         * Modify the modificationDate.
191 a52ea5e4 pastith
         *
192 0e4865ee pastith
         * @param aModificationDate the modificationDate to set
193 a52ea5e4 pastith
         */
194 0e4865ee pastith
        public void setModificationDate(Date aModificationDate) {
195 0e4865ee pastith
                modificationDate = aModificationDate;
196 a52ea5e4 pastith
        }
197 a52ea5e4 pastith
198 a52ea5e4 pastith
        /**
199 a52ea5e4 pastith
         * Retrieve the filePaths.
200 a52ea5e4 pastith
         *
201 a52ea5e4 pastith
         * @return the filePaths
202 a52ea5e4 pastith
         */
203 a52ea5e4 pastith
        public List<String> getFilePaths() {
204 a52ea5e4 pastith
                return filePaths;
205 a52ea5e4 pastith
        }
206 a52ea5e4 pastith
207 a52ea5e4 pastith
        /**
208 a52ea5e4 pastith
         * Modify the filePaths.
209 a52ea5e4 pastith
         *
210 0e4865ee pastith
         * @param newFilePaths the filePaths to set
211 a52ea5e4 pastith
         */
212 0e4865ee pastith
        public void setFilePaths(List<String> newFilePaths) {
213 0e4865ee pastith
                filePaths = newFilePaths;
214 a52ea5e4 pastith
        }
215 a52ea5e4 pastith
216 a52ea5e4 pastith
        /**
217 a52ea5e4 pastith
         * Retrieve the subfolderPaths.
218 a52ea5e4 pastith
         *
219 a52ea5e4 pastith
         * @return the subfolderPaths
220 a52ea5e4 pastith
         */
221 a52ea5e4 pastith
        public List<String> getSubfolderPaths() {
222 a52ea5e4 pastith
                return subfolderPaths;
223 a52ea5e4 pastith
        }
224 a52ea5e4 pastith
225 a52ea5e4 pastith
        /**
226 a52ea5e4 pastith
         * Modify the subfolderPaths.
227 a52ea5e4 pastith
         *
228 0e4865ee pastith
         * @param newSubfolderPaths the subfolderPaths to set
229 a52ea5e4 pastith
         */
230 0e4865ee pastith
        public void setSubfolderPaths(List<String> newSubfolderPaths) {
231 0e4865ee pastith
                subfolderPaths = newSubfolderPaths;
232 a52ea5e4 pastith
        }
233 a52ea5e4 pastith
234 a52ea5e4 pastith
        /**
235 a52ea5e4 pastith
         * Retrieve the permissions.
236 a52ea5e4 pastith
         *
237 a52ea5e4 pastith
         * @return the permissions
238 a52ea5e4 pastith
         */
239 a52ea5e4 pastith
        public Set<PermissionHolder> getPermissions() {
240 a52ea5e4 pastith
                return permissions;
241 a52ea5e4 pastith
        }
242 a52ea5e4 pastith
243 a52ea5e4 pastith
        /**
244 a52ea5e4 pastith
         * Modify the permissions.
245 a52ea5e4 pastith
         *
246 0e4865ee pastith
         * @param newPermissions the permissions to set
247 a52ea5e4 pastith
         */
248 0e4865ee pastith
        public void setPermissions(Set<PermissionHolder> newPermissions) {
249 0e4865ee pastith
                permissions = newPermissions;
250 a52ea5e4 pastith
        }
251 a52ea5e4 pastith
252 a52ea5e4 pastith
        /**
253 a52ea5e4 pastith
         * Retrieve the deleted.
254 a52ea5e4 pastith
         *
255 a52ea5e4 pastith
         * @return the deleted
256 a52ea5e4 pastith
         */
257 a52ea5e4 pastith
        public boolean isDeleted() {
258 a52ea5e4 pastith
                return deleted;
259 a52ea5e4 pastith
        }
260 a52ea5e4 pastith
261 a52ea5e4 pastith
        /**
262 a52ea5e4 pastith
         * Modify the deleted.
263 a52ea5e4 pastith
         *
264 0e4865ee pastith
         * @param newDeleted the deleted to set
265 a52ea5e4 pastith
         */
266 0e4865ee pastith
        public void setDeleted(boolean newDeleted) {
267 0e4865ee pastith
                deleted = newDeleted;
268 a52ea5e4 pastith
        }
269 a52ea5e4 pastith
270 a52ea5e4 pastith
        public void removeSubfolderPath(String spath) {
271 a52ea5e4 pastith
                if (subfolderPaths.remove(spath))
272 a52ea5e4 pastith
                        return;
273 a52ea5e4 pastith
                else if (subfolderPaths.remove(spath + "/"))
274 a52ea5e4 pastith
                        return;
275 a52ea5e4 pastith
                else
276 a52ea5e4 pastith
                        subfolderPaths.remove(spath.substring(0, spath.length() - 1));
277 a52ea5e4 pastith
        }
278 a52ea5e4 pastith
279 a52ea5e4 pastith
        /**
280 a52ea5e4 pastith
         * Retrieve the folders.
281 a52ea5e4 pastith
         *
282 a52ea5e4 pastith
         * @return the folders
283 a52ea5e4 pastith
         */
284 a52ea5e4 pastith
        public List<FolderResource> getFolders() {
285 a52ea5e4 pastith
                return folders;
286 a52ea5e4 pastith
        }
287 a52ea5e4 pastith
288 a52ea5e4 pastith
        /**
289 a52ea5e4 pastith
         * Modify the folders.
290 a52ea5e4 pastith
         *
291 0e4865ee pastith
         * @param newFolders the folders to set
292 a52ea5e4 pastith
         */
293 0e4865ee pastith
        public void setFolders(List<FolderResource> newFolders) {
294 0e4865ee pastith
                folders = newFolders;
295 a52ea5e4 pastith
        }
296 a52ea5e4 pastith
297 a52ea5e4 pastith
        /**
298 a52ea5e4 pastith
         * Retrieve the files.
299 a52ea5e4 pastith
         *
300 a52ea5e4 pastith
         * @return the files
301 a52ea5e4 pastith
         */
302 a52ea5e4 pastith
        public List<FileResource> getFiles() {
303 a52ea5e4 pastith
                return files;
304 a52ea5e4 pastith
        }
305 a52ea5e4 pastith
306 a52ea5e4 pastith
        /**
307 a52ea5e4 pastith
         * Modify the files.
308 a52ea5e4 pastith
         *
309 0e4865ee pastith
         * @param newFiles the files to set
310 a52ea5e4 pastith
         */
311 0e4865ee pastith
        public void setFiles(List<FileResource> newFiles) {
312 0e4865ee pastith
                files = newFiles;
313 a52ea5e4 pastith
        }
314 a52ea5e4 pastith
315 a52ea5e4 pastith
        /**
316 a52ea5e4 pastith
         * Retrieve the parentURI.
317 a52ea5e4 pastith
         *
318 a52ea5e4 pastith
         * @return the parentURI
319 a52ea5e4 pastith
         */
320 a52ea5e4 pastith
        public String getParentURI() {
321 a52ea5e4 pastith
                return parentURI;
322 a52ea5e4 pastith
        }
323 a52ea5e4 pastith
324 a52ea5e4 pastith
        /**
325 a52ea5e4 pastith
         * Modify the parentURI.
326 a52ea5e4 pastith
         *
327 0e4865ee pastith
         * @param aParentURI the parentURI to set
328 a52ea5e4 pastith
         */
329 0e4865ee pastith
        public void setParentURI(String aParentURI) {
330 0e4865ee pastith
                parentURI = aParentURI;
331 a52ea5e4 pastith
        }
332 a52ea5e4 pastith
333 0e4865ee pastith
        @Override
334 a52ea5e4 pastith
        public void createFromJSON(String text) {
335 a52ea5e4 pastith
                JSONObject json = (JSONObject) JSONParser.parse(text);
336 a52ea5e4 pastith
                name = unmarshallString(json, "name");
337 a52ea5e4 pastith
                owner = unmarshallString(json, "owner");
338 a52ea5e4 pastith
                deleted = unmarshallBoolean(json, "deleted");
339 a52ea5e4 pastith
                if (deleted)
340 a52ea5e4 pastith
                        GWT.log("FOUND A DELETED FOLDER:" + name, null);
341 a52ea5e4 pastith
342 8cc77d04 pastith
                if (json.get("parent") != null) {
343 8cc77d04 pastith
                        JSONObject parent = json.get("parent").isObject();
344 8cc77d04 pastith
                        parentURI = unmarshallString(parent, "uri");
345 8cc77d04 pastith
                        parentName = unmarshallString(parent, "name");
346 8cc77d04 pastith
                        if(parentName != null)
347 8cc77d04 pastith
                                parentName = URL.decodeComponent(parentName);
348 8cc77d04 pastith
                }
349 8cc77d04 pastith
350 a52ea5e4 pastith
                if (json.get("permissions") != null) {
351 a52ea5e4 pastith
                        JSONArray perm = json.get("permissions").isArray();
352 a52ea5e4 pastith
                        if (perm != null)
353 a52ea5e4 pastith
                                for (int i = 0; i < perm.size(); i++) {
354 a52ea5e4 pastith
                                        JSONObject obj = perm.get(i).isObject();
355 a52ea5e4 pastith
                                        if (obj != null) {
356 a52ea5e4 pastith
                                                PermissionHolder permission = new PermissionHolder();
357 a52ea5e4 pastith
                                                if (obj.get("user") != null)
358 a52ea5e4 pastith
                                                        permission.setUser(unmarshallString(obj, "user"));
359 a52ea5e4 pastith
                                                if (obj.get("group") != null)
360 fc5ef2cc droutsis
                                                        permission.setGroup(URL.decodeComponent(unmarshallString(obj, "group")));
361 a52ea5e4 pastith
                                                permission.setRead(unmarshallBoolean(obj, "read"));
362 a52ea5e4 pastith
                                                permission.setWrite(unmarshallBoolean(obj, "write"));
363 a52ea5e4 pastith
                                                permission.setModifyACL(unmarshallBoolean(obj, "modifyACL"));
364 a52ea5e4 pastith
                                                permissions.add(permission);
365 a52ea5e4 pastith
                                        }
366 a52ea5e4 pastith
                                }
367 a52ea5e4 pastith
                }
368 a52ea5e4 pastith
                if (json.get("folders") != null) {
369 a52ea5e4 pastith
                        JSONArray subs = json.get("folders").isArray();
370 a52ea5e4 pastith
                        if (subs != null)
371 a52ea5e4 pastith
                                for (int i = 0; i < subs.size(); i++) {
372 a52ea5e4 pastith
                                        JSONObject so = subs.get(i).isObject();
373 a52ea5e4 pastith
                                        if (so != null) {
374 a52ea5e4 pastith
                                                String subUri = unmarshallString(so, "uri");
375 a52ea5e4 pastith
                                                String subName = unmarshallString(so, "name");
376 a52ea5e4 pastith
                                                if (subUri != null && subName != null) {
377 a52ea5e4 pastith
                                                        if (!subUri.endsWith("/"))
378 a52ea5e4 pastith
                                                                subUri = subUri + "/";
379 a52ea5e4 pastith
                                                        FolderResource sub = new FolderResource(subUri);
380 a52ea5e4 pastith
                                                        sub.setName(subName);
381 a52ea5e4 pastith
                                                        sub.setNeedsExpanding(true);
382 a52ea5e4 pastith
                                                        folders.add(sub);
383 a52ea5e4 pastith
                                                        subfolderPaths.add(subUri);
384 a52ea5e4 pastith
                                                }
385 a52ea5e4 pastith
                                        }
386 a52ea5e4 pastith
                                }
387 a52ea5e4 pastith
                }
388 a52ea5e4 pastith
                if (json.get("files") != null) {
389 a52ea5e4 pastith
                        JSONArray subs = json.get("files").isArray();
390 a52ea5e4 pastith
                        if (subs != null)
391 a52ea5e4 pastith
                                for (int i = 0; i < subs.size(); i++) {
392 a52ea5e4 pastith
                                        JSONObject fo = subs.get(i).isObject();
393 a52ea5e4 pastith
                                        if (fo != null) {
394 a52ea5e4 pastith
                                                String fname = unmarshallString(fo, "name");
395 a52ea5e4 pastith
                                                String fowner = unmarshallString(fo, "owner");
396 0e4865ee pastith
                                                String fcontent = unmarshallString(fo, "content");
397 d6ba3052 koutsoub
                                                String fpath = unmarshallString(fo, "path");
398 d6ba3052 koutsoub
                                                fpath = URL.decodeComponent(fpath);
399 a52ea5e4 pastith
                                                Integer fversion = null;
400 a52ea5e4 pastith
                                                if (fo.get("version") != null)
401 a52ea5e4 pastith
                                                        fversion = new Integer(fo.get("version").toString());
402 a52ea5e4 pastith
                                                boolean fdeleted = unmarshallBoolean(fo, "deleted");
403 a52ea5e4 pastith
                                                Date fcreationDate = null;
404 a52ea5e4 pastith
                                                if (fo.get("creationDate") != null)
405 a52ea5e4 pastith
                                                        fcreationDate = new Date(new Long(fo.get("creationDate").toString()));
406 c73e2b13 Panagiotis Astithas
                                                Date fmodificationDate = null;
407 c73e2b13 Panagiotis Astithas
                                                if (fo.get("modificationDate") != null)
408 c73e2b13 Panagiotis Astithas
                                                        fmodificationDate = new Date(new Long(fo.get("modificationDate").toString()));
409 a52ea5e4 pastith
                                                String furi = unmarshallString(fo, "uri");
410 a52ea5e4 pastith
                                                Long fsize = 0L;
411 a52ea5e4 pastith
                                                if (fo.get("size") != null)
412 a52ea5e4 pastith
                                                        fsize = new Long(fo.get("size").toString());
413 a52ea5e4 pastith
                                                filePaths.add(furi);
414 a52ea5e4 pastith
                                                FileResource fs = new FileResource(furi);
415 a52ea5e4 pastith
                                                fs.setName(fname);
416 a52ea5e4 pastith
                                                fs.setOwner(fowner);
417 555e8e59 pastith
                                                fs.setPath(fpath);
418 a52ea5e4 pastith
                                                fs.setVersion(fversion);
419 a52ea5e4 pastith
                                                fs.setContentLength(fsize);
420 a52ea5e4 pastith
                                                fs.setDeleted(fdeleted);
421 a52ea5e4 pastith
                                                fs.setCreationDate(fcreationDate);
422 c73e2b13 Panagiotis Astithas
                                                fs.setModificationDate(fmodificationDate);
423 0e4865ee pastith
                                                fs.setContentType(fcontent);
424 a52ea5e4 pastith
                                                files.add(fs);
425 a52ea5e4 pastith
                                        }
426 a52ea5e4 pastith
                                }
427 a52ea5e4 pastith
                }
428 a52ea5e4 pastith
                if (json.get("creationDate") != null)
429 a52ea5e4 pastith
                        creationDate = new Date(new Long(json.get("creationDate").toString()));
430 a52ea5e4 pastith
                if (json.get("modificationDate") != null)
431 a52ea5e4 pastith
                        modificationDate = new Date(new Long(json.get("modificationDate").toString()));
432 a52ea5e4 pastith
        }
433 a52ea5e4 pastith
434 b2bc76a3 koutsoub
        public String getParentName(){
435 d6ba3052 koutsoub
                return parentName;
436 b2bc76a3 koutsoub
        }
437 b2bc76a3 koutsoub
438 a52ea5e4 pastith
        /**
439 a52ea5e4 pastith
         * Retrieve the needsExpanding.
440 a52ea5e4 pastith
         *
441 a52ea5e4 pastith
         * @return the needsExpanding
442 a52ea5e4 pastith
         */
443 a52ea5e4 pastith
        public boolean isNeedsExpanding() {
444 a52ea5e4 pastith
                return needsExpanding;
445 a52ea5e4 pastith
        }
446 a52ea5e4 pastith
447 a52ea5e4 pastith
        /**
448 a52ea5e4 pastith
         * Modify the needsExpanding.
449 a52ea5e4 pastith
         *
450 0e4865ee pastith
         * @param newNeedsExpanding the needsExpanding to set
451 a52ea5e4 pastith
         */
452 0e4865ee pastith
        public void setNeedsExpanding(boolean newNeedsExpanding) {
453 0e4865ee pastith
                needsExpanding = newNeedsExpanding;
454 a52ea5e4 pastith
        }
455 a52ea5e4 pastith
456 8c4469ce koutsoub
        public boolean isShared(){
457 8c4469ce koutsoub
458 8c4469ce koutsoub
                for(PermissionHolder perm : permissions){
459 8c4469ce koutsoub
                        if(perm.getUser() != null && !owner.equals(perm.getUser()))
460 8c4469ce koutsoub
                                return true;
461 8c4469ce koutsoub
                        if(perm.getGroup() != null)
462 8c4469ce koutsoub
                                return true;
463 8c4469ce koutsoub
                }
464 8c4469ce koutsoub
                return false;
465 8c4469ce koutsoub
        }
466 62f168b2 Giannis Koutsoubos
467 62f168b2 Giannis Koutsoubos
        @Override
468 62f168b2 Giannis Koutsoubos
        public String getLastModifiedSince() {
469 62f168b2 Giannis Koutsoubos
                if(modificationDate != null)
470 62f168b2 Giannis Koutsoubos
                        return getDate(modificationDate.getTime());
471 62f168b2 Giannis Koutsoubos
                return null;
472 62f168b2 Giannis Koutsoubos
        }
473 62f168b2 Giannis Koutsoubos
474 62f168b2 Giannis Koutsoubos
        public MultipleGetCommand.Cached[] getCache(){
475 62f168b2 Giannis Koutsoubos
                if(getSubfolderPaths().size() != getFolders().size()){
476 62f168b2 Giannis Koutsoubos
                        GWT.log("MISMATCH IN PATH AND FOLDERS SIZE", null);
477 62f168b2 Giannis Koutsoubos
                        return null;
478 62f168b2 Giannis Koutsoubos
                }
479 62f168b2 Giannis Koutsoubos
                MultipleGetCommand.Cached[] result = new MultipleGetCommand.Cached[getSubfolderPaths().size()];
480 62f168b2 Giannis Koutsoubos
                for(int i=0; i<getFolders().size();i++){
481 62f168b2 Giannis Koutsoubos
                        FolderResource r = getFolders().get(i);
482 62f168b2 Giannis Koutsoubos
                        Cached c = new Cached();
483 62f168b2 Giannis Koutsoubos
                        c.cache=r;
484 62f168b2 Giannis Koutsoubos
                        c.uri=r.uri;
485 62f168b2 Giannis Koutsoubos
                        result[i] = c;
486 62f168b2 Giannis Koutsoubos
                }
487 62f168b2 Giannis Koutsoubos
                return result;
488 62f168b2 Giannis Koutsoubos
        }
489 62f168b2 Giannis Koutsoubos
490 62f168b2 Giannis Koutsoubos
        public MultipleGetCommand.Cached[] getFileCache(){
491 62f168b2 Giannis Koutsoubos
                if(getFilePaths().size() != getFiles().size()){
492 62f168b2 Giannis Koutsoubos
                        GWT.log("MISMATCH IN PATH AND FILES SIZE", null);
493 62f168b2 Giannis Koutsoubos
                        return null;
494 62f168b2 Giannis Koutsoubos
                }
495 62f168b2 Giannis Koutsoubos
                if(!filesExpanded)
496 62f168b2 Giannis Koutsoubos
                        return null;
497 62f168b2 Giannis Koutsoubos
                MultipleGetCommand.Cached[] result = new MultipleGetCommand.Cached[getFilePaths().size()];
498 62f168b2 Giannis Koutsoubos
                for(int i=0; i<getFiles().size();i++){
499 62f168b2 Giannis Koutsoubos
                        FileResource r = getFiles().get(i);
500 62f168b2 Giannis Koutsoubos
                        Cached c = new Cached();
501 62f168b2 Giannis Koutsoubos
                        c.cache=r;
502 62f168b2 Giannis Koutsoubos
                        c.uri=r.uri;
503 62f168b2 Giannis Koutsoubos
                        result[i] = c;
504 62f168b2 Giannis Koutsoubos
                }
505 62f168b2 Giannis Koutsoubos
                return result;
506 62f168b2 Giannis Koutsoubos
        }
507 62f168b2 Giannis Koutsoubos
508 86c951b2 Panagiotis Astithas
        public void setFilesExpanded(boolean newFilesExpanded) {
509 86c951b2 Panagiotis Astithas
                filesExpanded = newFilesExpanded;
510 62f168b2 Giannis Koutsoubos
        }
511 c5070ebe Natasa Kapravelou
512 c5070ebe Natasa Kapravelou
        @Override
513 c5070ebe Natasa Kapravelou
        public void updateHistoryAbs(TreeItem item, String path){
514 c5070ebe Natasa Kapravelou
                try{
515 c5070ebe Natasa Kapravelou
                        if(getParentURI() == null){
516 c5070ebe Natasa Kapravelou
                                if(GSS.get().getFolders().getPopupTree().containsFolder(item, "Trash")){
517 c5070ebe Natasa Kapravelou
//                                        case: selected folders below Trash folder
518 c5070ebe Natasa Kapravelou
                                        String partialUri = GSS.get().getFolders().getPopupTree().constructPartialPath(item);
519 c5070ebe Natasa Kapravelou
                                        GSS.get().updateHistory("Files/trash/" + partialUri, item);
520 c5070ebe Natasa Kapravelou
                                } else
521 c5070ebe Natasa Kapravelou
//                                        case: home folders are selected
522 c5070ebe Natasa Kapravelou
                                        GSS.get().updateHistory("Files/files/" + getName(), item);
523 c5070ebe Natasa Kapravelou
                        }
524 c5070ebe Natasa Kapravelou
                        else if(item.getParentItem() == null){
525 c5070ebe Natasa Kapravelou
//                                this is the case when the user uses the browser's forward arrow to navigate through other's
526 c5070ebe Natasa Kapravelou
//                                shared folders and        item.getParentItem is null only inside other's shared folder
527 c5070ebe Natasa Kapravelou
                                String apiPath = GSS.get().getApiPath();
528 c5070ebe Natasa Kapravelou
                                String newPath = getParentURI().substring(apiPath.lastIndexOf("/"));
529 c5070ebe Natasa Kapravelou
                                GSS.get().updateHistory("Files"+ newPath + getName(), item);
530 c5070ebe Natasa Kapravelou
                        }
531 c5070ebe Natasa Kapravelou
                        else if(GSS.get().getFolders().getPopupTree().containsFolder(item, "My Shared")){
532 c5070ebe Natasa Kapravelou
//                                case: selected folders below My Shared folder
533 c5070ebe Natasa Kapravelou
                                String partialUri = GSS.get().getFolders().getPopupTree().constructPartialPath(item);
534 c5070ebe Natasa Kapravelou
                                GSS.get().updateHistory("Files/shared/" + partialUri, item);
535 c5070ebe Natasa Kapravelou
                        }else if(GSS.get().getFolders().getPopupTree().containsFolder(item, "Other's Shared")){
536 c5070ebe Natasa Kapravelou
//                                case: selected folders below Other's Shared folder
537 c5070ebe Natasa Kapravelou
                                String partialPath = GSS.get().getFolders().getPopupTree().constructPartialPath(item);
538 c5070ebe Natasa Kapravelou
                                GSS.get().updateHistory("Files/others/"+ partialPath, item);
539 c5070ebe Natasa Kapravelou
                        }
540 c5070ebe Natasa Kapravelou
                        else{
541 c5070ebe Natasa Kapravelou
//                                case:all folders in user's folders tree
542 c5070ebe Natasa Kapravelou
                                String finalUri = getParentURI().substring(path.lastIndexOf("/")) + getName();
543 c5070ebe Natasa Kapravelou
                                GSS.get().updateHistory("Files"+ finalUri, item);
544 c5070ebe Natasa Kapravelou
                        }
545 c5070ebe Natasa Kapravelou
546 c5070ebe Natasa Kapravelou
                }catch (Exception e){
547 c5070ebe Natasa Kapravelou
                        throw new UnsupportedOperationException(e);
548 c5070ebe Natasa Kapravelou
                }
549 c5070ebe Natasa Kapravelou
550 c5070ebe Natasa Kapravelou
        }
551 c5070ebe Natasa Kapravelou
552 a52ea5e4 pastith
}