001/**
002 * Copyright 2005-2016 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 org.kuali.rice.kim.api.identity.name.EntityName;
019import org.kuali.rice.kim.api.identity.principal.EntityNamePrincipalName;
020import org.springframework.ldap.core.ContextMapper;
021import org.springframework.ldap.core.DirContextOperations;
022
023/**
024 * 
025 * @author Kuali Rice Team (rice.collab@kuali.org)
026 */
027public class EntityNamePrincipalNameMapper extends BaseMapper<EntityNamePrincipalName> {
028
029    private ContextMapper defaultNameMapper;
030    
031    @Override
032    EntityNamePrincipalName mapDtoFromContext(DirContextOperations context) {
033        EntityNamePrincipalName.Builder builder = mapBuilderFromContext(context);
034        return builder != null ? builder.build() : null;
035    }
036    
037    EntityNamePrincipalName.Builder mapBuilderFromContext(DirContextOperations context) {
038        final EntityNamePrincipalName.Builder person = EntityNamePrincipalName.Builder.create();
039        person.setDefaultName((EntityName.Builder) getDefaultNameMapper().mapFromContext(context));
040        person.setPrincipalName(context.getStringAttribute(getConstants().getKimLdapNameProperty()));
041        return person;
042    }
043
044    /**
045     * Gets the value of defaultNameMapper
046     *
047     * @return the value of defaultNameMapper
048     */
049    public final ContextMapper getDefaultNameMapper() {
050        return this.defaultNameMapper;
051    }
052
053    /**
054     * Sets the value of defaultNameMapper
055     *
056     * @param argDefaultNameMapper Value to assign to this.defaultNameMapper
057     */
058    public final void setDefaultNameMapper(final ContextMapper argDefaultNameMapper) {
059        this.defaultNameMapper = argDefaultNameMapper;
060    }
061}