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
.rights
;
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
.validation
.constraints
.Pattern
;
22 import javax
.xml
.bind
.annotation
.XmlAccessType
;
23 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
24 import javax
.xml
.bind
.annotation
.XmlElement
;
25 import javax
.xml
.bind
.annotation
.XmlElementWrapper
;
26 import javax
.xml
.bind
.annotation
.XmlIDREF
;
27 import javax
.xml
.bind
.annotation
.XmlRootElement
;
28 import javax
.xml
.bind
.annotation
.XmlSchemaType
;
29 import javax
.xml
.bind
.annotation
.XmlType
;
31 import org
.apache
.commons
.lang3
.StringUtils
;
32 import org
.apache
.log4j
.Logger
;
33 import org
.hibernate
.annotations
.Cascade
;
34 import org
.hibernate
.annotations
.CascadeType
;
35 import org
.hibernate
.search
.annotations
.Field
;
36 import org
.springframework
.security
.core
.GrantedAuthority
;
38 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
40 @XmlAccessorType(XmlAccessType
.FIELD
)
41 @XmlType(name
= "Group", propOrder
= {
46 @XmlRootElement(name
= "Group")
48 //@Indexed disabled to reduce clutter in indexes, since this type is not used by any search
49 //@Indexed(index = "eu.etaxonomy.cdm.model.common.Group")
50 @Table(name
= "PermissionGroup")
51 public class Group
extends CdmBase
{
52 private static final long serialVersionUID
= 7216686200093054648L;
53 private static final Logger logger
= Logger
.getLogger(Group
.class);
55 public final static UUID GROUP_EDITOR_UUID
= UUID
.fromString("22e5e8af-b99c-4884-a92f-71978efd3770");
56 public final static UUID GROUP_EDITOR_EXTENDED_CREATE_UUID
= UUID
.fromString("89a7f47f-6f2b-45ac-88d4-a99a4cf29f07");
57 public final static UUID GROUP_PROJECT_MANAGER_UUID
= UUID
.fromString("645191ae-32a4-4d4e-9b86-c90e0d41944a");
58 public final static UUID GROUP_PUBLISHER_UUID
= UUID
.fromString("c1f20ad8-1782-40a7-b06b-ce4773acb5ea");
59 public final static UUID GROUP_ADMIN_UUID
= UUID
.fromString("1739df71-bf73-4dc6-8320-aaaf72cb555f");
61 public final static String GROUP_EDITOR_NAME
= "Editor";
63 * This group will in future replace the group Editor, see issue #7150
65 public final static String GROUP_EDITOR_EXTENDED_CREATE_NAME
= "EditorExtendedCreate";
66 public final static String GROUP_PROJECT_MANAGER_NAME
= "ProjectManager";
67 public final static String GROUP_ADMIN_NAME
= "Admin";
70 //*********************** FACTORY *********************/
72 public static Group
NewInstance(){
76 public static Group
NewInstance(String name
){
77 Group group
= Group
.NewInstance();
82 //**************** FIELDS ******************************/
84 @XmlElement(name
= "Name")
85 @Column(unique
= true)
88 @Pattern(regexp
=User
.USERNAME_REGEX
)
89 protected String name
;
91 @XmlElementWrapper(name
= "Members")
92 @XmlElement(name
= "Member")
94 @XmlSchemaType(name
= "IDREF")
95 @ManyToMany(fetch
= FetchType
.LAZY
, mappedBy
= "groups")
96 protected Set
<User
> members
= new HashSet
<>();
98 @XmlElementWrapper(name
= "GrantedAuthorities")
99 @XmlElement(name
= "GrantedAuthority", type
= GrantedAuthorityImpl
.class)
101 @XmlSchemaType(name
= "IDREF")
102 @ManyToMany(fetch
= FetchType
.LAZY
, targetEntity
= GrantedAuthorityImpl
.class)
103 @Cascade({CascadeType
.SAVE_UPDATE
,CascadeType
.MERGE
})
104 protected Set
<GrantedAuthority
> grantedAuthorities
= new HashSet
<>();
106 // ********************* CONSTRUCTOR ************************/
112 // *************** METHODS ***********************************/
114 public Set
<GrantedAuthority
> getGrantedAuthorities() {
115 return grantedAuthorities
;
118 public boolean addGrantedAuthority(GrantedAuthority grantedAuthority
){
119 return grantedAuthorities
.add(grantedAuthority
);
122 public boolean removeGrantedAuthority(GrantedAuthority grantedAuthority
){
123 return grantedAuthorities
.remove(grantedAuthority
);
126 public void setName(String name
) {
130 public String
getName() {
134 public Set
<User
> getMembers() {
138 public boolean addMember(User user
) {
139 user
.getGroups().add(this);
140 return this.members
.add(user
);
143 public boolean removeMember(User user
) {
144 if(members
.contains(user
)) {
145 user
.getGroups().remove(this);
146 return this.members
.remove(user
);
152 //*********************** CLONE ********************************************************/
155 * Clones <i>this</i> Group. This is a shortcut that enables to create
156 * a new instance that differs only slightly from <i>this</i> group by
157 * modifying only some of the attributes.
159 * @see eu.etaxonomy.cdm.model.term.TermBase#clone()
160 * @see java.lang.Object#clone()
163 public Object
clone() {
166 result
= (Group
)super.clone();
167 result
.grantedAuthorities
= new HashSet
<>();
168 for (GrantedAuthority grantedauthority
: this.grantedAuthorities
){
169 result
.addGrantedAuthority(grantedauthority
);
172 result
.members
= new HashSet
<>();
173 for (User member
: this.members
){
174 result
.addMember(member
);
179 } catch (CloneNotSupportedException e
) {
180 logger
.warn("Object does not implement cloneable");
186 //************************************** toString ***************************************
189 public String
toString() {
190 if (StringUtils
.isNotBlank(name
)){
193 return super.toString();