Coverage Report - org.kuali.rice.kim.ldap.EntityNameMapper
 
Classes in this File Line Coverage Branch Coverage Complexity
EntityNameMapper
0%
0/23
0%
0/4
1.333
 
 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.kuali.rice.kim.api.identity.CodedAttribute;
 19  
 import org.kuali.rice.kim.api.identity.name.EntityName;
 20  
 import org.kuali.rice.kim.util.Constants;
 21  
 import org.springframework.ldap.core.DirContextOperations;
 22  
 import org.springframework.ldap.core.support.AbstractContextMapper;
 23  
 
 24  
 /**
 25  
  * 
 26  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 27  
  */
 28  0
 public class EntityNameMapper extends AbstractContextMapper {
 29  
     private Constants constants;
 30  
     
 31  
     public EntityName.Builder mapFromContext(DirContextOperations context, boolean isdefault) {
 32  0
         return (EntityName.Builder) doMapFromContext(context, isdefault);
 33  
     }
 34  
 
 35  
     public EntityName.Builder mapFromContext(DirContextOperations context) {
 36  0
         return mapFromContext(context, true);
 37  
     }
 38  
 
 39  
     public Object doMapFromContext(DirContextOperations context) {
 40  0
         return doMapFromContext(context, true);
 41  
     }
 42  
 
 43  
     protected Object doMapFromContext(DirContextOperations context, boolean isdefault) {        
 44  0
         final EntityName.Builder person = EntityName.Builder.create();
 45  0
         person.setEntityId(context.getStringAttribute(getConstants().getKimLdapIdProperty()));
 46  0
         person.setId(context.getStringAttribute(getConstants().getKimLdapIdProperty()));
 47  
         
 48  0
         final String fullName = (String) context.getStringAttribute(getConstants().getGivenNameLdapProperty());
 49  
         
 50  0
         if (fullName != null) {
 51  0
             final String[] name = fullName.split(" ");
 52  0
             person.setFirstName(name[0]);
 53  0
             if (name.length > 1) {
 54  0
                 person.setMiddleName(name[1]);
 55  
             }
 56  0
         }
 57  
         else {
 58  0
             person.setFirstName(fullName);
 59  
         }
 60  
         
 61  0
         person.setLastName(context.getStringAttribute(getConstants().getSnLdapProperty()));
 62  0
         person.setDefaultValue(isdefault);
 63  0
         person.setActive(true);
 64  0
         person.setNameType(CodedAttribute.Builder.create("PRI"));
 65  
         
 66  0
         return person;
 67  
     }
 68  
     
 69  
     /**
 70  
      * Gets the value of constants
 71  
      *
 72  
      * @return the value of constants
 73  
      */
 74  
     public final Constants getConstants() {
 75  0
         return this.constants;
 76  
     }
 77  
 
 78  
     /**
 79  
      * Sets the value of constants
 80  
      *
 81  
      * @param argConstants Value to assign to this.constants
 82  
      */
 83  
     public final void setConstants(final Constants argConstants) {
 84  0
         this.constants = argConstants;
 85  0
     }
 86  
 }