View Javadoc

1   /**
2    * Copyright 2005-2013 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 org.kuali.rice.kim.api.identity.CodedAttribute;
19  import org.kuali.rice.kim.api.identity.address.EntityAddress;
20  import org.springframework.ldap.core.DirContextOperations;
21  
22  /**
23   * 
24   * @author Kuali Rice Team (rice.collab@kuali.org)
25   */
26  public class EntityAddressMapper extends BaseMapper<EntityAddress> {
27  	
28  	@Override
29  	EntityAddress mapDtoFromContext(DirContextOperations context) {
30  		return mapDtoFromContext(context, false);
31  	}
32  	
33      EntityAddress mapDtoFromContext(DirContextOperations context, boolean isdefault) {
34      	EntityAddress.Builder builder = mapBuilderFromContext(context, isdefault);
35          return builder != null ? builder.build() : null;
36      }
37  
38      EntityAddress.Builder mapBuilderFromContext(DirContextOperations context) {
39          return mapBuilderFromContext(context, false);
40      }
41  
42      EntityAddress.Builder mapBuilderFromContext(DirContextOperations context, boolean isdefault) {        
43          final EntityAddress.Builder builder = EntityAddress.Builder.create();
44          final String line1              = context.getStringAttribute("employeePrimaryDeptName");
45          final String line2              = context.getStringAttribute("employeePoBox");
46          final String city               = context.getStringAttribute("employeeCity");
47          final String stateProvinceCode  = context.getStringAttribute("employeeState");
48          final String postalCode         = context.getStringAttribute("employeeZip");
49          
50          builder.setAddressType(CodedAttribute.Builder.create("WORK"));
51          builder.setLine1(line1);
52          builder.setLine2(line2);
53          builder.setCity(city);
54          builder.setStateProvinceCode(stateProvinceCode);
55          builder.setPostalCode(postalCode);
56          builder.setDefaultValue(isdefault);
57          builder.setActive(true);
58          return builder;
59      }
60      
61  }