]> git.mxchange.org Git - pizzaservice-ejb.git/commitdiff
No more fancy stuff in EJBs, like auto-linking, straight ahead only adding non-existi...
authorRoland Häder <roland@mxchange.org>
Tue, 26 Apr 2016 13:43:32 +0000 (15:43 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 27 Apr 2016 19:07:14 +0000 (21:07 +0200)
src/java/org/mxchange/pizzaapplication/model/customer/PizzaAdminCustomerSessionBean.java

index 70ebcb307d68348e57793aa8237326086e012bc8..511be1e7dbae9b541cd094ab4148c6b74d90fbaf 100644 (file)
@@ -17,7 +17,6 @@
 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;
@@ -25,6 +24,7 @@ import javax.persistence.NoResultException;
 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;
@@ -56,7 +56,7 @@ public class PizzaAdminCustomerSessionBean extends BasePizzaDatabaseBean impleme
        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
 
@@ -90,28 +90,12 @@ public class PizzaAdminCustomerSessionBean extends BasePizzaDatabaseBean impleme
 
                // 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);
@@ -119,12 +103,6 @@ public class PizzaAdminCustomerSessionBean extends BasePizzaDatabaseBean impleme
                // 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