1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 import org.springframework.util.StringUtils;
32
33 import javax.persistence.CascadeType;
34 import javax.persistence.Column;
35 import javax.persistence.Entity;
36 import javax.persistence.FetchType;
37 import javax.persistence.Id;
38 import javax.persistence.IdClass;
39 import javax.persistence.JoinColumn;
40 import javax.persistence.JoinColumns;
41 import javax.persistence.ManyToMany;
42 import javax.persistence.OneToMany;
43 import javax.persistence.Table;
44 import javax.persistence.Transient;
45 import javax.persistence.UniqueConstraint;
46 import java.util.ArrayList;
47 import java.util.Collections;
48 import java.util.HashMap;
49 import java.util.List;
50 import java.util.Map;
51
52
53
54
55
56
57
58
59 @Entity
60 @IdClass(org.kuali.rice.kim.bo.ui.PersonDocumentRoleId.class)
61 @Table(name="KRIM_PND_ROLE_MT",uniqueConstraints=@UniqueConstraint(columnNames={"FDOC_NBR", "ROLE_ID"}))
62 public class PersonDocumentRole extends KimDocumentBoActivatableEditableBase {
63 private static final Logger LOG = Logger.getLogger(PersonDocumentRole.class);
64 private static final long serialVersionUID = 4908044213007222739L;
65 @Id
66 @Column(name="ROLE_ID")
67 protected String roleId;
68 @Column(name="KIM_TYP_ID")
69 protected String kimTypeId;
70 @Column(name="ROLE_NM")
71 protected String roleName;
72 @Transient
73 protected RoleBo roleBo;
74 @Column(name="NMSPC_CD")
75 protected String namespaceCode;
76 @Transient
77 protected KimTypeBo kimRoleType;
78 @Transient
79 protected List<? extends KimAttributes> attributes;
80 @Transient
81 protected transient List<KimAttributeField> definitions;
82 @Transient
83 protected transient Map<String,Object> attributeEntry;
84 @OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.ALL})
85 @Fetch(value = FetchMode.SELECT)
86 @JoinColumns({
87 @JoinColumn(name="ROLE_ID",insertable=false,updatable=false),
88 @JoinColumn(name="FDOC_NBR", insertable=false, updatable=false)
89 })
90 protected List<KimDocumentRoleMember> rolePrncpls;
91 @Transient
92 protected KimDocumentRoleMember newRolePrncpl;
93
94
95
96 @ManyToMany(fetch=FetchType.EAGER, cascade={CascadeType.ALL})
97 @Fetch(value = FetchMode.SELECT)
98 @JoinColumn(name="ROLE_ID",insertable=false,updatable=false)
99
100
101
102
103 protected List<RoleResponsibilityBo> assignedResponsibilities = new AutoPopulatingList(RoleResponsibilityBo.class);
104
105 @Transient
106 protected boolean isEditable = true;
107
108 public PersonDocumentRole() {
109 attributes = new ArrayList<KimAttributes>();
110 rolePrncpls = new ArrayList<KimDocumentRoleMember>();
111 attributeEntry = new HashMap<String,Object>();
112 }
113
114 public String getRoleId() {
115 return this.roleId;
116 }
117
118 public void setRoleId(String roleId) {
119 this.roleId = roleId;
120 }
121
122 public String getKimTypeId() {
123 return this.kimTypeId;
124 }
125
126 public void setKimTypeId(String kimTypeId) {
127 this.kimTypeId = kimTypeId;
128 }
129
130 public String getRoleName() {
131 return this.roleName;
132 }
133
134 public void setRoleName(String roleName) {
135 this.roleName = roleName;
136 }
137
138 public List<? extends KimAttributes> getAttributes() {
139 return this.attributes;
140 }
141
142 public void setAttributes(List<? extends KimAttributes> attributes) {
143 this.attributes = attributes;
144 }
145
146 public KimTypeBo getKimRoleType() {
147 if ( kimRoleType == null && StringUtils.hasText(kimTypeId)) {
148 kimRoleType = KimTypeBo.from(KimApiServiceLocator.getKimTypeInfoService().getKimType(kimTypeId));
149 }
150 return kimRoleType;
151 }
152
153 public Map<String, KimAttributeField> getDefinitionsKeyedByAttributeName() {
154 final Map<String, KimAttributeField> map = new HashMap<String, KimAttributeField>();
155 for (KimAttributeField field : getDefinitions()) {
156 map.put(field.getAttributeField().getName(), field);
157 }
158 return map;
159 }
160
161 public List<KimAttributeField> getDefinitions() {
162 if (definitions == null || definitions.isEmpty()) {
163 KimTypeService kimTypeService = KimFrameworkServiceLocator.getKimTypeService(KimTypeBo.to(
164 this.getKimRoleType()));
165
166
167 try {
168 if ( kimTypeService != null ) {
169 definitions = kimTypeService.getAttributeDefinitions(getKimTypeId());
170 } else {
171 definitions = Collections.emptyList();
172 }
173 } catch (Exception ex) {
174 LOG.warn("Not able to retrieve KimTypeService from remote system for KIM Role Type: " + this.getKimRoleType(), ex);
175 }
176 }
177
178 return definitions;
179 }
180
181 public void setDefinitions(List<KimAttributeField> definitions) {
182 this.definitions = definitions;
183 }
184
185 public Map<String,Object> getAttributeEntry() {
186 if (attributeEntry == null || attributeEntry.isEmpty()) {
187 attributeEntry = KIMServiceLocatorInternal.getUiDocumentService().getAttributeEntries(getDefinitions());
188 }
189
190 return this.attributeEntry;
191 }
192
193 public void setAttributeEntry(Map<String,Object> attributeEntry) {
194 this.attributeEntry = attributeEntry;
195 }
196
197 public List<KimDocumentRoleMember> getRolePrncpls() {
198 return this.rolePrncpls;
199 }
200
201 public void setRolePrncpls(List<KimDocumentRoleMember> rolePrncpls) {
202 this.rolePrncpls = rolePrncpls;
203 }
204
205 public KimDocumentRoleMember getNewRolePrncpl() {
206 return this.newRolePrncpl;
207 }
208
209 public void setNewRolePrncpl(KimDocumentRoleMember newRolePrncpl) {
210 this.newRolePrncpl = newRolePrncpl;
211 }
212
213 public String getNamespaceCode() {
214 return this.namespaceCode;
215 }
216
217 public void setNamespaceCode(String namespaceCode) {
218 this.namespaceCode = namespaceCode;
219 }
220
221 public List<RoleResponsibilityBo> getAssignedResponsibilities() {
222 return this.assignedResponsibilities;
223 }
224
225 public void setAssignedResponsibilities(
226 List<RoleResponsibilityBo> assignedResponsibilities) {
227 this.assignedResponsibilities = assignedResponsibilities;
228 }
229
230
231
232
233 public RoleBo getRoleBo() {
234 return this.roleBo;
235 }
236
237
238
239
240 public void setRoleBo(RoleBo roleBo) {
241 this.roleBo = roleBo;
242 }
243
244
245
246
247 public boolean isEditable() {
248 return this.isEditable;
249 }
250
251
252
253
254 public void setEditable(boolean isEditable) {
255 this.isEditable = isEditable;
256 }
257
258 }