Remove the redundant gss top-level directory.
[pithos] / src / gr / ebs / gss / client / rest / resource / UploadStatusResource.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 com.google.gwt.json.client.JSONObject;
22 import com.google.gwt.json.client.JSONParser;
23
24
25 /**
26  * @author kman
27  *
28  */
29 public class UploadStatusResource extends RestResource{
30         long bytesTransferred;
31         long fileSize;
32
33         public UploadStatusResource(String aUri) {
34                 super(aUri);
35         }
36
37         /**
38          * Retrieve the bytesTransferred.
39          *
40          * @return the bytesTransferred
41          */
42         public long getBytesTransferred() {
43                 return bytesTransferred;
44         }
45
46         /**
47          * Modify the bytesTransferred.
48          *
49          * @param newBytesTransferred the bytesTransferred to set
50          */
51         public void setBytesTransferred(long newBytesTransferred) {
52                 bytesTransferred = newBytesTransferred;
53         }
54
55         /**
56          * Retrieve the fileSize.
57          *
58          * @return the fileSize
59          */
60         public long getFileSize() {
61                 return fileSize;
62         }
63
64         /**
65          * Modify the fileSize.
66          *
67          * @param newFileSize the fileSize to set
68          */
69         public void setFileSize(long newFileSize) {
70                 fileSize = newFileSize;
71         }
72
73         public int percent(){
74                 return new Long(bytesTransferred * 100 / fileSize).intValue();
75         }
76
77         @Override
78         public void createFromJSON(String text) {
79                 JSONObject json = (JSONObject) JSONParser.parse(text);
80                 if(json.get("bytesTotal") != null)
81                         fileSize = new Long(json.get("bytesTotal").toString());
82                 if(json.get("bytesUploaded") != null)
83                         bytesTransferred = new Long(json.get("bytesUploaded").toString());
84
85         }
86
87 }