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
.validation
.constraints
.NotNull
;
21 import javax
.xml
.bind
.annotation
.XmlAccessType
;
22 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
23 import javax
.xml
.bind
.annotation
.XmlElement
;
24 import javax
.xml
.bind
.annotation
.XmlElementWrapper
;
25 import javax
.xml
.bind
.annotation
.XmlIDREF
;
26 import javax
.xml
.bind
.annotation
.XmlRootElement
;
27 import javax
.xml
.bind
.annotation
.XmlSchemaType
;
28 import javax
.xml
.bind
.annotation
.XmlType
;
30 import org
.apache
.log4j
.Logger
;
31 import org
.hibernate
.annotations
.Cascade
;
32 import org
.hibernate
.annotations
.CascadeType
;
33 import org
.hibernate
.search
.annotations
.Field
;
34 import org
.hibernate
.search
.annotations
.Indexed
;
35 import org
.springframework
.security
.core
.GrantedAuthority
;
37 @XmlAccessorType(XmlAccessType
.FIELD
)
38 @XmlType(name
= "Group", propOrder
= {
43 @XmlRootElement(name
= "Group")
45 @Indexed(index
= "eu.etaxonomy.cdm.model.common.Group")
46 @Table(name
= "PermissionGroup")
47 public class Group
extends CdmBase
{
48 private static final long serialVersionUID
= 7216686200093054648L;
49 private static final Logger logger
= Logger
.getLogger(Group
.class);
51 public final static UUID groupEditorUuid
= UUID
.fromString("22e5e8af-b99c-4884-a92f-71978efd3770");
52 public final static UUID groupProjectManagerUuid
= UUID
.fromString("645191ae-32a4-4d4e-9b86-c90e0d41944a");
53 public final static UUID groupPublisherUuid
= UUID
.fromString("c1f20ad8-1782-40a7-b06b-ce4773acb5ea");
55 //*********************** FACTORY *********************/
57 public static Group
NewInstance(){
61 public static Group
NewInstance(String name
){
62 Group group
= Group
.NewInstance();
67 //**************** FIELDS ******************************/
69 @XmlElement(name
= "Name")
70 @Column(unique
= true)
73 protected String name
;
75 @XmlElementWrapper(name
= "Members")
76 @XmlElement(name
= "Member")
78 @XmlSchemaType(name
= "IDREF")
79 @ManyToMany(fetch
= FetchType
.LAZY
, mappedBy
= "groups")
80 @Cascade({CascadeType
.REFRESH
, CascadeType
.MERGE
}) // see #2414 (Group updating doesn't work)
81 protected Set
<User
> members
= new HashSet
<User
>();
83 @XmlElementWrapper(name
= "GrantedAuthorities")
84 @XmlElement(name
= "GrantedAuthority", type
= GrantedAuthorityImpl
.class)
86 @XmlSchemaType(name
= "IDREF")
87 @ManyToMany(fetch
= FetchType
.LAZY
, targetEntity
= GrantedAuthorityImpl
.class)
88 @Cascade({CascadeType
.SAVE_UPDATE
,CascadeType
.MERGE
})
89 protected Set
<GrantedAuthority
> grantedAuthorities
= new HashSet
<GrantedAuthority
>();
91 // ********************* CONSTRUCTOR ************************/
97 // *************** METHODS ***********************************/
99 public Set
<GrantedAuthority
> getGrantedAuthorities() {
100 return grantedAuthorities
;
103 public boolean addGrantedAuthority(GrantedAuthority grantedAuthority
){
104 return grantedAuthorities
.add(grantedAuthority
);
107 public boolean removeGrantedAuthority(GrantedAuthority grantedAuthority
){
108 return grantedAuthorities
.remove(grantedAuthority
);
111 public void setName(String name
) {
115 public String
getName() {
119 public Set
<User
> getMembers() {
123 public boolean addMember(User user
) {
124 user
.getGroups().add(this);
125 return this.members
.add(user
);
128 public boolean removeMember(User user
) {
129 if(members
.contains(user
)) {
130 user
.getGroups().remove(this);
131 return this.members
.remove(user
);
136 //*********************** CLONE ********************************************************/
139 * Clones <i>this</i> Group. This is a shortcut that enables to create
140 * a new instance that differs only slightly from <i>this</i> group by
141 * modifying only some of the attributes.
143 * @see eu.etaxonomy.cdm.model.common.TermBase#clone()
144 * @see java.lang.Object#clone()
147 public Object
clone() {
150 result
= (Group
)super.clone();
151 result
.grantedAuthorities
= new HashSet
<GrantedAuthority
>();
152 for (GrantedAuthority grantedauthority
: this.grantedAuthorities
){
153 result
.addGrantedAuthority(grantedauthority
);
156 result
.members
= new HashSet
<User
>();
157 for (User member
: this.members
){
158 result
.addMember(member
);
163 } catch (CloneNotSupportedException e
) {
164 logger
.warn("Object does not implement cloneable");