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.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
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
71
72
73
74 public final Constants getConstants() {
75 return this.constants;
76 }
77
78
79
80
81
82
83 public final void setConstants(final Constants argConstants) {
84 this.constants = argConstants;
85 }
86 }