| 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.CodedAttribute; |
| 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 | 0 | public class EntityPhoneMapper extends AbstractContextMapper { |
| 34 | |
private Constants constants; |
| 35 | |
|
| 36 | |
public EntityPhone.Builder mapFromContext(DirContextOperations context, boolean isdefault) { |
| 37 | 0 | return (EntityPhone.Builder) doMapFromContext(context, isdefault); |
| 38 | |
} |
| 39 | |
|
| 40 | |
public EntityPhone.Builder mapFromContext(DirContextOperations context) { |
| 41 | 0 | return mapFromContext(context, true); |
| 42 | |
} |
| 43 | |
|
| 44 | |
public Object doMapFromContext(DirContextOperations context) { |
| 45 | 0 | return doMapFromContext(context, true); |
| 46 | |
} |
| 47 | |
|
| 48 | |
protected Object doMapFromContext(DirContextOperations context, boolean isdefault) { |
| 49 | 0 | final EntityPhone.Builder builder = EntityPhone.Builder.create(); |
| 50 | 0 | debug("Looking up attribute from context ", getConstants().getEmployeePhoneLdapProperty()); |
| 51 | 0 | final String pn = context.getStringAttribute(getConstants().getEmployeePhoneLdapProperty()); |
| 52 | |
|
| 53 | 0 | if (isBlank(pn) || equalsIgnoreCase("NA", pn)) { |
| 54 | 0 | debug("Got nothing. Giving nothing back."); |
| 55 | 0 | return null; |
| 56 | |
} |
| 57 | |
|
| 58 | 0 | String phoneNumber = pn; |
| 59 | 0 | if (pn.length() >= 10) { |
| 60 | 0 | phoneNumber = pn.substring(0, 3) + "-" + pn.substring(3, 6) + "-" + pn.substring(6); |
| 61 | 0 | } else if (pn.length() >= 6) { |
| 62 | 0 | phoneNumber = pn.substring(0, 3) + "-" + pn.substring(3); |
| 63 | |
} |
| 64 | 0 | final String countryCode = getConstants().getDefaultCountryCode(); |
| 65 | |
|
| 66 | 0 | builder.setCountryCode(countryCode); |
| 67 | 0 | builder.setPhoneNumber(phoneNumber); |
| 68 | 0 | builder.setPhoneType(CodedAttribute.Builder.create("WORK")); |
| 69 | 0 | builder.setActive(true); |
| 70 | 0 | builder.setDefaultValue(isdefault); |
| 71 | |
|
| 72 | 0 | return builder; |
| 73 | |
} |
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
public final Constants getConstants() { |
| 81 | 0 | return this.constants; |
| 82 | |
} |
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
public final void setConstants(final Constants argConstants) { |
| 90 | 0 | this.constants = argConstants; |
| 91 | 0 | } |
| 92 | |
} |