View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * @author Kuali Rice Team (rice.collab@kuali.org)
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          //inactivate unless we find a matching affiliation
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       * Gets the value of affiliationMapper
90       *
91       * @return the value of affiliationMapper
92       */
93      public final EntityAffiliationMapper getAffiliationMapper() {
94          return this.affiliationMapper;
95      }
96  
97      /**
98       * Sets the value of affiliationMapper
99       *
100      * @param argAffiliationMapper Value to assign to this.affiliationMapper
101      */
102     public final void setAffiliationMapper(final EntityAffiliationMapper argAffiliationMapper) {
103         this.affiliationMapper = argAffiliationMapper;
104     }
105 
106     /**
107      * Gets the value of entityTypeMapper
108      *
109      * @return the value of entityTypeMapper
110      */
111     public final EntityTypeContactInfoDefaultMapper getEntityTypeContactInfoDefaultMapper() {
112         return this.entityTypeContactInfoDefaultMapper;
113     }
114 
115     /**
116      * Sets the value of entityTypeMapper
117      *
118      * @param argEntityTypeMapper Value to assign to this.entityTypeMapper
119      */
120     public final void setEntityTypeContactInfoDefaultMapper(final EntityTypeContactInfoDefaultMapper argEntityTypeMapper) {
121         this.entityTypeContactInfoDefaultMapper = argEntityTypeMapper;
122     }
123 
124     /**
125      * Gets the value of defaultNameMapper
126      *
127      * @return the value of defaultNameMapper
128      */
129     public final EntityNameMapper getDefaultNameMapper() {
130         return this.defaultNameMapper;
131     }
132 
133     /**
134      * Sets the value of defaultNameMapper
135      *
136      * @param argDefaultNameMapper Value to assign to this.defaultNameMapper
137      */
138     public final void setDefaultNameMapper(final EntityNameMapper argDefaultNameMapper) {
139         this.defaultNameMapper = argDefaultNameMapper;
140     }
141 
142     /**
143      * Gets the value of employmentMapper
144      *
145      * @return the value of employmentMapper
146      */
147     public final EntityEmploymentMapper getEmploymentMapper() {
148         return this.employmentMapper;
149     }
150 
151     /**
152      * Sets the value of employmentMapper
153      *
154      * @param argEmploymentMapper Value to assign to this.employmentMapper
155      */
156     public final void setEmploymentMapper(final EntityEmploymentMapper argEmploymentMapper) {
157         this.employmentMapper = argEmploymentMapper;
158     }
159 
160 }