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