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 | 0 | 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 | 0 | final String entityId = context.getStringAttribute(getConstants().getKimLdapIdProperty()); |
48 | 0 | final String principalName = context.getStringAttribute(getConstants().getKimLdapNameProperty()); |
49 | |
|
50 | 0 | final EntityDefault.Builder person = EntityDefault.Builder.create(entityId); |
51 | |
|
52 | 0 | if (entityId == null) { |
53 | 0 | throw new InvalidLdapEntityException("LDAP Search Results yielded an invalid result with attributes " |
54 | |
+ context.getAttributes()); |
55 | |
} |
56 | |
|
57 | 0 | person.setAffiliations(new ArrayList<EntityAffiliation.Builder>()); |
58 | 0 | person.setExternalIdentifiers(new ArrayList<EntityExternalIdentifier.Builder>()); |
59 | |
|
60 | 0 | final EntityExternalIdentifier.Builder externalId = EntityExternalIdentifier.Builder.create(); |
61 | 0 | externalId.setExternalIdentifierTypeCode(getConstants().getTaxExternalIdTypeCode()); |
62 | 0 | externalId.setExternalId(entityId); |
63 | 0 | person.getExternalIdentifiers().add(externalId); |
64 | |
|
65 | 0 | person.setAffiliations((List<EntityAffiliation.Builder>) getAffiliationMapper().mapFromContext(context)); |
66 | |
|
67 | 0 | person.setEntityTypeContactInfos(new ArrayList<EntityTypeContactInfoDefault.Builder>()); |
68 | 0 | person.getEntityTypeContactInfos().add((EntityTypeContactInfoDefault.Builder) getEntityTypeMapper().mapFromContext(context)); |
69 | |
|
70 | 0 | person.setName(getDefaultNameMapper().mapFromContext(context)); |
71 | 0 | person.setEntityId(entityId); |
72 | |
|
73 | 0 | person.setEmployment((EntityEmployment.Builder) getEmploymentMapper().mapFromContext(context)); |
74 | |
|
75 | 0 | person.setEntityId(entityId); |
76 | 0 | person.setPrincipals(new ArrayList<Principal.Builder>()); |
77 | |
|
78 | 0 | person.setActive(true); |
79 | |
|
80 | 0 | final Principal.Builder defaultPrincipal = Principal.Builder.create(principalName); |
81 | 0 | defaultPrincipal.setPrincipalId(entityId); |
82 | 0 | defaultPrincipal.setEntityId(entityId); |
83 | |
|
84 | 0 | person.getPrincipals().add(defaultPrincipal); |
85 | |
|
86 | 0 | return person; |
87 | |
} |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
public final Constants getConstants() { |
95 | 0 | return this.constants; |
96 | |
} |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
public final void setConstants(final Constants argConstants) { |
104 | 0 | this.constants = argConstants; |
105 | 0 | } |
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
public final EntityAffiliationMapper getAffiliationMapper() { |
114 | 0 | return this.affiliationMapper; |
115 | |
} |
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
public final void setAffiliationMapper(final EntityAffiliationMapper argAffiliationMapper) { |
123 | 0 | this.affiliationMapper = argAffiliationMapper; |
124 | 0 | } |
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
public final EntityTypeContactInfoMapper getEntityTypeMapper() { |
132 | 0 | return this.entityTypeMapper; |
133 | |
} |
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
public final void setEntityTypeMapper(final EntityTypeContactInfoMapper argEntityTypeMapper) { |
141 | 0 | this.entityTypeMapper = argEntityTypeMapper; |
142 | 0 | } |
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
public final EntityNameMapper getDefaultNameMapper() { |
150 | 0 | return this.defaultNameMapper; |
151 | |
} |
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
public final void setDefaultNameMapper(final EntityNameMapper argDefaultNameMapper) { |
159 | 0 | this.defaultNameMapper = argDefaultNameMapper; |
160 | 0 | } |
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
public final EntityEmploymentMapper getEmploymentMapper() { |
168 | 0 | return this.employmentMapper; |
169 | |
} |
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
public final void setEmploymentMapper(final EntityEmploymentMapper argEmploymentMapper) { |
177 | 0 | this.employmentMapper = argEmploymentMapper; |
178 | 0 | } |
179 | |
|
180 | |
} |