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 aPath) {
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;
64 public String getName() {
71 * @param aName the name to set
73 public void setName(String aName) {
78 * Retrieve the username.
80 * @return the username
82 public String getUsername() {
87 * Modify the username.
89 * @param aUsername the username to set
91 public void setUsername(String aUsername) {
100 public String getEmail() {
107 * @param anEmail the email to set
109 public void setEmail(String anEmail) {
114 * Retrieve the creationDate.
116 * @return the creationDate
118 public Date getCreationDate() {
123 * Modify the creationDate.
125 * @param aCreationDate the creationDate to set
127 public void setCreationDate(Date aCreationDate) {
128 creationDate = aCreationDate;
132 * Retrieve the modificationDate.
134 * @return the modificationDate
136 public Date getModificationDate() {
137 return modificationDate;
141 * Modify the modificationDate.
143 * @param aModificationDate the modificationDate to set
145 public void setModificationDate(Date aModificationDate) {
146 modificationDate = aModificationDate;
150 * Retrieve the filesPath.
152 * @return the filesPath
154 public String getFilesPath() {
159 * Modify the filesPath.
161 * @param aFilesPath the filesPath to set
163 public void setFilesPath(String aFilesPath) {
164 filesPath = aFilesPath;
168 * Retrieve the trashPath.
170 * @return the trashPath
172 public String getTrashPath() {
177 * Modify the trashPath.
179 * @param aTrashPath the trashPath to set
181 public void setTrashPath(String aTrashPath) {
182 trashPath = aTrashPath;
186 * Retrieve the sharedPath.
188 * @return the sharedPath
190 public String getSharedPath() {
195 * Modify the sharedPath.
197 * @param aSharedPath the sharedPath to set
199 public void setSharedPath(String aSharedPath) {
200 sharedPath = aSharedPath;
204 * Retrieve the othersPath.
206 * @return the othersPath
208 public String getOthersPath() {
213 * Modify the othersPath.
215 * @param anOthersPath the othersPath to set
217 public void setOthersPath(String anOthersPath) {
218 othersPath = anOthersPath;
222 * Retrieve the tagsPath.
224 * @return the tagsPath
226 public String getTagsPath() {
231 * Modify the tagsPath.
233 * @param aTagsPath the tagsPath to set
235 public void setTagsPath(String aTagsPath) {
236 tagsPath = aTagsPath;
240 * Retrieve the groupsPath.
242 * @return the groupsPath
244 public String getGroupsPath() {
249 * Modify the groupsPath.
251 * @param aGroupsPath the groupsPath to set
253 public void setGroupsPath(String aGroupsPath) {
254 groupsPath = aGroupsPath;
258 * Retrieve the quota.
262 public QuotaHolder getQuota() {
269 * @param aQuota the quota to set
271 public void setQuota(QuotaHolder aQuota) {
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");
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()));
306 public String toString() {
307 String res = email + "\n" + name + "\n" + username + "\n" + filesPath + "\n" + groupsPath;