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