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 java.util.ArrayList;
19
20 import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliation;
21 import org.kuali.rice.kim.api.identity.entity.EntityDefault;
22 import org.kuali.rice.kim.api.identity.external.EntityExternalIdentifier;
23 import org.kuali.rice.kim.api.identity.principal.Principal;
24 import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfoDefault;
25 import org.springframework.ldap.core.DirContextOperations;
26
27
28
29
30
31 public class EntityDefaultMapper extends BaseMapper<EntityDefault> {
32
33 private EntityAffiliationMapper affiliationMapper;
34 private EntityTypeContactInfoDefaultMapper entityTypeContactInfoDefaultMapper;
35 private EntityNameMapper defaultNameMapper;
36 private EntityEmploymentMapper employmentMapper;
37
38 @Override
39 EntityDefault mapDtoFromContext(DirContextOperations context) {
40 EntityDefault.Builder builder = mapBuilderFromContext(context);
41 return builder != null ? builder.build() : null;
42 }
43
44 EntityDefault.Builder mapBuilderFromContext(DirContextOperations context) {
45
46 final String entityId = context.getStringAttribute(getConstants().getKimLdapIdProperty());
47 final String principalName = context.getStringAttribute(getConstants().getKimLdapNameProperty());
48
49 final EntityDefault.Builder person = EntityDefault.Builder.create(entityId);
50
51 if (entityId == null) {
52 throw new InvalidLdapEntityException("LDAP Search Results yielded an invalid result with attributes "
53 + context.getAttributes());
54 }
55
56 person.setAffiliations(new ArrayList<EntityAffiliation.Builder>());
57 person.setExternalIdentifiers(new ArrayList<EntityExternalIdentifier.Builder>());
58
59 final EntityExternalIdentifier.Builder externalId = EntityExternalIdentifier.Builder.create();
60 externalId.setExternalIdentifierTypeCode(getConstants().getTaxExternalIdTypeCode());
61 externalId.setExternalId(entityId);
62 person.getExternalIdentifiers().add(externalId);
63
64 person.setAffiliations(getAffiliationMapper().mapBuilderFromContext(context));
65
66 person.setEntityTypeContactInfos(new ArrayList<EntityTypeContactInfoDefault.Builder>());
67 person.getEntityTypeContactInfos().add(getEntityTypeContactInfoDefaultMapper().mapBuilderFromContext(context));
68
69 person.setName(getDefaultNameMapper().mapBuilderFromContext(context));
70 person.setEntityId(entityId);
71
72 person.setEmployment(getEmploymentMapper().mapBuilderFromContext(context));
73
74 person.setEntityId(entityId);
75 person.setPrincipals(new ArrayList<Principal.Builder>());
76
77 person.setActive(true);
78
79 final Principal.Builder defaultPrincipal = Principal.Builder.create(principalName);
80 defaultPrincipal.setPrincipalId(entityId);
81 defaultPrincipal.setEntityId(entityId);
82
83 person.getPrincipals().add(defaultPrincipal);
84
85 return person;
86 }
87
88
89
90
91
92
93 public final EntityAffiliationMapper getAffiliationMapper() {
94 return this.affiliationMapper;
95 }
96
97
98
99
100
101
102 public final void setAffiliationMapper(final EntityAffiliationMapper argAffiliationMapper) {
103 this.affiliationMapper = argAffiliationMapper;
104 }
105
106
107
108
109
110
111 public final EntityTypeContactInfoDefaultMapper getEntityTypeContactInfoDefaultMapper() {
112 return this.entityTypeContactInfoDefaultMapper;
113 }
114
115
116
117
118
119
120 public final void setEntityTypeContactInfoDefaultMapper(final EntityTypeContactInfoDefaultMapper argEntityTypeMapper) {
121 this.entityTypeContactInfoDefaultMapper = argEntityTypeMapper;
122 }
123
124
125
126
127
128
129 public final EntityNameMapper getDefaultNameMapper() {
130 return this.defaultNameMapper;
131 }
132
133
134
135
136
137
138 public final void setDefaultNameMapper(final EntityNameMapper argDefaultNameMapper) {
139 this.defaultNameMapper = argDefaultNameMapper;
140 }
141
142
143
144
145
146
147 public final EntityEmploymentMapper getEmploymentMapper() {
148 return this.employmentMapper;
149 }
150
151
152
153
154
155
156 public final void setEmploymentMapper(final EntityEmploymentMapper argEmploymentMapper) {
157 this.employmentMapper = argEmploymentMapper;
158 }
159
160 }