* @return AddressDTO
*/
public AddressDTO maintainAddress(CustomerDTO theCustomer, AddressDTO theAddress) {
User customer = null;
Address address = null;
EntityMapper mapper = new EntityMapper();
AddressDTO addressDTO = null;
if (theAddress.getid() != null) {
// address has an id, so just update the address itself
address = _updateAddress(mapper.getAddressfromAddressDTO(theAddress));
if (address == null) {
addressDTO = new AddressDTO();
addressDTO.setReturncode(99);
addressDTO.setMessage("Error during update of customers addressdata.");
} else {
addressDTO = mapper.getAddressDTOfromAddress(address);
}
} else {
customer = _checkCustomerExists(theCustomer.getid());
// address has no id, put it to customer and update customer
if (customer != null) {
customer.getAddresses().add(mapper.getAddressfromAddressDTO(theAddress));
customer = _updateCustomer(customer);
if (customer != null) {
address = _findNewAddressFromCustomer(customer);
addressDTO = mapper.getAddressDTOfromAddress(address);
} else {
addressDTO = new AddressDTO();
addressDTO.setReturncode(99);
addressDTO.setMessage("Error during update of customers addressdata.");
}