View Javadoc

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  public class EntityNameMapper extends AbstractContextMapper {
29      private Constants constants;
30      
31      public EntityName.Builder mapFromContext(DirContextOperations context, boolean isdefault) {
32          return (EntityName.Builder) doMapFromContext(context, isdefault);
33      }
34  
35      public EntityName.Builder mapFromContext(DirContextOperations context) {
36          return mapFromContext(context, true);
37      }
38  
39      public Object doMapFromContext(DirContextOperations context) {
40          return doMapFromContext(context, true);
41      }
42  
43      protected Object doMapFromContext(DirContextOperations context, boolean isdefault) {        
44          final EntityName.Builder person = EntityName.Builder.create();
45          person.setEntityId(context.getStringAttribute(getConstants().getKimLdapIdProperty()));
46          person.setId(context.getStringAttribute(getConstants().getKimLdapIdProperty()));
47          
48          final String fullName = (String) context.getStringAttribute(getConstants().getGivenNameLdapProperty());
49          
50          if (fullName != null) {
51              final String[] name = fullName.split(" ");
52              person.setFirstName(name[0]);
53              if (name.length > 1) {
54                  person.setMiddleName(name[1]);
55              }
56          }
57          else {
58              person.setFirstName(fullName);
59          }
60          
61          person.setLastName(context.getStringAttribute(getConstants().getSnLdapProperty()));
62          person.setDefaultValue(isdefault);
63          person.setActive(true);
64          person.setNameType(CodedAttribute.Builder.create("PRI"));
65          
66          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          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          this.constants = argConstants;
85      }
86  }