View Javadoc
1   /*
2    * Copyright 2007-2009 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.ole.coa.document.web;
17  
18  import javax.servlet.http.HttpServletRequest;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.kuali.ole.coa.businessobject.Organization;
22  import org.kuali.ole.sys.context.SpringContext;
23  import org.kuali.rice.kns.document.MaintenanceDocumentBase;
24  import org.kuali.rice.kns.web.derivedvaluesetter.DerivedValuesSetter;
25  import org.kuali.rice.kns.web.struts.form.KualiForm;
26  import org.kuali.rice.kns.web.struts.form.KualiMaintenanceForm;
27  import org.kuali.rice.krad.util.KRADConstants;
28  import org.kuali.rice.krad.util.ObjectUtils;
29  import org.kuali.rice.location.api.postalcode.PostalCode;
30  import org.kuali.rice.location.api.postalcode.PostalCodeService;
31  
32  /**
33   * This is a description of what this class does - wliang don't forget to fill this in. 
34   * 
35   * @author Kuali Rice Team (kuali-rice@googlegroups.com)
36   *
37   */
38  public class OrgDerivedValuesSetter implements DerivedValuesSetter {
39  	public void setDerivedValues(KualiForm form, HttpServletRequest request){
40  	    KualiMaintenanceForm maintenanceForm = (KualiMaintenanceForm) form;
41  	    MaintenanceDocumentBase maintenanceDocument = (MaintenanceDocumentBase) maintenanceForm.getDocument();
42  	    Organization newOrg = (Organization) maintenanceDocument.getNewMaintainableObject().getBusinessObject();
43  	    String organizationZipCode = newOrg.getOrganizationZipCode();
44  	    String organizationCountryCode = newOrg.getOrganizationCountryCode();
45  	    if (StringUtils.isNotBlank(organizationZipCode) && StringUtils.isNotBlank(organizationCountryCode)) {
46  	        PostalCode postalZipCode = SpringContext.getBean(PostalCodeService.class).getPostalCode(organizationCountryCode, organizationZipCode);
47  	        if (ObjectUtils.isNotNull(postalZipCode)) {
48  	            newOrg.setOrganizationCityName(postalZipCode.getCityName());
49  	            newOrg.setOrganizationStateCode(postalZipCode.getStateCode());
50  	        }
51  	        else {
52  	            newOrg.setOrganizationCityName(KRADConstants.EMPTY_STRING);
53                  newOrg.setOrganizationStateCode(KRADConstants.EMPTY_STRING);
54  	        }
55  	    }
56  	    else {
57              newOrg.setOrganizationCityName(KRADConstants.EMPTY_STRING);
58              newOrg.setOrganizationStateCode(KRADConstants.EMPTY_STRING);
59  	    }
60  	}
61  }