001 /**
002 * Copyright 2005-2014 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 */
016 package org.kuali.rice.kim.ldap;
017
018 import org.kuali.rice.kim.api.identity.CodedAttribute;
019 import org.kuali.rice.kim.api.identity.address.EntityAddress;
020 import org.springframework.ldap.core.DirContextOperations;
021
022 /**
023 *
024 * @author Kuali Rice Team (rice.collab@kuali.org)
025 */
026 public class EntityAddressMapper extends BaseMapper<EntityAddress> {
027
028 @Override
029 EntityAddress mapDtoFromContext(DirContextOperations context) {
030 return mapDtoFromContext(context, false);
031 }
032
033 EntityAddress mapDtoFromContext(DirContextOperations context, boolean isdefault) {
034 EntityAddress.Builder builder = mapBuilderFromContext(context, isdefault);
035 return builder != null ? builder.build() : null;
036 }
037
038 EntityAddress.Builder mapBuilderFromContext(DirContextOperations context) {
039 return mapBuilderFromContext(context, false);
040 }
041
042 EntityAddress.Builder mapBuilderFromContext(DirContextOperations context, boolean isdefault) {
043 final EntityAddress.Builder builder = EntityAddress.Builder.create();
044 final String line1 = context.getStringAttribute("employeePrimaryDeptName");
045 final String line2 = context.getStringAttribute("employeePoBox");
046 final String city = context.getStringAttribute("employeeCity");
047 final String stateProvinceCode = context.getStringAttribute("employeeState");
048 final String postalCode = context.getStringAttribute("employeeZip");
049
050 builder.setAddressType(CodedAttribute.Builder.create("WORK"));
051 builder.setLine1(line1);
052 builder.setLine2(line2);
053 builder.setCity(city);
054 builder.setStateProvinceCode(stateProvinceCode);
055 builder.setPostalCode(postalCode);
056 builder.setDefaultValue(isdefault);
057 builder.setActive(true);
058 return builder;
059 }
060
061 }