1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.bo.impl;
17
18 import java.util.ArrayList;
19 import java.util.LinkedHashMap;
20 import java.util.List;
21
22 import javax.persistence.CascadeType;
23 import javax.persistence.Column;
24 import javax.persistence.Entity;
25 import javax.persistence.FetchType;
26 import javax.persistence.Id;
27 import javax.persistence.JoinColumn;
28 import javax.persistence.OneToMany;
29 import javax.persistence.Table;
30
31 import org.apache.commons.lang.builder.EqualsBuilder;
32 import org.apache.commons.lang.builder.HashCodeBuilder;
33 import org.kuali.rice.kim.bo.Role;
34 import org.kuali.rice.kim.bo.role.dto.KimRoleInfo;
35 import org.kuali.rice.kim.bo.role.impl.RoleMemberImpl;
36 import org.kuali.rice.kim.bo.types.dto.KimTypeInfo;
37 import org.kuali.rice.kim.service.KIMServiceLocator;
38 import org.kuali.rice.kim.service.KimTypeInfoService;
39 import org.kuali.rice.kim.util.KimConstants;
40 import org.kuali.rice.kns.bo.PersistableBusinessObjectBase;
41 import org.kuali.rice.kns.util.TypedArrayList;
42
43
44
45
46
47
48
49 @Entity
50 @Table(name="KRIM_ROLE_T")
51 public class RoleImpl extends PersistableBusinessObjectBase implements Role {
52
53 private static final long serialVersionUID = 1L;
54
55 @Id
56 @Column(name="ROLE_ID")
57 protected String roleId;
58 @Column(name="ROLE_NM")
59 protected String roleName;
60 @Column(name="DESC_TXT",length=4000)
61 protected String roleDescription;
62 @Column(name="ACTV_IND")
63 protected boolean active;
64 @Column(name="KIM_TYP_ID")
65 protected String kimTypeId;
66 @Column(name="NMSPC_CD")
67 protected String namespaceCode;
68
69 @OneToMany(targetEntity=RoleMemberImpl.class,cascade={CascadeType.ALL},fetch=FetchType.LAZY)
70 @JoinColumn(name="ROLE_ID", insertable=false, updatable=false)
71 protected List<RoleMemberImpl> members = new TypedArrayList(RoleMemberImpl.class);
72
73 protected String principalName;
74 protected String groupNamespaceCode;
75 protected String groupName;
76 protected String permNamespaceCode;
77 protected String permName;
78 protected String permTmplNamespaceCode;
79 protected String permTmplName;
80 protected String respNamespaceCode;
81 protected String respName;
82 protected String respTmplNamespaceCode;
83 protected String respTmplName;
84
85
86
87
88
89
90 @SuppressWarnings("unchecked")
91 @Override
92 protected LinkedHashMap toStringMapper() {
93 LinkedHashMap m = new LinkedHashMap();
94 m.put( "roleId", roleId );
95 m.put( "namespaceCode", namespaceCode );
96 m.put( "roleName", roleName );
97 return m;
98 }
99
100 public String getRoleId() {
101 return this.roleId;
102 }
103
104 public void setRoleId(String roleId) {
105 this.roleId = roleId;
106 }
107
108 public String getRoleName() {
109 return this.roleName;
110 }
111
112 public void setRoleName(String roleName) {
113 this.roleName = roleName;
114 }
115
116 public String getKimTypeId() {
117 return this.kimTypeId;
118 }
119
120 public void setKimTypeId(String kimTypeId) {
121 this.kimTypeId = kimTypeId;
122 }
123
124 public String getNamespaceCode() {
125 return this.namespaceCode;
126 }
127
128 public void setNamespaceCode(String namespaceCode) {
129 this.namespaceCode = namespaceCode;
130 }
131
132 public String getPrincipalName() {
133 return this.principalName;
134 }
135
136 public void setPrincipalName(String principalName) {
137 this.principalName = principalName;
138 }
139
140 public String getGroupNamespaceCode() {
141 return this.groupNamespaceCode;
142 }
143
144 public void setGroupNamespaceCode(String groupNamespaceCode) {
145 this.groupNamespaceCode = groupNamespaceCode;
146 }
147
148 public String getGroupName() {
149 return this.groupName;
150 }
151
152 public void setGroupName(String groupName) {
153 this.groupName = groupName;
154 }
155
156 public String getPermNamespaceCode() {
157 return this.permNamespaceCode;
158 }
159
160 public void setPermNamespaceCode(String permNamespaceCode) {
161 this.permNamespaceCode = permNamespaceCode;
162 }
163
164 public String getPermName() {
165 return this.permName;
166 }
167
168 public void setPermName(String permName) {
169 this.permName = permName;
170 }
171
172 public String getRespNamespaceCode() {
173 return this.respNamespaceCode;
174 }
175
176 public void setRespNamespaceCode(String respNamespaceCode) {
177 this.respNamespaceCode = respNamespaceCode;
178 }
179
180 public String getRespName() {
181 return this.respName;
182 }
183
184 public void setRespName(String respName) {
185 this.respName = respName;
186 }
187
188 public String getPermTmplNamespaceCode() {
189 return this.permTmplNamespaceCode;
190 }
191
192 public void setPermTmplNamespaceCode(String permTmplNamespaceCode) {
193 this.permTmplNamespaceCode = permTmplNamespaceCode;
194 }
195
196 public String getPermTmplName() {
197 return this.permTmplName;
198 }
199
200 public void setPermTmplName(String permTmplName) {
201 this.permTmplName = permTmplName;
202 }
203
204 public String getRespTmplNamespaceCode() {
205 return this.respTmplNamespaceCode;
206 }
207
208 public void setRespTmplNamespaceCode(String respTmplNamespaceCode) {
209 this.respTmplNamespaceCode = respTmplNamespaceCode;
210 }
211
212 public String getRespTmplName() {
213 return this.respTmplName;
214 }
215
216 public void setRespTmplName(String respTmplName) {
217 this.respTmplName = respTmplName;
218 }
219
220
221
222
223 public String getRoleDescription() {
224 return this.roleDescription;
225 }
226
227
228
229
230 public void setRoleDescription(String roleDescription) {
231 this.roleDescription = roleDescription;
232 }
233
234 protected List<String> getMembersOfType( String memberTypeCode ) {
235 List<String> roleMembers = new ArrayList<String>();
236 for ( RoleMemberImpl member : getMembers() ) {
237 if ( member.getMemberTypeCode().equals ( memberTypeCode )
238 && member.isActive() ) {
239 roleMembers.add( member.getMemberId() );
240 }
241 }
242 return roleMembers;
243 }
244
245
246
247
248
249 public boolean equals(Object object) {
250 if ( !(object instanceof Role) ) {
251 return false;
252 }
253 Role rhs = (Role)object;
254 return new EqualsBuilder().append( this.roleId, rhs.getRoleId() ).isEquals();
255 }
256
257
258
259
260
261 public int hashCode() {
262 return new HashCodeBuilder( -460627871, 746615189 ).append( this.roleId ).toHashCode();
263 }
264
265 public KimTypeInfo getKimRoleType() {
266 return getTypeInfoService().getKimType(kimTypeId);
267 }
268 private transient static KimTypeInfoService kimTypeInfoService;
269 protected KimTypeInfoService getTypeInfoService() {
270 if(kimTypeInfoService == null){
271 kimTypeInfoService = KIMServiceLocator.getTypeInfoService();
272 }
273 return kimTypeInfoService;
274 }
275
276 public KimRoleInfo toSimpleInfo() {
277 KimRoleInfo dto = new KimRoleInfo();
278
279 dto.setRoleId( getRoleId() );
280 dto.setRoleName( getRoleName() );
281 dto.setNamespaceCode( getNamespaceCode() );
282 dto.setRoleDescription( getRoleDescription() );
283 dto.setKimTypeId( getKimTypeId() );
284 dto.setActive( isActive() );
285
286 return dto;
287 }
288
289 public List<RoleMemberImpl> getMembers() {
290 return this.members;
291 }
292
293 public void setMembers(List<RoleMemberImpl> members) {
294 this.members = members;
295 }
296
297
298
299
300 @SuppressWarnings("unchecked")
301 @Override
302 public String toStringBuilder(LinkedHashMap mapper) {
303 if(getKimRoleType() != null){
304 return getKimRoleType().getName()+KimConstants.KimUIConstants.NAME_VALUE_SEPARATOR+
305 getNamespaceCode()+KimConstants.KimUIConstants.NAME_VALUE_SEPARATOR+
306 getRoleName()+KimConstants.KimUIConstants.COMMA_SEPARATOR;
307 }
308 else {
309 return super.toStringBuilder(mapper);
310 }
311 }
312
313
314
315
316 public boolean isActive() {
317 return this.active;
318 }
319
320
321
322
323 public void setActive(boolean active) {
324 this.active = active;
325 }
326 }