1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.impl.identity.name |
17 | |
|
18 | |
import javax.persistence.Id |
19 | |
import javax.persistence.Column |
20 | |
import javax.persistence.ManyToOne |
21 | |
import javax.persistence.JoinColumn |
22 | |
import javax.persistence.FetchType |
23 | |
import javax.persistence.Transient |
24 | |
import org.hibernate.annotations.Type |
25 | |
import org.kuali.rice.kim.api.identity.name.EntityName |
26 | |
import org.kuali.rice.kim.api.identity.name.EntityNameContract |
27 | |
import org.kuali.rice.krad.bo.PersistableBusinessObjectBase |
28 | |
import org.kuali.rice.kim.api.identity.privacy.EntityPrivacyPreferences |
29 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator |
30 | |
|
31 | |
import org.kuali.rice.kim.api.KimApiConstants |
32 | |
import java.sql.Timestamp |
33 | |
import org.joda.time.DateTime |
34 | |
|
35 | |
|
36 | |
class EntityNameBo extends PersistableBusinessObjectBase implements EntityNameContract { |
37 | |
|
38 | |
@Id |
39 | |
@Column(name = "ENTITY_NM_ID") |
40 | |
String id; |
41 | |
|
42 | |
@Column(name = "ENTITY_ID") |
43 | |
String entityId; |
44 | |
|
45 | |
@Column(name = "NM_TYP_CD") |
46 | |
String nameCode; |
47 | |
|
48 | |
@Column(name = "FIRST_NM") |
49 | |
String firstName; |
50 | |
|
51 | |
@Column(name = "MIDDLE_NM") |
52 | |
String middleName; |
53 | |
|
54 | |
@Column(name = "LAST_NM") |
55 | |
String lastName; |
56 | |
|
57 | |
@Column(name = "PREFIX_NM") |
58 | |
String namePrefix; |
59 | |
|
60 | |
@Column(name = "TITLE_NM") |
61 | |
String nameTitle; |
62 | |
|
63 | |
@Column(name = "SUFFIX_NM") |
64 | |
String nameSuffix; |
65 | |
|
66 | |
@ManyToOne(targetEntity=EntityNameTypeBo.class, fetch = FetchType.EAGER, cascade = []) |
67 | |
@JoinColumn(name = "NM_TYP_CD", insertable = false, updatable = false) |
68 | |
EntityNameTypeBo nameType; |
69 | |
|
70 | |
@Type(type="yes_no") |
71 | |
@Column(name="ACTV_IND") |
72 | |
boolean active; |
73 | |
|
74 | |
@Type(type="yes_no") |
75 | |
@Column(name="DFLT_IND") |
76 | |
boolean defaultValue; |
77 | |
|
78 | |
@Column(name = "NOTE_MSG") |
79 | |
String noteMessage; |
80 | |
|
81 | |
@Column(name = "NM_CHNG_DT") |
82 | |
Timestamp nameChangedDate; |
83 | |
|
84 | |
@Transient |
85 | |
boolean suppressName; |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
static EntityName to(EntityNameBo bo) { |
93 | 0 | if (bo == null) { return null } |
94 | 0 | return EntityName.Builder.create(bo).build() |
95 | |
} |
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
static EntityNameBo from(EntityName immutable) { |
103 | 0 | if (immutable == null) {return null} |
104 | |
|
105 | 0 | EntityNameBo bo = new EntityNameBo() |
106 | 0 | bo.id = immutable.id |
107 | 0 | bo.active = immutable.active |
108 | |
|
109 | 0 | bo.entityId = immutable.entityId |
110 | 0 | if (immutable.nameType != null) { |
111 | 0 | bo.nameCode = immutable.nameType.code |
112 | |
} |
113 | 0 | bo.firstName = immutable.firstNameUnmasked |
114 | 0 | bo.lastName = immutable.lastNameUnmasked |
115 | 0 | bo.middleName = immutable.middleNameUnmasked |
116 | 0 | bo.namePrefix = immutable.namePrefixUnmasked |
117 | 0 | bo.nameTitle = immutable.nameTitleUnmasked |
118 | 0 | bo.nameSuffix = immutable.nameSuffixUnmasked |
119 | 0 | bo.noteMessage = immutable.noteMessage |
120 | 0 | if (immutable.nameChangedDate != null) { |
121 | 0 | bo.nameChangedDate = new Timestamp(immutable.nameChangedDate.millis); |
122 | |
} |
123 | |
|
124 | 0 | bo.defaultValue = immutable.defaultValue |
125 | 0 | bo.versionNumber = immutable.versionNumber |
126 | 0 | bo.objectId = immutable.objectId |
127 | |
|
128 | 0 | return bo; |
129 | |
} |
130 | |
|
131 | |
|
132 | |
@Override |
133 | |
EntityNameTypeBo getNameType() { |
134 | 0 | return this.nameType |
135 | |
} |
136 | |
|
137 | |
String getFirstName() { |
138 | 0 | if (isSuppressName()) { |
139 | 0 | return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK |
140 | |
} |
141 | 0 | return this.firstName |
142 | |
} |
143 | |
|
144 | |
String getMiddleName() { |
145 | 0 | if (isSuppressName()) { |
146 | 0 | return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK |
147 | |
} |
148 | 0 | return this.middleName |
149 | |
} |
150 | |
|
151 | |
String getLastName() { |
152 | 0 | if (isSuppressName()) { |
153 | 0 | return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK |
154 | |
} |
155 | 0 | return this.lastName |
156 | |
} |
157 | |
|
158 | |
String getNamePrefix() { |
159 | 0 | if (isSuppressName()) { |
160 | 0 | return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK |
161 | |
} |
162 | 0 | return this.namePrefix |
163 | |
} |
164 | |
|
165 | |
String getNameTitle() { |
166 | 0 | if (isSuppressName()) { |
167 | 0 | return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK |
168 | |
} |
169 | 0 | return this.nameTitle |
170 | |
} |
171 | |
|
172 | |
String getFirstNameUnmasked() { |
173 | 0 | return this.firstName |
174 | |
} |
175 | |
|
176 | |
String getMiddleNameUnmasked() { |
177 | 0 | return this.middleName |
178 | |
} |
179 | |
|
180 | |
String getLastNameUnmasked() { |
181 | 0 | return this.lastName |
182 | |
} |
183 | |
|
184 | |
String getNamePrefixUnmasked() { |
185 | 0 | return this.namePrefix |
186 | |
} |
187 | |
|
188 | |
String getNameTitleUnmasked() { |
189 | 0 | return this.nameTitle |
190 | |
} |
191 | |
|
192 | |
String getNameSuffixUnmasked() { |
193 | 0 | return this.nameSuffix |
194 | |
} |
195 | |
|
196 | |
String getCompositeName() { |
197 | 0 | if (isSuppressName()) { |
198 | 0 | return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK |
199 | |
} |
200 | 0 | return getCompositeNameUnmasked() |
201 | |
} |
202 | |
|
203 | |
String getCompositeNameUnmasked() { |
204 | 0 | return getLastName() + ", " + getFirstName() + (getMiddleName()==null?"":" " + getMiddleName()) |
205 | |
} |
206 | |
|
207 | |
DateTime getNameChangedDate() { |
208 | 0 | return nameChangedDate ? new DateTime(nameChangedDate.time) : null |
209 | |
} |
210 | |
|
211 | |
boolean isSuppressName() { |
212 | 0 | if (this.suppressName == null) { |
213 | 0 | EntityPrivacyPreferences privacy = KimApiServiceLocator.getIdentityService().getEntityPrivacyPreferences(getEntityId()) |
214 | 0 | if (privacy != null) { |
215 | 0 | this.suppressName = privacy.isSuppressName() |
216 | |
} else { |
217 | 0 | this.suppressName = false |
218 | |
} |
219 | |
} |
220 | 0 | return this.suppressName; |
221 | |
} |
222 | |
} |