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