1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.bo.role.impl; |
17 | |
|
18 | |
import org.hibernate.annotations.Fetch; |
19 | |
import org.hibernate.annotations.FetchMode; |
20 | |
import org.hibernate.annotations.Type; |
21 | |
import org.kuali.rice.kim.bo.Role; |
22 | |
import org.kuali.rice.kim.bo.role.KimDelegation; |
23 | |
import org.kuali.rice.kim.bo.role.dto.DelegateMemberCompleteInfo; |
24 | |
import org.kuali.rice.kim.bo.role.dto.DelegateTypeInfo; |
25 | |
import org.kuali.rice.kim.impl.type.KimTypeBo; |
26 | |
import org.kuali.rice.krad.bo.PersistableBusinessObjectBase; |
27 | |
import org.springframework.util.AutoPopulatingList; |
28 | |
|
29 | |
import javax.persistence.CascadeType; |
30 | |
import javax.persistence.Column; |
31 | |
import javax.persistence.Entity; |
32 | |
import javax.persistence.FetchType; |
33 | |
import javax.persistence.Id; |
34 | |
import javax.persistence.JoinColumn; |
35 | |
import javax.persistence.OneToMany; |
36 | |
import javax.persistence.Table; |
37 | |
import javax.persistence.Transient; |
38 | |
import java.util.ArrayList; |
39 | |
import java.util.List; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
@Entity |
48 | |
@Table(name="KRIM_DLGN_T") |
49 | 0 | public class KimDelegationImpl extends PersistableBusinessObjectBase implements KimDelegation { |
50 | |
|
51 | |
private static final long serialVersionUID = 1L; |
52 | |
|
53 | |
@Id |
54 | |
@Column(name="DLGN_ID") |
55 | |
protected String delegationId; |
56 | |
|
57 | |
@Column(name="ROLE_ID") |
58 | |
protected String roleId; |
59 | |
|
60 | 0 | @Type(type="yes_no") |
61 | |
@Column(name="ACTV_IND") |
62 | |
protected boolean active = true; |
63 | |
|
64 | |
@Column(name="KIM_TYP_ID") |
65 | |
protected String kimTypeId; |
66 | |
|
67 | |
@Column(name="DLGN_TYP_CD") |
68 | |
protected String delegationTypeCode; |
69 | |
|
70 | 0 | @OneToMany(targetEntity=KimDelegationMemberImpl.class,cascade={CascadeType.ALL},fetch=FetchType.EAGER) |
71 | |
@Fetch(value = FetchMode.SELECT) |
72 | |
@JoinColumn(name="DLGN_ID", insertable=false, updatable=false) |
73 | |
protected List<KimDelegationMemberImpl> members = new AutoPopulatingList(KimDelegationMemberImpl.class); |
74 | |
|
75 | |
@Transient |
76 | |
protected KimTypeBo kimType; |
77 | |
|
78 | |
public String getRoleId() { |
79 | 0 | return this.roleId; |
80 | |
} |
81 | |
|
82 | |
public void setRoleId(String roleId) { |
83 | 0 | this.roleId = roleId; |
84 | 0 | } |
85 | |
|
86 | |
public boolean isActive() { |
87 | 0 | return this.active; |
88 | |
} |
89 | |
|
90 | |
public void setActive(boolean active) { |
91 | 0 | this.active = active; |
92 | 0 | } |
93 | |
|
94 | |
public String getKimTypeId() { |
95 | 0 | return this.kimTypeId; |
96 | |
} |
97 | |
|
98 | |
public void setKimTypeId(String typeId) { |
99 | 0 | this.kimTypeId = typeId; |
100 | 0 | } |
101 | |
|
102 | |
public KimTypeBo getKimType() { |
103 | 0 | return this.kimType; |
104 | |
} |
105 | |
|
106 | |
public String getDelegationTypeCode() { |
107 | 0 | return this.delegationTypeCode; |
108 | |
} |
109 | |
|
110 | |
public void setDelegationTypeCode(String delegationTypeCode) { |
111 | 0 | this.delegationTypeCode = delegationTypeCode; |
112 | 0 | } |
113 | |
|
114 | |
public String getDelegationId() { |
115 | 0 | return this.delegationId; |
116 | |
} |
117 | |
|
118 | |
public void setDelegationId(String delegationId) { |
119 | 0 | this.delegationId = delegationId; |
120 | 0 | } |
121 | |
|
122 | |
public List<String> getMemberGroupIds() { |
123 | 0 | return getMembersOfType( Role.GROUP_MEMBER_TYPE ); |
124 | |
} |
125 | |
|
126 | |
public List<String> getMemberPrincipalIds() { |
127 | 0 | return getMembersOfType( Role.PRINCIPAL_MEMBER_TYPE ); |
128 | |
} |
129 | |
|
130 | |
public List<String> getMemberRoleIds() { |
131 | 0 | return getMembersOfType( Role.ROLE_MEMBER_TYPE ); |
132 | |
} |
133 | |
|
134 | |
protected List<String> getMembersOfType( String memberTypeCode ) { |
135 | 0 | List<String> roleMembers = new ArrayList<String>(); |
136 | 0 | for ( KimDelegationMemberImpl member : getMembers() ) { |
137 | 0 | if ( member.getMemberTypeCode().equals ( memberTypeCode ) |
138 | |
&& member.isActive() ) { |
139 | 0 | roleMembers.add( member.getMemberId() ); |
140 | |
} |
141 | |
} |
142 | 0 | return roleMembers; |
143 | |
} |
144 | |
|
145 | |
public List<KimDelegationMemberImpl> getMembers() { |
146 | 0 | return this.members; |
147 | |
} |
148 | |
|
149 | |
public void setMembers(List<KimDelegationMemberImpl> members) { |
150 | 0 | this.members = members; |
151 | 0 | } |
152 | |
|
153 | |
public DelegateTypeInfo toSimpleInfo(){ |
154 | 0 | DelegateTypeInfo delegateTypeInfo = new DelegateTypeInfo(); |
155 | 0 | delegateTypeInfo.setActive(active); |
156 | 0 | delegateTypeInfo.setDelegationId(delegationId); |
157 | 0 | delegateTypeInfo.setDelegationTypeCode(delegationTypeCode); |
158 | |
|
159 | 0 | delegateTypeInfo.setKimTypeId(kimTypeId); |
160 | 0 | delegateTypeInfo.setRoleId(roleId); |
161 | 0 | delegateTypeInfo.setMembers(new ArrayList<DelegateMemberCompleteInfo>()); |
162 | 0 | if(members!=null){ |
163 | 0 | for(KimDelegationMemberImpl member: members) |
164 | 0 | delegateTypeInfo.getMembers().add(member.toSimpleInfo()); |
165 | |
} |
166 | 0 | return delegateTypeInfo; |
167 | |
} |
168 | |
|
169 | |
} |