- Add an administration application.
[pithos] / src / gr / ebs / gss / server / domain / dto / UserClassDTO.java
1 /*
2  * Copyright 2007, 2008, 2009, 2010 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 import java.util.ArrayList;
23 import java.util.List;
24
25 import com.google.gwt.i18n.client.NumberFormat;
26
27 /**
28  * A group of users with common attributes.
29  *
30  * @author droutsis
31  */
32 public class UserClassDTO implements Serializable {
33
34         /**
35          * The serial version UID of the class.
36          */
37         private static final long serialVersionUID = 1L;
38
39         /**
40          * The persistence ID of the object.
41          */
42         private Long id;
43
44         /**
45          * A name for this class.
46          */
47         private String name;
48
49         /**
50          * The disk quota of this user class.
51          */
52         private long quota;
53
54         /**
55          * The users belonging to this class
56          *
57          */
58         private List<UserDTO> users = new ArrayList<UserDTO>();
59
60         private SystemStatsDTO statistics;
61
62         @Override
63         public String toString() {
64                 return name;
65         }
66
67         /**
68          * Retrieve the id.
69          *
70          * @return the id
71          */
72         public Long getId() {
73                 return id;
74         }
75
76         /**
77          * Modify the id.
78          *
79          * @param newId the id to set
80          */
81         public void setId(final Long newId) {
82                 id = newId;
83         }
84
85         /**
86          * Retrieve the name.
87          *
88          * @return the name
89          */
90         public String getName() {
91                 return name;
92         }
93
94         /**
95          * Modify the name.
96          *
97          * @param newName the name to set
98          */
99         public void setName(final String newName) {
100                 name = newName;
101         }
102
103         /**
104          * Retrieve the quota.
105          *
106          * @return the quota
107          */
108         public long getQuota() {
109                 return quota;
110         }
111
112         /**
113          * Modify the quota.
114          *
115          * @param newQuota the quota to set
116          */
117         public void setQuota(final long newQuota) {
118                 quota = newQuota;
119         }
120
121         /**
122          * Retrieve the users.
123          *
124          * @return the users
125          */
126         public List<UserDTO> getUsers() {
127                 return users;
128         }
129
130         /**
131          * Modify the users.
132          *
133          * @param newUsers the users to set
134          */
135         public void setUsers(final List<UserDTO> newUsers) {
136                 users = newUsers;
137         }
138
139         /**
140          * Retrieve the statistics.
141          *
142          * @return the statistics
143          */
144         public SystemStatsDTO getStatistics() {
145                 return statistics;
146         }
147
148         /**
149          * Modify the statistics.
150          *
151          * @param theStatistics the statistics to set
152          */
153         public void setStatistics(SystemStatsDTO theStatistics) {
154                 statistics = theStatistics;
155         }
156
157         public String getQuotaAsString() {
158                 if (quota < 1024)
159                         return String.valueOf(quota) + " B";
160                 else if (quota <= 1024*1024)
161                         return getSize(quota, 1024D) + " KB";
162                 else if (quota <= 1024*1024*1024)
163                         return getSize(quota,(1024D*1024D)) + " MB";
164                 return getSize(quota , (1024D*1024D*1024D)) + " GB";
165         }
166
167         private String getSize(Long size, Double divisor){
168                 Double res = Double.valueOf(size.toString())/divisor;
169                 NumberFormat nf = NumberFormat.getFormat("######.#");
170                 return nf.format(res);
171         }
172 }