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