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