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