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 List<KimAttributeField> getDefinitions() {
154 if (definitions == null || definitions.isEmpty()) {
155 KimTypeService kimTypeService = KimFrameworkServiceLocator.getKimTypeService(KimTypeBo.to(
156 this.getKimRoleType()));
157
158
159 try {
160 if ( kimTypeService != null ) {
161 definitions = kimTypeService.getAttributeDefinitions(getKimTypeId());
162 } else {
163 definitions = Collections.emptyList();
164 }
165 } catch (Exception ex) {
166 LOG.warn("Not able to retrieve KimTypeService from remote system for KIM Role Type: " + this.getKimRoleType(), ex);
167 }
168 }
169
170 return definitions;
171 }
172
173 public void setDefinitions(List<KimAttributeField> definitions) {
174 this.definitions = definitions;
175 }
176
177 public Map<String,Object> getAttributeEntry() {
178 if (attributeEntry == null || attributeEntry.isEmpty()) {
179 attributeEntry = KIMServiceLocatorInternal.getUiDocumentService().getAttributeEntries(getDefinitions());
180 }
181
182 return this.attributeEntry;
183 }
184
185 public void setAttributeEntry(Map<String,Object> attributeEntry) {
186 this.attributeEntry = attributeEntry;
187 }
188
189 public List<KimDocumentRoleMember> getRolePrncpls() {
190 return this.rolePrncpls;
191 }
192
193 public void setRolePrncpls(List<KimDocumentRoleMember> rolePrncpls) {
194 this.rolePrncpls = rolePrncpls;
195 }
196
197 public KimDocumentRoleMember getNewRolePrncpl() {
198 return this.newRolePrncpl;
199 }
200
201 public void setNewRolePrncpl(KimDocumentRoleMember newRolePrncpl) {
202 this.newRolePrncpl = newRolePrncpl;
203 }
204
205 public String getNamespaceCode() {
206 return this.namespaceCode;
207 }
208
209 public void setNamespaceCode(String namespaceCode) {
210 this.namespaceCode = namespaceCode;
211 }
212
213 public List<RoleResponsibilityBo> getAssignedResponsibilities() {
214 return this.assignedResponsibilities;
215 }
216
217 public void setAssignedResponsibilities(
218 List<RoleResponsibilityBo> assignedResponsibilities) {
219 this.assignedResponsibilities = assignedResponsibilities;
220 }
221
222
223
224
225 public RoleBo getRoleBo() {
226 return this.roleBo;
227 }
228
229
230
231
232 public void setRoleBo(RoleBo roleBo) {
233 this.roleBo = roleBo;
234 }
235
236
237
238
239 public boolean isEditable() {
240 return this.isEditable;
241 }
242
243
244
245
246 public void setEditable(boolean isEditable) {
247 this.isEditable = isEditable;
248 }
249
250 }