1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.impl.identity.phone |
17 | |
|
18 | |
import javax.persistence.Column |
19 | |
import javax.persistence.Entity |
20 | |
import javax.persistence.FetchType |
21 | |
import javax.persistence.Id |
22 | |
import javax.persistence.JoinColumn |
23 | |
import javax.persistence.ManyToOne |
24 | |
import javax.persistence.Table |
25 | |
import javax.persistence.Transient |
26 | |
import org.apache.commons.lang.StringUtils |
27 | |
import org.hibernate.annotations.Type |
28 | |
|
29 | |
import org.kuali.rice.kim.api.identity.phone.EntityPhone |
30 | |
import org.kuali.rice.kim.api.identity.phone.EntityPhoneContract |
31 | |
import org.kuali.rice.kim.api.identity.privacy.EntityPrivacyPreferences |
32 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator |
33 | |
import org.kuali.rice.krad.bo.PersistableBusinessObjectBase |
34 | |
import org.kuali.rice.kim.api.KimApiConstants |
35 | |
|
36 | |
@Entity |
37 | |
@Table(name = "KRIM_ENTITY_PHONE_T") |
38 | |
public class EntityPhoneBo extends PersistableBusinessObjectBase implements EntityPhoneContract { |
39 | |
private static final long serialVersionUID = 1L; |
40 | |
|
41 | |
@Id |
42 | |
@Column(name = "ENTITY_PHONE_ID") |
43 | |
String id; |
44 | |
|
45 | |
@Column(name = "ENTITY_ID") |
46 | |
String entityId; |
47 | |
|
48 | |
@Column(name = "ENT_TYP_CD") |
49 | |
String entityTypeCode; |
50 | |
|
51 | |
@Column(name = "PHONE_TYP_CD") |
52 | |
String phoneTypeCode; |
53 | |
|
54 | |
@Column(name = "PHONE_NBR") |
55 | |
String phoneNumber; |
56 | |
|
57 | |
@Column(name = "PHONE_EXTN_NBR") |
58 | |
String extensionNumber; |
59 | |
|
60 | |
@Column(name = "POSTAL_CNTRY_CD") |
61 | |
String countryCode; |
62 | |
|
63 | |
@ManyToOne(targetEntity=EntityPhoneTypeBo.class, fetch = FetchType.EAGER, cascade = []) |
64 | |
@JoinColumn(name = "PHONE_TYP_CD", insertable = false, updatable = false) |
65 | |
EntityPhoneTypeBo phoneType; |
66 | |
|
67 | |
@Transient |
68 | |
boolean suppressPhone; |
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 | |
|
79 | |
public String getPhoneTypeCode(){ |
80 | 0 | return this.phoneTypeCode |
81 | |
} |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
static EntityPhone to(EntityPhoneBo bo) { |
88 | 0 | if (bo == null) { return null } |
89 | 0 | return EntityPhone.Builder.create(bo).build() |
90 | |
} |
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
static EntityPhoneBo from(EntityPhone immutable) { |
98 | 0 | if (immutable == null) {return null} |
99 | |
|
100 | 0 | EntityPhoneBo bo = new EntityPhoneBo() |
101 | 0 | bo.id = immutable.id |
102 | 0 | bo.active = immutable.active |
103 | |
|
104 | 0 | bo.entityId = immutable.entityId |
105 | 0 | bo.entityTypeCode = immutable.entityTypeCode |
106 | 0 | if (immutable.phoneType != null) { |
107 | 0 | bo.phoneTypeCode = immutable.phoneType.code |
108 | |
} |
109 | 0 | bo.phoneType = EntityPhoneTypeBo.from(immutable.phoneType) |
110 | 0 | bo.defaultValue = immutable.defaultValue |
111 | 0 | bo.countryCode = immutable.countryCodeUnmasked |
112 | 0 | bo.phoneNumber = immutable.phoneNumberUnmasked |
113 | 0 | bo.extensionNumber = immutable.extensionNumberUnmasked |
114 | 0 | bo.versionNumber = immutable.versionNumber |
115 | 0 | bo.objectId = immutable.objectId |
116 | |
|
117 | 0 | return bo; |
118 | |
} |
119 | |
|
120 | |
@Override |
121 | |
EntityPhoneTypeBo getPhoneType() { |
122 | 0 | return this.phoneType |
123 | |
} |
124 | |
|
125 | |
public void setPhoneType(EntityPhoneTypeBo phoneType) { |
126 | 0 | this.phoneType = phoneType |
127 | |
} |
128 | |
|
129 | |
@Override |
130 | |
boolean isSuppressPhone() { |
131 | 0 | if (this.suppressPhone == null) { |
132 | 0 | EntityPrivacyPreferences privacy = KimApiServiceLocator.getIdentityService().getEntityPrivacyPreferences(getEntityId()) |
133 | 0 | if (privacy != null) { |
134 | 0 | this.suppressPhone = privacy.isSuppressPhone() |
135 | |
} else { |
136 | 0 | this.suppressPhone = false |
137 | |
} |
138 | |
} |
139 | |
|
140 | 0 | return this.suppressPhone; |
141 | |
} |
142 | |
|
143 | |
@Override |
144 | |
String getFormattedPhoneNumber() { |
145 | 0 | if (isSuppressPhone()) { |
146 | 0 | return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK |
147 | |
} |
148 | 0 | return getFormattedPhoneNumberUnmasked() |
149 | |
} |
150 | |
|
151 | |
@Override |
152 | |
String getPhoneNumberUnmasked() { |
153 | 0 | return this.phoneNumber |
154 | |
} |
155 | |
|
156 | |
@Override |
157 | |
String getExtensionNumberUnmasked() { |
158 | 0 | return this.extensionNumber |
159 | |
} |
160 | |
|
161 | |
@Override |
162 | |
String getCountryCodeUnmasked() { |
163 | 0 | return this.countryCode |
164 | |
} |
165 | |
|
166 | |
@Override |
167 | |
String getFormattedPhoneNumberUnmasked() { |
168 | 0 | StringBuffer sb = new StringBuffer( 30 ) |
169 | |
|
170 | |
|
171 | |
|
172 | 0 | sb.append( this.phoneNumber ) |
173 | 0 | if ( StringUtils.isNotBlank( this.extensionNumber ) ) { |
174 | 0 | sb.append( " x" ) |
175 | 0 | sb.append( this.extensionNumber ) |
176 | |
} |
177 | |
|
178 | 0 | return sb.toString(); |
179 | |
} |
180 | |
|
181 | |
@Override |
182 | |
String getPhoneNumber() { |
183 | 0 | if (isSuppressPhone()) { |
184 | 0 | return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_PHONE |
185 | |
} |
186 | 0 | return this.phoneNumber |
187 | |
} |
188 | |
|
189 | |
@Override |
190 | |
String getCountryCode() { |
191 | 0 | if (isSuppressPhone()){ |
192 | 0 | return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE |
193 | |
} |
194 | 0 | return this.countryCode |
195 | |
} |
196 | |
|
197 | |
@Override |
198 | |
String getExtensionNumber() { |
199 | 0 | if (isSuppressPhone()) { |
200 | 0 | return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK |
201 | |
} |
202 | 0 | return this.extensionNumber |
203 | |
} |
204 | |
|
205 | |
} |