Role.java
4.74 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package fi.insomnia.bortal.model;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import org.eclipse.persistence.annotations.PrivateOwned;
/**
*
*/
@Entity
@Table(name = "roles", uniqueConstraints = { @UniqueConstraint(columnNames = { Role.EVENT_ID_COLUMN, Role.NAME_COLUMN }) })
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class Role extends GenericEntity {
private static final long serialVersionUID = -4602863502464505404L;
protected static final String NAME_COLUMN = "role_name";
protected static final String EVENT_ID_COLUMN = "event_id";
public static final Role EMPTY_ROLE = new Role("----");
@Column(name = NAME_COLUMN, nullable = false)
private String name;
@ManyToMany()
@JoinTable(name = "role_memberships",
joinColumns = { @JoinColumn(name = "role_id", referencedColumnName = Role.ID_COLUMN) },
inverseJoinColumns = { @JoinColumn(name = "user_id", referencedColumnName = User.ID_COLUMN) })
private List<User> users;
@ManyToMany(mappedBy = "parents")
private List<Role> children = new ArrayList<Role>();
@OneToMany(mappedBy = "provides")
private List<Product> productsProvide;
@OneToMany(mappedBy = "providesRole")
private List<Place> placesProvide;
@ManyToMany()
private List<Role> parents = new ArrayList<Role>();
@OneToMany(cascade = CascadeType.ALL, mappedBy = "role")
@PrivateOwned
private List<ApplicationPermission> permissions = new ArrayList<ApplicationPermission>();
@ManyToOne
private CardTemplate cardTemplate;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "role")
private List<Discount> discounts;
@OneToMany(mappedBy = "writerRole")
private List<NewsGroup> writeNews;
@ManyToMany(mappedBy = "readerRoles")
private List<NewsGroup> newsGroups;
@ManyToOne
@JoinColumn(name = EVENT_ID_COLUMN, nullable = false)
private LanEvent event;
public Role() {
super();
}
public Role(LanEvent event) {
this.event = event;
}
public Role(LanEvent event, String roleName) {
this(event);
this.name = roleName;
}
private Role(String rolename) {
setId(0);
name = rolename;
}
public String getName() {
return name;
}
public void setName(String roleName) {
this.name = roleName;
}
public CardTemplate getCardTemplate() {
return cardTemplate;
}
public void setCardTemplate(CardTemplate cardTemplatesId) {
this.cardTemplate = cardTemplatesId;
}
public void setUsers(List<User> users) {
this.users = users;
}
public List<User> getUsers() {
return users;
}
public void setDiscounts(List<Discount> discounts) {
this.discounts = discounts;
}
public List<Discount> getDiscounts() {
return discounts;
}
public void setParents(List<Role> parents) {
this.parents = parents;
}
public List<Role> getParents() {
return parents;
}
public void setChildren(List<Role> children) {
this.children = children;
}
public List<Role> getChildren() {
return children;
}
public void setNewsGroups(List<NewsGroup> newsGroups) {
this.newsGroups = newsGroups;
}
public List<NewsGroup> getNewsGroups() {
return newsGroups;
}
public LanEvent getEvent() {
return event;
}
public void setProductsProvide(List<Product> productsProvide) {
this.productsProvide = productsProvide;
}
public List<Product> getProductsProvide() {
return productsProvide;
}
public void setPlacesProvide(List<Place> placesProvide) {
this.placesProvide = placesProvide;
}
public List<Place> getPlacesProvide() {
return placesProvide;
}
public void setEvent(LanEvent event) {
this.event = event;
}
public void setWriteNews(List<NewsGroup> writeNews) {
this.writeNews = writeNews;
}
public List<NewsGroup> getWriteNews() {
return writeNews;
}
public void setPermissions(List<ApplicationPermission> permissions) {
this.permissions = permissions;
}
public List<ApplicationPermission> getPermissions() {
return permissions;
}
}