Coverage Report - org.kuali.rice.kim.ldap.EntityDefaultMapper
 
Classes in this File Line Coverage Branch Coverage Complexity
EntityDefaultMapper
0%
0/41
0%
0/2
1.182
 
 1  
 /**
 2  
  * Copyright 2005-2011 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  
 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  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 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  
         //inactivate unless we find a matching affiliation
 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  
      * Gets the value of constants
 91  
      *
 92  
      * @return the value of constants
 93  
      */
 94  
     public final Constants getConstants() {
 95  0
         return this.constants;
 96  
     }
 97  
 
 98  
     /**
 99  
      * Sets the value of constants
 100  
      *
 101  
      * @param argConstants Value to assign to this.constants
 102  
      */
 103  
     public final void setConstants(final Constants argConstants) {
 104  0
         this.constants = argConstants;
 105  0
     }
 106  
 
 107  
     
 108  
     /**
 109  
      * Gets the value of affiliationMapper
 110  
      *
 111  
      * @return the value of affiliationMapper
 112  
      */
 113  
     public final EntityAffiliationMapper getAffiliationMapper() {
 114  0
         return this.affiliationMapper;
 115  
     }
 116  
 
 117  
     /**
 118  
      * Sets the value of affiliationMapper
 119  
      *
 120  
      * @param argAffiliationMapper Value to assign to this.affiliationMapper
 121  
      */
 122  
     public final void setAffiliationMapper(final EntityAffiliationMapper argAffiliationMapper) {
 123  0
         this.affiliationMapper = argAffiliationMapper;
 124  0
     }
 125  
 
 126  
     /**
 127  
      * Gets the value of entityTypeMapper
 128  
      *
 129  
      * @return the value of entityTypeMapper
 130  
      */
 131  
     public final EntityTypeContactInfoMapper getEntityTypeMapper() {
 132  0
         return this.entityTypeMapper;
 133  
     }
 134  
 
 135  
     /**
 136  
      * Sets the value of entityTypeMapper
 137  
      *
 138  
      * @param argEntityTypeMapper Value to assign to this.entityTypeMapper
 139  
      */
 140  
     public final void setEntityTypeMapper(final EntityTypeContactInfoMapper argEntityTypeMapper) {
 141  0
         this.entityTypeMapper = argEntityTypeMapper;
 142  0
     }
 143  
 
 144  
     /**
 145  
      * Gets the value of defaultNameMapper
 146  
      *
 147  
      * @return the value of defaultNameMapper
 148  
      */
 149  
     public final EntityNameMapper getDefaultNameMapper() {
 150  0
         return this.defaultNameMapper;
 151  
     }
 152  
 
 153  
     /**
 154  
      * Sets the value of defaultNameMapper
 155  
      *
 156  
      * @param argDefaultNameMapper Value to assign to this.defaultNameMapper
 157  
      */
 158  
     public final void setDefaultNameMapper(final EntityNameMapper argDefaultNameMapper) {
 159  0
         this.defaultNameMapper = argDefaultNameMapper;
 160  0
     }
 161  
 
 162  
     /**
 163  
      * Gets the value of employmentMapper
 164  
      *
 165  
      * @return the value of employmentMapper
 166  
      */
 167  
     public final EntityEmploymentMapper getEmploymentMapper() {
 168  0
         return this.employmentMapper;
 169  
     }
 170  
 
 171  
     /**
 172  
      * Sets the value of employmentMapper
 173  
      *
 174  
      * @param argEmploymentMapper Value to assign to this.employmentMapper
 175  
      */
 176  
     public final void setEmploymentMapper(final EntityEmploymentMapper argEmploymentMapper) {
 177  0
         this.employmentMapper = argEmploymentMapper;
 178  0
     }
 179  
 
 180  
 }