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