View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kim.bo.ui;
17  
18  import org.kuali.rice.core.api.delegation.DelegationType;
19  import org.kuali.rice.core.api.membership.MemberType;
20  import org.kuali.rice.kim.api.KimConstants;
21  import org.kuali.rice.kim.api.group.Group;
22  import org.kuali.rice.kim.api.role.Role;
23  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
24  import org.kuali.rice.kim.impl.role.RoleBo;
25  import org.kuali.rice.kim.impl.type.KimTypeAttributesHelper;
26  import org.kuali.rice.kim.impl.type.KimTypeBo;
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.GeneratedValue;
34  import javax.persistence.Id;
35  import javax.persistence.IdClass;
36  import javax.persistence.JoinColumn;
37  import javax.persistence.JoinColumns;
38  import javax.persistence.OneToMany;
39  import javax.persistence.Table;
40  import javax.persistence.Transient;
41  import java.util.List;
42  
43  /**
44   * This is a description of what this class does - kellerj don't forget to fill this in. 
45   * 
46   * @author Kuali Rice Team (kuali-rice@googleroles.com)
47   *
48   */
49  @IdClass(RoleDocumentDelegationMemberId.class)
50  @Entity
51  @Table(name="KRIM_PND_DLGN_MBR_T")
52  public class RoleDocumentDelegationMember extends KimDocumentBoActivatableToFromBase {
53  
54  	private static final long serialVersionUID = 1L;
55  	
56  	@Id
57  	@GeneratedValue(generator="KRIM_DLGN_MBR_ID_S")
58  	@Column(name="DLGN_MBR_ID")
59  	protected String delegationMemberId;
60  	
61  	@Column(name="ROLE_MBR_ID")
62  	protected String roleMemberId;
63  	@Transient
64  	protected String roleMemberMemberId;
65  	@Transient
66  	protected String roleMemberMemberTypeCode;
67  	@Transient
68  	protected String roleMemberName;
69  	@Transient
70  	protected String roleMemberNamespaceCode;
71  
72  	@Transient
73  	private KimTypeAttributesHelper attributesHelper;
74  	//For Person Document UI - flattening the delegation - delegation member hierarchy
75  	@Transient
76  	protected RoleBo roleBo = new RoleBo();
77  	
78  	@Column(name="DLGN_ID")
79  	protected String delegationId;
80  	
81  	@Column(name="MBR_ID")
82  	protected String memberId;
83  
84  	@Column(name="MBR_TYP_CD")
85  	protected String memberTypeCode = KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE.getCode();
86  	
87  	@Transient
88  	protected String memberNamespaceCode;
89  	
90  	@Column(name="MBR_NM")
91  	protected String memberName;
92  	@OneToMany(targetEntity=RoleDocumentDelegationMemberQualifier.class, fetch=FetchType.EAGER, cascade={CascadeType.ALL})
93      @JoinColumns({
94  		@JoinColumn(name="dlgn_id",insertable=false,updatable=false),
95  		@JoinColumn(name="fdoc_nbr", insertable=false, updatable=false)
96  	})
97  	protected List <RoleDocumentDelegationMemberQualifier> qualifiers = new AutoPopulatingList(RoleDocumentDelegationMemberQualifier.class);
98  	
99  	@Transient
100 	protected String delegationTypeCode;
101 	
102 	/**
103 	 * @return the delegationTypeCode
104 	 */
105 	public String getDelegationTypeCode() {
106 		return this.delegationTypeCode;
107 	}
108 
109 	/**
110 	 * @param delegationTypeCode the delegationTypeCode to set
111 	 */
112 	public void setDelegationTypeCode(String delegationTypeCode) {
113 		this.delegationTypeCode = delegationTypeCode;
114 	}
115 
116 	public String getDelegationId() {
117 		return this.delegationId;
118 	}
119 
120 	public void setDelegationId(String delegationId) {
121 		this.delegationId = delegationId;
122 	}
123 
124 	/**
125 	 * @return the qualifiers
126 	 */
127 	public List<RoleDocumentDelegationMemberQualifier> getQualifiers() {
128 		return this.qualifiers;
129 	}
130 
131 	public RoleDocumentDelegationMemberQualifier getQualifier(String kimAttributeDefnId) {
132 		for(RoleDocumentDelegationMemberQualifier qualifier:qualifiers){
133 			if(qualifier.getKimAttrDefnId().equals(kimAttributeDefnId)) {
134 				return qualifier;
135             }
136 		}
137 		return null;
138 	}
139 
140 	/**
141 	 * @param qualifiers the qualifiers to set
142 	 */
143 	public void setQualifiers(List<RoleDocumentDelegationMemberQualifier> qualifiers) {
144 		this.qualifiers = qualifiers;
145 	}
146 
147 	public int getNumberOfQualifiers(){
148 		return qualifiers==null?0:qualifiers.size();
149 	}
150 
151 	/**
152 	 * @return the memberId
153 	 */
154 	public String getMemberId() {
155 		return this.memberId;
156 	}
157 
158 	/**
159 	 * @param memberId the memberId to set
160 	 */
161 	public void setMemberId(String memberId) {
162 		this.memberId = memberId;
163 	}
164 
165 	/**
166 	 * @return the memberName
167 	 */
168 	public String getMemberName() {
169 		return this.memberName;
170 	}
171 
172 	/**
173 	 * @param memberName the memberName to set
174 	 */
175 	public void setMemberName(String memberName) {
176 		this.memberName = memberName;
177 	}
178 
179 	/**
180 	 * @return the assignedToId
181 	 */
182 	public String getDelegationMemberId() {
183 		return this.delegationMemberId;
184 	}
185 
186 	/**
187 	 * @param delegationMemberId the assignedToId to set
188 	 */
189 	public void setDelegationMemberId(String delegationMemberId) {
190 		this.delegationMemberId = delegationMemberId;
191 	}
192 
193 	/**
194 	 * @return the memberTypeCode
195 	 */
196 	public String getMemberTypeCode() {
197 		return this.memberTypeCode;
198 	}
199 
200 	/**
201 	 * @param memberTypeCode the memberTypeCode to set
202 	 */
203 	public void setMemberTypeCode(String memberTypeCode) {
204 		this.memberTypeCode = memberTypeCode;
205 	}
206 
207 
208 	public boolean isDelegationPrimary(){
209 		return DelegationType.PRIMARY.getCode().equals(getDelegationTypeCode());
210 	}
211 
212 	public boolean isDelegationSecondary(){
213 		return DelegationType.SECONDARY.getCode().equals(getDelegationTypeCode());
214 	}
215 
216 	/**
217 	 * @return the memberNamespaceCode
218 	 */
219 	public String getMemberNamespaceCode() {
220 		if ( memberNamespaceCode == null ) {
221 			populateDerivedValues();
222 		}
223 		return this.memberNamespaceCode;
224 	}
225 
226 	/**
227 	 * @param memberNamespaceCode the memberNamespaceCode to set
228 	 */
229 	public void setMemberNamespaceCode(String memberNamespaceCode) {
230 		this.memberNamespaceCode = memberNamespaceCode;
231 	}
232 
233 	protected void populateDerivedValues() {
234 		if(MemberType.GROUP.getCode().equals(getMemberTypeCode())){
235         	Group groupInfo = null;
236         	groupInfo = KimApiServiceLocator.getGroupService().getGroup(getMemberId());
237         	if (groupInfo != null) {
238         		setMemberNamespaceCode(groupInfo.getNamespaceCode());
239         	}        	
240         } else if(MemberType.ROLE.getCode().equals(getMemberTypeCode())){
241         	Role role;
242         	role = KimApiServiceLocator.getRoleService().getRole(getMemberId());
243         	setMemberNamespaceCode(role.getNamespaceCode());
244         }
245 	}
246 	
247 	/**
248 	 * @return the roleMemberId
249 	 */
250 	public String getRoleMemberId() {
251 		return this.roleMemberId;
252 	}
253 
254 	/**
255 	 * @param roleMemberId the roleMemberId to set
256 	 */
257 	public void setRoleMemberId(String roleMemberId) {
258 		this.roleMemberId = roleMemberId;
259 	}
260 
261 	public boolean isRole(){
262 		return getMemberTypeCode()!=null && getMemberTypeCode().equals(MemberType.ROLE.getCode());
263 	}
264 	
265 	public boolean isGroup(){
266 		return getMemberTypeCode()!=null && getMemberTypeCode().equals(MemberType.GROUP.getCode());
267 	}
268 
269 	public boolean isPrincipal(){
270 		return getMemberTypeCode()!=null && getMemberTypeCode().equals(MemberType.PRINCIPAL.getCode());
271 	}
272 
273 	/**
274 	 * @return the roleMemberName
275 	 */
276 	public String getRoleMemberName() {
277 		return this.roleMemberName;
278 	}
279 
280 	/**
281 	 * @param roleMemberName the roleMemberName to set
282 	 */
283 	public void setRoleMemberName(String roleMemberName) {
284 		this.roleMemberName = roleMemberName;
285 	}
286 
287 	/**
288 	 * @return the roleMemberNamespaceCode
289 	 */
290 	public String getRoleMemberNamespaceCode() {
291 		return this.roleMemberNamespaceCode;
292 	}
293 
294 	/**
295 	 * @param roleMemberNamespaceCode the roleMemberNamespaceCode to set
296 	 */
297 	public void setRoleMemberNamespaceCode(String roleMemberNamespaceCode) {
298 		this.roleMemberNamespaceCode = roleMemberNamespaceCode;
299 	}
300 
301 	/**
302 	 * @return the roleBo
303 	 */
304 	public RoleBo getRoleBo() {
305 		return this.roleBo;
306 	}
307 
308 	/**
309 	 * @param roleBo the roleBo to set
310 	 */
311 	public void setRoleBo(RoleBo roleBo) {
312 		this.roleBo = roleBo;
313 		setAttributesHelper(new KimTypeAttributesHelper(KimTypeBo.to(roleBo.getKimRoleType())));
314 	}
315 
316 	/**
317 	 * @return the attributesHelper
318 	 */
319 	public KimTypeAttributesHelper getAttributesHelper() {
320 		return this.attributesHelper;
321 	}
322 
323 	/**
324 	 * @param attributesHelper the attributesHelper to set
325 	 */
326 	public void setAttributesHelper(KimTypeAttributesHelper attributesHelper) {
327 		this.attributesHelper = attributesHelper;
328 	}
329 
330 	/**
331 	 * @return the roleMemberMemberId
332 	 */
333 	public String getRoleMemberMemberId() {
334 		return this.roleMemberMemberId;
335 	}
336 
337 	/**
338 	 * @param roleMemberMemberId the roleMemberMemberId to set
339 	 */
340 	public void setRoleMemberMemberId(String roleMemberMemberId) {
341 		this.roleMemberMemberId = roleMemberMemberId;
342 	}
343 
344 	/**
345 	 * @return the roleMemberMemberTypeCode
346 	 */
347 	public String getRoleMemberMemberTypeCode() {
348 		return this.roleMemberMemberTypeCode;
349 	}
350 
351 	/**
352 	 * @param roleMemberMemberTypeCode the roleMemberMemberTypeCode to set
353 	 */
354 	public void setRoleMemberMemberTypeCode(String roleMemberMemberTypeCode) {
355 		this.roleMemberMemberTypeCode = roleMemberMemberTypeCode;
356 	}
357 }