root / src / gr / ebs / gss / server / domain / UserClass.java @ 01a30cd0
History | View | Annotate | Download (3 kB)
1 | 14ad7326 | pastith | /*
|
---|---|---|---|
2 | 01a30cd0 | Panagiotis Astithas | * Copyright 2007, 2008, 2009, 2010 Electronic Business Systems Ltd.
|
3 | 14ad7326 | pastith | *
|
4 | 14ad7326 | pastith | * This file is part of GSS.
|
5 | 14ad7326 | pastith | *
|
6 | 14ad7326 | pastith | * GSS is free software: you can redistribute it and/or modify
|
7 | 14ad7326 | pastith | * it under the terms of the GNU General Public License as published by
|
8 | 14ad7326 | pastith | * the Free Software Foundation, either version 3 of the License, or
|
9 | 14ad7326 | pastith | * (at your option) any later version.
|
10 | 14ad7326 | pastith | *
|
11 | 14ad7326 | pastith | * GSS is distributed in the hope that it will be useful,
|
12 | 14ad7326 | pastith | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 14ad7326 | pastith | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 14ad7326 | pastith | * GNU General Public License for more details.
|
15 | 14ad7326 | pastith | *
|
16 | 14ad7326 | pastith | * You should have received a copy of the GNU General Public License
|
17 | 14ad7326 | pastith | * along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 | 14ad7326 | pastith | */
|
19 | 14ad7326 | pastith | package gr.ebs.gss.server.domain; |
20 | 14ad7326 | pastith | |
21 | 2f2da9c7 | pastith | import gr.ebs.gss.server.domain.dto.UserClassDTO; |
22 | 14ad7326 | pastith | |
23 | 14ad7326 | pastith | import java.io.Serializable; |
24 | 01a30cd0 | Panagiotis Astithas | import java.text.DecimalFormat; |
25 | 14ad7326 | pastith | import java.util.List; |
26 | 14ad7326 | pastith | |
27 | 14ad7326 | pastith | import javax.persistence.CascadeType; |
28 | 14ad7326 | pastith | import javax.persistence.Entity; |
29 | 14ad7326 | pastith | import javax.persistence.GeneratedValue; |
30 | 14ad7326 | pastith | import javax.persistence.Id; |
31 | 14ad7326 | pastith | import javax.persistence.OneToMany; |
32 | 14ad7326 | pastith | import javax.persistence.Version; |
33 | 14ad7326 | pastith | |
34 | e8e1ac78 | Panagiotis Astithas | import org.hibernate.annotations.Cache; |
35 | e8e1ac78 | Panagiotis Astithas | import org.hibernate.annotations.CacheConcurrencyStrategy; |
36 | e8e1ac78 | Panagiotis Astithas | |
37 | 14ad7326 | pastith | /**
|
38 | 14ad7326 | pastith | * A group of users with common attributes.
|
39 | 14ad7326 | pastith | *
|
40 | 14ad7326 | pastith | * @author droutsis
|
41 | 14ad7326 | pastith | */
|
42 | 14ad7326 | pastith | @Entity
|
43 | e8e1ac78 | Panagiotis Astithas | @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
|
44 | 14ad7326 | pastith | public class UserClass implements Serializable{ |
45 | 14ad7326 | pastith | |
46 | 14ad7326 | pastith | /**
|
47 | 14ad7326 | pastith | * The persistence ID of the object.
|
48 | 14ad7326 | pastith | */
|
49 | 14ad7326 | pastith | @Id
|
50 | 14ad7326 | pastith | @GeneratedValue
|
51 | 14ad7326 | pastith | private Long id; |
52 | 14ad7326 | pastith | |
53 | 14ad7326 | pastith | /**
|
54 | 14ad7326 | pastith | * Version field for optimistic locking.
|
55 | 14ad7326 | pastith | */
|
56 | 14ad7326 | pastith | @SuppressWarnings("unused") |
57 | 14ad7326 | pastith | @Version
|
58 | 14ad7326 | pastith | private int version; |
59 | 14ad7326 | pastith | |
60 | 14ad7326 | pastith | /**
|
61 | 14ad7326 | pastith | * A name for this class.
|
62 | 14ad7326 | pastith | */
|
63 | 14ad7326 | pastith | private String name; |
64 | 14ad7326 | pastith | |
65 | 14ad7326 | pastith | /**
|
66 | 14ad7326 | pastith | * The disk quota of this user class.
|
67 | 14ad7326 | pastith | */
|
68 | 14ad7326 | pastith | private long quota; |
69 | 14ad7326 | pastith | |
70 | 14ad7326 | pastith | /**
|
71 | 14ad7326 | pastith | * The users belonging to this class
|
72 | 14ad7326 | pastith | */
|
73 | 14ad7326 | pastith | @OneToMany(cascade = CascadeType.ALL, mappedBy = "userClass") |
74 | 14ad7326 | pastith | private List<User> users; |
75 | 14ad7326 | pastith | |
76 | 01a30cd0 | Panagiotis Astithas | public Long getId() { |
77 | 01a30cd0 | Panagiotis Astithas | return id;
|
78 | 01a30cd0 | Panagiotis Astithas | } |
79 | 01a30cd0 | Panagiotis Astithas | |
80 | 01a30cd0 | Panagiotis Astithas | public String getName() { |
81 | 01a30cd0 | Panagiotis Astithas | return name;
|
82 | 01a30cd0 | Panagiotis Astithas | } |
83 | 01a30cd0 | Panagiotis Astithas | |
84 | 01a30cd0 | Panagiotis Astithas | public void setName(String aName) { |
85 | 01a30cd0 | Panagiotis Astithas | name = aName; |
86 | 01a30cd0 | Panagiotis Astithas | } |
87 | 01a30cd0 | Panagiotis Astithas | |
88 | 01a30cd0 | Panagiotis Astithas | public long getQuota() { |
89 | 01a30cd0 | Panagiotis Astithas | return quota;
|
90 | 01a30cd0 | Panagiotis Astithas | } |
91 | 01a30cd0 | Panagiotis Astithas | |
92 | 01a30cd0 | Panagiotis Astithas | public void setQuota(long aQuota) { |
93 | 01a30cd0 | Panagiotis Astithas | quota = aQuota; |
94 | 01a30cd0 | Panagiotis Astithas | } |
95 | 01a30cd0 | Panagiotis Astithas | |
96 | 14ad7326 | pastith | @Override
|
97 | 14ad7326 | pastith | public String toString() { |
98 | 14ad7326 | pastith | return name;
|
99 | 14ad7326 | pastith | } |
100 | 14ad7326 | pastith | |
101 | 14ad7326 | pastith | /**
|
102 | 14ad7326 | pastith | * Return a new Data Transfer Object for this user class.
|
103 | 14ad7326 | pastith | *
|
104 | 14ad7326 | pastith | * @return a new DTO with the same contents as this object
|
105 | 14ad7326 | pastith | */
|
106 | 14ad7326 | pastith | public UserClassDTO getDTO() {
|
107 | 01a30cd0 | Panagiotis Astithas | UserClassDTO u = new UserClassDTO();
|
108 | 14ad7326 | pastith | u.setId(id); |
109 | 14ad7326 | pastith | u.setName(name); |
110 | 14ad7326 | pastith | u.setQuota(quota); |
111 | 14ad7326 | pastith | for (final User user : users) |
112 | 14ad7326 | pastith | u.getUsers().add(user.getDTO()); |
113 | 14ad7326 | pastith | return u;
|
114 | 14ad7326 | pastith | } |
115 | 01a30cd0 | Panagiotis Astithas | |
116 | 01a30cd0 | Panagiotis Astithas | /**
|
117 | 01a30cd0 | Panagiotis Astithas | * Return the quota size in a humanly readable form.
|
118 | 01a30cd0 | Panagiotis Astithas | */
|
119 | 01a30cd0 | Panagiotis Astithas | public String getQuotaAsString() { |
120 | 01a30cd0 | Panagiotis Astithas | if (quota < 1024) |
121 | 01a30cd0 | Panagiotis Astithas | return String.valueOf(quota) + " B"; |
122 | 01a30cd0 | Panagiotis Astithas | else if (quota < 1024*1024) |
123 | 01a30cd0 | Panagiotis Astithas | return getSize(quota, 1024D) + " KB"; |
124 | 01a30cd0 | Panagiotis Astithas | else if (quota < 1024*1024*1024) |
125 | 01a30cd0 | Panagiotis Astithas | return getSize(quota,(1024D*1024D)) + " MB"; |
126 | 01a30cd0 | Panagiotis Astithas | return getSize(quota , (1024D*1024D*1024D)) + " GB"; |
127 | 01a30cd0 | Panagiotis Astithas | } |
128 | 01a30cd0 | Panagiotis Astithas | |
129 | 01a30cd0 | Panagiotis Astithas | private String getSize(Long size, Double divisor){ |
130 | 01a30cd0 | Panagiotis Astithas | DecimalFormat formatter = new DecimalFormat("######"); |
131 | 01a30cd0 | Panagiotis Astithas | return formatter.format((Double) (size.doubleValue()/divisor)); |
132 | 01a30cd0 | Panagiotis Astithas | } |
133 | 14ad7326 | pastith | } |