1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.ldap;
17
18 import static org.apache.commons.lang.StringUtils.equalsIgnoreCase;
19 import static org.apache.commons.lang.StringUtils.isBlank;
20 import static org.kuali.rice.core.util.BufferedLogger.debug;
21
22 import org.kuali.rice.kim.api.identity.CodedAttribute;
23 import org.kuali.rice.kim.api.identity.phone.EntityPhone;
24 import org.springframework.ldap.core.DirContextOperations;
25
26
27
28
29
30 public class EntityPhoneMapper extends BaseMapper<EntityPhone> {
31
32 @Override
33 EntityPhone mapDtoFromContext(DirContextOperations context) {
34 return mapDtoFromContext(context, true);
35 }
36
37 EntityPhone mapDtoFromContext(DirContextOperations context, boolean isdefault) {
38 EntityPhone.Builder builder = mapBuilderFromContext(context, isdefault);
39 return builder != null ? builder.build() : null;
40 }
41
42 EntityPhone.Builder mapBuilderFromContext(DirContextOperations context) {
43 return mapBuilderFromContext(context, true);
44 }
45
46 EntityPhone.Builder mapBuilderFromContext(DirContextOperations context, boolean isdefault) {
47 final EntityPhone.Builder builder = EntityPhone.Builder.create();
48 debug("Looking up attribute from context ", getConstants().getEmployeePhoneLdapProperty());
49 final String pn = context.getStringAttribute(getConstants().getEmployeePhoneLdapProperty());
50
51 if (isBlank(pn) || equalsIgnoreCase("NA", pn)) {
52 debug("Got nothing. Giving nothing back.");
53 return null;
54 }
55
56 String phoneNumber = pn;
57 if (pn.length() >= 10) {
58 phoneNumber = pn.substring(0, 3) + "-" + pn.substring(3, 6) + "-" + pn.substring(6);
59 } else if (pn.length() >= 6) {
60 phoneNumber = pn.substring(0, 3) + "-" + pn.substring(3);
61 }
62 final String countryCode = getConstants().getDefaultCountryCode();
63
64 builder.setCountryCode(countryCode);
65 builder.setPhoneNumber(phoneNumber);
66 builder.setPhoneType(CodedAttribute.Builder.create("WORK"));
67 builder.setActive(true);
68 builder.setDefaultValue(isdefault);
69
70 return builder;
71 }
72
73 }