Use separate progress bars next to each file, in order to better track the progress...
[pithos] / src / gr / ebs / gss / client / rest / resource / UserResource.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.Date;
22
23 import com.google.gwt.json.client.JSONObject;
24 import com.google.gwt.json.client.JSONParser;
25
26 /**
27  * @author kman
28  */
29 public class UserResource extends RestResource {
30
31         public UserResource(String aUri) {
32                 super(aUri);
33         }
34
35         private String name;
36
37         private String username;
38
39         private String email;
40
41         private Date creationDate;
42
43         private Date modificationDate;
44
45         private String filesPath;
46
47         private String trashPath;
48
49         private String sharedPath;
50
51         private String othersPath;
52
53         private String tagsPath;
54
55         private String groupsPath;
56
57         private QuotaHolder quota;
58
59         private String announcement;
60
61         /**
62          * Retrieve the name.
63          *
64          * @return the name
65          */
66         public String getName() {
67                 return name;
68         }
69
70         /**
71          * Modify the name.
72          *
73          * @param aName the name to set
74          */
75         public void setName(String aName) {
76                 name = aName;
77         }
78
79         /**
80          * Retrieve the username.
81          *
82          * @return the username
83          */
84         public String getUsername() {
85                 return username;
86         }
87
88         /**
89          * Modify the username.
90          *
91          * @param aUsername the username to set
92          */
93         public void setUsername(String aUsername) {
94                 username = aUsername;
95         }
96
97         /**
98          * Retrieve the email.
99          *
100          * @return the email
101          */
102         public String getEmail() {
103                 return email;
104         }
105
106         /**
107          * Modify the email.
108          *
109          * @param anEmail the email to set
110          */
111         public void setEmail(String anEmail) {
112                 email = anEmail;
113         }
114
115         /**
116          * Retrieve the creationDate.
117          *
118          * @return the creationDate
119          */
120         public Date getCreationDate() {
121                 return creationDate;
122         }
123
124         /**
125          * Modify the creationDate.
126          *
127          * @param aCreationDate the creationDate to set
128          */
129         public void setCreationDate(Date aCreationDate) {
130                 creationDate = aCreationDate;
131         }
132
133         /**
134          * Retrieve the modificationDate.
135          *
136          * @return the modificationDate
137          */
138         public Date getModificationDate() {
139                 return modificationDate;
140         }
141
142         /**
143          * Modify the modificationDate.
144          *
145          * @param aModificationDate the modificationDate to set
146          */
147         public void setModificationDate(Date aModificationDate) {
148                 modificationDate = aModificationDate;
149         }
150
151         /**
152          * Retrieve the filesPath.
153          *
154          * @return the filesPath
155          */
156         public String getFilesPath() {
157                 return filesPath;
158         }
159
160         /**
161          * Modify the filesPath.
162          *
163          * @param aFilesPath the filesPath to set
164          */
165         public void setFilesPath(String aFilesPath) {
166                 filesPath = aFilesPath;
167         }
168
169         /**
170          * Retrieve the trashPath.
171          *
172          * @return the trashPath
173          */
174         public String getTrashPath() {
175                 return trashPath;
176         }
177
178         /**
179          * Modify the trashPath.
180          *
181          * @param aTrashPath the trashPath to set
182          */
183         public void setTrashPath(String aTrashPath) {
184                 trashPath = aTrashPath;
185         }
186
187         /**
188          * Retrieve the sharedPath.
189          *
190          * @return the sharedPath
191          */
192         public String getSharedPath() {
193                 return sharedPath;
194         }
195
196         /**
197          * Modify the sharedPath.
198          *
199          * @param aSharedPath the sharedPath to set
200          */
201         public void setSharedPath(String aSharedPath) {
202                 sharedPath = aSharedPath;
203         }
204
205         /**
206          * Retrieve the othersPath.
207          *
208          * @return the othersPath
209          */
210         public String getOthersPath() {
211                 return othersPath;
212         }
213
214         /**
215          * Modify the othersPath.
216          *
217          * @param anOthersPath the othersPath to set
218          */
219         public void setOthersPath(String anOthersPath) {
220                 othersPath = anOthersPath;
221         }
222
223         /**
224          * Retrieve the tagsPath.
225          *
226          * @return the tagsPath
227          */
228         public String getTagsPath() {
229                 return tagsPath;
230         }
231
232         /**
233          * Modify the tagsPath.
234          *
235          * @param aTagsPath the tagsPath to set
236          */
237         public void setTagsPath(String aTagsPath) {
238                 tagsPath = aTagsPath;
239         }
240
241         /**
242          * Retrieve the groupsPath.
243          *
244          * @return the groupsPath
245          */
246         public String getGroupsPath() {
247                 return groupsPath;
248         }
249
250         /**
251          * Modify the groupsPath.
252          *
253          * @param aGroupsPath the groupsPath to set
254          */
255         public void setGroupsPath(String aGroupsPath) {
256                 groupsPath = aGroupsPath;
257         }
258
259         /**
260          * Retrieve the quota.
261          *
262          * @return the quota
263          */
264         public QuotaHolder getQuota() {
265                 return quota;
266         }
267
268         /**
269          * Modify the quota.
270          *
271          * @param aQuota the quota to set
272          */
273         public void setQuota(QuotaHolder aQuota) {
274                 quota = aQuota;
275         }
276
277
278         /**
279          * Retrieve the announcement.
280          *
281          * @return the announcement
282          */
283         public String getAnnouncement() {
284                 return announcement;
285         }
286
287
288         /**
289          * Modify the announcement.
290          *
291          * @param anAnnouncement the announcement to set
292          */
293         public void setAnnouncement(String anAnnouncement) {
294                 announcement = anAnnouncement;
295         }
296
297         @Override
298         public void createFromJSON(String text) {
299                 JSONObject json = (JSONObject) JSONParser.parse(text);
300                 email = unmarshallString(json, "email");
301                 name = unmarshallString(json, "name");
302                 username = unmarshallString(json, "username");
303                 filesPath = unmarshallString(json, "fileroot");
304                 groupsPath = unmarshallString(json, "groups");
305                 othersPath = unmarshallString(json, "others");
306                 sharedPath = unmarshallString(json, "shared");
307                 tagsPath = unmarshallString(json, "tags");
308                 trashPath = unmarshallString(json, "trash");
309                 announcement = unmarshallString(json, "announcement");
310                 if (json.get("creationDate") != null)
311                         creationDate = new Date(new Long(json.get("creationDate").toString()));
312                 if (json.get("modificationDate") != null)
313                         modificationDate = new Date(new Long(json.get("modificationDate").toString()));
314                 if (json.get("quota") != null) {
315                         JSONObject qj = (JSONObject) json.get("quota");
316                         if (qj != null) {
317                                 quota = new QuotaHolder();
318                                 if(qj.get("totalFiles") != null)
319                                         quota.setFileCount(new Long(qj.get("totalFiles").toString()));
320                                 if(qj.get("totalBytes") != null)
321                                         quota.setFileSize(new Long(qj.get("totalBytes").toString()));
322                                 if(qj.get("bytesRemaining") != null)
323                                         quota.setQuotaLeftSize(new Long(qj.get("bytesRemaining").toString()));
324                         }
325                 }
326         }
327
328         @Override
329         public String toString() {
330                 String res = email + "\n" + name + "\n" + username + "\n" + filesPath + "\n" + groupsPath;
331                 return res;
332         }
333
334 }