1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.impl.role;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import javax.persistence.CascadeType;
22 import javax.persistence.Column;
23 import javax.persistence.Convert;
24 import javax.persistence.Entity;
25 import javax.persistence.GeneratedValue;
26 import javax.persistence.Id;
27 import javax.persistence.JoinColumn;
28 import javax.persistence.OneToMany;
29 import javax.persistence.Table;
30 import javax.persistence.Transient;
31
32 import org.eclipse.persistence.annotations.JoinFetch;
33 import org.eclipse.persistence.annotations.JoinFetchType;
34 import org.joda.time.DateTime;
35 import org.kuali.rice.core.api.membership.MemberType;
36 import org.kuali.rice.kim.api.role.Role;
37 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
38 import org.kuali.rice.kim.api.type.KimType;
39 import org.kuali.rice.kim.api.type.KimTypeInfoService;
40 import org.kuali.rice.kim.framework.role.RoleEbo;
41 import org.kuali.rice.kim.impl.type.KimTypeBo;
42 import org.kuali.rice.krad.bo.DataObjectBase;
43 import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
44 import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter;
45 import org.springframework.util.AutoPopulatingList;
46
47 @Entity
48 @Table(name = "KRIM_ROLE_T")
49 public class RoleBo extends DataObjectBase implements RoleEbo {
50
51 private static final long serialVersionUID = 1L;
52
53 @PortableSequenceGenerator(name = "KRIM_ROLE_ID_S")
54 @GeneratedValue(generator = "KRIM_ROLE_ID_S")
55 @Id
56 @Column(name = "ROLE_ID")
57 private String id;
58
59 @Column(name = "ROLE_NM")
60 private String name;
61
62 @Column(name = "DESC_TXT")
63 private String description;
64
65 @Column(name = "ACTV_IND")
66 @Convert(converter = BooleanYNConverter.class)
67 private boolean active;
68
69 @Column(name = "KIM_TYP_ID")
70 private String kimTypeId;
71
72 @Column(name = "NMSPC_CD")
73 private String namespaceCode;
74
75 @JoinFetch(value= JoinFetchType.OUTER)
76 @OneToMany(targetEntity = RoleMemberBo.class, orphanRemoval = true, cascade = CascadeType.ALL)
77 @JoinColumn(name = "ROLE_ID", referencedColumnName = "ROLE_ID", insertable = false, updatable = false)
78 private List<RoleMemberBo> members = new AutoPopulatingList<RoleMemberBo>(RoleMemberBo.class);
79
80 @Transient
81 private String principalName;
82
83 @Transient
84 private String groupNamespaceCode;
85
86 @Transient
87 private String groupName;
88
89 @Transient
90 private String permNamespaceCode;
91
92 @Transient
93 private String permName;
94
95 @Transient
96 private String permTmplNamespaceCode;
97
98 @Transient
99 private String permTmplName;
100
101 @Transient
102 private String respNamespaceCode;
103
104 @Transient
105 private String respName;
106
107 @Transient
108 private String respTmplNamespaceCode;
109
110 @Transient
111 private String respTmplName;
112
113 @Transient
114 private transient KimTypeInfoService kimTypeInfoService;
115
116 protected List<String> getMembersOfType(String memberTypeCode) {
117 List<String> roleMembers = new ArrayList<String>();
118 for (RoleMemberBo member : getMembers()) {
119 if (member.getType().equals(MemberType.valueOf(memberTypeCode)) && member.isActive(new DateTime())) {
120 roleMembers.add(member.getMemberId());
121 }
122 }
123 return roleMembers;
124 }
125
126 public KimTypeBo getKimRoleType() {
127 if (kimTypeId == null) {
128 return null;
129 }
130 KimType type = getTypeInfoService().getKimType(kimTypeId);
131 if (type == null) {
132 return null;
133 }
134 return KimTypeBo.from(type);
135 }
136
137 protected KimTypeInfoService getTypeInfoService() {
138 if (kimTypeInfoService == null) {
139 kimTypeInfoService = KimApiServiceLocator.getKimTypeInfoService();
140 }
141 return kimTypeInfoService;
142 }
143
144 public static Role to(RoleBo bo) {
145 if (bo == null) {
146 return null;
147 }
148 return Role.Builder.create(bo).build();
149 }
150
151 public static RoleBo from(Role immutable) {
152 if (immutable == null) {
153 return null;
154 }
155 RoleBo bo = new RoleBo();
156 bo.id = immutable.getId();
157 bo.name = immutable.getName();
158 bo.namespaceCode = immutable.getNamespaceCode();
159 bo.description = immutable.getDescription();
160 bo.kimTypeId = immutable.getKimTypeId();
161 bo.active = immutable.isActive();
162 bo.setVersionNumber(immutable.getVersionNumber());
163 bo.setObjectId(immutable.getObjectId());
164 return bo;
165 }
166
167 @Override
168 public String getId() {
169 return id;
170 }
171
172 public void setId(String id) {
173 this.id = id;
174 }
175
176 @Override
177 public String getName() {
178 return name;
179 }
180
181 public void setName(String name) {
182 this.name = name;
183 }
184
185 @Override
186 public String getDescription() {
187 return description;
188 }
189
190 public void setDescription(String description) {
191 this.description = description;
192 }
193
194 public boolean getActive() {
195 return active;
196 }
197
198 @Override
199 public boolean isActive() {
200 return active;
201 }
202
203 public void setActive(boolean active) {
204 this.active = active;
205 }
206
207 @Override
208 public String getKimTypeId() {
209 return kimTypeId;
210 }
211
212 public void setKimTypeId(String kimTypeId) {
213 this.kimTypeId = kimTypeId;
214 }
215
216 @Override
217 public String getNamespaceCode() {
218 return namespaceCode;
219 }
220
221 public void setNamespaceCode(String namespaceCode) {
222 this.namespaceCode = namespaceCode;
223 }
224
225 public List<RoleMemberBo> getMembers() {
226 return members;
227 }
228
229 public void setMembers(List<RoleMemberBo> members) {
230 this.members = members;
231 }
232
233 public String getPrincipalName() {
234 return principalName;
235 }
236
237 public void setPrincipalName(String principalName) {
238 this.principalName = principalName;
239 }
240
241 public String getGroupNamespaceCode() {
242 return groupNamespaceCode;
243 }
244
245 public void setGroupNamespaceCode(String groupNamespaceCode) {
246 this.groupNamespaceCode = groupNamespaceCode;
247 }
248
249 public String getGroupName() {
250 return groupName;
251 }
252
253 public void setGroupName(String groupName) {
254 this.groupName = groupName;
255 }
256
257 public String getPermNamespaceCode() {
258 return permNamespaceCode;
259 }
260
261 public void setPermNamespaceCode(String permNamespaceCode) {
262 this.permNamespaceCode = permNamespaceCode;
263 }
264
265 public String getPermName() {
266 return permName;
267 }
268
269 public void setPermName(String permName) {
270 this.permName = permName;
271 }
272
273 public String getPermTmplNamespaceCode() {
274 return permTmplNamespaceCode;
275 }
276
277 public void setPermTmplNamespaceCode(String permTmplNamespaceCode) {
278 this.permTmplNamespaceCode = permTmplNamespaceCode;
279 }
280
281 public String getPermTmplName() {
282 return permTmplName;
283 }
284
285 public void setPermTmplName(String permTmplName) {
286 this.permTmplName = permTmplName;
287 }
288
289 public String getRespNamespaceCode() {
290 return respNamespaceCode;
291 }
292
293 public void setRespNamespaceCode(String respNamespaceCode) {
294 this.respNamespaceCode = respNamespaceCode;
295 }
296
297 public String getRespName() {
298 return respName;
299 }
300
301 public void setRespName(String respName) {
302 this.respName = respName;
303 }
304
305 public String getRespTmplNamespaceCode() {
306 return respTmplNamespaceCode;
307 }
308
309 public void setRespTmplNamespaceCode(String respTmplNamespaceCode) {
310 this.respTmplNamespaceCode = respTmplNamespaceCode;
311 }
312
313 public String getRespTmplName() {
314 return respTmplName;
315 }
316
317 public void setRespTmplName(String respTmplName) {
318 this.respTmplName = respTmplName;
319 }
320
321 @Override
322 public void refresh() {
323 }
324 }