From: Roland Häder Date: Tue, 26 Apr 2016 09:38:23 +0000 (+0200) Subject: Continued a bit: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=22eef7786d73a7d952549f3a8b18e776da16b545;p=pizzaservice-ejb.git Continued a bit: - renamed some fields and added thrown exception - added general customer EJB for checking if the customer is already registered --- 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);