View Javadoc

1   /**
2    * Copyright 2005-2011 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.hibernate.annotations.GenericGenerator;
19  import org.hibernate.annotations.Parameter;
20  import org.kuali.rice.core.api.membership.MemberType;
21  import org.kuali.rice.kim.api.KimConstants;
22  import org.kuali.rice.kim.api.group.Group;
23  import org.kuali.rice.kim.api.identity.principal.Principal;
24  import org.kuali.rice.kim.api.role.Role;
25  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
26  import org.springframework.util.AutoPopulatingList;
27  
28  import javax.persistence.CascadeType;
29  import javax.persistence.Column;
30  import javax.persistence.Entity;
31  import javax.persistence.FetchType;
32  import javax.persistence.GeneratedValue;
33  import javax.persistence.Id;
34  import javax.persistence.IdClass;
35  import javax.persistence.JoinColumn;
36  import javax.persistence.JoinColumns;
37  import javax.persistence.OneToMany;
38  import javax.persistence.Table;
39  import javax.persistence.Transient;
40  import java.util.ArrayList;
41  import java.util.HashMap;
42  import java.util.List;
43  import java.util.Map;
44  
45  /**
46   * This is a description of what this class does - shyu don't forget to fill this in. 
47   * 
48   * @author Kuali Rice Team (rice.collab@kuali.org)
49   *
50   */
51  @IdClass(KimDocumentRoleMemberId.class)
52  @Entity
53  @Table(name="KRIM_PND_ROLE_MBR_MT")
54  public class KimDocumentRoleMember  extends KimDocumentBoActivatableToFromEditableBase {
55  	private static final long serialVersionUID = -2463865643038170979L;
56  
57  	@Id
58  	@GeneratedValue(generator="KRIM_ROLE_MBR_ID_S")
59  	@GenericGenerator(name="KRIM_ROLE_MBR_ID_S",strategy="org.kuali.rice.core.jpa.spring.RiceNumericStringSequenceStyleGenerator",parameters={
60  			@Parameter(name="sequence_name",value="KRIM_ROLE_MBR_ID_S"),
61  			@Parameter(name="value_column",value="id")
62  		})
63  	@Column(name="ROLE_MBR_ID")
64  	protected String roleMemberId;
65  	
66  	@Column(name="ROLE_ID")
67  	protected String roleId;
68  	@Column(name="MBR_ID")
69  	protected String memberId;
70  	
71  	//TODO: remove the default
72  	@Column(name="MBR_TYP_CD")
73  	protected String memberTypeCode = KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE.getCode();
74  	@Transient
75  	protected String memberName;
76  	@Transient
77  	protected String memberNamespaceCode;
78  	
79  	protected String memberFullName;
80  
81  	@OneToMany(fetch=FetchType.LAZY,cascade=CascadeType.ALL)
82  	@JoinColumns({
83  	    @JoinColumn(name="ROLE_MBR_ID", insertable = false, updatable = false), 
84  	    @JoinColumn(name="FDOC_NBR", insertable = false, updatable = false)
85  	})
86  	protected List <KimDocumentRoleQualifier> qualifiers = new AutoPopulatingList(KimDocumentRoleQualifier.class);
87  	@Transient
88  	protected String qualifiersToDisplay;
89  	
90  	@OneToMany(fetch=FetchType.LAZY,cascade=CascadeType.ALL)
91  	@JoinColumns({
92  	    @JoinColumn(name="ROLE_MBR_ID", insertable = false, updatable = false), 
93  	    @JoinColumn(name="FDOC_NBR", insertable = false, updatable = false)
94  	})
95  	private List<KimDocumentRoleResponsibilityAction> roleRspActions;
96  
97  	public KimDocumentRoleMember() {
98  		qualifiers = new ArrayList <KimDocumentRoleQualifier>();
99  		roleRspActions = new ArrayList <KimDocumentRoleResponsibilityAction>();
100 	}
101 
102 	public int getNumberOfQualifiers(){
103 		return qualifiers==null?0:qualifiers.size();
104 	}
105 	
106 	/**
107 	 * @return the memberId
108 	 */
109 	public String getMemberId() {
110 		return this.memberId;
111 	}
112 
113 	/**
114 	 * @param memberId the memberId to set
115 	 */
116 	public void setMemberId(String memberId) {
117 		this.memberId = memberId;
118 	}
119 
120 	public String getRoleMemberId() {
121 		return this.roleMemberId;
122 	}
123 
124 	public void setRoleMemberId(String roleMemberId) {
125 		this.roleMemberId = roleMemberId;
126 	}
127 
128 	public String getRoleId() {
129 		return this.roleId;
130 	}
131 
132 	public void setRoleId(String roleId) {
133 		this.roleId = roleId;
134 	}
135 
136 	public KimDocumentRoleQualifier getQualifier(String kimAttributeDefnId) {
137 		for(KimDocumentRoleQualifier qualifier:qualifiers){
138 			if(qualifier.getKimAttrDefnId().equals(kimAttributeDefnId)) {
139 				return qualifier;
140             }
141 		}
142 		return null;
143 	}
144 
145 	public List<KimDocumentRoleQualifier> getQualifiers() {
146 		return this.qualifiers;
147 	}
148 
149 	public void setQualifiers(List<KimDocumentRoleQualifier> qualifiers) {
150 		this.qualifiers = qualifiers;
151 	}
152 
153 	/**
154 	 * @return the memberTypeCode
155 	 */
156 	public String getMemberTypeCode() {
157 		return this.memberTypeCode;
158 	}
159 
160 	/**
161 	 * @param memberTypeCode the memberTypeCode to set
162 	 */
163 	public void setMemberTypeCode(String memberTypeCode) {
164 		this.memberTypeCode = memberTypeCode;
165 	}
166 
167 	/**
168 	 * @return the memberName
169 	 */
170 	public String getMemberName() {
171 		if ( memberName == null ) {
172 			populateDerivedValues();
173 		}
174 		return memberName;
175 	}
176 
177 	/**
178 	 * @param memberName the memberName to set
179 	 */
180 	public void setMemberName(String memberName) {
181 		this.memberName = memberName;
182 	}
183 
184 	public List<KimDocumentRoleResponsibilityAction> getRoleRspActions() {
185 		return this.roleRspActions;
186 	}
187 
188 	public void setRoleRspActions(
189 			List<KimDocumentRoleResponsibilityAction> roleRspActions) {
190 		this.roleRspActions = roleRspActions;
191 	}
192 
193 	/**
194 	 * @return the memberNamespaceCode
195 	 */
196 	public String getMemberNamespaceCode() {
197 		if ( memberNamespaceCode == null ) {
198 			populateDerivedValues();
199 		}
200 		return memberNamespaceCode;
201 	}
202 
203 	/**
204 	 * @param memberNamespaceCode the memberNamespaceCode to set
205 	 */
206 	public void setMemberNamespaceCode(String memberNamespaceCode) {
207 		this.memberNamespaceCode = memberNamespaceCode;
208 	}
209 
210 	protected void populateDerivedValues() {
211         if(MemberType.PRINCIPAL.getCode().equals(getMemberTypeCode())){
212             Principal principalInfo = KimApiServiceLocator.getIdentityService().getPrincipal(getMemberId());
213         	if (principalInfo != null) {
214         		setMemberName(principalInfo.getPrincipalName());
215         	}        	        	
216         } else if(MemberType.GROUP.getCode().equals(getMemberTypeCode())){
217         	Group groupInfo = KimApiServiceLocator.getGroupService().getGroup(getMemberId());
218         	if (groupInfo != null) {
219         		setMemberName(groupInfo.getName());
220         		setMemberNamespaceCode(groupInfo.getNamespaceCode());
221         	}
222         	
223         } else if(MemberType.ROLE.getCode().equals(getMemberTypeCode())){
224         	Role role = KimApiServiceLocator.getRoleService().getRole(getMemberId());
225         	setMemberName(role.getName());
226         	setMemberNamespaceCode(role.getNamespaceCode());
227         }
228 	}
229 	
230 	public boolean isRole(){
231 		return getMemberTypeCode()!=null && getMemberTypeCode().equals(MemberType.ROLE.getCode());
232 	}
233 	
234 	public boolean isGroup(){
235 		return getMemberTypeCode()!=null && getMemberTypeCode().equals(MemberType.GROUP.getCode());
236 	}
237 
238 	public boolean isPrincipal(){
239 		return getMemberTypeCode()!=null && getMemberTypeCode().equals(MemberType.PRINCIPAL.getCode());
240 	}
241 
242 	public Map<String, String> getQualifierAsMap() {
243 		Map<String, String> m = new HashMap<String, String>();
244 		for ( KimDocumentRoleQualifier data : getQualifiers() ) {
245 			if (data.getKimAttribute() == null){
246 				data.refreshReferenceObject("kimAttribute");
247 			}
248 			if (data.getKimAttribute() != null){
249 				m.put( data.getKimAttribute().getAttributeName(), data.getAttrVal() );
250 			}
251 		}
252 		return m;
253 	}
254 
255 	/**
256 	 * @return the qualifiersToDisplay
257 	 */
258 	public String getQualifiersToDisplay() {
259 		return this.qualifiersToDisplay;
260 	}
261 
262 	/**
263 	 * @param qualifiersToDisplay the qualifiersToDisplay to set
264 	 */
265 	public void setQualifiersToDisplay(String qualifiersToDisplay) {
266 		this.qualifiersToDisplay = qualifiersToDisplay;
267 	}
268 	
269 	/**
270 	 * @return the memberFullName
271 	 */
272 	public String getMemberFullName() {
273 		return this.memberFullName;
274 	}
275 
276 	/**
277 	 * @param memberFullName the memberFullName to set
278 	 */
279 	public void setMemberFullName(String memberFullName) {
280 		this.memberFullName = memberFullName;
281 	}
282 
283 }