public String viewCustomerAddress(HttpServletRequest request, Model model, Long customerAddressId) { CustomerAddress customerAddress = customerAddressService.readCustomerAddressById(customerAddressId); if (customerAddress == null) { throw new IllegalArgumentException("Customer Address not found with the specified customerAddressId"); } validateCustomerOwnedData(customerAddress); CustomerAddressForm form = new CustomerAddressForm(); form.setAddress(customerAddress.getAddress()); form.setAddressName(customerAddress.getAddressName()); form.setCustomerAddressId(customerAddress.getId()); model.addAttribute("customerAddressForm", form); return getCustomerAddressesView(); }
public String removeCustomerAddress(HttpServletRequest request, Model model, Long customerAddressId, RedirectAttributes redirectAttributes) { try { CustomerAddress customerAddress = customerAddressService.readCustomerAddressById(customerAddressId); // we don't care if the address is null on a remove if (customerAddress != null) { validateCustomerOwnedData(customerAddress); customerAddressService.deleteCustomerAddressById(customerAddressId); } redirectAttributes.addFlashAttribute("successMessage", getAddressRemovedMessage()); } catch (DataIntegrityViolationException e) { // This likely occurred because there is an order or cart in the system that is currently utilizing this // address. Therefore, we're not able to remove it as it breaks a foreign key constraint redirectAttributes.addFlashAttribute("errorMessage", getAddressRemovedErrorMessage()); } return getCustomerAddressesRedirect(); }
CustomerAddress customerAddress = customerAddressService.readCustomerAddressById(customerAddressId); if (customerAddress == null) { throw new IllegalArgumentException("Customer Address not found with the specified customerAddressId");