2 * Copyright 2009 Electronic Business Systems Ltd.
4 * This file is part of GSS.
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.
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.
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/>.
19 package gr.ebs.gss.client.rest.resource;
21 import java.util.Date;
23 import com.google.gwt.json.client.JSONObject;
24 import com.google.gwt.json.client.JSONParser;
29 public class UserResource extends RestResource {
31 public UserResource(String aUri) {
37 private String username;
41 private Date creationDate;
43 private Date modificationDate;
45 private String filesPath;
47 private String trashPath;
49 private String sharedPath;
51 private String othersPath;
53 private String tagsPath;
55 private String groupsPath;
57 private QuotaHolder quota;
59 private String announcement;
66 public String getName() {
73 * @param aName the name to set
75 public void setName(String aName) {
80 * Retrieve the username.
82 * @return the username
84 public String getUsername() {
89 * Modify the username.
91 * @param aUsername the username to set
93 public void setUsername(String aUsername) {
102 public String getEmail() {
109 * @param anEmail the email to set
111 public void setEmail(String anEmail) {
116 * Retrieve the creationDate.
118 * @return the creationDate
120 public Date getCreationDate() {
125 * Modify the creationDate.
127 * @param aCreationDate the creationDate to set
129 public void setCreationDate(Date aCreationDate) {
130 creationDate = aCreationDate;
134 * Retrieve the modificationDate.
136 * @return the modificationDate
138 public Date getModificationDate() {
139 return modificationDate;
143 * Modify the modificationDate.
145 * @param aModificationDate the modificationDate to set
147 public void setModificationDate(Date aModificationDate) {
148 modificationDate = aModificationDate;
152 * Retrieve the filesPath.
154 * @return the filesPath
156 public String getFilesPath() {
161 * Modify the filesPath.
163 * @param aFilesPath the filesPath to set
165 public void setFilesPath(String aFilesPath) {
166 filesPath = aFilesPath;
170 * Retrieve the trashPath.
172 * @return the trashPath
174 public String getTrashPath() {
179 * Modify the trashPath.
181 * @param aTrashPath the trashPath to set
183 public void setTrashPath(String aTrashPath) {
184 trashPath = aTrashPath;
188 * Retrieve the sharedPath.
190 * @return the sharedPath
192 public String getSharedPath() {
197 * Modify the sharedPath.
199 * @param aSharedPath the sharedPath to set
201 public void setSharedPath(String aSharedPath) {
202 sharedPath = aSharedPath;
206 * Retrieve the othersPath.
208 * @return the othersPath
210 public String getOthersPath() {
215 * Modify the othersPath.
217 * @param anOthersPath the othersPath to set
219 public void setOthersPath(String anOthersPath) {
220 othersPath = anOthersPath;
224 * Retrieve the tagsPath.
226 * @return the tagsPath
228 public String getTagsPath() {
233 * Modify the tagsPath.
235 * @param aTagsPath the tagsPath to set
237 public void setTagsPath(String aTagsPath) {
238 tagsPath = aTagsPath;
242 * Retrieve the groupsPath.
244 * @return the groupsPath
246 public String getGroupsPath() {
251 * Modify the groupsPath.
253 * @param aGroupsPath the groupsPath to set
255 public void setGroupsPath(String aGroupsPath) {
256 groupsPath = aGroupsPath;
260 * Retrieve the quota.
264 public QuotaHolder getQuota() {
271 * @param aQuota the quota to set
273 public void setQuota(QuotaHolder aQuota) {
279 * Retrieve the announcement.
281 * @return the announcement
283 public String getAnnouncement() {
289 * Modify the announcement.
291 * @param anAnnouncement the announcement to set
293 public void setAnnouncement(String anAnnouncement) {
294 announcement = anAnnouncement;
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");
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()));
329 public String toString() {
330 String res = email + "\n" + name + "\n" + username + "\n" + filesPath + "\n" + groupsPath;