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.springframework.ldap.core.DirContextOperations;
21
22
23
24
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 }