2 * Copyright 2007, 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;
21 import gr.ebs.gss.server.domain.dto.GroupDTO;
23 import java.io.Serializable;
26 import javax.persistence.CascadeType;
27 import javax.persistence.Embedded;
28 import javax.persistence.Entity;
29 import javax.persistence.FetchType;
30 import javax.persistence.GeneratedValue;
31 import javax.persistence.Id;
32 import javax.persistence.JoinColumn;
33 import javax.persistence.JoinTable;
34 import javax.persistence.ManyToMany;
35 import javax.persistence.ManyToOne;
36 import javax.persistence.OneToMany;
37 import javax.persistence.Table;
38 import javax.persistence.Version;
40 import org.hibernate.annotations.Cache;
41 import org.hibernate.annotations.CacheConcurrencyStrategy;
44 * A group of users of the GSS service.
49 @Table(name = "GSS_Group")
50 @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
51 public class Group implements Serializable{
54 * The persistence ID of the object.
61 * Version field for optimistic locking.
63 @SuppressWarnings("unused")
68 * The audit information.
71 private AuditInfo auditInfo;
74 * The name of the group.
79 * The user that owns this group.
81 @ManyToOne(optional = false)
82 @JoinColumn(nullable = false)
86 * The set of users that belong to this group.
88 @ManyToMany(fetch = FetchType.LAZY)
89 @JoinTable(joinColumns = {@JoinColumn(nullable = false)}, inverseJoinColumns = {@JoinColumn(nullable = false)})
90 private Set<User> members;
92 @OneToMany(mappedBy="group", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
93 private Set<Permission> permissions;
96 * A default constructor.
103 * Retrieve the permissions.
105 * @return the permissions
107 public Set<Permission> getPermissions() {
112 * Modify the permissions.
114 * @param newPermissions the permissions to set
116 public void setPermissions(Set<Permission> newPermissions) {
117 permissions = newPermissions;
121 * A constructor that creates a group with the specified name.
125 public Group(final String aName) {
130 public String toString() {
139 public Long getId() {
148 public String getName() {
155 * @param newName the name to set
157 public void setName(final String newName) {
162 * Retrieve the owner.
166 public User getOwner() {
173 * @param newOwner the owner to set
175 public void setOwner(final User newOwner) {
180 * Retrieve the members.
182 * @return the members
184 public Set<User> getMembers() {
189 * Replace the member set.
191 * @param newMembers the new members
193 public void setMembers(final Set<User> newMembers) {
194 members = newMembers;
198 * Retrieve the audit info.
200 * @return the audit info
202 public AuditInfo getAuditInfo() {
207 * Modify the audit info.
209 * @param newAuditInfo the new audit info
211 public void setAuditInfo(final AuditInfo newAuditInfo) {
212 auditInfo = newAuditInfo;
216 * Returns a Data Transfer Object for this Group
220 public GroupDTO getDTO() {
221 final GroupDTO g = new GroupDTO();
224 g.setOwner(owner.getDTO());
225 for (final User u : members)
226 g.getMembers().add(u.getDTO());
231 * Checks if this groups contains the specified user
236 public boolean contains(final User user) {
237 return members.contains(user);
240 public void removeMemberFromGroup(final User member){
241 getMembers().remove(member);
242 member.getGroupsMember().remove(this);