root / src / gr / ebs / gss / client / rest / resource / OtherUserResource.java @ c5070ebe
History | View | Annotate | Download (6.3 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 |
import gr.ebs.gss.client.rest.MultipleGetCommand; |
23 |
import gr.ebs.gss.client.rest.MultipleGetCommand.Cached; |
24 |
|
25 |
import java.util.ArrayList; |
26 |
import java.util.Date; |
27 |
import java.util.LinkedList; |
28 |
import java.util.List; |
29 |
|
30 |
import com.google.gwt.core.client.GWT; |
31 |
import com.google.gwt.http.client.URL; |
32 |
import com.google.gwt.json.client.JSONArray; |
33 |
import com.google.gwt.json.client.JSONObject; |
34 |
import com.google.gwt.json.client.JSONParser; |
35 |
import com.google.gwt.user.client.ui.TreeItem; |
36 |
|
37 |
|
38 |
/**
|
39 |
* @author kman
|
40 |
*
|
41 |
*/
|
42 |
public class OtherUserResource extends RestResource{ |
43 |
public OtherUserResource(String aUri) { |
44 |
super(aUri);
|
45 |
} |
46 |
|
47 |
String username;
|
48 |
List<String> filePaths = new LinkedList<String>(); |
49 |
List<String> subfolderPaths = new LinkedList<String>(); |
50 |
List<FolderResource> folders = new ArrayList<FolderResource>(); |
51 |
List<FileResource> files = new ArrayList<FileResource>(); |
52 |
|
53 |
private boolean filesExpanded=false; |
54 |
/**
|
55 |
* Retrieve the username.
|
56 |
*
|
57 |
* @return the username
|
58 |
*/
|
59 |
public String getUsername() { |
60 |
return username;
|
61 |
} |
62 |
|
63 |
/**
|
64 |
* Modify the username.
|
65 |
*
|
66 |
* @param aUsername the username to set
|
67 |
*/
|
68 |
public void setUsername(String aUsername) { |
69 |
username = aUsername; |
70 |
} |
71 |
|
72 |
/**
|
73 |
* Retrieve the files.
|
74 |
*
|
75 |
* @return the files
|
76 |
*/
|
77 |
public List<String> getFilePaths() { |
78 |
return filePaths;
|
79 |
} |
80 |
|
81 |
/**
|
82 |
* Modify the files.
|
83 |
*
|
84 |
* @param newFiles the files to set
|
85 |
*/
|
86 |
public void setFilePaths(List<String> newFiles) { |
87 |
filePaths = newFiles; |
88 |
} |
89 |
|
90 |
/**
|
91 |
* Retrieve the subfolders.
|
92 |
*
|
93 |
* @return the subfolders
|
94 |
*/
|
95 |
public List<String> getSubfolderPaths() { |
96 |
return subfolderPaths;
|
97 |
} |
98 |
|
99 |
/**
|
100 |
* Modify the subfolders.
|
101 |
*
|
102 |
* @param subfolders the subfolders to set
|
103 |
*/
|
104 |
public void setSubfolderPaths(List<String> subfolders) { |
105 |
subfolderPaths = subfolders; |
106 |
} |
107 |
|
108 |
/**
|
109 |
* Retrieve the folders.
|
110 |
*
|
111 |
* @return the folders
|
112 |
*/
|
113 |
public List<FolderResource> getFolders() { |
114 |
return folders;
|
115 |
} |
116 |
|
117 |
/**
|
118 |
* Modify the folders.
|
119 |
*
|
120 |
* @param newFolders the folders to set
|
121 |
*/
|
122 |
public void setFolders(List<FolderResource> newFolders) { |
123 |
folders = newFolders; |
124 |
} |
125 |
|
126 |
/**
|
127 |
* Retrieve the files.
|
128 |
*
|
129 |
* @return the files
|
130 |
*/
|
131 |
public List<FileResource> getFiles() { |
132 |
return files;
|
133 |
} |
134 |
|
135 |
/**
|
136 |
* Modify the files.
|
137 |
*
|
138 |
* @param newFiles the files to set
|
139 |
*/
|
140 |
public void setFiles(List<FileResource> newFiles) { |
141 |
files = newFiles; |
142 |
} |
143 |
|
144 |
@Override
|
145 |
public void createFromJSON(String text) { |
146 |
JSONObject json = (JSONObject) JSONParser.parse(text); |
147 |
if (json.get("folders") != null) { |
148 |
JSONArray subs = json.get("folders").isArray();
|
149 |
if (subs != null) |
150 |
for (int i = 0; i < subs.size(); i++) { |
151 |
JSONObject so = subs.get(i).isObject(); |
152 |
if (so != null) { |
153 |
String subUri = unmarshallString(so, "uri"); |
154 |
String subName = unmarshallString(so, "name"); |
155 |
if (subUri != null && subName != null) { |
156 |
if (!subUri.endsWith("/")) |
157 |
subUri = subUri + "/";
|
158 |
FolderResource sub = new FolderResource(subUri);
|
159 |
sub.setName(subName); |
160 |
sub.setNeedsExpanding(true);
|
161 |
folders.add(sub); |
162 |
subfolderPaths.add(subUri); |
163 |
} |
164 |
} |
165 |
} |
166 |
} |
167 |
if (json.get("files") != null) { |
168 |
JSONArray subs = json.get("files").isArray();
|
169 |
if (subs != null) |
170 |
for (int i = 0; i < subs.size(); i++) { |
171 |
JSONObject fo = subs.get(i).isObject(); |
172 |
if (fo != null) { |
173 |
String fname = unmarshallString(fo, "name"); |
174 |
String fowner = unmarshallString(fo, "owner"); |
175 |
String fcontent = unmarshallString(fo, "content"); |
176 |
Integer fversion = null; |
177 |
if (fo.get("version") != null) |
178 |
fversion = new Integer(fo.get("version").toString()); |
179 |
boolean fdeleted = unmarshallBoolean(fo, "deleted"); |
180 |
Date fcreationDate = null; |
181 |
if (fo.get("creationDate") != null) |
182 |
fcreationDate = new Date(new Long(fo.get("creationDate").toString())); |
183 |
Date fmodificationDate = null; |
184 |
if (fo.get("modificationDate") != null) |
185 |
fmodificationDate = new Date(new Long(fo.get("modificationDate").toString())); |
186 |
String furi = unmarshallString(fo,"uri"); |
187 |
Long fsize = 0L; |
188 |
if(fo.get("size") != null) |
189 |
fsize = new Long(fo.get("size").toString()); |
190 |
filePaths.add(furi); |
191 |
String fpath = unmarshallString(fo, "path"); |
192 |
fpath = URL.decodeComponent(fpath);
|
193 |
FileResource fs = new FileResource(furi);
|
194 |
fs.setName(fname); |
195 |
fs.setPath(fpath); |
196 |
fs.setOwner(fowner); |
197 |
fs.setVersion(fversion); |
198 |
fs.setContentLength(fsize); |
199 |
fs.setDeleted(fdeleted); |
200 |
fs.setCreationDate(fcreationDate); |
201 |
fs.setModificationDate(fmodificationDate); |
202 |
fs.setContentType(fcontent); |
203 |
files.add(fs); |
204 |
} |
205 |
} |
206 |
} |
207 |
} |
208 |
|
209 |
public String getName(){ |
210 |
String[] names = uri.split("/"); |
211 |
return names[names.length -1]; |
212 |
} |
213 |
|
214 |
@Override
|
215 |
public String getLastModifiedSince() { |
216 |
return null; |
217 |
} |
218 |
|
219 |
public MultipleGetCommand.Cached[] getFileCache(){ |
220 |
if(getFilePaths().size() != getFiles().size()){
|
221 |
GWT.log("MISMATCH IN PATH AND FILES SIZE", null); |
222 |
return null; |
223 |
} |
224 |
if(!filesExpanded)
|
225 |
return null; |
226 |
MultipleGetCommand.Cached[] result = new MultipleGetCommand.Cached[getFilePaths().size()]; |
227 |
for(int i=0; i<getFiles().size();i++){ |
228 |
FileResource r = getFiles().get(i); |
229 |
Cached c = new Cached();
|
230 |
c.cache=r; |
231 |
c.uri=r.uri; |
232 |
result[i] = c; |
233 |
} |
234 |
return result;
|
235 |
} |
236 |
|
237 |
public void setFilesExpanded(boolean newFilesExpanded) { |
238 |
filesExpanded = newFilesExpanded; |
239 |
} |
240 |
|
241 |
/**
|
242 |
* Bugzilla – Bug 371, Add history support for folder navigation
|
243 |
*/
|
244 |
@Override
|
245 |
public void updateHistoryAbs(TreeItem item, String path){ |
246 |
try{
|
247 |
GSS.get().updateHistory("Files/others/"+ getName(), item);
|
248 |
}catch(Exception e){ |
249 |
throw new UnsupportedOperationException(); |
250 |
} |
251 |
} |
252 |
} |