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