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