2 * Copyright 2008, 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.server.domain.dto;
21 import java.io.Serializable;
23 import com.google.gwt.i18n.client.NumberFormat;
27 * DTO Object holding stats for User: file count, size count and quota
31 public class StatsDTO implements Serializable{
33 private Long fileCount = 0L;
34 private Long fileSize = 0L;
35 private Long quotaLeftSize = 0L;
36 private Long bandwithQuotaUsed=0L;
42 public StatsDTO(Long aFileCount, Long aFileSize, Long aQuotaLeftSize) {
43 fileCount = aFileCount;
45 quotaLeftSize = aQuotaLeftSize;
49 * Retrieve the fileCount.
51 * @return the fileCount
53 public Long getFileCount() {
58 * Modify the fileCount.
60 * @param aFileCount the fileCount to set
62 public void setFileCount(Long aFileCount) {
63 fileCount = aFileCount;
67 * Retrieve the fileSize.
69 * @return the fileSize
71 public Long getFileSize() {
76 * Modify the fileSize.
78 * @param aFileSize the fileSize to set
80 public void setFileSize(Long aFileSize) {
85 * Retrieve the quotaLeftSize.
87 * @return the quotaLeftSize
89 public Long getQuotaLeftSize() {
94 * Modify the quotaLeftSize.
96 * @param aQuotaLeftSize the quotaLeftSize to set
98 public void setQuotaLeftSize(Long aQuotaLeftSize) {
99 quotaLeftSize = aQuotaLeftSize;
105 * Retrieve the bandwithQuotaUsed.
107 * @return the bandwithQuotaUsed
109 public Long getBandwithQuotaUsed() {
110 return bandwithQuotaUsed;
115 * Modify the bandwithQuotaUsed.
117 * @param aBandwithQuotaUsed the bandwithQuotaUsed to set
119 public void setBandwithQuotaUsed(Long aBandwithQuotaUsed) {
120 bandwithQuotaUsed = aBandwithQuotaUsed;
123 public String getFileSizeAsString() {
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";
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";
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";
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);
159 public long percentOfFreeSpace(){
160 return quotaLeftSize*100/(fileSize+quotaLeftSize);