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 public class IdentityManagementKimDocument extends TransactionalDocumentBase {
56
57 protected static final Logger LOG = Logger.getLogger(IdentityManagementKimDocument.class);
58
59 @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 @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 if(DelegationType.PRIMARY.getCode().equals(delegationMember.getDelegationTypeCode())){
70 delegation = getPrimaryDelegation();
71 } else{
72 delegation = getSecondaryDelegation();
73 }
74 delegationMember.setDelegationId(delegation.getDelegationId());
75 delegation.getMembers().add(delegationMember);
76 delegation.setRoleId(delegationMember.getRoleBo().getId());
77 delegation.setKimTypeId(delegationMember.getRoleBo().getKimTypeId());
78 }
79
80 protected RoleDocumentDelegation getPrimaryDelegation(){
81 RoleDocumentDelegation primaryDelegation = null;
82 for(RoleDocumentDelegation delegation: getDelegations()){
83 if(delegation.isDelegationPrimary()) {
84 primaryDelegation = delegation;
85 }
86 }
87 if(primaryDelegation==null){
88 primaryDelegation = new RoleDocumentDelegation();
89 primaryDelegation.setDelegationId(getDelegationId());
90 primaryDelegation.setDelegationTypeCode(DelegationType.PRIMARY.getCode());
91 getDelegations().add(primaryDelegation);
92 }
93 return primaryDelegation;
94 }
95
96 protected String getDelegationId(){
97 return getSequenceAccessorService().getNextAvailableSequenceNumber(KimConstants.SequenceNames.KRIM_DLGN_ID_S).toString();
98 }
99
100 protected RoleDocumentDelegation getSecondaryDelegation(){
101 RoleDocumentDelegation secondaryDelegation = null;
102 for(RoleDocumentDelegation delegation: getDelegations()){
103 if(delegation.isDelegationSecondary()) {
104 secondaryDelegation = delegation;
105 }
106 }
107 if(secondaryDelegation==null){
108 secondaryDelegation = new RoleDocumentDelegation();
109 secondaryDelegation.setDelegationId(getDelegationId());
110 secondaryDelegation.setDelegationTypeCode(DelegationType.SECONDARY.getCode());
111 getDelegations().add(secondaryDelegation);
112 }
113 return secondaryDelegation;
114 }
115
116
117
118
119 public List<RoleDocumentDelegation> getDelegations() {
120 return this.delegations;
121 }
122
123
124
125
126 public void setDelegations(List<RoleDocumentDelegation> delegations) {
127 this.delegations = delegations;
128 }
129
130
131
132
133 public List<RoleDocumentDelegationMember> getDelegationMembers() {
134 return this.delegationMembers;
135 }
136
137
138
139
140 public void setDelegationMembers(
141 List<RoleDocumentDelegationMember> delegationMembers) {
142 this.delegationMembers = delegationMembers;
143 }
144
145 protected SequenceAccessorService getSequenceAccessorService(){
146 if(this.sequenceAccessorService==null){
147 this.sequenceAccessorService = KRADServiceLocator.getSequenceAccessorService();
148 }
149 return this.sequenceAccessorService;
150 }
151
152 public String getKimAttributeDefnId(KimAttributeField definition){
153 return definition.getId();
154 }
155
156 }