1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.impl.identity;
17
18 import java.sql.Timestamp;
19 import java.util.Collections;
20 import java.util.UUID;
21
22 import javax.persistence.Column;
23 import javax.persistence.Entity;
24 import javax.persistence.Id;
25 import javax.persistence.PrePersist;
26 import javax.persistence.PreUpdate;
27 import javax.persistence.Table;
28
29 import org.apache.commons.lang.StringUtils;
30 import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliation;
31 import org.kuali.rice.kim.api.identity.employment.EntityEmployment;
32 import org.kuali.rice.kim.api.identity.entity.EntityDefault;
33 import org.kuali.rice.kim.api.identity.external.EntityExternalIdentifier;
34 import org.kuali.rice.kim.api.identity.name.EntityName;
35 import org.kuali.rice.kim.api.identity.principal.Principal;
36 import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfoDefault;
37
38
39
40
41
42
43 @Entity
44 @Table(name = "KRIM_ENTITY_CACHE_T")
45 public class EntityDefaultInfoCacheBo {
46
47 private static final String UNAVAILABLE = "Unavailable";
48
49 @Id
50 @Column(name = "PRNCPL_ID")
51 private String principalId;
52
53 @Column(name = "PRNCPL_NM")
54 private String principalName;
55
56 @Column(name = "ENTITY_ID")
57 private String entityId;
58
59 @Column(name = "ENTITY_TYP_CD")
60 private String entityTypeCode;
61
62 @Column(name = "FIRST_NM")
63 private String firstName = "";
64
65 @Column(name = "MIDDLE_NM")
66 private String middleName = "";
67
68 @Column(name = "LAST_NM")
69 private String lastName = "";
70
71 @Column(name = "PRSN_NM")
72 private String name = "";
73
74 @Column(name = "CAMPUS_CD")
75 private String campusCode = "";
76
77 @Column(name = "PRMRY_DEPT_CD")
78 private String primaryDepartmentCode = "";
79
80 @Column(name = "EMP_ID")
81 private String employeeId = "";
82
83 @Column(name = "LAST_UPDT_TS")
84 private Timestamp lastUpdateTimestamp;
85
86 @Column(name="OBJ_ID", length=36, unique=true, nullable = false)
87 protected String objectId;
88
89 public EntityDefaultInfoCacheBo() {
90 }
91
92 public EntityDefaultInfoCacheBo(EntityDefault entity) {
93 if (entity != null) {
94 entityId = entity.getEntityId();
95 if (entity.getPrincipals() != null && !entity.getPrincipals().isEmpty()) {
96 principalId = entity.getPrincipals().get(0).getPrincipalId();
97 if (entity.getPrincipals().get(0).getPrincipalName() != null) {
98 principalName = entity.getPrincipals().get(0).getPrincipalName();
99 } else {
100 principalName = UNAVAILABLE;
101 }
102 }
103 if (entity.getEntityTypeContactInfos() != null && !entity.getEntityTypeContactInfos().isEmpty()) {
104 entityTypeCode = entity.getEntityTypeContactInfos().get(0).getEntityTypeCode();
105 }
106 if (entity.getName() != null) {
107 firstName = entity.getName().getFirstNameUnmasked();
108 middleName = entity.getName().getMiddleNameUnmasked();
109 lastName = entity.getName().getLastNameUnmasked();
110 name = entity.getName().getCompositeNameUnmasked();
111 }
112 if (entity.getDefaultAffiliation() != null) {
113 campusCode = entity.getDefaultAffiliation().getCampusCode();
114 }
115 if (entity.getEmployment() != null) {
116 primaryDepartmentCode = entity.getEmployment().getPrimaryDepartmentCode();
117 employeeId = entity.getEmployment().getEmployeeId();
118 }
119 }
120 }
121
122 public EntityDefault convertCacheToEntityDefaultInfo() {
123 EntityDefault.Builder info = EntityDefault.Builder.create(this.entityId);
124
125 info.setActive(this.isActive());
126
127 Principal.Builder principalInfo = null;
128 if (this.getPrincipalName() != null) {
129 principalInfo = Principal.Builder.create(this.getPrincipalName());
130 } else {
131 principalInfo = Principal.Builder.create(UNAVAILABLE);
132 }
133 principalInfo.setEntityId(this.getEntityId());
134 principalInfo.setPrincipalId(this.getPrincipalId());
135 principalInfo.setActive(this.isActive());
136 info.setPrincipals(Collections.singletonList(principalInfo));
137
138 EntityName.Builder nameInfo = EntityName.Builder.create();
139 nameInfo.setEntityId(this.getEntityId());
140 nameInfo.setFirstName(this.getFirstName());
141 nameInfo.setLastName(this.getLastName());
142 nameInfo.setMiddleName(this.getMiddleName());
143 info.setName(nameInfo);
144
145 EntityTypeContactInfoDefault.Builder entityTypeInfo = EntityTypeContactInfoDefault.Builder.create();
146 entityTypeInfo.setEntityTypeCode(this.getEntityTypeCode());
147 info.setEntityTypeContactInfos(Collections.singletonList(entityTypeInfo));
148
149 EntityAffiliation.Builder aff = EntityAffiliation.Builder.create();
150 aff.setCampusCode(this.getCampusCode());
151 aff.setDefaultValue(true);
152 aff.setEntityId(info.getEntityId());
153 info.setDefaultAffiliation(aff);
154 info.setAffiliations(Collections.singletonList(aff));
155
156 EntityEmployment.Builder empInfo = EntityEmployment.Builder.create();
157 empInfo.setEmployeeId(this.getEmployeeId());
158 empInfo.setPrimary(true);
159 empInfo.setPrimaryDepartmentCode(this.getPrimaryDepartmentCode());
160 info.setEmployment(empInfo);
161
162 info.setExternalIdentifiers(Collections.singletonList(EntityExternalIdentifier.Builder.create()));
163 return info.build();
164 }
165
166 @PrePersist
167 protected void prePersist() {
168 if (StringUtils.isEmpty(getObjectId())) {
169 setObjectId(UUID.randomUUID().toString());
170 }
171
172 lastUpdateTimestamp = new Timestamp(System.currentTimeMillis());
173 }
174 @PreUpdate
175 protected void preUpdate() {
176 if (StringUtils.isEmpty(getObjectId())) {
177 setObjectId(UUID.randomUUID().toString());
178 }
179
180 lastUpdateTimestamp = new Timestamp(System.currentTimeMillis());
181 }
182
183 public boolean isActive() {
184 return false;
185 }
186
187 public String getPrincipalId() {
188 return principalId;
189 }
190
191 public void setPrincipalId(String principalId) {
192 this.principalId = principalId;
193 }
194
195 public String getPrincipalName() {
196 return principalName;
197 }
198
199 public void setPrincipalName(String principalName) {
200 this.principalName = principalName;
201 }
202
203 public String getEntityId() {
204 return entityId;
205 }
206
207 public void setEntityId(String entityId) {
208 this.entityId = entityId;
209 }
210
211 public String getEntityTypeCode() {
212 return entityTypeCode;
213 }
214
215 public void setEntityTypeCode(String entityTypeCode) {
216 this.entityTypeCode = entityTypeCode;
217 }
218
219 public String getFirstName() {
220 return firstName;
221 }
222
223 public void setFirstName(String firstName) {
224 this.firstName = firstName;
225 }
226
227 public String getMiddleName() {
228 return middleName;
229 }
230
231 public void setMiddleName(String middleName) {
232 this.middleName = middleName;
233 }
234
235 public String getLastName() {
236 return lastName;
237 }
238
239 public void setLastName(String lastName) {
240 this.lastName = lastName;
241 }
242
243 public String getName() {
244 return name;
245 }
246
247 public void setName(String name) {
248 this.name = name;
249 }
250
251 public String getCampusCode() {
252 return campusCode;
253 }
254
255 public void setCampusCode(String campusCode) {
256 this.campusCode = campusCode;
257 }
258
259 public String getPrimaryDepartmentCode() {
260 return primaryDepartmentCode;
261 }
262
263 public void setPrimaryDepartmentCode(String primaryDepartmentCode) {
264 this.primaryDepartmentCode = primaryDepartmentCode;
265 }
266
267 public String getEmployeeId() {
268 return employeeId;
269 }
270
271 public void setEmployeeId(String employeeId) {
272 this.employeeId = employeeId;
273 }
274
275 public Timestamp getLastUpdateTimestamp() {
276 return lastUpdateTimestamp;
277 }
278
279 public void setLastUpdateTimestamp(Timestamp lastUpdateTimestamp) {
280 this.lastUpdateTimestamp = lastUpdateTimestamp;
281 }
282
283
284
285
286 public String getObjectId() {
287 return this.objectId;
288 }
289
290
291
292
293 public void setObjectId(String objectId) {
294 this.objectId = objectId;
295 }
296 }