Clover Coverage Report - Implementation 2.0.0-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
201   584   93   4.02
74   411   0.46   25
50     1.86  
2    
 
  IdentityManagementRoleDocument       Line # 45 188 0% 84 299 0% 0.0
  IdentityManagementRoleDocument.RoleMemberMetaDataType       Line # 223 13 0% 9 26 0% 0.0
 
No Tests
 
1    /*
2    * Copyright 2007-2009 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
15    */
16    package org.kuali.rice.kim.document;
17   
18    import org.apache.commons.lang.StringUtils;
19    import org.kuali.rice.kew.dto.DocumentRouteStatusChangeDTO;
20    import org.kuali.rice.kim.bo.types.dto.KimTypeInfo;
21    import org.kuali.rice.kim.bo.ui.*;
22    import org.kuali.rice.kim.service.KIMServiceLocator;
23    import org.kuali.rice.kim.service.KIMServiceLocatorInternal;
24    import org.kuali.rice.kim.service.KIMServiceLocatorWeb;
25    import org.kuali.rice.kim.service.ResponsibilityService;
26    import org.kuali.rice.kim.util.KimConstants;
27    import org.kuali.rice.kim.web.struts.form.IdentityManagementRoleDocumentForm;
28    import org.kuali.rice.kns.datadictionary.AttributeDefinition;
29    import org.kuali.rice.kns.datadictionary.KimDataDictionaryAttributeDefinition;
30    import org.kuali.rice.kns.datadictionary.KimNonDataDictionaryAttributeDefinition;
31    import org.kuali.rice.kns.service.SequenceAccessorService;
32    import org.springframework.util.AutoPopulatingList;
33   
34    import java.util.ArrayList;
35    import java.util.Comparator;
36    import java.util.List;
37   
38   
39    /**
40    * This is a description of what this class does - bhargavp don't forget to fill this in.
41    *
42    * @author Kuali Rice Team (rice.collab@kuali.org)
43    *
44    */
 
45    public class IdentityManagementRoleDocument extends IdentityManagementTypeAttributeTransactionalDocument {
46   
47    private static final long serialVersionUID = 1L;
48    // principal data
49    protected String roleId;
50    protected String roleTypeId;
51    protected String roleTypeName;
52    protected String roleNamespace = "";
53    protected String roleName = "";
54    protected String roleDescription = "";
55   
56    protected boolean active = true;
57   
58    protected boolean editing;
59   
60    protected List<KimDocumentRolePermission> permissions = new AutoPopulatingList(KimDocumentRolePermission.class);
61    protected List<KimDocumentRoleResponsibility> responsibilities = new AutoPopulatingList(KimDocumentRoleResponsibility.class);
62    protected List<KimDocumentRoleMember> members = new AutoPopulatingList(KimDocumentRoleMember.class);
63    private List<RoleDocumentDelegationMember> delegationMembers = new AutoPopulatingList(RoleDocumentDelegationMember.class);
64    private List<RoleDocumentDelegation> delegations = new AutoPopulatingList(RoleDocumentDelegation.class);
65   
66    transient private ResponsibilityService responsibilityService;
67   
 
68  0 toggle public IdentityManagementRoleDocument() {
69    }
70   
71    /**
72    * @return the active
73    */
 
74  0 toggle public boolean isActive() {
75  0 return this.active;
76    }
77   
78    /**
79    * @param active the active to set
80    */
 
81  0 toggle public void setActive(boolean active) {
82  0 this.active = active;
83    }
84   
85    /**
86    * @param roleId the roleId to set
87    */
 
88  0 toggle public void setRoleId(String roleId) {
89  0 this.roleId = roleId;
90    }
91   
92    /**
93    * @return the roleName
94    */
 
95  0 toggle public String getRoleName() {
96  0 return this.roleName;
97    }
98   
99    /**
100    * @param roleName the roleName to set
101    */
 
102  0 toggle public void setRoleName(String roleName) {
103  0 this.roleName = roleName;
104    }
105   
106    /**
107    * @return the roleDescription
108    */
 
109  0 toggle public String getRoleDescription() {
110  0 return this.roleDescription;
111    }
112   
113    /**
114    * @param roleDescription the roleDescription to set
115    */
 
116  0 toggle public void setRoleDescription(String roleDescription) {
117  0 this.roleDescription = roleDescription;
118    }
119   
120    /**
121    * @return the roleNamespace
122    */
 
123  0 toggle public String getRoleNamespace() {
124  0 return this.roleNamespace;
125    }
126   
127    /**
128    * @param roleNamespace the roleNamespace to set
129    */
 
130  0 toggle public void setRoleNamespace(String roleNamespace) {
131  0 this.roleNamespace = roleNamespace;
132    }
133   
134    /**
135    * @return the roleTypeId
136    */
 
137  0 toggle public String getRoleTypeId() {
138  0 return this.roleTypeId;
139    }
140   
141    /**
142    * @param roleTypeId the roleTypeId to set
143    */
 
144  0 toggle public void setRoleTypeId(String roleTypeId) {
145  0 this.roleTypeId = roleTypeId;
146    }
147   
148    /**
149    * @return the roleTypeName
150    */
 
151  0 toggle public String getRoleTypeName() {
152  0 if ( roleTypeName == null ) {
153  0 if ( kimType != null ) {
154  0 roleTypeName = kimType.getName();
155  0 } else if ( roleTypeId != null ) {
156  0 setKimType( KIMServiceLocatorWeb.getTypeInfoService().getKimType(roleTypeId) );
157  0 if ( kimType != null ) {
158  0 roleTypeName = kimType.getName();
159    }
160    }
161    }
162  0 return this.roleTypeName;
163    }
164   
165    /**
166    * @param roleTypeName the roleTypeName to set
167    */
 
168  0 toggle public void setRoleTypeName(String roleTypeName) {
169  0 this.roleTypeName = roleTypeName;
170    }
171   
172    /**
173    * @return the delegationMembers
174    */
 
175  0 toggle public List<RoleDocumentDelegationMember> getDelegationMembers() {
176  0 return this.delegationMembers;
177    }
178   
179    /**
180    * @param delegationMembers the delegationMembers to set
181    */
 
182  0 toggle public void setDelegationMembers(
183    List<RoleDocumentDelegationMember> delegationMembers) {
184  0 this.delegationMembers = delegationMembers;
185    }
186   
187    /**
188    * @return the permissions
189    */
 
190  0 toggle public List<KimDocumentRolePermission> getPermissions() {
191  0 return this.permissions;
192    }
193   
194    /**
195    * @param permissions the permissions to set
196    */
 
197  0 toggle public void setPermissions(List<KimDocumentRolePermission> permissions) {
198  0 this.permissions = permissions;
199    }
200   
201    /**
202    * @return the responsibilities
203    */
 
204  0 toggle public List<KimDocumentRoleResponsibility> getResponsibilities() {
205  0 return this.responsibilities;
206    }
207   
208    /**
209    * @param responsibilities the responsibilities to set
210    */
 
211  0 toggle public void setResponsibilities(
212    List<KimDocumentRoleResponsibility> responsibilities) {
213  0 this.responsibilities = responsibilities;
214    }
215   
216    /**
217    * @return the members
218    */
 
219  0 toggle public List<KimDocumentRoleMember> getMembers() {
220  0 return this.members;
221    }
222   
 
223    public enum RoleMemberMetaDataType implements Comparator<KimDocumentRoleMember>{
224    MEMBER_ID("memberId"),
225    MEMBER_NAME("memberName"),
226    FULL_MEMBER_NAME("memberFullName");
227   
228    private final String attributeName;
229   
 
230  0 toggle RoleMemberMetaDataType(String anAttributeName) {
231  0 this.attributeName = anAttributeName;
232    }
233   
 
234  0 toggle public String getAttributeName() {
235  0 return attributeName;
236    }
237   
 
238  0 toggle @Override
239    public int compare(KimDocumentRoleMember m1, KimDocumentRoleMember m2) {
240  0 if (m1 == null && m2 == null) {
241  0 return 0;
242  0 } else if (m1 == null) {
243  0 return -1;
244  0 } else if (m2 == null) {
245  0 return 1;
246    }
247  0 if (this.getAttributeName().equals(MEMBER_ID.getAttributeName()))
248  0 return m1.getMemberId().compareToIgnoreCase(m2.getMemberId());
249  0 else if (this.getAttributeName().equals(FULL_MEMBER_NAME.getAttributeName()))
250  0 return m1.getMemberFullName().compareToIgnoreCase(m2.getMemberFullName());
251  0 return m1.getMemberName().compareToIgnoreCase(m2.getMemberName());
252    }
253    }
254   
 
255  0 toggle public void setMemberMetaDataTypeToSort(Integer columnNumber)
256    {
257  0 switch( columnNumber )
258    {
259  0 case 1:
260  0 this.memberMetaDataType = RoleMemberMetaDataType.MEMBER_ID;
261  0 break;
262  0 case 2:
263  0 this.memberMetaDataType = RoleMemberMetaDataType.MEMBER_NAME;
264  0 break;
265  0 case 3:
266  0 this.memberMetaDataType = RoleMemberMetaDataType.FULL_MEMBER_NAME;
267  0 break;
268  0 default:
269  0 this.memberMetaDataType = RoleMemberMetaDataType.MEMBER_NAME;
270  0 break;
271    }
272    }
273   
274    protected RoleMemberMetaDataType memberMetaDataType = RoleMemberMetaDataType.MEMBER_NAME;
275   
 
276  0 toggle public RoleMemberMetaDataType getMemberMetaDataType() {
277  0 return memberMetaDataType;
278    }
279   
 
280  0 toggle public void setMemberMetaDataType(RoleMemberMetaDataType memberMetaDataType) {
281  0 this.memberMetaDataType = memberMetaDataType;
282    }
283   
284    /**
285    * @return the members
286    */
 
287  0 toggle public KimDocumentRoleMember getMember(String roleMemberId) {
288  0 if(StringUtils.isEmpty(roleMemberId)) return null;
289  0 for(KimDocumentRoleMember roleMember: getMembers()){
290  0 if(roleMemberId.equals(roleMember.getRoleMemberId()))
291  0 return roleMember;
292    }
293  0 return null;
294    }
295   
296    /**
297    * @param members the members to set
298    */
 
299  0 toggle public void setMembers(List<KimDocumentRoleMember> members) {
300  0 this.members = members;
301    }
302   
 
303  0 toggle public void addResponsibility(KimDocumentRoleResponsibility roleResponsibility){
304  0 if(!getResponsibilityService().areActionsAtAssignmentLevelById(roleResponsibility.getResponsibilityId())) {
305  0 roleResponsibility.getRoleRspActions().add(getNewRespAction(roleResponsibility));
306    }
307  0 getResponsibilities().add(roleResponsibility);
308    }
309   
 
310  0 toggle protected KimDocumentRoleResponsibilityAction getNewRespAction(KimDocumentRoleResponsibility roleResponsibility){
311  0 KimDocumentRoleResponsibilityAction roleRspAction = new KimDocumentRoleResponsibilityAction();
312  0 roleRspAction.setKimResponsibility(roleResponsibility.getKimResponsibility());
313  0 roleRspAction.setRoleResponsibilityId(roleResponsibility.getRoleResponsibilityId());
314  0 return roleRspAction;
315    }
316   
 
317  0 toggle public void addDelegationMember(RoleDocumentDelegationMember newDelegationMember){
318  0 getDelegationMembers().add(newDelegationMember);
319    }
320   
321    /**
322    * @param member the members to set
323    */
 
324  0 toggle public void addMember(KimDocumentRoleMember member) {
325  0 SequenceAccessorService sas = getSequenceAccessorService();
326  0 Long nextSeq = sas.getNextAvailableSequenceNumber(
327    KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S,
328    KimDocumentRoleMember.class);
329  0 String roleMemberId = nextSeq.toString();
330  0 member.setRoleMemberId(roleMemberId);
331  0 setupMemberRspActions(member);
332  0 getMembers().add(member);
333    }
334   
 
335  0 toggle public KimDocumentRoleMember getBlankMember() {
336  0 KimDocumentRoleMember member = new KimDocumentRoleMember();
337  0 KimDocumentRoleQualifier qualifier;
338  0 if(getDefinitions()!=null){
339  0 for(String key : getDefinitions().keySet()) {
340  0 qualifier = new KimDocumentRoleQualifier();
341  0 qualifier.setKimAttrDefnId(getKimAttributeDefnId(getDefinitions().get(key)));
342  0 member.getQualifiers().add(qualifier);
343    }
344    }
345  0 setupMemberRspActions(member);
346  0 return member;
347    }
348   
 
349  0 toggle public RoleDocumentDelegationMember getBlankDelegationMember() {
350  0 RoleDocumentDelegationMember member = new RoleDocumentDelegationMember();
351  0 RoleDocumentDelegationMemberQualifier qualifier;
352  0 if(getDefinitions()!=null){
353  0 for(String key : getDefinitions().keySet()) {
354  0 qualifier = new RoleDocumentDelegationMemberQualifier();
355  0 setAttrDefnIdForDelMemberQualifier(qualifier, getDefinitions().get(key));
356  0 member.getQualifiers().add(qualifier);
357    }
358    }
359  0 return member;
360    }
361   
 
362  0 toggle public void setupMemberRspActions(KimDocumentRoleMember member) {
363  0 member.getRoleRspActions().clear();
364  0 for (KimDocumentRoleResponsibility roleResp: getResponsibilities()) {
365  0 if (getResponsibilityService().areActionsAtAssignmentLevelById(roleResp.getResponsibilityId())) {
366  0 KimDocumentRoleResponsibilityAction action = new KimDocumentRoleResponsibilityAction();
367  0 action.setRoleResponsibilityId("*");
368  0 action.setRoleMemberId(member.getRoleMemberId());
369  0 member.getRoleRspActions().add(action);
370  0 break;
371    }
372    }
373    }
374   
 
375  0 toggle public void updateMembers(IdentityManagementRoleDocumentForm roleDocumentForm){
376  0 for(KimDocumentRoleMember member: roleDocumentForm.getRoleDocument().getMembers()){
377  0 roleDocumentForm.getRoleDocument().setupMemberRspActions(member);
378    }
379    }
380   
 
381  0 toggle public void updateMembers(KimDocumentRoleResponsibility newResponsibility){
382  0 for(KimDocumentRoleMember member: getMembers()){
383  0 setupMemberRspActions(newResponsibility, member);
384    }
385    }
386   
 
387  0 toggle public void setupMemberRspActions(KimDocumentRoleResponsibility roleResp, KimDocumentRoleMember member) {
388  0 if ((member.getRoleRspActions()==null || member.getRoleRspActions().size()<1) && getResponsibilityService().areActionsAtAssignmentLevelById(roleResp.getResponsibilityId())) {
389  0 KimDocumentRoleResponsibilityAction action = new KimDocumentRoleResponsibilityAction();
390  0 action.setRoleResponsibilityId("*");
391  0 action.setRoleMemberId(member.getRoleMemberId());
392  0 if(member.getRoleRspActions()==null)
393  0 member.setRoleRspActions(new ArrayList<KimDocumentRoleResponsibilityAction>());
394  0 member.getRoleRspActions().add(action);
395    }
396    }
397   
 
398  0 toggle protected void setAttrDefnIdForDelMemberQualifier(RoleDocumentDelegationMemberQualifier qualifier,AttributeDefinition definition) {
399  0 if (definition instanceof KimDataDictionaryAttributeDefinition) {
400  0 qualifier.setKimAttrDefnId(((KimDataDictionaryAttributeDefinition)definition).getKimAttrDefnId());
401    //qualifier.refreshReferenceObject("kimAttribute");
402    } else {
403  0 qualifier.setKimAttrDefnId(((KimNonDataDictionaryAttributeDefinition)definition).getKimAttrDefnId());
404    //qualifier.refreshReferenceObject("kimAttribute");
405   
406    }
407    }
408   
409    /**
410    * @see org.kuali.rice.kns.document.DocumentBase#doRouteStatusChange(org.kuali.rice.kew.dto.DocumentRouteStatusChangeDTO)
411    */
 
412  0 toggle @Override
413    public void doRouteStatusChange(DocumentRouteStatusChangeDTO statusChangeEvent) {
414  0 super.doRouteStatusChange(statusChangeEvent);
415  0 if (getDocumentHeader().getWorkflowDocument().stateIsProcessed()) {
416  0 KIMServiceLocatorInternal.getUiDocumentService().saveRole(this);
417    }
418    }
419   
 
420  0 toggle public void initializeDocumentForNewRole() {
421  0 if(StringUtils.isBlank(this.roleId)){
422  0 SequenceAccessorService sas = getSequenceAccessorService();
423  0 Long nextSeq = sas.getNextAvailableSequenceNumber(
424    KimConstants.SequenceNames.KRIM_ROLE_ID_S, this.getClass());
425  0 this.roleId = nextSeq.toString();
426    }
427  0 if(StringUtils.isBlank(this.roleTypeId)) {
428  0 this.roleTypeId = "1";
429    }
430    }
431   
 
432  0 toggle public String getRoleId(){
433  0 if(StringUtils.isBlank(this.roleId)){
434  0 initializeDocumentForNewRole();
435    }
436  0 return roleId;
437    }
438   
 
439  0 toggle @Override
440    public void prepareForSave(){
441  0 SequenceAccessorService sas = getSequenceAccessorService();
442   
443  0 String roleId;
444  0 if(StringUtils.isBlank(getRoleId())){
445  0 Long nextSeq = sas.getNextAvailableSequenceNumber(
446    KimConstants.SequenceNames.KRIM_ROLE_ID_S, this.getClass());
447  0 roleId = nextSeq.toString();
448  0 setRoleId(roleId);
449    } else
450  0 roleId = getRoleId();
451   
452  0 if(getPermissions()!=null){
453  0 String rolePermissionId;
454  0 for(KimDocumentRolePermission permission: getPermissions()){
455  0 permission.setRoleId(roleId);
456  0 if(StringUtils.isBlank(permission.getRolePermissionId())){
457  0 Long nextSeq = sas.getNextAvailableSequenceNumber(
458    KimConstants.SequenceNames.KRIM_ROLE_PERM_ID_S,
459    KimDocumentRolePermission.class);
460  0 rolePermissionId = nextSeq.toString();
461  0 permission.setRolePermissionId(rolePermissionId);
462    }
463    }
464    }
465  0 if(getResponsibilities()!=null){
466  0 String roleResponsibilityId;
467  0 for(KimDocumentRoleResponsibility responsibility: getResponsibilities()){
468  0 if(StringUtils.isBlank(responsibility.getRoleResponsibilityId())){
469  0 Long nextSeq = sas.getNextAvailableSequenceNumber(
470    KimConstants.SequenceNames.KRIM_ROLE_RSP_ID_S,
471    KimDocumentRoleResponsibility.class);
472  0 roleResponsibilityId = nextSeq.toString();
473  0 responsibility.setRoleResponsibilityId(roleResponsibilityId);
474    }
475  0 responsibility.setRoleId(roleId);
476  0 if(!getResponsibilityService().areActionsAtAssignmentLevelById(responsibility.getResponsibilityId())){
477  0 if(StringUtils.isBlank(responsibility.getRoleRspActions().get(0).getRoleResponsibilityActionId())){
478  0 Long nextSeq = sas.getNextAvailableSequenceNumber(
479    KimConstants.SequenceNames.KRIM_ROLE_RSP_ACTN_ID_S,
480    KimDocumentRoleResponsibilityAction.class);
481  0 String roleResponsibilityActionId = nextSeq.toString();
482  0 responsibility.getRoleRspActions().get(0).setRoleResponsibilityActionId(roleResponsibilityActionId);
483    }
484  0 responsibility.getRoleRspActions().get(0).setRoleMemberId("*");
485  0 responsibility.getRoleRspActions().get(0).setDocumentNumber(getDocumentNumber());
486    }
487    }
488    }
489  0 if(getMembers()!=null){
490  0 String roleMemberId;
491  0 String roleResponsibilityActionId;
492  0 for(KimDocumentRoleMember member: getMembers()){
493  0 member.setRoleId(roleId);
494  0 if(StringUtils.isBlank(member.getRoleMemberId())){
495  0 Long nextSeq = sas.getNextAvailableSequenceNumber(
496    KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S,
497    KimDocumentRoleMember.class);
498  0 roleMemberId = nextSeq.toString();
499  0 member.setRoleMemberId(roleMemberId);
500    }
501  0 for(KimDocumentRoleQualifier qualifier: member.getQualifiers()){
502  0 qualifier.setKimTypId(getKimType().getKimTypeId());
503    }
504  0 for(KimDocumentRoleResponsibilityAction roleRespAction: member.getRoleRspActions()){
505  0 if(StringUtils.isBlank(roleRespAction.getRoleResponsibilityActionId())){
506  0 Long nextSeq = sas.getNextAvailableSequenceNumber(
507    KimConstants.SequenceNames.KRIM_ROLE_RSP_ACTN_ID_S,
508    KimDocumentRoleResponsibilityAction.class);
509  0 roleResponsibilityActionId = nextSeq.toString();
510  0 roleRespAction.setRoleResponsibilityActionId(roleResponsibilityActionId);
511    }
512  0 roleRespAction.setRoleMemberId(member.getRoleMemberId());
513  0 roleRespAction.setDocumentNumber(getDocumentNumber());
514  0 if ( !StringUtils.equals( roleRespAction.getRoleResponsibilityId(), "*" ) ) {
515  0 for(KimDocumentRoleResponsibility responsibility: getResponsibilities()){
516  0 if( StringUtils.equals( roleRespAction.getKimResponsibility().getResponsibilityId(), responsibility.getResponsibilityId() ) ) {
517  0 roleRespAction.setRoleResponsibilityId(responsibility.getRoleResponsibilityId());
518    }
519    }
520    }
521    }
522    }
523    }
524  0 if(getDelegationMembers()!=null){
525  0 for(RoleDocumentDelegationMember delegationMember: getDelegationMembers()){
526  0 delegationMember.setDocumentNumber(getDocumentNumber());
527  0 addDelegationMemberToDelegation(delegationMember);
528    }
529  0 for(RoleDocumentDelegation delegation: getDelegations()){
530  0 delegation.setDocumentNumber(getDocumentNumber());
531  0 delegation.setKimTypeId(getKimType().getKimTypeId());
532  0 for(RoleDocumentDelegationMember member: delegation.getMembers()){
533  0 for(RoleDocumentDelegationMemberQualifier qualifier: member.getQualifiers()){
534  0 qualifier.setKimTypId(getKimType().getKimTypeId());
535    }
536    }
537  0 delegation.setRoleId(roleId);
538    }
539    }
540    }
541   
 
542  0 toggle public ResponsibilityService getResponsibilityService() {
543  0 if ( responsibilityService == null ) {
544  0 responsibilityService = KIMServiceLocator.getResponsibilityService();
545    }
546  0 return responsibilityService;
547    }
548   
549    /**
550    * @return the editing
551    */
 
552  0 toggle public boolean isEditing() {
553  0 return this.editing;
554    }
555   
556    /**
557    * @param editing the editing to set
558    */
 
559  0 toggle public void setEditing(boolean editing) {
560  0 this.editing = editing;
561    }
562   
563    /**
564    * @return the delegations
565    */
 
566  0 toggle public List<RoleDocumentDelegation> getDelegations() {
567  0 return this.delegations;
568    }
569   
570    /**
571    * @param delegations the delegations to set
572    */
 
573  0 toggle public void setDelegations(List<RoleDocumentDelegation> delegations) {
574  0 this.delegations = delegations;
575    }
576   
 
577  0 toggle public void setKimType(KimTypeInfo kimType) {
578  0 super.setKimType(kimType);
579  0 if (kimType != null){
580  0 setRoleTypeId(kimType.getKimTypeId());
581  0 setRoleTypeName(kimType.getName());
582    }
583    }
584    }