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