forked from p2-inc/keycloak-orgs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OrganizationRoleEntity.java
111 lines (88 loc) · 2.76 KB
/
OrganizationRoleEntity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package io.phasetwo.service.model.jpa.entity;
import static io.phasetwo.service.model.jpa.entity.Entities.setCollection;
import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Objects;
/** */
@NamedQueries({
@NamedQuery(
name = "getOrganizationRoles",
query = "SELECT m FROM OrganizationRoleEntity m WHERE m.organization = :organization"),
@NamedQuery(
name = "getOrganizationRoleByName",
query =
"SELECT m FROM OrganizationRoleEntity m WHERE m.organization = :organization AND m.name = :name"),
@NamedQuery(
name = "removeOrganizationRole",
query =
"DELETE FROM OrganizationRoleEntity m WHERE m.organization = :organization AND m.name = :name")
})
@Table(
name = "ORGANIZATION_ROLE",
uniqueConstraints = {@UniqueConstraint(columnNames = {"ORGANIZATION_ID", "NAME"})})
@Entity
public class OrganizationRoleEntity {
@Id
@Column(name = "ID", length = 36)
@Access(AccessType.PROPERTY)
protected String id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ORGANIZATION_ID")
protected OrganizationEntity organization;
@Column(name = "NAME", nullable = false)
protected String name;
@Column(name = "DESCRIPTION")
protected String description;
@OneToMany(
fetch = FetchType.LAZY,
cascade = CascadeType.ALL,
orphanRemoval = true,
mappedBy = "role")
protected Collection<UserOrganizationRoleMappingEntity> userMappings =
new ArrayList<UserOrganizationRoleMappingEntity>();
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public OrganizationEntity getOrganization() {
return organization;
}
public void setOrganization(OrganizationEntity organization) {
this.organization = organization;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Collection<UserOrganizationRoleMappingEntity> getUserMappings() {
return userMappings;
}
public void setUserMappings(Collection<UserOrganizationRoleMappingEntity> userMappings) {
setCollection(userMappings, this.userMappings);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
if (!(o instanceof OrganizationRoleEntity)) return false;
OrganizationRoleEntity key = (OrganizationRoleEntity) o;
if (!name.equals(key.name)) return false;
if (!organization.equals(key.organization)) return false;
return true;
}
@Override
public int hashCode() {
return Objects.hash(organization, name);
}
}