2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.model
.common
;
11 import java
.util
.HashSet
;
13 import java
.util
.UUID
;
15 import javax
.persistence
.Column
;
16 import javax
.persistence
.Entity
;
17 import javax
.persistence
.FetchType
;
18 import javax
.persistence
.ManyToMany
;
19 import javax
.persistence
.Table
;
20 import javax
.xml
.bind
.annotation
.XmlAccessType
;
21 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
22 import javax
.xml
.bind
.annotation
.XmlElement
;
23 import javax
.xml
.bind
.annotation
.XmlElementWrapper
;
24 import javax
.xml
.bind
.annotation
.XmlIDREF
;
25 import javax
.xml
.bind
.annotation
.XmlRootElement
;
26 import javax
.xml
.bind
.annotation
.XmlSchemaType
;
27 import javax
.xml
.bind
.annotation
.XmlType
;
29 import org
.apache
.log4j
.Logger
;
30 import org
.hibernate
.annotations
.Cascade
;
31 import org
.hibernate
.annotations
.CascadeType
;
32 import org
.hibernate
.search
.annotations
.Field
;
33 import org
.hibernate
.search
.annotations
.Indexed
;
34 import org
.springframework
.security
.core
.GrantedAuthority
;
36 @XmlAccessorType(XmlAccessType
.FIELD
)
37 @XmlType(name
= "Group", propOrder
= {
42 @XmlRootElement(name
= "Group")
44 @Indexed(index
= "eu.etaxonomy.cdm.model.common.Group")
45 @Table(name
= "PermissionGroup")
46 public class Group
extends CdmBase
{
47 private static final long serialVersionUID
= 7216686200093054648L;
48 private static final Logger logger
= Logger
.getLogger(Group
.class);
50 public final static UUID groupEditorUuid
= UUID
.fromString("22e5e8af-b99c-4884-a92f-71978efd3770");
51 public final static UUID groupProjectManagerUuid
= UUID
.fromString("645191ae-32a4-4d4e-9b86-c90e0d41944a");
53 //*********************** FACTORY *********************/
55 public static Group
NewInstance(){
59 public static Group
NewInstance(String name
){
60 Group group
= Group
.NewInstance();
65 //**************** FIELDS ******************************/
67 @XmlElement(name
= "Name")
68 @Column(unique
= true)
70 protected String name
;
72 @XmlElementWrapper(name
= "Members")
73 @XmlElement(name
= "Member")
75 @XmlSchemaType(name
= "IDREF")
76 @ManyToMany(fetch
= FetchType
.LAZY
, mappedBy
= "groups")
77 @Cascade(CascadeType
.REFRESH
) // see #2414 (Group updating doesn't work)
78 protected Set
<User
> members
= new HashSet
<User
>();
80 @XmlElementWrapper(name
= "GrantedAuthorities")
81 @XmlElement(name
= "GrantedAuthority", type
= GrantedAuthorityImpl
.class)
83 @XmlSchemaType(name
= "IDREF")
84 @ManyToMany(fetch
= FetchType
.LAZY
, targetEntity
= GrantedAuthorityImpl
.class)
85 @Cascade({CascadeType
.SAVE_UPDATE
})
86 protected Set
<GrantedAuthority
> grantedAuthorities
= new HashSet
<GrantedAuthority
>();
88 // ********************* CONSTRUCTOR ************************/
94 // *************** METHODS ***********************************/
96 public Set
<GrantedAuthority
> getGrantedAuthorities() {
97 return grantedAuthorities
;
100 public boolean addGrantedAuthority(GrantedAuthority grantedAuthority
){
101 return grantedAuthorities
.add(grantedAuthority
);
104 public boolean removeGrantedAuthority(GrantedAuthority grantedAuthority
){
105 return grantedAuthorities
.remove(grantedAuthority
);
108 public void setName(String name
) {
112 public String
getName() {
116 public Set
<User
> getMembers() {
120 public boolean addMember(User user
) {
121 user
.getGroups().add(this);
122 return this.members
.add(user
);
125 public boolean removeMember(User user
) {
126 if(members
.contains(user
)) {
127 user
.getGroups().remove(this);
128 return this.members
.remove(user
);
133 //*********************** CLONE ********************************************************/
136 * Clones <i>this</i> Group. This is a shortcut that enables to create
137 * a new instance that differs only slightly from <i>this</i> group by
138 * modifying only some of the attributes.
140 * @see eu.etaxonomy.cdm.model.common.TermBase#clone()
141 * @see java.lang.Object#clone()
144 public Object
clone() {
147 result
= (Group
)super.clone();
148 result
.grantedAuthorities
= new HashSet
<GrantedAuthority
>();
149 for (GrantedAuthority grantedauthority
: this.grantedAuthorities
){
150 result
.addGrantedAuthority(grantedauthority
);
153 result
.members
= new HashSet
<User
>();
154 for (User member
: this.members
){
155 result
.addMember(member
);
160 } catch (CloneNotSupportedException e
) {
161 logger
.warn("Object does not implement cloneable");