1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
34
35
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 }