Removed all DTO where possible
[pithos] / src / gr / ebs / gss / server / domain / dto / StatsDTO.java
1 /*
2  * Copyright 2008, 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.server.domain.dto;
20
21 import java.io.Serializable;
22
23 import com.google.gwt.i18n.client.NumberFormat;
24
25
26 /**
27  * DTO Object holding stats for User: file count, size count and quota
28  * @author kman
29  *
30  */
31 public class StatsDTO implements Serializable{
32
33         private Long fileCount = 0L;
34         private Long fileSize = 0L;
35         private Long quotaLeftSize = 0L;
36         private Long bandwithQuotaUsed=0L;
37
38         public StatsDTO() {
39
40         }
41
42         public StatsDTO(Long aFileCount, Long aFileSize, Long aQuotaLeftSize) {
43                 fileCount = aFileCount;
44                 fileSize = aFileSize;
45                 quotaLeftSize = aQuotaLeftSize;
46         }
47
48         /**
49          * Retrieve the fileCount.
50          *
51          * @return the fileCount
52          */
53         public Long getFileCount() {
54                 return fileCount;
55         }
56
57         /**
58          * Modify the fileCount.
59          *
60          * @param aFileCount the fileCount to set
61          */
62         public void setFileCount(Long aFileCount) {
63                 fileCount = aFileCount;
64         }
65
66         /**
67          * Retrieve the fileSize.
68          *
69          * @return the fileSize
70          */
71         public Long getFileSize() {
72                 return fileSize;
73         }
74
75         /**
76          * Modify the fileSize.
77          *
78          * @param aFileSize the fileSize to set
79          */
80         public void setFileSize(Long aFileSize) {
81                 fileSize = aFileSize;
82         }
83
84         /**
85          * Retrieve the quotaLeftSize.
86          *
87          * @return the quotaLeftSize
88          */
89         public Long getQuotaLeftSize() {
90                 return quotaLeftSize;
91         }
92
93         /**
94          * Modify the quotaLeftSize.
95          *
96          * @param aQuotaLeftSize the quotaLeftSize to set
97          */
98         public void setQuotaLeftSize(Long aQuotaLeftSize) {
99                 quotaLeftSize = aQuotaLeftSize;
100         }
101
102
103
104         /**
105          * Retrieve the bandwithQuotaUsed.
106          *
107          * @return the bandwithQuotaUsed
108          */
109         public Long getBandwithQuotaUsed() {
110                 return bandwithQuotaUsed;
111         }
112
113
114         /**
115          * Modify the bandwithQuotaUsed.
116          *
117          * @param aBandwithQuotaUsed the bandwithQuotaUsed to set
118          */
119         public void setBandwithQuotaUsed(Long aBandwithQuotaUsed) {
120                 bandwithQuotaUsed = aBandwithQuotaUsed;
121         }
122
123         public String getFileSizeAsString() {
124                 if (fileSize < 1024)
125                         return String.valueOf(fileSize) + " B";
126                 else if (fileSize <= 1024*1024)
127                         return getSize(fileSize, 1024D) + " KB";
128                 else if (fileSize <= 1024*1024*1024)
129                         return getSize(fileSize,(1024D*1024D)) + " MB";
130                 return getSize(fileSize , (1024D*1024D*1024D)) + " GB";
131         }
132
133         public String getQuotaLeftAsString() {
134                 if (quotaLeftSize < 1024)
135                         return String.valueOf(quotaLeftSize) + " B";
136                 else if (quotaLeftSize <= 1024*1024)
137                         return getSize(quotaLeftSize, 1024D) + " KB";
138                 else if (quotaLeftSize <= 1024*1024*1024)
139                         return getSize(quotaLeftSize,(1024D*1024D)) + " MB";
140                 return getSize(quotaLeftSize , (1024D*1024D*1024D)) + " GB";
141         }
142
143         public String getBandwithQuotaUsedAsString() {
144                 if (bandwithQuotaUsed < 1024)
145                         return String.valueOf(bandwithQuotaUsed) + " B";
146                 else if (bandwithQuotaUsed <= 1024*1024)
147                         return getSize(bandwithQuotaUsed, 1024D) + " KB";
148                 else if (bandwithQuotaUsed <= 1024*1024*1024)
149                         return getSize(bandwithQuotaUsed,(1024D*1024D)) + " MB";
150                 return getSize(bandwithQuotaUsed , (1024D*1024D*1024D)) + " GB";
151         }
152
153         private String getSize(Long size, Double division){
154                 Double res = Double.valueOf(size.toString())/division;
155                 NumberFormat nf = NumberFormat.getFormat("######.#");
156                 return nf.format(res);
157         }
158
159         public long percentOfFreeSpace(){
160                 return quotaLeftSize*100/(fileSize+quotaLeftSize);
161         }
162 }