View Javadoc
1   /**
2    * Copyright 2005-2014 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 java.util.ArrayList;
19  import java.util.Collections;
20  import java.util.HashMap;
21  import java.util.List;
22  import java.util.Map;
23  
24  import javax.persistence.CascadeType;
25  import javax.persistence.Column;
26  import javax.persistence.Entity;
27  import javax.persistence.Id;
28  import javax.persistence.JoinColumn;
29  import javax.persistence.JoinColumns;
30  import javax.persistence.ManyToMany;
31  import javax.persistence.OneToMany;
32  import javax.persistence.Table;
33  import javax.persistence.Transient;
34  
35  import org.apache.log4j.Logger;
36  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
37  import org.kuali.rice.kim.api.type.KimAttributeField;
38  import org.kuali.rice.kim.bo.impl.KimAttributes;
39  import org.kuali.rice.kim.framework.services.KimFrameworkServiceLocator;
40  import org.kuali.rice.kim.framework.type.KimTypeService;
41  import org.kuali.rice.kim.impl.role.RoleBo;
42  import org.kuali.rice.kim.impl.role.RoleResponsibilityBo;
43  import org.kuali.rice.kim.impl.type.KimTypeBo;
44  import org.kuali.rice.kim.service.KIMServiceLocatorInternal;
45  import org.springframework.util.AutoPopulatingList;
46  import org.springframework.util.StringUtils;
47  
48  /**
49   * This is a description of what this class does - shyu don't forget to fill this in. 
50   * 
51   * @author Kuali Rice Team (rice.collab@kuali.org)
52   *
53   */
54  @Entity
55  @Table(name = "KRIM_PND_ROLE_MT")
56  public class PersonDocumentRole extends KimDocumentBoActivatableEditableBase {
57      private static final Logger LOG = Logger.getLogger(PersonDocumentRole.class);
58      private static final long serialVersionUID = 4908044213007222739L;
59  
60      @Id
61      @Column(name = "ROLE_ID")
62      protected String roleId;
63  
64      @Column(name = "KIM_TYP_ID")
65      protected String kimTypeId;
66  
67      @Column(name = "ROLE_NM")
68      protected String roleName;
69  
70      @Transient
71      protected RoleBo roleBo;
72  
73      @Column(name = "NMSPC_CD")
74      protected String namespaceCode;
75  
76      @Transient
77      protected KimTypeBo kimRoleType;
78  
79      @Transient
80      protected List<? extends KimAttributes> attributes;
81  
82      @Transient
83      protected transient List<KimAttributeField> definitions;
84  
85      @Transient
86      protected transient Map<String, Object> attributeEntry;
87  
88      @OneToMany(targetEntity = KimDocumentRoleMember.class, orphanRemoval = true, cascade = { CascadeType.REFRESH, CascadeType.REMOVE, CascadeType.PERSIST })
89      @JoinColumns({ 
90          @JoinColumn(name = "FDOC_NBR", referencedColumnName = "FDOC_NBR", insertable = false, updatable = false), 
91          @JoinColumn(name = "ROLE_ID", referencedColumnName = "ROLE_ID", insertable = false, updatable = false) })
92      protected List<KimDocumentRoleMember> rolePrncpls;
93  
94      @Transient
95      protected KimDocumentRoleMember newRolePrncpl;
96  
97      @Transient
98      protected boolean isEditable = true;
99  
100     public PersonDocumentRole() {
101         attributes = new ArrayList<KimAttributes>();
102         rolePrncpls = new ArrayList<KimDocumentRoleMember>();
103         attributeEntry = new HashMap<String, Object>();
104     }
105 
106     public String getRoleId() {
107         return this.roleId;
108     }
109 
110     public void setRoleId(String roleId) {
111         this.roleId = roleId;
112     }
113 
114     public String getKimTypeId() {
115         return this.kimTypeId;
116     }
117 
118     public void setKimTypeId(String kimTypeId) {
119         this.kimTypeId = kimTypeId;
120     }
121 
122     public String getRoleName() {
123         return this.roleName;
124     }
125 
126     public void setRoleName(String roleName) {
127         this.roleName = roleName;
128     }
129 
130     public List<? extends KimAttributes> getAttributes() {
131         return this.attributes;
132     }
133 
134     public void setAttributes(List<? extends KimAttributes> attributes) {
135         this.attributes = attributes;
136     }
137 
138     public KimTypeBo getKimRoleType() {
139         if (kimRoleType == null && StringUtils.hasText(kimTypeId)) {
140             kimRoleType = KimTypeBo.from(KimApiServiceLocator.getKimTypeInfoService().getKimType(kimTypeId));
141         }
142         return kimRoleType;
143     }
144 
145     public Map<String, KimAttributeField> getDefinitionsKeyedByAttributeName() {
146         final Map<String, KimAttributeField> map = new HashMap<String, KimAttributeField>();
147         for (KimAttributeField field : getDefinitions()) {
148             map.put(field.getAttributeField().getName(), field);
149         }
150         return map;
151     }
152 
153     public List<KimAttributeField> getDefinitions() {
154         if (definitions == null || definitions.isEmpty()) {
155             KimTypeService kimTypeService = KimFrameworkServiceLocator.getKimTypeService(KimTypeBo.to(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         return definitions;
169     }
170 
171     public void setDefinitions(List<KimAttributeField> definitions) {
172         this.definitions = definitions;
173     }
174 
175     public Map<String, Object> getAttributeEntry() {
176         if (attributeEntry == null || attributeEntry.isEmpty()) {
177             attributeEntry = KIMServiceLocatorInternal.getUiDocumentService().getAttributeEntries(getDefinitions());
178         }
179         return this.attributeEntry;
180     }
181 
182     public void setAttributeEntry(Map<String, Object> attributeEntry) {
183         this.attributeEntry = attributeEntry;
184     }
185 
186     public List<KimDocumentRoleMember> getRolePrncpls() {
187         return this.rolePrncpls;
188     }
189 
190     public void setRolePrncpls(List<KimDocumentRoleMember> rolePrncpls) {
191         this.rolePrncpls = rolePrncpls;
192     }
193 
194     public KimDocumentRoleMember getNewRolePrncpl() {
195         return this.newRolePrncpl;
196     }
197 
198     public void setNewRolePrncpl(KimDocumentRoleMember newRolePrncpl) {
199         this.newRolePrncpl = newRolePrncpl;
200     }
201 
202     public String getNamespaceCode() {
203         return this.namespaceCode;
204     }
205 
206     public void setNamespaceCode(String namespaceCode) {
207         this.namespaceCode = namespaceCode;
208     }
209 
210     /**
211 	 * @return the roleBo
212 	 */
213     public RoleBo getRoleBo() {
214         return this.roleBo;
215     }
216 
217     /**
218 	 * @param roleBo the roleBo to set
219 	 */
220     public void setRoleBo(RoleBo roleBo) {
221         this.roleBo = roleBo;
222     }
223 
224     /**
225 	 * @return the isEditable
226 	 */
227     public boolean isEditable() {
228         return this.isEditable;
229     }
230 
231     /**
232 	 * @param isEditable the isEditable to set
233 	 */
234     public void setEditable(boolean isEditable) {
235         this.isEditable = isEditable;
236     }
237 }