View Javadoc

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 org.springframework.ldap.core.DirContextOperations;
19  import org.springframework.ldap.core.support.AbstractContextMapper;
20  
21  import org.kuali.rice.kim.api.identity.CodedAttribute;
22  import org.kuali.rice.kim.api.identity.address.EntityAddress;
23  import org.kuali.rice.kim.util.Constants;
24  
25  /**
26   * 
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   */
29  public class EntityAddressMapper extends AbstractContextMapper {
30      private Constants constants;
31  
32      public EntityAddress.Builder mapFromContext(DirContextOperations context, boolean isdefault) {
33          return (EntityAddress.Builder) doMapFromContext(context, isdefault);
34      }
35  
36      public EntityAddress.Builder mapFromContext(DirContextOperations context) {
37          return mapFromContext(context, false);
38      }
39  
40      public Object doMapFromContext(DirContextOperations context) {
41          return doMapFromContext(context, false);
42      }
43  
44      protected Object doMapFromContext(DirContextOperations context, boolean isdefault) {        
45          final EntityAddress.Builder builder = EntityAddress.Builder.create();
46          final String line1              = context.getStringAttribute("employeePrimaryDeptName");
47          final String line2              = context.getStringAttribute("employeePoBox");
48          final String city               = context.getStringAttribute("employeeCity");
49          final String stateProvinceCode  = context.getStringAttribute("employeeState");
50          final String postalCode         = context.getStringAttribute("employeeZip");
51          
52          builder.setAddressType(CodedAttribute.Builder.create("WORK"));
53          builder.setLine1(line1);
54          builder.setLine2(line2);
55          builder.setCity(city);
56          builder.setStateProvinceCode(stateProvinceCode);
57          builder.setPostalCode(postalCode);
58          builder.setDefaultValue(isdefault);
59          builder.setActive(true);
60          return builder;
61      }
62      
63      
64      /**
65       * Gets the value of constants
66       *
67       * @return the value of constants
68       */
69      public final Constants getConstants() {
70          return this.constants;
71      }
72  
73      /**
74       * Sets the value of constants
75       *
76       * @param argConstants Value to assign to this.constants
77       */
78      public final void setConstants(final Constants argConstants) {
79          this.constants = argConstants;
80      }
81  }