Statistics
| Branch: | Tag: | Revision:

root / web_client / src / gr / grnet / pithos / web / client / rest / resource / UserResource.java @ 58777026

History | View | Annotate | Download (7.8 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.Date;
38

    
39
import com.google.gwt.json.client.JSONObject;
40
import com.google.gwt.json.client.JSONParser;
41

    
42
public class UserResource extends RestResource {
43

    
44
        public UserResource(String aUri) {
45
                super(aUri);
46
        }
47

    
48
        private String name;
49

    
50
        private String username;
51

    
52
        private String email;
53

    
54
        private Date creationDate;
55

    
56
        private Date modificationDate;
57

    
58
        private String filesPath;
59

    
60
        private String trashPath;
61

    
62
        private String sharedPath;
63

    
64
        private String othersPath;
65

    
66
        private String tagsPath;
67

    
68
        private String groupsPath;
69

    
70
        private QuotaHolder quota;
71

    
72
        private String announcement;
73

    
74
        private Date lastLogin;
75
        
76
        private Date currentLogin;
77

    
78
        /**
79
         * Retrieve the name.
80
         *
81
         * @return the name
82
         */
83
        @Override
84
        public String getName() {
85
                return name;
86
        }
87

    
88
        /**
89
         * Modify the name.
90
         *
91
         * @param aName the name to set
92
         */
93
        public void setName(String aName) {
94
                name = aName;
95
        }
96

    
97
        /**
98
         * Retrieve the username.
99
         *
100
         * @return the username
101
         */
102
        public String getUsername() {
103
                return username;
104
        }
105

    
106
        /**
107
         * Modify the username.
108
         *
109
         * @param aUsername the username to set
110
         */
111
        public void setUsername(String aUsername) {
112
                username = aUsername;
113
        }
114

    
115
        /**
116
         * Retrieve the email.
117
         *
118
         * @return the email
119
         */
120
        public String getEmail() {
121
                return email;
122
        }
123

    
124
        /**
125
         * Modify the email.
126
         *
127
         * @param anEmail the email to set
128
         */
129
        public void setEmail(String anEmail) {
130
                email = anEmail;
131
        }
132

    
133
        /**
134
         * Retrieve the creationDate.
135
         *
136
         * @return the creationDate
137
         */
138
        public Date getCreationDate() {
139
                return creationDate;
140
        }
141

    
142
        /**
143
         * Modify the creationDate.
144
         *
145
         * @param aCreationDate the creationDate to set
146
         */
147
        public void setCreationDate(Date aCreationDate) {
148
                creationDate = aCreationDate;
149
        }
150

    
151
        /**
152
         * Retrieve the modificationDate.
153
         *
154
         * @return the modificationDate
155
         */
156
        public Date getModificationDate() {
157
                return modificationDate;
158
        }
159

    
160
        /**
161
         * Modify the modificationDate.
162
         *
163
         * @param aModificationDate the modificationDate to set
164
         */
165
        public void setModificationDate(Date aModificationDate) {
166
                modificationDate = aModificationDate;
167
        }
168

    
169
        /**
170
         * Retrieve the filesPath.
171
         *
172
         * @return the filesPath
173
         */
174
        public String getFilesPath() {
175
                return filesPath;
176
        }
177

    
178
        /**
179
         * Modify the filesPath.
180
         *
181
         * @param aFilesPath the filesPath to set
182
         */
183
        public void setFilesPath(String aFilesPath) {
184
                filesPath = aFilesPath;
185
        }
186

    
187
        /**
188
         * Retrieve the trashPath.
189
         *
190
         * @return the trashPath
191
         */
192
        public String getTrashPath() {
193
                return trashPath;
194
        }
195

    
196
        /**
197
         * Modify the trashPath.
198
         *
199
         * @param aTrashPath the trashPath to set
200
         */
201
        public void setTrashPath(String aTrashPath) {
202
                trashPath = aTrashPath;
203
        }
204

    
205
        /**
206
         * Retrieve the sharedPath.
207
         *
208
         * @return the sharedPath
209
         */
210
        public String getSharedPath() {
211
                return sharedPath;
212
        }
213

    
214
        /**
215
         * Modify the sharedPath.
216
         *
217
         * @param aSharedPath the sharedPath to set
218
         */
219
        public void setSharedPath(String aSharedPath) {
220
                sharedPath = aSharedPath;
221
        }
222

    
223
        /**
224
         * Retrieve the othersPath.
225
         *
226
         * @return the othersPath
227
         */
228
        public String getOthersPath() {
229
                return othersPath;
230
        }
231

    
232
        /**
233
         * Modify the othersPath.
234
         *
235
         * @param anOthersPath the othersPath to set
236
         */
237
        public void setOthersPath(String anOthersPath) {
238
                othersPath = anOthersPath;
239
        }
240

    
241
        /**
242
         * Retrieve the tagsPath.
243
         *
244
         * @return the tagsPath
245
         */
246
        public String getTagsPath() {
247
                return tagsPath;
248
        }
249

    
250
        /**
251
         * Modify the tagsPath.
252
         *
253
         * @param aTagsPath the tagsPath to set
254
         */
255
        public void setTagsPath(String aTagsPath) {
256
                tagsPath = aTagsPath;
257
        }
258

    
259
        /**
260
         * Retrieve the groupsPath.
261
         *
262
         * @return the groupsPath
263
         */
264
        public String getGroupsPath() {
265
                return groupsPath;
266
        }
267

    
268
        /**
269
         * Modify the groupsPath.
270
         *
271
         * @param aGroupsPath the groupsPath to set
272
         */
273
        public void setGroupsPath(String aGroupsPath) {
274
                groupsPath = aGroupsPath;
275
        }
276

    
277
        /**
278
         * Retrieve the quota.
279
         *
280
         * @return the quota
281
         */
282
        public QuotaHolder getQuota() {
283
                return quota;
284
        }
285

    
286
        /**
287
         * Modify the quota.
288
         *
289
         * @param aQuota the quota to set
290
         */
291
        public void setQuota(QuotaHolder aQuota) {
292
                quota = aQuota;
293
        }
294

    
295

    
296
        /**
297
         * Retrieve the announcement.
298
         *
299
         * @return the announcement
300
         */
301
        public String getAnnouncement() {
302
                return announcement;
303
        }
304

    
305
        /**
306
         * Modify the announcement.
307
         *
308
         * @param anAnnouncement the announcement to set
309
         */
310
        public void setAnnouncement(String anAnnouncement) {
311
                announcement = anAnnouncement;
312
        }
313

    
314
        /**
315
         * Retrieve the lastLogin.
316
         *
317
         * @return the lastLogin
318
         */
319
        public Date getLastLogin() {
320
                return lastLogin;
321
        }
322

    
323
        /**
324
         * Retrieve the currentLogin.
325
         *
326
         * @return the currentLogin
327
         */
328
        public Date getCurrentLogin() {
329
                return currentLogin;
330
        }
331

    
332
        @Override
333
        public void createFromJSON(String text) {
334
                JSONObject json = (JSONObject) JSONParser.parse(text);
335
                email = unmarshallString(json, "email");
336
                name = unmarshallString(json, "name");
337
                username = unmarshallString(json, "username");
338
                filesPath = unmarshallString(json, "fileroot");
339
                groupsPath = unmarshallString(json, "groups");
340
                othersPath = unmarshallString(json, "others");
341
                sharedPath = unmarshallString(json, "shared");
342
                tagsPath = unmarshallString(json, "tags");
343
                trashPath = unmarshallString(json, "trash");
344
                announcement = unmarshallString(json, "announcement");
345
                if (json.get("lastLogin") != null)
346
                        lastLogin = new Date(new Long(json.get("lastLogin").toString()));
347
                if (json.get("currentLogin") != null)
348
                        currentLogin = new Date(new Long(json.get("currentLogin").toString()));                        
349
                if (json.get("creationDate") != null)
350
                        creationDate = new Date(new Long(json.get("creationDate").toString()));
351
                if (json.get("modificationDate") != null)
352
                        modificationDate = new Date(new Long(json.get("modificationDate").toString()));
353
                if (json.get("quota") != null) {
354
                        JSONObject qj = (JSONObject) json.get("quota");
355
                        if (qj != null) {
356
                                quota = new QuotaHolder();
357
                                if(qj.get("totalFiles") != null)
358
                                        quota.setFileCount(new Long(qj.get("totalFiles").toString()));
359
                                if(qj.get("totalBytes") != null)
360
                                        quota.setFileSize(new Long(qj.get("totalBytes").toString()));
361
                                if(qj.get("bytesRemaining") != null)
362
                                        quota.setQuotaLeftSize(new Long(qj.get("bytesRemaining").toString()));
363
                        }
364
                }
365
        }
366

    
367
        @Override
368
        public String toString() {
369
                String res = email + "\n" + name + "\n" + username + "\n" + filesPath + "\n" + groupsPath;
370
                return res;
371
        }
372

    
373
        @Override
374
        public String getLastModifiedSince() {
375
                return null;
376
        }
377
}