Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
EntityDefaultInfoCacheBo |
|
| 0.0;0 |
1 | /** | |
2 | * Copyright 2005-2011 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.opensource.org/licenses/ecl2.php | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | package org.kuali.rice.kim.impl.identity | |
17 | ||
18 | import java.sql.Timestamp | |
19 | import javax.persistence.Column | |
20 | import javax.persistence.Entity | |
21 | import javax.persistence.Id | |
22 | import javax.persistence.Table | |
23 | import javax.persistence.Transient | |
24 | import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliation | |
25 | import org.kuali.rice.kim.api.identity.employment.EntityEmployment | |
26 | import org.kuali.rice.kim.api.identity.entity.EntityDefault | |
27 | import org.kuali.rice.kim.api.identity.external.EntityExternalIdentifier | |
28 | import org.kuali.rice.kim.api.identity.name.EntityName | |
29 | import org.kuali.rice.kim.api.identity.principal.Principal | |
30 | import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfoDefault | |
31 | import org.kuali.rice.krad.bo.PersistableBusinessObjectBase | |
32 | ||
33 | /** | |
34 | * Used to store a cache of person information to be used if the user's information disappears from KIM. | |
35 | * | |
36 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
37 | * | |
38 | */ | |
39 | @Entity | |
40 | @Table(name="KRIM_ENTITY_CACHE_T") | |
41 | class EntityDefaultInfoCacheBo extends PersistableBusinessObjectBase { | |
42 | ||
43 | private static final long serialVersionUID = 1L; | |
44 | ||
45 | @Transient | |
46 | Long versionNumber; // prevent JPA from attempting to persist the version number attribute | |
47 | ||
48 | // principal data | |
49 | @Id | |
50 | @Column(name="PRNCPL_ID") | |
51 | String principalId; | |
52 | @Column(name="PRNCPL_NM") | |
53 | String principalName; | |
54 | @Column(name="ENTITY_ID") | |
55 | String entityId; | |
56 | @Column(name="ENTITY_TYP_CD") | |
57 | String entityTypeCode; | |
58 | ||
59 | // name data | |
60 | @Column(name="FIRST_NM") | |
61 | String firstName = ""; | |
62 | @Column(name="MIDDLE_NM") | |
63 | String middleName = ""; | |
64 | @Column(name="LAST_NM") | |
65 | String lastName = ""; | |
66 | @Column(name="PRSN_NM") | |
67 | String name = ""; | |
68 | ||
69 | @Column(name="CAMPUS_CD") | |
70 | String campusCode = ""; | |
71 | ||
72 | // employment data | |
73 | @Column(name="PRMRY_DEPT_CD") | |
74 | String primaryDepartmentCode = ""; | |
75 | @Column(name="EMP_ID") | |
76 | String employeeId = ""; | |
77 | ||
78 | @Column(name="LAST_UPDT_TS") | |
79 | Timestamp lastUpdateTimestamp; | |
80 | ||
81 | EntityDefaultInfoCacheBo() { | |
82 | } | |
83 | ||
84 | EntityDefaultInfoCacheBo(EntityDefault entity) { | |
85 | 0 | if ( entity != null ) { |
86 | 0 | entityId = entity.getEntityId(); |
87 | 0 | if ( entity.getPrincipals() != null && !entity.getPrincipals().isEmpty() ) { |
88 | 0 | principalId = entity.getPrincipals().get(0).getPrincipalId(); |
89 | 0 | principalName = entity.getPrincipals().get(0).getPrincipalName(); |
90 | } | |
91 | 0 | if ( entity.getEntityTypeContactInfos() != null && !entity.getEntityTypeContactInfos().isEmpty() ) { |
92 | 0 | entityTypeCode = entity.getEntityTypeContactInfos().get(0).getEntityTypeCode(); |
93 | } | |
94 | 0 | if ( entity.getName() != null ) { |
95 | 0 | firstName = entity.getName().getFirstNameUnmasked(); |
96 | 0 | middleName = entity.getName().getMiddleNameUnmasked(); |
97 | 0 | lastName = entity.getName().getLastNameUnmasked(); |
98 | 0 | name = entity.getName().getCompositeNameUnmasked(); |
99 | } | |
100 | 0 | if ( entity.getDefaultAffiliation() != null ) { |
101 | 0 | campusCode = entity.getDefaultAffiliation().getCampusCode(); |
102 | } | |
103 | 0 | if ( entity.getEmployment() != null ) { |
104 | 0 | primaryDepartmentCode = entity.getEmployment().getPrimaryDepartmentCode(); |
105 | 0 | employeeId = entity.getEmployment().getEmployeeId(); |
106 | } | |
107 | } | |
108 | } | |
109 | ||
110 | @SuppressWarnings("unchecked") | |
111 | EntityDefault convertCacheToEntityDefaultInfo() { | |
112 | 0 | EntityDefault.Builder info = EntityDefault.Builder.create(this.entityId); |
113 | ||
114 | // identity info | |
115 | 0 | info.setActive( this.isActive() ); |
116 | ||
117 | // principal info | |
118 | 0 | Principal.Builder principalInfo = Principal.Builder.create(this.getPrincipalName()); |
119 | 0 | principalInfo.setEntityId(this.getEntityId()); |
120 | 0 | principalInfo.setPrincipalId(this.getPrincipalId()); |
121 | 0 | principalInfo.setActive(this.isActive()); |
122 | 0 | info.setPrincipals(Collections.singletonList(principalInfo)); |
123 | ||
124 | // name info | |
125 | 0 | EntityName.Builder nameInfo = EntityName.Builder.create(); |
126 | 0 | nameInfo.setEntityId( this.getEntityId()); |
127 | 0 | nameInfo.setFirstName( this.getFirstName() ); |
128 | 0 | nameInfo.setLastName( this.getLastName() ); |
129 | 0 | nameInfo.setMiddleName( this.getMiddleName() ); |
130 | 0 | info.setName(nameInfo); |
131 | ||
132 | // identity type information | |
133 | 0 | EntityTypeContactInfoDefault.Builder entityTypeInfo = EntityTypeContactInfoDefault.Builder.create(); |
134 | 0 | entityTypeInfo.setEntityTypeCode(this.getEntityTypeCode()); |
135 | 0 | info.setEntityTypeContactInfos(Collections.singletonList(entityTypeInfo)); |
136 | ||
137 | // affiliations | |
138 | 0 | EntityAffiliation.Builder aff = EntityAffiliation.Builder.create(); |
139 | 0 | aff.setCampusCode(this.getCampusCode()); |
140 | 0 | aff.setDefaultValue(true); |
141 | 0 | aff.setEntityId(info.getEntityId()); |
142 | 0 | info.setDefaultAffiliation(aff); |
143 | 0 | info.setAffiliations(Collections.singletonList(aff)); |
144 | ||
145 | // employment information | |
146 | 0 | EntityEmployment.Builder empInfo = EntityEmployment.Builder.create(); |
147 | 0 | empInfo.setEmployeeId( this.getEmployeeId() ); |
148 | 0 | empInfo.setPrimary(true); |
149 | 0 | empInfo.setPrimaryDepartmentCode(this.getPrimaryDepartmentCode()); |
150 | 0 | info.setEmployment(empInfo); |
151 | ||
152 | // external identifiers | |
153 | 0 | info.setExternalIdentifiers( Collections.singletonList(EntityExternalIdentifier.Builder.create()) ); |
154 | 0 | return info.build(); |
155 | ||
156 | } | |
157 | ||
158 | // handle automatic updating of the timestamp | |
159 | ||
160 | @Override | |
161 | protected void prePersist() { | |
162 | 0 | super.prePersist(); |
163 | 0 | lastUpdateTimestamp = new Timestamp(System.currentTimeMillis()); |
164 | } | |
165 | ||
166 | @Override | |
167 | protected void preUpdate() { | |
168 | 0 | super.preUpdate(); |
169 | 0 | lastUpdateTimestamp = new Timestamp(System.currentTimeMillis()); |
170 | } | |
171 | ||
172 | boolean isActive() { | |
173 | 0 | return false; |
174 | } | |
175 | ||
176 | } |