001/** 002 * Copyright 2005-2015 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.kim.ldap; 017 018import static org.kuali.rice.core.util.BufferedLogger.debug; 019 020import java.util.ArrayList; 021import java.util.List; 022 023import org.kuali.rice.kim.api.identity.address.EntityAddress; 024import org.kuali.rice.kim.api.identity.email.EntityEmail; 025import org.kuali.rice.kim.api.identity.phone.EntityPhone; 026import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfo; 027import org.kuali.rice.kim.util.Constants; 028import org.springframework.ldap.core.DirContextOperations; 029 030/** 031 * 032 * @author Kuali Rice Team (rice.collab@kuali.org) 033 */ 034public class EntityTypeContactInfoMapper extends BaseMapper<EntityTypeContactInfo> { 035 036 private EntityAddressMapper addressMapper; 037 private EntityPhoneMapper phoneMapper; 038 private EntityEmailMapper emailMapper;; 039 040 @Override 041 EntityTypeContactInfo mapDtoFromContext(DirContextOperations context) { 042 EntityTypeContactInfo.Builder builder = mapBuilderFromContext(context); 043 return builder != null ? builder.build() : null; 044 } 045 046 EntityTypeContactInfo.Builder mapBuilderFromContext(DirContextOperations context) { 047 final String entityId = (String) context.getStringAttribute(getConstants().getKimLdapIdProperty()); 048 final String entityTypeCode = (String ) getConstants().getPersonEntityTypeCode(); 049 050 final EntityTypeContactInfo.Builder builder = EntityTypeContactInfo.Builder.create(entityId, entityTypeCode); 051 final EntityAddress.Builder address = getAddressMapper().mapBuilderFromContext(context); 052 final List<EntityAddress.Builder> addresses = new ArrayList<EntityAddress.Builder>(); 053 addresses.add(address); 054 final List<EntityEmail.Builder> email = new ArrayList<EntityEmail.Builder>(); 055 email.add(getEmailMapper().mapBuilderFromContext(context)); 056 final List<EntityPhone.Builder> phone = new ArrayList<EntityPhone.Builder>(); 057 phone.add(getPhoneMapper().mapBuilderFromContext(context)); 058 builder.setAddresses(addresses); 059 builder.setEmailAddresses(email); 060 builder.setPhoneNumbers(phone); 061 debug("Created Entity Type with code ", builder.getEntityTypeCode()); 062 063 return builder; 064 } 065 066 /** 067 * Gets the value of addressMapper 068 * 069 * @return the value of addressMapper 070 */ 071 public final EntityAddressMapper getAddressMapper() { 072 return this.addressMapper; 073 } 074 075 /** 076 * Sets the value of addressMapper 077 * 078 * @param argAddressMapper Value to assign to this.addressMapper 079 */ 080 public final void setAddressMapper(final EntityAddressMapper argAddressMapper) { 081 this.addressMapper = argAddressMapper; 082 } 083 084 /** 085 * Gets the value of phoneMapper 086 * 087 * @return the value of phoneMapper 088 */ 089 public final EntityPhoneMapper getPhoneMapper() { 090 return this.phoneMapper; 091 } 092 093 /** 094 * Sets the value of phoneMapper 095 * 096 * @param argPhoneMapper Value to assign to this.phoneMapper 097 */ 098 public final void setPhoneMapper(final EntityPhoneMapper argPhoneMapper) { 099 this.phoneMapper = argPhoneMapper; 100 } 101 102 /** 103 * Gets the value of emailMapper 104 * 105 * @return the value of emailMapper 106 */ 107 public final EntityEmailMapper getEmailMapper() { 108 return this.emailMapper; 109 } 110 111 /** 112 * Sets the value of emailMapper 113 * 114 * @param argEmailMapper Value to assign to this.emailMapper 115 */ 116 public final void setEmailMapper(final EntityEmailMapper argEmailMapper) { 117 this.emailMapper = argEmailMapper; 118 } 119}