1 | |
package org.kuali.rice.kim.impl.identity.name |
2 | |
|
3 | |
import javax.persistence.Id |
4 | |
import javax.persistence.Column |
5 | |
import javax.persistence.ManyToOne |
6 | |
import javax.persistence.JoinColumn |
7 | |
import javax.persistence.FetchType |
8 | |
import javax.persistence.Transient |
9 | |
import org.hibernate.annotations.Type |
10 | |
import org.kuali.rice.kim.api.identity.name.EntityName |
11 | |
import org.kuali.rice.kim.api.identity.name.EntityNameContract |
12 | |
import org.kuali.rice.krad.bo.PersistableBusinessObjectBase |
13 | |
import org.kuali.rice.kim.api.identity.privacy.EntityPrivacyPreferences |
14 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator |
15 | |
import org.kuali.rice.kim.api.KimConstants |
16 | |
|
17 | |
|
18 | |
class EntityNameBo extends PersistableBusinessObjectBase implements EntityNameContract { |
19 | |
|
20 | |
@Id |
21 | |
@Column(name = "ENTITY_NM_ID") |
22 | |
String id; |
23 | |
|
24 | |
@Column(name = "ENTITY_ID") |
25 | |
String entityId; |
26 | |
|
27 | |
@Column(name = "NM_TYP_CD") |
28 | |
String nameTypeCode ; |
29 | |
|
30 | |
@Column(name = "FIRST_NM") |
31 | |
String firstName; |
32 | |
|
33 | |
@Column(name = "MIDDLE_NM") |
34 | |
String middleName; |
35 | |
|
36 | |
@Column(name = "LAST_NM") |
37 | |
String lastName; |
38 | |
|
39 | |
@Column(name = "TITLE_NM") |
40 | |
String title; |
41 | |
|
42 | |
@Column(name = "SUFFIX_NM") |
43 | |
String suffix; |
44 | |
|
45 | |
@ManyToOne(targetEntity=EntityNameTypeBo.class, fetch = FetchType.EAGER, cascade = []) |
46 | |
@JoinColumn(name = "NM_TYP_CD", insertable = false, updatable = false) |
47 | |
EntityNameTypeBo nameType; |
48 | |
|
49 | |
@Type(type="yes_no") |
50 | |
@Column(name="ACTV_IND") |
51 | |
boolean active; |
52 | |
|
53 | |
@Type(type="yes_no") |
54 | |
@Column(name="DFLT_IND") |
55 | |
boolean defaultValue; |
56 | |
|
57 | |
@Transient |
58 | |
boolean suppressName; |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
static EntityName to(EntityNameBo bo) { |
66 | 1 | if (bo == null) { return null } |
67 | 1 | return EntityName.Builder.create(bo).build() |
68 | |
} |
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
static EntityNameBo from(EntityName immutable) { |
76 | 1 | if (immutable == null) {return null} |
77 | |
|
78 | 1 | EntityNameBo bo = new EntityNameBo() |
79 | 1 | bo.id = immutable.id |
80 | 1 | bo.active = immutable.active |
81 | |
|
82 | 1 | bo.entityId = immutable.entityId |
83 | 1 | if (immutable.nameType != null) { |
84 | 0 | bo.nameTypeCode = immutable.nameType.code |
85 | |
} |
86 | 1 | bo.firstName = immutable.firstNameUnmasked |
87 | 1 | bo.lastName = immutable.lastNameUnmasked |
88 | 1 | bo.middleName = immutable.middleNameUnmasked |
89 | 1 | bo.title = immutable.titleUnmasked |
90 | 1 | bo.suffix = immutable.suffixUnmasked |
91 | |
|
92 | 1 | bo.defaultValue = immutable.defaultValue |
93 | 1 | bo.versionNumber = immutable.versionNumber |
94 | 1 | bo.objectId = immutable.objectId |
95 | |
|
96 | 1 | return bo; |
97 | |
} |
98 | |
|
99 | |
|
100 | |
@Override |
101 | |
EntityNameTypeBo getNameType() { |
102 | 1 | return this.nameType |
103 | |
} |
104 | |
|
105 | |
String getFirstName() { |
106 | 1 | if (isSuppressName()) { |
107 | 0 | return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK |
108 | |
} |
109 | 1 | return this.firstName |
110 | |
} |
111 | |
|
112 | |
String getMiddleName() { |
113 | 1 | if (isSuppressName()) { |
114 | 0 | return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK |
115 | |
} |
116 | 1 | return this.middleName |
117 | |
} |
118 | |
|
119 | |
String getLastName() { |
120 | 1 | if (isSuppressName()) { |
121 | 0 | return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK |
122 | |
} |
123 | 1 | return this.lastName |
124 | |
} |
125 | |
|
126 | |
String getTitle() { |
127 | 1 | if (isSuppressName()) { |
128 | 0 | return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK |
129 | |
} |
130 | 1 | return this.title |
131 | |
} |
132 | |
|
133 | |
|
134 | |
String getFirstNameUnmasked() { |
135 | 0 | return this.firstName |
136 | |
} |
137 | |
|
138 | |
String getMiddleNameUnmasked() { |
139 | 0 | return this.middleName |
140 | |
} |
141 | |
|
142 | |
String getLastNameUnmasked() { |
143 | 0 | return this.lastName |
144 | |
} |
145 | |
|
146 | |
String getTitleUnmasked() { |
147 | 0 | return this.title |
148 | |
} |
149 | |
|
150 | |
String getSuffixUnmasked() { |
151 | 0 | return this.suffix |
152 | |
} |
153 | |
|
154 | |
String getFormattedName() { |
155 | 0 | if (isSuppressName()) { |
156 | 0 | return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK |
157 | |
} |
158 | 0 | return getFormattedNameUnmasked() |
159 | |
} |
160 | |
|
161 | |
String getFormattedNameUnmasked() { |
162 | 0 | return getLastName() + ", " + getFirstName() + (getMiddleName()==null?"":" " + getMiddleName()) |
163 | |
} |
164 | |
|
165 | |
boolean isSuppressName() { |
166 | 5 | if (this.suppressName == null) { |
167 | 0 | EntityPrivacyPreferences privacy = KimApiServiceLocator.getIdentityService().getEntityPrivacyPreferences(getEntityId()) |
168 | 0 | if (privacy != null) { |
169 | 0 | this.suppressName = privacy.isSuppressName() |
170 | |
} else { |
171 | 0 | this.suppressName = false |
172 | |
} |
173 | |
} |
174 | 5 | return this.suppressName; |
175 | |
} |
176 | |
} |