root / web_client / src / gr / grnet / pithos / web / client / rest / resource / TrashResource.java @ 58777026
History | View | Annotate | Download (6.6 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2011 GRNET S.A. All rights reserved.
|
3 |
*
|
4 |
* Redistribution and use in source and binary forms, with or
|
5 |
* without modification, are permitted provided that the following
|
6 |
* conditions are met:
|
7 |
*
|
8 |
* 1. Redistributions of source code must retain the above
|
9 |
* copyright notice, this list of conditions and the following
|
10 |
* disclaimer.
|
11 |
*
|
12 |
* 2. Redistributions in binary form must reproduce the above
|
13 |
* copyright notice, this list of conditions and the following
|
14 |
* disclaimer in the documentation and/or other materials
|
15 |
* provided with the distribution.
|
16 |
*
|
17 |
* THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 |
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 |
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 |
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 |
* POSSIBILITY OF SUCH DAMAGE.
|
29 |
*
|
30 |
* The views and conclusions contained in the software and
|
31 |
* documentation are those of the authors and should not be
|
32 |
* interpreted as representing official policies, either expressed
|
33 |
* or implied, of GRNET S.A.
|
34 |
*/
|
35 |
package gr.grnet.pithos.web.client.rest.resource; |
36 |
|
37 |
import java.util.ArrayList; |
38 |
import java.util.Date; |
39 |
import java.util.LinkedList; |
40 |
import java.util.List; |
41 |
|
42 |
import com.google.gwt.http.client.URL; |
43 |
import com.google.gwt.json.client.JSONArray; |
44 |
import com.google.gwt.json.client.JSONObject; |
45 |
import com.google.gwt.json.client.JSONParser; |
46 |
import com.google.gwt.user.client.ui.TreeItem; |
47 |
|
48 |
|
49 |
public class TrashResource extends RestResource{ |
50 |
|
51 |
public TrashResource(String aUri) { |
52 |
super(aUri);
|
53 |
} |
54 |
|
55 |
List<String> filePaths = new LinkedList<String>(); |
56 |
List<String> subfolderPaths = new LinkedList<String>(); |
57 |
List<FolderResource> folders = new ArrayList<FolderResource>(); |
58 |
List<FileResource> files = new ArrayList<FileResource>(); |
59 |
|
60 |
/**
|
61 |
* Retrieve the file paths.
|
62 |
*
|
63 |
* @return the file paths
|
64 |
*/
|
65 |
public List<String> getFilePaths() { |
66 |
return filePaths;
|
67 |
} |
68 |
|
69 |
/**
|
70 |
* Modify the file paths.
|
71 |
*
|
72 |
* @param newFilePaths the file paths to set
|
73 |
*/
|
74 |
public void setFilePaths(List<String> newFilePaths) { |
75 |
filePaths = newFilePaths; |
76 |
} |
77 |
|
78 |
/**
|
79 |
* Retrieve the subfolder paths.
|
80 |
*
|
81 |
* @return the subfolder paths
|
82 |
*/
|
83 |
public List<String> getSubfolderPaths() { |
84 |
return subfolderPaths;
|
85 |
} |
86 |
|
87 |
/**
|
88 |
* Modify the subfolder paths.
|
89 |
*
|
90 |
* @param newSubfolderPaths the subfolders to set
|
91 |
*/
|
92 |
public void setSubfolderPaths(List<String> newSubfolderPaths) { |
93 |
subfolderPaths = newSubfolderPaths; |
94 |
} |
95 |
|
96 |
/**
|
97 |
* Retrieve the folders.
|
98 |
*
|
99 |
* @return the folders
|
100 |
*/
|
101 |
public List<FolderResource> getFolders() { |
102 |
return folders;
|
103 |
} |
104 |
|
105 |
/**
|
106 |
* Modify the folders.
|
107 |
*
|
108 |
* @param newFolders the folders to set
|
109 |
*/
|
110 |
public void setFolders(List<FolderResource> newFolders) { |
111 |
folders = newFolders; |
112 |
} |
113 |
|
114 |
/**
|
115 |
* Retrieve the files.
|
116 |
*
|
117 |
* @return the files
|
118 |
*/
|
119 |
public List<FileResource> getFiles() { |
120 |
return files;
|
121 |
} |
122 |
|
123 |
/**
|
124 |
* Modify the files.
|
125 |
*
|
126 |
* @param newFiles the files to set
|
127 |
*/
|
128 |
public void setFiles(List<FileResource> newFiles) { |
129 |
files = newFiles; |
130 |
} |
131 |
|
132 |
@Override
|
133 |
public void createFromJSON(String text) { |
134 |
JSONObject json = (JSONObject) JSONParser.parse(text); |
135 |
if (json.get("folders") != null) { |
136 |
JSONArray subs = json.get("folders").isArray();
|
137 |
if (subs != null) |
138 |
for (int i = 0; i < subs.size(); i++) { |
139 |
JSONObject so = subs.get(i).isObject(); |
140 |
if (so != null) { |
141 |
String subUri = unmarshallString(so, "uri"); |
142 |
String subName = unmarshallString(so, "name"); |
143 |
subName = URL.decodeComponent(subName);
|
144 |
if (subUri != null && subName != null) { |
145 |
if (!subUri.endsWith("/")) |
146 |
subUri = subUri + "/";
|
147 |
FolderResource sub = new FolderResource(subUri);
|
148 |
sub.setName(subName); |
149 |
sub.setNeedsExpanding(true);
|
150 |
folders.add(sub); |
151 |
subfolderPaths.add(subUri); |
152 |
} |
153 |
} |
154 |
} |
155 |
} |
156 |
if (json.get("files") != null) { |
157 |
JSONArray subs = json.get("files").isArray();
|
158 |
if (subs != null) |
159 |
for (int i = 0; i < subs.size(); i++) { |
160 |
JSONObject fo = subs.get(i).isObject(); |
161 |
if (fo != null) { |
162 |
String fname = unmarshallString(fo, "name"); |
163 |
String fowner = unmarshallString(fo, "owner"); |
164 |
String fcontent = unmarshallString(fo, "content"); |
165 |
Boolean fshared = unmarshallBoolean(fo, "shared"); |
166 |
Boolean fversioned = unmarshallBoolean(fo, "versioned"); |
167 |
String fpath = unmarshallString(fo, "path"); |
168 |
fpath = URL.decodeComponent(fpath);
|
169 |
Integer fversion = null; |
170 |
if (fo.get("version") != null) |
171 |
fversion = new Integer(fo.get("version").toString()); |
172 |
boolean fdeleted = unmarshallBoolean(fo, "deleted"); |
173 |
Date fcreationDate = null; |
174 |
if (fo.get("creationDate") != null) |
175 |
fcreationDate = new Date(new Long(fo.get("creationDate").toString())); |
176 |
Date fmodificationDate = null; |
177 |
if (fo.get("modificationDate") != null) |
178 |
fmodificationDate = new Date(new Long(fo.get("modificationDate").toString())); |
179 |
String furi = unmarshallString(fo,"uri"); |
180 |
Long fsize = 0L; |
181 |
if(fo.get("size") != null) |
182 |
fsize = new Long(fo.get("size").toString()); |
183 |
filePaths.add(furi); |
184 |
FileResource fs = new FileResource(furi);
|
185 |
fs.setName(fname); |
186 |
fs.setOwner(fowner); |
187 |
fs.setVersion(fversion); |
188 |
fs.setContentLength(fsize); |
189 |
fs.setDeleted(fdeleted); |
190 |
fs.setPath(fpath); |
191 |
fs.setCreationDate(fcreationDate); |
192 |
fs.setModificationDate(fmodificationDate); |
193 |
fs.setContentType(fcontent); |
194 |
fs.setShared(fshared); |
195 |
fs.setVersioned(fversioned); |
196 |
files.add(fs); |
197 |
} |
198 |
} |
199 |
} |
200 |
} |
201 |
|
202 |
public List<FolderResource> getTrashedFolders(){ |
203 |
List<FolderResource> res = new ArrayList<FolderResource>(); |
204 |
for(String s : subfolderPaths){ |
205 |
String[] pathElements = s.split("/"); |
206 |
FolderResource tr = new FolderResource(s);
|
207 |
tr.setName(URL.decodeComponent(pathElements[pathElements.length-1])); |
208 |
res.add(tr); |
209 |
} |
210 |
return res;
|
211 |
} |
212 |
|
213 |
@Override
|
214 |
public String getLastModifiedSince() { |
215 |
return null; |
216 |
} |
217 |
@Override
|
218 |
public String constructUri(TreeItem treeItem, String path){ |
219 |
String constructedUri = "Files/"+ getUri().substring(path.lastIndexOf("/")+1); |
220 |
if (!constructedUri.endsWith("/")) |
221 |
constructedUri += "/";
|
222 |
return constructedUri;
|
223 |
} |
224 |
} |