View Javadoc

1   /**
2    * Copyright 2005-2012 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.springframework.ldap.core.DirContextOperations;
21  
22  /**
23   * 
24   * @author Kuali Rice Team (rice.collab@kuali.org)
25   */
26  public class EntityNameMapper extends BaseMapper<EntityName> {
27  
28  	@Override
29      EntityName mapDtoFromContext(DirContextOperations context) {
30          return mapDtoFromContext(context, true);
31      }
32  	
33      EntityName mapDtoFromContext(DirContextOperations context, boolean isdefault) {
34          EntityName.Builder builder = mapBuilderFromContext(context, isdefault);
35          return builder != null ? builder.build() : null;
36      }
37  
38      EntityName.Builder mapBuilderFromContext(DirContextOperations context) {
39      	return mapBuilderFromContext(context, true);
40      }
41      
42      EntityName.Builder mapBuilderFromContext(DirContextOperations context, boolean isdefault) {        
43          final EntityName.Builder person = EntityName.Builder.create();
44          person.setEntityId(context.getStringAttribute(getConstants().getKimLdapIdProperty()));
45          person.setId(context.getStringAttribute(getConstants().getKimLdapIdProperty()));
46          
47          final String fullName = (String) context.getStringAttribute(getConstants().getGivenNameLdapProperty());
48          
49          if (fullName != null) {
50              final String[] name = fullName.split(" ");
51              person.setFirstName(name[0]);
52              if (name.length > 1) {
53                  person.setMiddleName(name[1]);
54              }
55          }
56          else {
57              person.setFirstName(fullName);
58          }
59          
60          person.setLastName(context.getStringAttribute(getConstants().getSnLdapProperty()));
61          person.setDefaultValue(isdefault);
62          person.setActive(true);
63          person.setNameType(CodedAttribute.Builder.create("PRI"));
64          
65          return person;
66      }
67      
68  }