Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (5.7 kB)

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 gr.ebs.gss.client.GSS;
22

    
23
import java.util.ArrayList;
24
import java.util.Date;
25
import java.util.LinkedList;
26
import java.util.List;
27

    
28
import com.google.gwt.http.client.URL;
29
import com.google.gwt.json.client.JSONArray;
30
import com.google.gwt.json.client.JSONObject;
31
import com.google.gwt.json.client.JSONParser;
32
import com.google.gwt.user.client.ui.TreeItem;
33

    
34

    
35
/**
36
 * @author kman
37
 *
38
 */
39
public class TrashResource extends RestResource{
40

    
41
        public TrashResource(String aUri) {
42
                super(aUri);
43
        }
44

    
45
        List<String> filePaths = new LinkedList<String>();
46
        List<String> subfolderPaths = new LinkedList<String>();
47
        List<FolderResource> folders = new ArrayList<FolderResource>();
48
        List<FileResource> files = new ArrayList<FileResource>();
49

    
50
        /**
51
         * Retrieve the file paths.
52
         *
53
         * @return the file paths
54
         */
55
        public List<String> getFilePaths() {
56
                return filePaths;
57
        }
58

    
59
        /**
60
         * Modify the file paths.
61
         *
62
         * @param newFilePaths the file paths to set
63
         */
64
        public void setFilePaths(List<String> newFilePaths) {
65
                filePaths = newFilePaths;
66
        }
67

    
68
        /**
69
         * Retrieve the subfolder paths.
70
         *
71
         * @return the subfolder paths
72
         */
73
        public List<String> getSubfolderPaths() {
74
                return subfolderPaths;
75
        }
76

    
77
        /**
78
         * Modify the subfolder paths.
79
         *
80
         * @param newSubfolderPaths the subfolders to set
81
         */
82
        public void setSubfolderPaths(List<String> newSubfolderPaths) {
83
                subfolderPaths = newSubfolderPaths;
84
        }
85

    
86
        /**
87
         * Retrieve the folders.
88
         *
89
         * @return the folders
90
         */
91
        public List<FolderResource> getFolders() {
92
                return folders;
93
        }
94

    
95
        /**
96
         * Modify the folders.
97
         *
98
         * @param newFolders the folders to set
99
         */
100
        public void setFolders(List<FolderResource> newFolders) {
101
                folders = newFolders;
102
        }
103

    
104
        /**
105
         * Retrieve the files.
106
         *
107
         * @return the files
108
         */
109
        public List<FileResource> getFiles() {
110
                return files;
111
        }
112

    
113
        /**
114
         * Modify the files.
115
         *
116
         * @param newFiles the files to set
117
         */
118
        public void setFiles(List<FileResource> newFiles) {
119
                files = newFiles;
120
        }
121

    
122
        @Override
123
        public void createFromJSON(String text) {
124
                JSONObject json = (JSONObject) JSONParser.parse(text);
125
                if (json.get("folders") != null) {
126
                        JSONArray subs = json.get("folders").isArray();
127
                        if (subs != null)
128
                                for (int i = 0; i < subs.size(); i++) {
129
                                        JSONObject so = subs.get(i).isObject();
130
                                        if (so != null) {
131
                                                String subUri = unmarshallString(so, "uri");
132
                                                String subName = unmarshallString(so, "name");
133
                                                subName = URL.decodeComponent(subName);
134
                                                if (subUri != null && subName != null) {
135
                                                        if (!subUri.endsWith("/"))
136
                                                                subUri = subUri + "/";
137
                                                        FolderResource sub = new FolderResource(subUri);
138
                                                        sub.setName(subName);
139
                                                        sub.setNeedsExpanding(true);
140
                                                        folders.add(sub);
141
                                                        subfolderPaths.add(subUri);
142
                                                }
143
                                        }
144
                                }
145
                }
146
                if (json.get("files") != null) {
147
                        JSONArray subs = json.get("files").isArray();
148
                        if (subs != null)
149
                                for (int i = 0; i < subs.size(); i++) {
150
                                        JSONObject fo = subs.get(i).isObject();
151
                                        if (fo != null) {
152
                                                String fname = unmarshallString(fo, "name");
153
                                                String fowner = unmarshallString(fo, "owner");
154
                                                String fcontent = unmarshallString(fo, "content");
155
                                                String fpath = unmarshallString(fo, "path");
156
                                                fpath = URL.decodeComponent(fpath);
157
                                                Integer fversion = null;
158
                                                if (fo.get("version") != null)
159
                                                        fversion = new Integer(fo.get("version").toString());
160
                                                boolean fdeleted = unmarshallBoolean(fo, "deleted");
161
                                                Date fcreationDate = null;
162
                                                if (fo.get("creationDate") != null)
163
                                                        fcreationDate = new Date(new Long(fo.get("creationDate").toString()));
164
                                                Date fmodificationDate = null;
165
                                                if (fo.get("modificationDate") != null)
166
                                                        fmodificationDate = new Date(new Long(fo.get("modificationDate").toString()));
167
                                                String furi = unmarshallString(fo,"uri");
168
                                                Long fsize = 0L;
169
                                                if(fo.get("size") != null)
170
                                                        fsize = new Long(fo.get("size").toString());
171
                                                filePaths.add(furi);
172
                                                FileResource fs = new FileResource(furi);
173
                                                fs.setName(fname);
174
                                                fs.setOwner(fowner);
175
                                                fs.setVersion(fversion);
176
                                                fs.setContentLength(fsize);
177
                                                fs.setDeleted(fdeleted);
178
                                                fs.setPath(fpath);
179
                                                fs.setCreationDate(fcreationDate);
180
                                                fs.setModificationDate(fmodificationDate);
181
                                                fs.setContentType(fcontent);
182
                                                files.add(fs);
183
                                        }
184
                                }
185
                }
186
        }
187

    
188
        public List<FolderResource> getTrashedFolders(){
189
                List<FolderResource> res = new ArrayList<FolderResource>();
190
                for(String s : subfolderPaths){
191
                        String[] pathElements =  s.split("/");
192
                        FolderResource tr = new FolderResource(s);
193
                        tr.setName(URL.decodeComponent(pathElements[pathElements.length-1]));
194
                        res.add(tr);
195
                }
196
                return res;
197
        }
198

    
199
        @Override
200
        public String getLastModifiedSince() {
201
                return null;
202
        }
203
        /**
204
         * Bugzilla – Bug 371, Add history support for folder navigation
205
         */
206
        public void updateHistoryAbs(TreeItem item, String path){
207
                try{
208
                        GSS.get().updateHistory("Files/"+ getUri().substring(path.lastIndexOf("/")+1), item);
209
                }catch (Exception e){
210
                        throw new UnsupportedOperationException();
211
                }
212
        }
213
}