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 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
static EntityPhone to(EntityPhoneBo bo) { |
68 | 1 | if (bo == null) { return null } |
69 | 1 | return EntityPhone.Builder.create(bo).build() |
70 | |
} |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
static EntityPhoneBo from(EntityPhone immutable) { |
78 | 1 | if (immutable == null) {return null} |
79 | |
|
80 | 1 | EntityPhoneBo bo = new EntityPhoneBo() |
81 | 1 | bo.id = immutable.id |
82 | 1 | bo.active = immutable.active |
83 | |
|
84 | 1 | bo.entityId = immutable.entityId |
85 | 1 | bo.entityTypeCode = immutable.entityTypeCode |
86 | 1 | if (immutable.phoneType != null) { |
87 | 0 | bo.phoneTypeCode = immutable.phoneType.code |
88 | |
} |
89 | 1 | bo.phoneType = EntityPhoneTypeBo.from(immutable.phoneType) |
90 | 1 | bo.defaultValue = immutable.defaultValue |
91 | 1 | bo.countryCode = immutable.countryCodeUnmasked |
92 | 1 | bo.phoneNumber = immutable.phoneNumberUnmasked |
93 | 1 | bo.extensionNumber = immutable.extensionNumberUnmasked |
94 | 1 | bo.versionNumber = immutable.versionNumber |
95 | 1 | bo.objectId = immutable.objectId |
96 | |
|
97 | 1 | return bo; |
98 | |
} |
99 | |
|
100 | |
@Override |
101 | |
EntityPhoneTypeBo getPhoneType() { |
102 | 1 | return this.phoneType |
103 | |
} |
104 | |
|
105 | |
public void setPhoneType(EntityPhoneTypeBo phoneType) { |
106 | 1 | this.phoneType = phoneType |
107 | |
} |
108 | |
|
109 | |
@Override |
110 | |
boolean isSuppressPhone() { |
111 | 1 | if (this.suppressPhone == null) { |
112 | 0 | EntityPrivacyPreferences privacy = KimApiServiceLocator.getIdentityService().getEntityPrivacyPreferences(getEntityId()) |
113 | 0 | if (privacy != null) { |
114 | 0 | this.suppressPhone = privacy.isSuppressPhone() |
115 | |
} else { |
116 | 0 | this.suppressPhone = false |
117 | |
} |
118 | |
} |
119 | |
|
120 | 1 | return this.suppressPhone; |
121 | |
} |
122 | |
|
123 | |
@Override |
124 | |
String getFormattedPhoneNumber() { |
125 | 0 | if (isSuppressPhone()) { |
126 | 0 | return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK |
127 | |
} |
128 | 0 | return getFormattedPhoneNumberUnmasked() |
129 | |
} |
130 | |
|
131 | |
@Override |
132 | |
String getPhoneNumberUnmasked() { |
133 | 1 | return this.phoneNumber |
134 | |
} |
135 | |
|
136 | |
@Override |
137 | |
String getExtensionNumberUnmasked() { |
138 | 1 | return this.extensionNumber |
139 | |
} |
140 | |
|
141 | |
@Override |
142 | |
String getCountryCodeUnmasked() { |
143 | 1 | return this.countryCode |
144 | |
} |
145 | |
|
146 | |
@Override |
147 | |
String getFormattedPhoneNumberUnmasked() { |
148 | 0 | StringBuffer sb = new StringBuffer( 30 ) |
149 | |
|
150 | |
|
151 | |
|
152 | 0 | sb.append( this.phoneNumber ) |
153 | 0 | if ( StringUtils.isNotBlank( this.extensionNumber ) ) { |
154 | 0 | sb.append( " x" ) |
155 | 0 | sb.append( this.extensionNumber ) |
156 | |
} |
157 | |
|
158 | 0 | return sb.toString(); |
159 | |
} |
160 | |
|
161 | |
@Override |
162 | |
String getPhoneNumber() { |
163 | 0 | if (isSuppressPhone()) { |
164 | 0 | return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK_PHONE |
165 | |
} |
166 | 0 | return this.phoneNumber |
167 | |
} |
168 | |
|
169 | |
@Override |
170 | |
String getCountryCode() { |
171 | 0 | if (isSuppressPhone()){ |
172 | 0 | return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE |
173 | |
} |
174 | 0 | return this.countryCode |
175 | |
} |
176 | |
|
177 | |
@Override |
178 | |
String getExtensionNumber() { |
179 | 0 | if (isSuppressPhone()) { |
180 | 0 | return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK |
181 | |
} |
182 | 0 | return this.extensionNumber |
183 | |
} |
184 | |
|
185 | |
} |