1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.document;
17
18 import java.util.List;
19
20 import org.apache.log4j.Logger;
21 import org.kuali.rice.kew.util.KEWConstants;
22 import org.kuali.rice.kim.bo.ui.RoleDocumentDelegation;
23 import org.kuali.rice.kim.bo.ui.RoleDocumentDelegationMember;
24 import org.kuali.rice.kim.util.KimConstants;
25 import org.kuali.rice.kns.datadictionary.AttributeDefinition;
26 import org.kuali.rice.kns.datadictionary.KimDataDictionaryAttributeDefinition;
27 import org.kuali.rice.kns.datadictionary.KimNonDataDictionaryAttributeDefinition;
28 import org.kuali.rice.kns.document.TransactionalDocumentBase;
29 import org.kuali.rice.kns.service.KNSServiceLocator;
30 import org.kuali.rice.kns.service.SequenceAccessorService;
31 import org.kuali.rice.kns.util.TypedArrayList;
32
33
34
35
36
37
38
39 public class IdentityManagementKimDocument extends TransactionalDocumentBase {
40
41 protected static final Logger LOG = Logger.getLogger(IdentityManagementKimDocument.class);
42
43 protected List<RoleDocumentDelegation> delegations = new TypedArrayList(RoleDocumentDelegation.class);
44 protected List<RoleDocumentDelegationMember> delegationMembers = new TypedArrayList(RoleDocumentDelegationMember.class);
45
46 protected transient SequenceAccessorService sequenceAccessorService;
47
48 protected void addDelegationMemberToDelegation(RoleDocumentDelegationMember delegationMember){
49 RoleDocumentDelegation delegation;
50 if(KEWConstants.DELEGATION_PRIMARY.equals(delegationMember.getDelegationTypeCode())){
51 delegation = getPrimaryDelegation();
52 } else{
53 delegation = getSecondaryDelegation();
54 }
55 delegationMember.setDelegationId(delegation.getDelegationId());
56 delegation.getMembers().add(delegationMember);
57 delegation.setRoleId(delegationMember.getRoleImpl().getRoleId());
58 delegation.setKimTypeId(delegationMember.getRoleImpl().getKimTypeId());
59 }
60
61 protected RoleDocumentDelegation getPrimaryDelegation(){
62 RoleDocumentDelegation primaryDelegation = null;
63 for(RoleDocumentDelegation delegation: getDelegations()){
64 if(delegation.isDelegationPrimary())
65 primaryDelegation = delegation;
66 }
67 if(primaryDelegation==null){
68 primaryDelegation = new RoleDocumentDelegation();
69 primaryDelegation.setDelegationId(getDelegationId());
70 primaryDelegation.setDelegationTypeCode(KEWConstants.DELEGATION_PRIMARY);
71 getDelegations().add(primaryDelegation);
72 }
73 return primaryDelegation;
74 }
75
76 protected String getDelegationId(){
77 return getSequenceAccessorService().getNextAvailableSequenceNumber(KimConstants.SequenceNames.KRIM_DLGN_ID_S).toString();
78 }
79
80 protected RoleDocumentDelegation getSecondaryDelegation(){
81 RoleDocumentDelegation secondaryDelegation = null;
82 for(RoleDocumentDelegation delegation: getDelegations()){
83 if(delegation.isDelegationSecondary())
84 secondaryDelegation = delegation;
85 }
86 if(secondaryDelegation==null){
87 secondaryDelegation = new RoleDocumentDelegation();
88 secondaryDelegation.setDelegationId(getDelegationId());
89 secondaryDelegation.setDelegationTypeCode(KEWConstants.DELEGATION_SECONDARY);
90 getDelegations().add(secondaryDelegation);
91 }
92 return secondaryDelegation;
93 }
94
95
96
97
98 public List<RoleDocumentDelegation> getDelegations() {
99 return this.delegations;
100 }
101
102
103
104
105 public void setDelegations(List<RoleDocumentDelegation> delegations) {
106 this.delegations = delegations;
107 }
108
109
110
111
112 public List<RoleDocumentDelegationMember> getDelegationMembers() {
113 return this.delegationMembers;
114 }
115
116
117
118
119 public void setDelegationMembers(
120 List<RoleDocumentDelegationMember> delegationMembers) {
121 this.delegationMembers = delegationMembers;
122 }
123
124 protected SequenceAccessorService getSequenceAccessorService(){
125 if(this.sequenceAccessorService==null){
126 this.sequenceAccessorService = KNSServiceLocator.getSequenceAccessorService();
127 }
128 return this.sequenceAccessorService;
129 }
130
131 public String getKimAttributeDefnId(AttributeDefinition definition){
132 if (definition instanceof KimDataDictionaryAttributeDefinition) {
133 return ((KimDataDictionaryAttributeDefinition)definition).getKimAttrDefnId();
134 } else {
135 return ((KimNonDataDictionaryAttributeDefinition)definition).getKimAttrDefnId();
136 }
137 }
138
139 }