package org.mxchange.pizzaapplication.model.customer;
import java.text.MessageFormat;
-import java.util.GregorianCalendar;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.persistence.Query;
import org.mxchange.jcontacts.contact.Contact;
import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
+import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
import org.mxchange.jcustomercore.exceptions.CustomerAlreadyRegisteredException;
import org.mxchange.jcustomercore.model.customer.Customer;
import org.mxchange.jcustomercore.utils.CustomerUtils;
private RateCalcCustomerSessionBeanRemote customerBean;
@Override
- public Customer addCustomer (final Customer customer) throws CustomerAlreadyRegisteredException {
+ public Customer addCustomer (final Customer customer) throws CustomerAlreadyRegisteredException, ContactAlreadyAddedException {
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("addCustomer: customer={0} - CALLED!", customer)); //NOI18N
// Is a customer found?
if (updatedContact instanceof Contact) {
- // Set all entries
- contact.setContactId(updatedContact.getContactId());
- this.setAllContactPhoneEntries(updatedContact, contact);
-
- // Yes, then get updated version
- updatedContact = this.contactBean.updateContactData(contact);
-
- // Remove it from customer so it won't get persisted again
- customer.setCustomerContact(null);
+ // Don't double-create
+ throw new ContactAlreadyAddedException(contact);
}
- // Set created timestamp(s)
- customer.setCustomerCreated(new GregorianCalendar());
-
- // No conrtact was found?
- if (null == updatedContact) {
- // Set created in contact, too
- contact.setContactCreated(new GregorianCalendar());
-
- // Set all "created" timestamps
- this.setAllContactPhoneEntriesCreated(contact);
- }
+ // Set all "created" timestamps
+ this.setAllContactPhoneEntriesCreated(contact);
// Persist the customer
this.getEntityManager().persist(customer);
// Flush it to get id number set
this.getEntityManager().flush();
- // Has the contact being updated?
- if (updatedContact instanceof Contact) {
- // Set it again
- customer.setCustomerContact(updatedContact);
- }
-
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("addCustomer: customer.customerId={0} - EXIT!", customer.getCustomerId())); //NOI18N