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