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.apache.log4j.Logger;
19  import org.hibernate.annotations.Fetch;
20  import org.hibernate.annotations.FetchMode;
21  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
22  import org.kuali.rice.kim.api.type.KimAttributeField;
23  import org.kuali.rice.kim.bo.impl.KimAttributes;
24  import org.kuali.rice.kim.framework.services.KimFrameworkServiceLocator;
25  import org.kuali.rice.kim.framework.type.KimTypeService;
26  import org.kuali.rice.kim.impl.role.RoleBo;
27  import org.kuali.rice.kim.impl.role.RoleResponsibilityBo;
28  import org.kuali.rice.kim.impl.type.KimTypeBo;
29  import org.kuali.rice.kim.service.KIMServiceLocatorInternal;
30  import org.springframework.util.AutoPopulatingList;
31  
32  import javax.persistence.CascadeType;
33  import javax.persistence.Column;
34  import javax.persistence.Entity;
35  import javax.persistence.FetchType;
36  import javax.persistence.Id;
37  import javax.persistence.IdClass;
38  import javax.persistence.JoinColumn;
39  import javax.persistence.JoinColumns;
40  import javax.persistence.ManyToMany;
41  import javax.persistence.OneToMany;
42  import javax.persistence.Table;
43  import javax.persistence.Transient;
44  import javax.persistence.UniqueConstraint;
45  import java.util.ArrayList;
46  import java.util.Collections;
47  import java.util.HashMap;
48  import java.util.List;
49  import java.util.Map;
50  
51  /**
52   * This is a description of what this class does - shyu don't forget to fill this in. 
53   * 
54   * @author Kuali Rice Team (rice.collab@kuali.org)
55   *
56   */
57  
58  @Entity
59  @IdClass(org.kuali.rice.kim.bo.ui.PersonDocumentRoleId.class)
60  @Table(name="KRIM_PND_ROLE_MT",uniqueConstraints=@UniqueConstraint(columnNames={"FDOC_NBR", "ROLE_ID"}))
61  public class PersonDocumentRole extends KimDocumentBoActivatableEditableBase {
62      private static final Logger LOG = Logger.getLogger(PersonDocumentRole.class);
63  	private static final long serialVersionUID = 4908044213007222739L;
64  	@Id
65  	@Column(name="ROLE_ID")
66  	protected String roleId;
67  	@Column(name="KIM_TYP_ID")
68  	protected String kimTypeId;
69  	@Column(name="ROLE_NM")
70  	protected String roleName;
71  	@Transient
72  	protected RoleBo roleBo;
73  	@Column(name="NMSPC_CD")
74  	protected String namespaceCode;
75  	@Transient
76  	protected KimTypeBo kimRoleType;
77  	@Transient
78  	protected List<? extends KimAttributes> attributes;
79  	@Transient
80  	protected transient List<KimAttributeField> definitions;
81  	@Transient
82  	protected transient Map<String,Object> attributeEntry;
83  	@OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.ALL})
84      @Fetch(value = FetchMode.SELECT)
85  	@JoinColumns({
86  		@JoinColumn(name="ROLE_ID",insertable=false,updatable=false),
87  		@JoinColumn(name="FDOC_NBR", insertable=false, updatable=false)
88  	})
89  	protected List<KimDocumentRoleMember> rolePrncpls;
90  	@Transient
91      protected KimDocumentRoleMember newRolePrncpl;
92  	//currently mapped as manyToMany even though it is technically a OneToMany
93  	//The reason for this is it is linked with a partial Composite-id, which technically can't 
94  	//guarantee uniqueness.  
95  	@ManyToMany(fetch=FetchType.EAGER, cascade={CascadeType.ALL})
96      @Fetch(value = FetchMode.SELECT)
97      @JoinColumn(name="ROLE_ID",insertable=false,updatable=false)
98      //@JoinColumns({
99  	//	@JoinColumn(name="ROLE_ID",insertable=false,updatable=false),
100 	//	@JoinColumn(name="FDOC_NBR", insertable=false, updatable=false, table="KRIM_PERSON_DOCUMENT_T")
101 	//})
102 	protected List<RoleResponsibilityBo> assignedResponsibilities = new AutoPopulatingList(RoleResponsibilityBo.class);
103 
104 	@Transient
105     protected boolean isEditable = true;
106     
107 	public PersonDocumentRole() {
108 		attributes = new ArrayList<KimAttributes>();	
109 		rolePrncpls = new ArrayList<KimDocumentRoleMember>();	
110 		attributeEntry = new HashMap<String,Object>();
111 	}
112 	
113 	public String getRoleId() {
114 		return this.roleId;
115 	}
116 
117 	public void setRoleId(String roleId) {
118 		this.roleId = roleId;
119 	}
120 
121 	public String getKimTypeId() {
122 		return this.kimTypeId;
123 	}
124 
125 	public void setKimTypeId(String kimTypeId) {
126 		this.kimTypeId = kimTypeId;
127 	}
128 
129 	public String getRoleName() {
130 		return this.roleName;
131 	}
132 
133 	public void setRoleName(String roleName) {
134 		this.roleName = roleName;
135 	}
136 
137 	public List<? extends KimAttributes> getAttributes() {
138 		return this.attributes;
139 	}
140 
141 	public void setAttributes(List<? extends KimAttributes> attributes) {
142 		this.attributes = attributes;
143 	}
144 
145 	public KimTypeBo getKimRoleType() {
146 		if ( kimRoleType == null ) {
147 			kimRoleType = KimTypeBo.from(KimApiServiceLocator.getKimTypeInfoService().getKimType(kimTypeId));
148 		}
149 		return kimRoleType;
150 	}
151 
152 	public List<KimAttributeField> getDefinitions() {
153 		if (definitions == null || definitions.isEmpty()) {
154 	        KimTypeService kimTypeService = KimFrameworkServiceLocator.getKimTypeService(KimTypeBo.to(
155                     this.getKimRoleType()));
156 	        //it is possible that the the roleTypeService is coming from a remote application 
157 	        // and therefore it can't be guarenteed that it is up and working, so using a try/catch to catch this possibility.
158 	        try {
159     	        if ( kimTypeService != null ) {
160     	        	definitions = kimTypeService.getAttributeDefinitions(getKimTypeId());
161     	        } else {
162     	        	definitions = Collections.emptyList();
163     	        }
164     		} catch (Exception ex) {
165                 LOG.warn("Not able to retrieve KimTypeService from remote system for KIM Role Type: " + this.getKimRoleType(), ex);
166             }
167 		}
168 		
169 		return definitions;
170 	}
171 
172 	public void setDefinitions(List<KimAttributeField> definitions) {
173 		this.definitions = definitions;
174 	}
175 
176 	public Map<String,Object> getAttributeEntry() {
177 		if (attributeEntry == null || attributeEntry.isEmpty()) {
178 			attributeEntry = KIMServiceLocatorInternal.getUiDocumentService().getAttributeEntries(getDefinitions());
179 		}
180 		
181 		return this.attributeEntry;
182 	}
183 
184 	public void setAttributeEntry(Map<String,Object> attributeEntry) {
185 		this.attributeEntry = attributeEntry;
186 	}
187 
188 	public List<KimDocumentRoleMember> getRolePrncpls() {
189 		return this.rolePrncpls;
190 	}
191 
192 	public void setRolePrncpls(List<KimDocumentRoleMember> rolePrncpls) {
193 		this.rolePrncpls = rolePrncpls;
194 	}
195 
196 	public KimDocumentRoleMember getNewRolePrncpl() {
197 		return this.newRolePrncpl;
198 	}
199 
200 	public void setNewRolePrncpl(KimDocumentRoleMember newRolePrncpl) {
201 		this.newRolePrncpl = newRolePrncpl;
202 	}
203 
204 	public String getNamespaceCode() {
205 		return this.namespaceCode;
206 	}
207 
208 	public void setNamespaceCode(String namespaceCode) {
209 		this.namespaceCode = namespaceCode;
210 	}
211 
212 	public List<RoleResponsibilityBo> getAssignedResponsibilities() {
213 		return this.assignedResponsibilities;
214 	}
215 
216 	public void setAssignedResponsibilities(
217 			List<RoleResponsibilityBo> assignedResponsibilities) {
218 		this.assignedResponsibilities = assignedResponsibilities;
219 	}
220 
221 	/**
222 	 * @return the roleBo
223 	 */
224 	public RoleBo getRoleBo() {
225 		return this.roleBo;
226 	}
227 
228 	/**
229 	 * @param roleBo the roleBo to set
230 	 */
231 	public void setRoleBo(RoleBo roleBo) {
232 		this.roleBo = roleBo;
233 	}
234 
235 	/**
236 	 * @return the isEditable
237 	 */
238 	public boolean isEditable() {
239 		return this.isEditable;
240 	}
241 
242 	/**
243 	 * @param isEditable the isEditable to set
244 	 */
245 	public void setEditable(boolean isEditable) {
246 		this.isEditable = isEditable;
247 	}
248 
249 }