Project

General

Profile

Download (2.5 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.model.common;
10

    
11
import java.util.HashSet;
12
import java.util.Set;
13

    
14
import javax.persistence.Entity;
15
import javax.persistence.FetchType;
16
import javax.persistence.ManyToMany;
17
import javax.persistence.Table;
18
import javax.xml.bind.annotation.XmlAccessType;
19
import javax.xml.bind.annotation.XmlAccessorType;
20
import javax.xml.bind.annotation.XmlElement;
21
import javax.xml.bind.annotation.XmlElementWrapper;
22
import javax.xml.bind.annotation.XmlIDREF;
23
import javax.xml.bind.annotation.XmlRootElement;
24
import javax.xml.bind.annotation.XmlSchemaType;
25
import javax.xml.bind.annotation.XmlType;
26

    
27
import org.hibernate.annotations.NaturalId;
28
import org.springframework.security.GrantedAuthority;
29

    
30
@XmlAccessorType(XmlAccessType.FIELD)
31
@XmlType(name = "Group", propOrder = {
32
    "name",
33
    "members",
34
    "grantedAuthorities"
35
})
36
@XmlRootElement(name = "Group")
37
@Entity
38
@Table(name = "PermissionGroup")
39
public class Group extends CdmBase {
40
	
41
	/**
42
	 * 
43
	 */
44
	private static final long serialVersionUID = 7216686200093054648L;
45
	
46
	@XmlElement(name = "Name")
47
	@NaturalId
48
	protected String name;
49
	
50
	@XmlElementWrapper(name = "Members")
51
	@XmlElement(name = "Member")
52
	@XmlIDREF
53
	@XmlSchemaType(name = "IDREF")
54
	@ManyToMany(fetch = FetchType.LAZY, mappedBy = "groups")
55
	protected Set<User> members = new HashSet<User>();
56
	
57
	@XmlElementWrapper(name = "GrantedAuthorities")
58
	@XmlElement(name = "GrantedAuthority", type = GrantedAuthorityImpl.class)
59
	@XmlIDREF
60
	@XmlSchemaType(name = "IDREF")
61
	@ManyToMany(fetch = FetchType.LAZY, targetEntity = GrantedAuthorityImpl.class)
62
	protected Set <GrantedAuthority> grantedAuthorities = new HashSet<GrantedAuthority>();
63
	
64
	public Set<GrantedAuthority> getGrantedAuthorities() {
65
		return grantedAuthorities;
66
	}
67
	
68
	public void setName(String name) {
69
		this.name = name;
70
	}
71
	
72
	public String getName() {
73
		return name;
74
	}
75
	
76
	public Set<User> getMembers() {
77
		return members;
78
	}
79

    
80
	public boolean addMember(User user) {
81
		user.getGroups().add(this);
82
		return this.members.add(user);
83
	}
84

    
85
	public boolean removeMember(User user) {
86
		if(members.contains(user)) {
87
			user.getGroups().remove(this);
88
		    return this.members.remove(user);
89
		} else {
90
			return false;
91
		}
92
	}
93
}
(13-13/58)