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