HttpServletResponse response)
throws Throwable {
createEmptySecureTemplateInfo(request);
String siteId = getContentBean(request).getContentSessionKey().getSiteId();
MyAccountShipInfoActionForm form = (MyAccountShipInfoActionForm) actionForm;
ActionMessages messages = validate(form);
if (messages.size() > 0) {
initSearchInfo(form, siteId);
saveMessages(request, messages);
ActionForward actionForward = actionMapping.findForward("error");
return actionForward;
}
EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
Customer customer = CustomerDAO.load(siteId, getCustomer(request).getCustId());
customer.setRecUpdateBy(Constants.USERNAME_CUSTOMER);
customer.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
em.persist(customer);
CustomerAddress billingAddress = getBillingAddress(customer);
if (billingAddress == null) {
billingAddress = new CustomerAddress();
billingAddress.setRecCreateBy(Constants.USERNAME_CUSTOMER);
billingAddress.setRecCreateDatetime(new Date(System.currentTimeMillis()));
customer.getCustAddresses().add(billingAddress);
}
billingAddress.setCustPrefix(form.getBillingCustPrefix());
billingAddress.setCustFirstName(form.getBillingCustFirstName());
billingAddress.setCustMiddleName(form.getBillingCustMiddleName());
billingAddress.setCustLastName(form.getBillingCustLastName());
billingAddress.setCustSuffix(form.getBillingCustSuffix());
billingAddress.setCustAddressType(Constants.CUSTOMER_ADDRESS_BILLING);
billingAddress.setCustAddressLine1(form.getBillingCustAddressLine1());
billingAddress.setCustAddressLine2(form.getBillingCustAddressLine2());
billingAddress.setCustCityName(form.getBillingCustCityName());
billingAddress.setCustStateCode(form.getBillingCustStateCode());
billingAddress.setCustStateName(Utility.getStateName(siteId, form.getBillingCustStateCode()));
billingAddress.setCustCountryCode(form.getBillingCustCountryCode());
billingAddress.setCustCountryName(Utility.getCountryName(siteId, form.getBillingCustCountryCode()));
billingAddress.setCustZipCode(form.getBillingCustZipCode());
billingAddress.setCustPhoneNum(form.getBillingCustPhoneNum());
billingAddress.setCustFaxNum(form.getBillingCustPhoneNum());
billingAddress.setRecUpdateBy(Constants.USERNAME_CUSTOMER);
billingAddress.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
if (billingAddress.getCustAddressId() == null) {
em.persist(billingAddress);
}
CustomerAddress shippingAddress = getShippingAddress(customer);
if (form.isUseBilling()) {
if (shippingAddress != null) {
customer.getCustAddresses().remove(shippingAddress);
em.remove(shippingAddress);
}
}
else {
if (shippingAddress == null) {
shippingAddress = new CustomerAddress();
shippingAddress.setRecCreateBy(Constants.USERNAME_CUSTOMER);
shippingAddress.setRecCreateDatetime(new Date(System.currentTimeMillis()));
customer.getCustAddresses().add(shippingAddress);
}
shippingAddress.setCustPrefix(form.getShippingCustPrefix());
shippingAddress.setCustFirstName(form.getShippingCustFirstName());
shippingAddress.setCustMiddleName(form.getShippingCustMiddleName());
shippingAddress.setCustLastName(form.getShippingCustLastName());
shippingAddress.setCustSuffix(form.getShippingCustSuffix());
shippingAddress.setCustAddressType(Constants.CUSTOMER_ADDRESS_BILLING);
shippingAddress.setCustAddressLine1(form.getShippingCustAddressLine1());
shippingAddress.setCustAddressLine2(form.getShippingCustAddressLine2());
shippingAddress.setCustCityName(form.getShippingCustCityName());
shippingAddress.setCustStateCode(form.getShippingCustStateCode());
shippingAddress.setCustStateName(Utility.getStateName(siteId, form.getShippingCustStateCode()));
shippingAddress.setCustCountryCode(form.getShippingCustCountryCode());
shippingAddress.setCustCountryName(Utility.getCountryName(siteId, form.getShippingCustCountryCode()));
shippingAddress.setCustZipCode(form.getShippingCustZipCode());
shippingAddress.setCustPhoneNum(form.getShippingCustPhoneNum());
shippingAddress.setCustFaxNum(form.getShippingCustPhoneNum());
shippingAddress.setRecUpdateBy(Constants.USERNAME_CUSTOMER);
shippingAddress.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
if (shippingAddress.getCustAddressId() == null) {
em.persist(shippingAddress);
}