1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.bo.ui;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.hibernate.annotations.GenericGenerator;
20 import org.hibernate.annotations.Parameter;
21 import org.kuali.rice.core.api.membership.MemberType;
22 import org.kuali.rice.kim.api.KimConstants;
23 import org.kuali.rice.kim.api.group.Group;
24 import org.kuali.rice.kim.api.identity.principal.Principal;
25 import org.kuali.rice.kim.api.role.Role;
26 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
27 import org.springframework.util.AutoPopulatingList;
28
29 import javax.persistence.CascadeType;
30 import javax.persistence.Column;
31 import javax.persistence.Entity;
32 import javax.persistence.FetchType;
33 import javax.persistence.GeneratedValue;
34 import javax.persistence.Id;
35 import javax.persistence.IdClass;
36 import javax.persistence.JoinColumn;
37 import javax.persistence.JoinColumns;
38 import javax.persistence.OneToMany;
39 import javax.persistence.Table;
40 import javax.persistence.Transient;
41 import java.util.ArrayList;
42 import java.util.HashMap;
43 import java.util.List;
44 import java.util.Map;
45
46
47
48
49
50
51
52 @IdClass(KimDocumentRoleMemberId.class)
53 @Entity
54 @Table(name="KRIM_PND_ROLE_MBR_MT")
55 public class KimDocumentRoleMember extends KimDocumentBoActivatableToFromEditableBase {
56 private static final long serialVersionUID = -2463865643038170979L;
57
58 @Id
59 @GeneratedValue(generator="KRIM_ROLE_MBR_ID_S")
60 @GenericGenerator(name="KRIM_ROLE_MBR_ID_S",strategy="org.kuali.rice.core.jpa.spring.RiceNumericStringSequenceStyleGenerator",parameters={
61 @Parameter(name="sequence_name",value="KRIM_ROLE_MBR_ID_S"),
62 @Parameter(name="value_column",value="id")
63 })
64 @Column(name="ROLE_MBR_ID")
65 protected String roleMemberId;
66
67 @Column(name="ROLE_ID")
68 protected String roleId;
69 @Column(name="MBR_ID")
70 protected String memberId;
71
72
73 @Column(name="MBR_TYP_CD")
74 protected String memberTypeCode = KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE.getCode();
75 @Transient
76 protected String memberName;
77 @Transient
78 protected String memberNamespaceCode;
79
80 protected String memberFullName;
81
82 @OneToMany(fetch=FetchType.LAZY,cascade=CascadeType.ALL)
83 @JoinColumns({
84 @JoinColumn(name="ROLE_MBR_ID", insertable = false, updatable = false),
85 @JoinColumn(name="FDOC_NBR", insertable = false, updatable = false)
86 })
87 protected List <KimDocumentRoleQualifier> qualifiers = new AutoPopulatingList(KimDocumentRoleQualifier.class);
88 @Transient
89 protected String qualifiersToDisplay;
90
91 @OneToMany(fetch=FetchType.LAZY,cascade=CascadeType.ALL)
92 @JoinColumns({
93 @JoinColumn(name="ROLE_MBR_ID", insertable = false, updatable = false),
94 @JoinColumn(name="FDOC_NBR", insertable = false, updatable = false)
95 })
96 private List<KimDocumentRoleResponsibilityAction> roleRspActions;
97
98 public KimDocumentRoleMember() {
99 qualifiers = new ArrayList <KimDocumentRoleQualifier>();
100 roleRspActions = new ArrayList <KimDocumentRoleResponsibilityAction>();
101 }
102
103 public int getNumberOfQualifiers(){
104 return qualifiers==null?0:qualifiers.size();
105 }
106
107
108
109
110 public String getMemberId() {
111 return this.memberId;
112 }
113
114
115
116
117 public void setMemberId(String memberId) {
118 this.memberId = memberId;
119 }
120
121 public String getRoleMemberId() {
122 return this.roleMemberId;
123 }
124
125 public void setRoleMemberId(String roleMemberId) {
126 this.roleMemberId = roleMemberId;
127 }
128
129 public String getRoleId() {
130 return this.roleId;
131 }
132
133 public void setRoleId(String roleId) {
134 this.roleId = roleId;
135 }
136
137 public KimDocumentRoleQualifier getQualifier(String kimAttributeDefnId) {
138 for(KimDocumentRoleQualifier qualifier:qualifiers){
139 if(qualifier.getKimAttrDefnId().equals(kimAttributeDefnId)) {
140 return qualifier;
141 }
142 }
143 return null;
144 }
145
146 public List<KimDocumentRoleQualifier> getQualifiers() {
147 return this.qualifiers;
148 }
149
150 public void setQualifiers(List<KimDocumentRoleQualifier> qualifiers) {
151 this.qualifiers = qualifiers;
152 }
153
154
155
156
157 public String getMemberTypeCode() {
158 return this.memberTypeCode;
159 }
160
161
162
163
164 public void setMemberTypeCode(String memberTypeCode) {
165 this.memberTypeCode = memberTypeCode;
166 }
167
168
169
170
171 public String getMemberName() {
172 if ( memberName == null ) {
173 populateDerivedValues();
174 }
175 return memberName;
176 }
177
178
179
180
181 public void setMemberName(String memberName) {
182 this.memberName = memberName;
183 }
184
185 public List<KimDocumentRoleResponsibilityAction> getRoleRspActions() {
186 return this.roleRspActions;
187 }
188
189 public void setRoleRspActions(
190 List<KimDocumentRoleResponsibilityAction> roleRspActions) {
191 this.roleRspActions = roleRspActions;
192 }
193
194
195
196
197 public String getMemberNamespaceCode() {
198 if ( memberNamespaceCode == null ) {
199 populateDerivedValues();
200 }
201 return memberNamespaceCode;
202 }
203
204
205
206
207 public void setMemberNamespaceCode(String memberNamespaceCode) {
208 this.memberNamespaceCode = memberNamespaceCode;
209 }
210
211 protected void populateDerivedValues() {
212 if(MemberType.PRINCIPAL.getCode().equals(getMemberTypeCode())){
213 if(!StringUtils.isEmpty(getMemberId())){
214 Principal principalInfo = KimApiServiceLocator.getIdentityService().getPrincipal(getMemberId());
215 if (principalInfo != null) {
216 setMemberName(principalInfo.getPrincipalName());
217 }
218 }
219 } else if(MemberType.GROUP.getCode().equals(getMemberTypeCode())){
220 Group groupInfo = KimApiServiceLocator.getGroupService().getGroup(getMemberId());
221 if (groupInfo != null) {
222 setMemberName(groupInfo.getName());
223 setMemberNamespaceCode(groupInfo.getNamespaceCode());
224 }
225
226 } else if(MemberType.ROLE.getCode().equals(getMemberTypeCode())){
227 Role role = KimApiServiceLocator.getRoleService().getRole(getMemberId());
228 setMemberName(role.getName());
229 setMemberNamespaceCode(role.getNamespaceCode());
230 }
231
232 }
233
234 public boolean isRole(){
235 return getMemberTypeCode()!=null && getMemberTypeCode().equals(MemberType.ROLE.getCode());
236 }
237
238 public boolean isGroup(){
239 return getMemberTypeCode()!=null && getMemberTypeCode().equals(MemberType.GROUP.getCode());
240 }
241
242 public boolean isPrincipal(){
243 return getMemberTypeCode()!=null && getMemberTypeCode().equals(MemberType.PRINCIPAL.getCode());
244 }
245
246 public Map<String, String> getQualifierAsMap() {
247 Map<String, String> m = new HashMap<String, String>();
248 for ( KimDocumentRoleQualifier data : getQualifiers() ) {
249 if (data.getKimAttribute() == null){
250 data.refreshReferenceObject("kimAttribute");
251 }
252 if (data.getKimAttribute() != null){
253 m.put( data.getKimAttribute().getAttributeName(), data.getAttrVal() );
254 }
255 }
256 return m;
257 }
258
259
260
261
262 public String getQualifiersToDisplay() {
263 return this.qualifiersToDisplay;
264 }
265
266
267
268
269 public void setQualifiersToDisplay(String qualifiersToDisplay) {
270 this.qualifiersToDisplay = qualifiersToDisplay;
271 }
272
273
274
275
276 public String getMemberFullName() {
277 return this.memberFullName;
278 }
279
280
281
282
283 public void setMemberFullName(String memberFullName) {
284 this.memberFullName = memberFullName;
285 }
286
287 public boolean isMemberNameNull() {
288 if (memberName==null) {
289 return true;
290 }
291 return false;
292 }
293
294 public boolean isMemberNameSpaceCodeNull() {
295 if (memberNamespaceCode==null) {
296 return true;
297 }
298 return false;
299 }
300
301 }