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 org.springframework.ldap.core.DirContextOperations;
19 import org.springframework.ldap.core.support.AbstractContextMapper;
20
21 import org.kuali.rice.kim.api.identity.Type;
22 import org.kuali.rice.kim.api.identity.phone.EntityPhone;
23 import org.kuali.rice.kim.util.Constants;
24
25 import static org.kuali.rice.core.util.BufferedLogger.*;
26 import static org.apache.commons.lang.StringUtils.isBlank;
27 import static org.apache.commons.lang.StringUtils.equalsIgnoreCase;
28
29
30
31
32
33 public class EntityPhoneMapper extends AbstractContextMapper {
34 private Constants constants;
35
36 public EntityPhone.Builder mapFromContext(DirContextOperations context, boolean isdefault) {
37 return (EntityPhone.Builder) doMapFromContext(context, isdefault);
38 }
39
40 public EntityPhone.Builder mapFromContext(DirContextOperations context) {
41 return mapFromContext(context, true);
42 }
43
44 public Object doMapFromContext(DirContextOperations context) {
45 return doMapFromContext(context, true);
46 }
47
48 protected Object doMapFromContext(DirContextOperations context, boolean isdefault) {
49 final EntityPhone.Builder builder = EntityPhone.Builder.create();
50 debug("Looking up attribute from context ", getConstants().getEmployeePhoneLdapProperty());
51 final String pn = context.getStringAttribute(getConstants().getEmployeePhoneLdapProperty());
52
53 if (isBlank(pn) || equalsIgnoreCase("NA", pn)) {
54 debug("Got nothing. Giving nothing back.");
55 return null;
56 }
57
58 String phoneNumber = pn;
59 if (pn.length() >= 10) {
60 phoneNumber = pn.substring(0, 3) + "-" + pn.substring(3, 6) + "-" + pn.substring(6);
61 } else if (pn.length() >= 6) {
62 phoneNumber = pn.substring(0, 3) + "-" + pn.substring(3);
63 }
64 final String countryCode = getConstants().getDefaultCountryCode();
65
66 builder.setCountryCode(countryCode);
67 builder.setPhoneNumber(phoneNumber);
68 builder.setPhoneType(Type.Builder.create("WORK"));
69 builder.setActive(true);
70 builder.setDefaultValue(isdefault);
71
72 return builder;
73 }
74
75
76
77
78
79
80 public final Constants getConstants() {
81 return this.constants;
82 }
83
84
85
86
87
88
89 public final void setConstants(final Constants argConstants) {
90 this.constants = argConstants;
91 }
92 }