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