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
.Entity
;
16 import javax
.persistence
.FetchType
;
17 import javax
.persistence
.ManyToMany
;
18 import javax
.persistence
.Table
;
19 import javax
.xml
.bind
.annotation
.XmlAccessType
;
20 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
21 import javax
.xml
.bind
.annotation
.XmlElement
;
22 import javax
.xml
.bind
.annotation
.XmlElementWrapper
;
23 import javax
.xml
.bind
.annotation
.XmlIDREF
;
24 import javax
.xml
.bind
.annotation
.XmlRootElement
;
25 import javax
.xml
.bind
.annotation
.XmlSchemaType
;
26 import javax
.xml
.bind
.annotation
.XmlType
;
28 import org
.apache
.log4j
.Logger
;
29 import org
.hibernate
.annotations
.Cascade
;
30 import org
.hibernate
.annotations
.CascadeType
;
31 import org
.hibernate
.annotations
.NaturalId
;
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 @XmlElement(name
= "Name")
56 protected String name
;
58 @XmlElementWrapper(name
= "Members")
59 @XmlElement(name
= "Member")
61 @XmlSchemaType(name
= "IDREF")
62 @ManyToMany(fetch
= FetchType
.LAZY
, mappedBy
= "groups")
63 @Cascade(CascadeType
.REFRESH
) // see #2414 (Group updating doesn't work)
64 protected Set
<User
> members
= new HashSet
<User
>();
66 @XmlElementWrapper(name
= "GrantedAuthorities")
67 @XmlElement(name
= "GrantedAuthority", type
= GrantedAuthorityImpl
.class)
69 @XmlSchemaType(name
= "IDREF")
70 @ManyToMany(fetch
= FetchType
.LAZY
, targetEntity
= GrantedAuthorityImpl
.class)
71 @Cascade({CascadeType
.SAVE_UPDATE
})
72 protected Set
<GrantedAuthority
> grantedAuthorities
= new HashSet
<GrantedAuthority
>();
78 public static Group
NewInstance(){
82 public static Group
NewInstance(String name
){
83 Group group
= Group
.NewInstance();
88 public Set
<GrantedAuthority
> getGrantedAuthorities() {
89 return grantedAuthorities
;
92 public boolean addGrantedAuthority(GrantedAuthority grantedAuthority
){
93 return grantedAuthorities
.add(grantedAuthority
);
96 public boolean removeGrantedAuthority(GrantedAuthority grantedAuthority
){
97 return grantedAuthorities
.remove(grantedAuthority
);
100 public void setName(String name
) {
104 public String
getName() {
108 public Set
<User
> getMembers() {
112 public boolean addMember(User user
) {
113 user
.getGroups().add(this);
114 return this.members
.add(user
);
117 public boolean removeMember(User user
) {
118 if(members
.contains(user
)) {
119 user
.getGroups().remove(this);
120 return this.members
.remove(user
);
125 //*********************** CLONE ********************************************************/
128 * Clones <i>this</i> Group. This is a shortcut that enables to create
129 * a new instance that differs only slightly from <i>this</i> group by
130 * modifying only some of the attributes.
132 * @see eu.etaxonomy.cdm.model.common.TermBase#clone()
133 * @see java.lang.Object#clone()
136 public Object
clone() {
139 result
= (Group
)super.clone();
140 result
.grantedAuthorities
= new HashSet
<GrantedAuthority
>();
141 for (GrantedAuthority grantedauthority
: this.grantedAuthorities
){
142 result
.addGrantedAuthority(grantedauthority
);
145 result
.members
= new HashSet
<User
>();
146 for (User member
: this.members
){
147 result
.addMember(member
);
152 } catch (CloneNotSupportedException e
) {
153 logger
.warn("Object does not implement cloneable");