root / src / gr / ebs / gss / server / domain / UserClass.java @ af6aa461
History | View | Annotate | Download (2.9 kB)
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; |
20 |
|
21 |
import gr.ebs.gss.common.dto.UserClassDTO; |
22 |
|
23 |
import java.io.Serializable; |
24 |
import java.text.DecimalFormat; |
25 |
import java.util.List; |
26 |
|
27 |
import javax.persistence.CascadeType; |
28 |
import javax.persistence.Entity; |
29 |
import javax.persistence.GeneratedValue; |
30 |
import javax.persistence.Id; |
31 |
import javax.persistence.OneToMany; |
32 |
import javax.persistence.Version; |
33 |
|
34 |
import org.hibernate.annotations.Cache; |
35 |
import org.hibernate.annotations.CacheConcurrencyStrategy; |
36 |
|
37 |
/**
|
38 |
* A group of users with common attributes.
|
39 |
*
|
40 |
* @author droutsis
|
41 |
*/
|
42 |
@Entity
|
43 |
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
|
44 |
public class UserClass implements Serializable{ |
45 |
|
46 |
/**
|
47 |
* The persistence ID of the object.
|
48 |
*/
|
49 |
@Id
|
50 |
@GeneratedValue
|
51 |
private Long id; |
52 |
|
53 |
/**
|
54 |
* Version field for optimistic locking.
|
55 |
*/
|
56 |
@SuppressWarnings("unused") |
57 |
@Version
|
58 |
private int version; |
59 |
|
60 |
/**
|
61 |
* A name for this class.
|
62 |
*/
|
63 |
private String name; |
64 |
|
65 |
/**
|
66 |
* The disk quota of this user class.
|
67 |
*/
|
68 |
private long quota; |
69 |
|
70 |
/**
|
71 |
* The users belonging to this class
|
72 |
*/
|
73 |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "userClass") |
74 |
private List<User> users; |
75 |
|
76 |
public Long getId() { |
77 |
return id;
|
78 |
} |
79 |
|
80 |
public String getName() { |
81 |
return name;
|
82 |
} |
83 |
|
84 |
public void setName(String aName) { |
85 |
name = aName; |
86 |
} |
87 |
|
88 |
public long getQuota() { |
89 |
return quota;
|
90 |
} |
91 |
|
92 |
public void setQuota(long aQuota) { |
93 |
quota = aQuota; |
94 |
} |
95 |
|
96 |
@Override
|
97 |
public String toString() { |
98 |
return name;
|
99 |
} |
100 |
|
101 |
/**
|
102 |
* Return a new Data Transfer Object for this user class.
|
103 |
*
|
104 |
* @return a new DTO with the same contents as this object
|
105 |
*/
|
106 |
public UserClassDTO getDTOWithoutUsers() {
|
107 |
UserClassDTO u = new UserClassDTO();
|
108 |
u.setId(id); |
109 |
u.setName(name); |
110 |
u.setQuota(quota); |
111 |
return u;
|
112 |
} |
113 |
|
114 |
/**
|
115 |
* Return the quota size in a humanly readable form.
|
116 |
*/
|
117 |
public String getQuotaAsString() { |
118 |
if (quota < 1024) |
119 |
return String.valueOf(quota) + " B"; |
120 |
else if (quota < 1024*1024) |
121 |
return getSize(quota, 1024D) + " KB"; |
122 |
else if (quota < 1024*1024*1024) |
123 |
return getSize(quota,(1024D*1024D)) + " MB"; |
124 |
return getSize(quota , (1024D*1024D*1024D)) + " GB"; |
125 |
} |
126 |
|
127 |
private String getSize(Long size, Double divisor){ |
128 |
DecimalFormat formatter = new DecimalFormat("######"); |
129 |
return formatter.format((Double) (size.doubleValue()/divisor)); |
130 |
} |
131 |
} |