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 javax.persistence.AssociationOverride; |
21 | |
import javax.persistence.AssociationOverrides; |
22 | |
import javax.persistence.AttributeOverride; |
23 | |
import javax.persistence.AttributeOverrides; |
24 | |
import javax.persistence.CascadeType; |
25 | |
import javax.persistence.Column; |
26 | |
import javax.persistence.FetchType; |
27 | |
import javax.persistence.JoinColumn; |
28 | |
import javax.persistence.MappedSuperclass; |
29 | |
import javax.persistence.OneToMany; |
30 | |
import javax.persistence.Transient; |
31 | |
|
32 | |
import org.apache.log4j.Logger; |
33 | |
import org.kuali.rice.kew.util.KEWConstants; |
34 | |
import org.kuali.rice.kim.bo.ui.RoleDocumentDelegation; |
35 | |
import org.kuali.rice.kim.bo.ui.RoleDocumentDelegationMember; |
36 | |
import org.kuali.rice.kim.util.KimConstants; |
37 | |
import org.kuali.rice.kns.datadictionary.AttributeDefinition; |
38 | |
import org.kuali.rice.kns.datadictionary.KimDataDictionaryAttributeDefinition; |
39 | |
import org.kuali.rice.kns.datadictionary.KimNonDataDictionaryAttributeDefinition; |
40 | |
import org.kuali.rice.kns.document.TransactionalDocumentBase; |
41 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
42 | |
import org.kuali.rice.kns.service.SequenceAccessorService; |
43 | |
import org.springframework.util.AutoPopulatingList; |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
@MappedSuperclass |
52 | |
@AttributeOverrides({ |
53 | |
@AttributeOverride(name="documentNumber",column=@Column(name="FDOC_NBR")) |
54 | |
}) |
55 | |
@AssociationOverrides({ |
56 | |
@AssociationOverride(name="documentHeader",joinColumns=@JoinColumn(name="FDOC_NBR",referencedColumnName="DOC_HDR_ID",insertable=false,updatable=false)) |
57 | |
}) |
58 | 0 | public class IdentityManagementKimDocument extends TransactionalDocumentBase { |
59 | |
|
60 | 0 | protected static final Logger LOG = Logger.getLogger(IdentityManagementKimDocument.class); |
61 | |
|
62 | 0 | @OneToMany(targetEntity=RoleDocumentDelegation.class, fetch=FetchType.EAGER, cascade={CascadeType.ALL}) |
63 | |
@JoinColumn(name="FDOC_NBR",insertable=false,updatable=false) |
64 | |
protected List<RoleDocumentDelegation> delegations = new AutoPopulatingList(RoleDocumentDelegation.class); |
65 | 0 | @Transient |
66 | |
protected List<RoleDocumentDelegationMember> delegationMembers = new AutoPopulatingList(RoleDocumentDelegationMember.class); |
67 | |
@Transient |
68 | |
protected transient SequenceAccessorService sequenceAccessorService; |
69 | |
|
70 | |
protected void addDelegationMemberToDelegation(RoleDocumentDelegationMember delegationMember){ |
71 | |
RoleDocumentDelegation delegation; |
72 | 0 | if(KEWConstants.DELEGATION_PRIMARY.equals(delegationMember.getDelegationTypeCode())){ |
73 | 0 | delegation = getPrimaryDelegation(); |
74 | |
} else{ |
75 | 0 | delegation = getSecondaryDelegation(); |
76 | |
} |
77 | 0 | delegationMember.setDelegationId(delegation.getDelegationId()); |
78 | 0 | delegation.getMembers().add(delegationMember); |
79 | 0 | delegation.setRoleId(delegationMember.getRoleImpl().getRoleId()); |
80 | 0 | delegation.setKimTypeId(delegationMember.getRoleImpl().getKimTypeId()); |
81 | 0 | } |
82 | |
|
83 | |
protected RoleDocumentDelegation getPrimaryDelegation(){ |
84 | 0 | RoleDocumentDelegation primaryDelegation = null; |
85 | 0 | for(RoleDocumentDelegation delegation: getDelegations()){ |
86 | 0 | if(delegation.isDelegationPrimary()) |
87 | 0 | primaryDelegation = delegation; |
88 | |
} |
89 | 0 | if(primaryDelegation==null){ |
90 | 0 | primaryDelegation = new RoleDocumentDelegation(); |
91 | 0 | primaryDelegation.setDelegationId(getDelegationId()); |
92 | 0 | primaryDelegation.setDelegationTypeCode(KEWConstants.DELEGATION_PRIMARY); |
93 | 0 | getDelegations().add(primaryDelegation); |
94 | |
} |
95 | 0 | return primaryDelegation; |
96 | |
} |
97 | |
|
98 | |
protected String getDelegationId(){ |
99 | 0 | return getSequenceAccessorService().getNextAvailableSequenceNumber(KimConstants.SequenceNames.KRIM_DLGN_ID_S).toString(); |
100 | |
} |
101 | |
|
102 | |
protected RoleDocumentDelegation getSecondaryDelegation(){ |
103 | 0 | RoleDocumentDelegation secondaryDelegation = null; |
104 | 0 | for(RoleDocumentDelegation delegation: getDelegations()){ |
105 | 0 | if(delegation.isDelegationSecondary()) |
106 | 0 | secondaryDelegation = delegation; |
107 | |
} |
108 | 0 | if(secondaryDelegation==null){ |
109 | 0 | secondaryDelegation = new RoleDocumentDelegation(); |
110 | 0 | secondaryDelegation.setDelegationId(getDelegationId()); |
111 | 0 | secondaryDelegation.setDelegationTypeCode(KEWConstants.DELEGATION_SECONDARY); |
112 | 0 | getDelegations().add(secondaryDelegation); |
113 | |
} |
114 | 0 | return secondaryDelegation; |
115 | |
} |
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
public List<RoleDocumentDelegation> getDelegations() { |
121 | 0 | return this.delegations; |
122 | |
} |
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
public void setDelegations(List<RoleDocumentDelegation> delegations) { |
128 | 0 | this.delegations = delegations; |
129 | 0 | } |
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
public List<RoleDocumentDelegationMember> getDelegationMembers() { |
135 | 0 | return this.delegationMembers; |
136 | |
} |
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
public void setDelegationMembers( |
142 | |
List<RoleDocumentDelegationMember> delegationMembers) { |
143 | 0 | this.delegationMembers = delegationMembers; |
144 | 0 | } |
145 | |
|
146 | |
protected SequenceAccessorService getSequenceAccessorService(){ |
147 | 0 | if(this.sequenceAccessorService==null){ |
148 | 0 | this.sequenceAccessorService = KNSServiceLocator.getSequenceAccessorService(); |
149 | |
} |
150 | 0 | return this.sequenceAccessorService; |
151 | |
} |
152 | |
|
153 | |
public String getKimAttributeDefnId(AttributeDefinition definition){ |
154 | 0 | if (definition instanceof KimDataDictionaryAttributeDefinition) { |
155 | 0 | return ((KimDataDictionaryAttributeDefinition)definition).getKimAttrDefnId(); |
156 | |
} else { |
157 | 0 | return ((KimNonDataDictionaryAttributeDefinition)definition).getKimAttrDefnId(); |
158 | |
} |
159 | |
} |
160 | |
|
161 | |
} |