]> git.mxchange.org Git - pizzaservice-ejb.git/commitdiff
Continued a bit:
authorRoland Häder <roland@mxchange.org>
Tue, 26 Apr 2016 09:38:23 +0000 (11:38 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 27 Apr 2016 19:02:36 +0000 (21:02 +0200)
- renamed some fields and added thrown exception
- added general customer EJB for checking if the customer is already registered

src/java/org/mxchange/pizzaapplication/model/customer/PizzaAdminCustomerSessionBean.java

index 6238c6e72113448bbc035521cfd6951a0b55c58f..ba05158c00ec9fa576c355634ea9d4bb2df0ef7e 100644 (file)
@@ -25,6 +25,7 @@ import javax.persistence.NoResultException;
 import javax.persistence.Query;
 import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
+import org.mxchange.jcustomercore.exceptions.CustomerAlreadyRegisteredException;
 import org.mxchange.jcustomercore.model.customer.Customer;
 import org.mxchange.jcustomercore.utils.CustomerUtils;
 import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean;
@@ -46,10 +47,16 @@ public class PizzaAdminCustomerSessionBean extends BasePizzaDatabaseBean impleme
         * Contact instance
         */
        @EJB
-       private ContactSessionBeanRemote customerBean;
+       private ContactSessionBeanRemote contactBean;
+
+       /**
+        * General customer bean
+        */
+       @EJB
+       private RateCalcCustomerSessionBeanRemote customerBean;
 
        @Override
-       public Customer addCustomer (final Customer customer) {
+       public Customer addCustomer (final Customer customer) throws CustomerAlreadyRegisteredException {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("addCustomer: customer={0} - CALLED!", customer)); //NOI18N
 
@@ -69,6 +76,9 @@ public class PizzaAdminCustomerSessionBean extends BasePizzaDatabaseBean impleme
                } else if (customer.getCustomerNumber().length() < RateCalcAdminCustomerSessionBeanRemote.CUSTOMER_NUMBER_LENGTH) {
                        // To short number
                        throw new IllegalArgumentException(MessageFormat.format("customer.customerNumber.length={0} is shorter than expected: {1}", customer.getCustomerNumber().length(), RateCalcAdminCustomerSessionBeanRemote.CUSTOMER_NUMBER_LENGTH)); //NOI18N
+               } else if (this.customerBean.isReqistered(customer)) {
+                       // Throw exception
+                       throw new CustomerAlreadyRegisteredException(customer);
                }
 
                // Get contact instance
@@ -76,9 +86,9 @@ public class PizzaAdminCustomerSessionBean extends BasePizzaDatabaseBean impleme
                Contact updatedContact = null;
 
                // Is a customer found?
-               if (this.customerBean.isContactFound(contact)) {
+               if (this.contactBean.isContactFound(contact)) {
                        // Yes, then get updated version
-                       updatedContact = this.customerBean.updateContactData(contact);
+                       updatedContact = this.contactBean.updateContactData(contact);
 
                        // Remove it from customer so it won't get persisted again
                        customer.setCustomerContact(null);