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;
41 * A group of users of the GSS service.
46 @Table(name = "GSS_Group")
47 public class Group implements Serializable{
50 * The persistence ID of the object.
57 * Version field for optimistic locking.
59 @SuppressWarnings("unused")
64 * The audit information.
67 private AuditInfo auditInfo;
70 * The name of the group.
75 * The user that owns this group.
77 @ManyToOne(optional = false)
78 @JoinColumn(nullable = false)
82 * The set of users that belong to this group.
84 @ManyToMany(fetch = FetchType.LAZY)
85 @JoinTable(joinColumns = {@JoinColumn(nullable = false)}, inverseJoinColumns = {@JoinColumn(nullable = false)})
86 private Set<User> members;
88 @OneToMany(mappedBy="group", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
89 private Set<Permission> permissions;
92 * A default constructor.
100 * Retrieve the permissions.
102 * @return the permissions
104 public Set<Permission> getPermissions() {
110 * Modify the permissions.
112 * @param permissions the permissions to set
114 public void setPermissions(Set<Permission> permissions) {
115 this.permissions = permissions;
119 * A constructor that creates a group with the specified name.
123 public Group(final String aName) {
130 * @see java.lang.Object#toString()
133 public String toString() {
142 public Long getId() {
151 public String getName() {
158 * @param newName the name to set
160 public void setName(final String newName) {
165 * Retrieve the owner.
169 public User getOwner() {
176 * @param newOwner the owner to set
178 public void setOwner(final User newOwner) {
183 * Retrieve the members.
185 * @return the members
187 public Set<User> getMembers() {
192 * Replace the member set.
194 * @param newMembers the new members
196 public void setMembers(final Set<User> newMembers) {
197 members = newMembers;
201 * Retrieve the audit info.
203 * @return the audit info
205 public AuditInfo getAuditInfo() {
210 * Modify the audit info.
212 * @param newAuditInfo the new audit info
214 public void setAuditInfo(final AuditInfo newAuditInfo) {
215 auditInfo = newAuditInfo;
219 * Returns a Data Transfer Object for this Group
223 public GroupDTO getDTO() {
224 final GroupDTO g = new GroupDTO();
227 g.setOwner(owner.getDTO());
228 for (final User u : members)
229 g.getMembers().add(u.getDTO());
234 * Checks if this groups contains the specified user
239 public boolean contains(final User user) {
240 return members.contains(user);
243 public void removeMemberFromGroup(final User member){
244 getMembers().remove(member);
245 member.getGroupsMember().remove(this);