From 22eef7786d73a7d952549f3a8b18e776da16b545 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 26 Apr 2016 11:38:23 +0200 Subject: [PATCH] Continued a bit: - renamed some fields and added thrown exception - added general customer EJB for checking if the customer is already registered --- .../PizzaAdminCustomerSessionBean.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/java/org/mxchange/pizzaapplication/model/customer/PizzaAdminCustomerSessionBean.java b/src/java/org/mxchange/pizzaapplication/model/customer/PizzaAdminCustomerSessionBean.java index 6238c6e..ba05158 100644 --- a/src/java/org/mxchange/pizzaapplication/model/customer/PizzaAdminCustomerSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/model/customer/PizzaAdminCustomerSessionBean.java @@ -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); -- 2.39.2