| 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.employment.EntityEmployment; |
| 27 | |
import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfo; |
| 28 | |
import org.kuali.rice.kim.api.identity.external.EntityExternalIdentifier; |
| 29 | |
import org.kuali.rice.kim.api.identity.entity.Entity; |
| 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 | |
import static org.apache.commons.lang.StringUtils.contains; |
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | 0 | public class EntityMapper extends AbstractContextMapper { |
| 41 | |
private Constants constants; |
| 42 | |
|
| 43 | |
private ContextMapper affiliationMapper; |
| 44 | |
private ContextMapper entityTypeMapper; |
| 45 | |
private ContextMapper defaultNameMapper; |
| 46 | |
private ContextMapper employmentMapper; |
| 47 | |
|
| 48 | |
public Object doMapFromContext(DirContextOperations context) { |
| 49 | |
|
| 50 | 0 | final String entityId = context.getStringAttribute(getConstants().getKimLdapIdProperty()); |
| 51 | 0 | final String principalName = context.getStringAttribute(getConstants().getKimLdapNameProperty()); |
| 52 | |
|
| 53 | 0 | final Entity.Builder person = Entity.Builder.create(); |
| 54 | 0 | person.setId(entityId); |
| 55 | |
|
| 56 | 0 | if (entityId == null) { |
| 57 | 0 | throw new InvalidLdapEntityException("LDAP Search Results yielded an invalid result with attributes " |
| 58 | |
+ context.getAttributes()); |
| 59 | |
} |
| 60 | |
|
| 61 | 0 | person.setAffiliations(new ArrayList<EntityAffiliation.Builder>()); |
| 62 | 0 | person.setExternalIdentifiers(new ArrayList<EntityExternalIdentifier.Builder>()); |
| 63 | |
|
| 64 | 0 | final EntityExternalIdentifier.Builder externalId = EntityExternalIdentifier.Builder.create(); |
| 65 | 0 | externalId.setExternalIdentifierTypeCode(getConstants().getTaxExternalIdTypeCode()); |
| 66 | 0 | externalId.setExternalId(entityId); |
| 67 | 0 | person.getExternalIdentifiers().add(externalId); |
| 68 | |
|
| 69 | 0 | person.setAffiliations((List<EntityAffiliation.Builder>) getAffiliationMapper().mapFromContext(context)); |
| 70 | |
|
| 71 | 0 | person.setEntityTypes(new ArrayList<EntityTypeContactInfo.Builder>()); |
| 72 | 0 | person.getEntityTypeContactInfos().add((EntityTypeContactInfo.Builder) getEntityTypeMapper().mapFromContext(context)); |
| 73 | |
|
| 74 | 0 | final List<EntityName.Builder> names = new ArrayList<EntityName.Builder>(); |
| 75 | 0 | final EntityName.Builder name = (EntityName.Builder) getDefaultNameMapper().mapFromContext(context); |
| 76 | 0 | name.setDefaultValue(true); |
| 77 | 0 | person.getNames().add(name); |
| 78 | 0 | person.setId(entityId); |
| 79 | |
|
| 80 | 0 | final EntityEmployment.Builder employmentInfo = (EntityEmployment.Builder) getEmploymentMapper().mapFromContext(context); |
| 81 | 0 | final EntityAffiliation.Builder employeeAffiliation = getAffiliation(getConstants().getEmployeeAffiliationCodes(), person); |
| 82 | |
|
| 83 | |
|
| 84 | 0 | if (employeeAffiliation != null && employmentInfo != null) { |
| 85 | 0 | employeeAffiliation.getAffiliationType().setEmploymentAffiliationType(true); |
| 86 | 0 | employmentInfo.setEntityAffiliation(employeeAffiliation); |
| 87 | 0 | person.getEmploymentInformation().add(employmentInfo); |
| 88 | |
} |
| 89 | |
|
| 90 | 0 | person.setPrincipals(new ArrayList<Principal.Builder>()); |
| 91 | 0 | person.setActive(true); |
| 92 | |
|
| 93 | 0 | final Principal.Builder defaultPrincipal = Principal.Builder.create(principalName); |
| 94 | 0 | defaultPrincipal.setPrincipalId(entityId); |
| 95 | 0 | defaultPrincipal.setEntityId(entityId); |
| 96 | |
|
| 97 | 0 | person.getPrincipals().add(defaultPrincipal); |
| 98 | |
|
| 99 | 0 | return person; |
| 100 | |
} |
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
protected EntityAffiliation.Builder getAffiliation(String affiliationCodes, Entity.Builder person) { |
| 110 | 0 | EntityAffiliation.Builder retval = null; |
| 111 | 0 | for (EntityAffiliation.Builder affil : person.getAffiliations()) { |
| 112 | 0 | if (contains(affiliationCodes, affil.getAffiliationType().getCode())) { |
| 113 | 0 | return affil; |
| 114 | |
} |
| 115 | |
} |
| 116 | 0 | return retval; |
| 117 | |
} |
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
public final Constants getConstants() { |
| 125 | 0 | return this.constants; |
| 126 | |
} |
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
public final void setConstants(final Constants argConstants) { |
| 134 | 0 | this.constants = argConstants; |
| 135 | 0 | } |
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
public final ContextMapper getAffiliationMapper() { |
| 142 | 0 | return this.affiliationMapper; |
| 143 | |
} |
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
public final void setAffiliationMapper(final ContextMapper argAffiliationMapper) { |
| 151 | 0 | this.affiliationMapper = argAffiliationMapper; |
| 152 | 0 | } |
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
public final ContextMapper getEntityTypeMapper() { |
| 160 | 0 | return this.entityTypeMapper; |
| 161 | |
} |
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
public final void setEntityTypeMapper(final ContextMapper argEntityTypeMapper) { |
| 169 | 0 | this.entityTypeMapper = argEntityTypeMapper; |
| 170 | 0 | } |
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
public final ContextMapper getDefaultNameMapper() { |
| 178 | 0 | return this.defaultNameMapper; |
| 179 | |
} |
| 180 | |
|
| 181 | |
|
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
public final void setDefaultNameMapper(final ContextMapper argDefaultNameMapper) { |
| 187 | 0 | this.defaultNameMapper = argDefaultNameMapper; |
| 188 | 0 | } |
| 189 | |
|
| 190 | |
|
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
public final ContextMapper getEmploymentMapper() { |
| 196 | 0 | return this.employmentMapper; |
| 197 | |
} |
| 198 | |
|
| 199 | |
|
| 200 | |
|
| 201 | |
|
| 202 | |
|
| 203 | |
|
| 204 | |
public final void setEmploymentMapper(final ContextMapper argEmploymentMapper) { |
| 205 | 0 | this.employmentMapper = argEmploymentMapper; |
| 206 | 0 | } |
| 207 | |
} |