Coverage Report - org.kuali.rice.kim.ldap.EntityPhoneMapper
 
Classes in this File Line Coverage Branch Coverage Complexity
EntityPhoneMapper
0%
0/25
0%
0/8
1.833
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 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  
      * Gets the value of constants
 77  
      *
 78  
      * @return the value of constants
 79  
      */
 80  
     public final Constants getConstants() {
 81  0
         return this.constants;
 82  
     }
 83  
 
 84  
     /**
 85  
      * Sets the value of constants
 86  
      *
 87  
      * @param argConstants Value to assign to this.constants
 88  
      */
 89  
     public final void setConstants(final Constants argConstants) {
 90  0
         this.constants = argConstants;
 91  0
     }
 92  
 }