From e110954a2a8143be075d646dfe03d7ba964c3dbd Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 29 Apr 2016 22:16:04 +0200 Subject: [PATCH] The customer is now differently created, first you need to get the contact-relevant data from the contact controller, then you need to generate a customer number and attach the contact instance to it. Method addCustomer(customer) was no need for calling external as the event does the same job. Remove event from general customer controller. --- .../checkout/PizzaCheckoutWebSessionBean.java | 9 ++- .../customer/PizzaCustomerWebSessionBean.java | 79 ++++++++++--------- .../PizzaCustomerWebSessionController.java | 8 -- 3 files changed, 50 insertions(+), 46 deletions(-) diff --git a/src/java/org/mxchange/pizzaapplication/beans/checkout/PizzaCheckoutWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/checkout/PizzaCheckoutWebSessionBean.java index e325da56..f4df6087 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/checkout/PizzaCheckoutWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/checkout/PizzaCheckoutWebSessionBean.java @@ -38,6 +38,7 @@ import org.mxchange.jshopcore.model.basket.AddableBasketItem; import org.mxchange.jshopcore.wrapper.CheckoutWrapper; import org.mxchange.jshopcore.wrapper.WrapableCheckout; import org.mxchange.pizzaapplication.beans.basket.PizzaBasketWebSessionController; +import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController; import org.mxchange.pizzaapplication.beans.customer.PizzaCustomerWebSessionController; import org.mxchange.pizzaapplication.beans.receipt.PizzaReceiptWebSessionController; @@ -67,6 +68,12 @@ public class PizzaCheckoutWebSessionBean implements PizzaCheckoutWebSessionContr */ private Connection connection; + /** + * Contact controller + */ + @Inject + private PizzaContactWebSessionController contactController; + /** * Customer instance */ @@ -135,7 +142,7 @@ public class PizzaCheckoutWebSessionBean implements PizzaCheckoutWebSessionContr } // Are at least the required fields set? - if (!this.customerController.isRequiredPersonalDataSet()) { + if (!this.contactController.isRequiredPersonalDataSet()) { // Trace message //this.getLogger().logTrace("doCheckout: Not all required fields are set, returning checkout2 ... - EXIT!"); diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionBean.java index 2be7b522..23cbe5a3 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionBean.java @@ -23,9 +23,7 @@ import java.util.List; import java.util.Objects; import javax.annotation.PostConstruct; import javax.enterprise.context.SessionScoped; -import javax.enterprise.event.Event; import javax.enterprise.event.Observes; -import javax.enterprise.inject.Any; import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; import javax.inject.Named; @@ -70,13 +68,6 @@ public class PizzaCustomerWebSessionBean implements PizzaCustomerWebSessionContr */ private final ContactSessionBeanRemote contactBean; - /** - * An event being fired when an administrator has added a new customer - */ - @Inject - @Any - private Event customerAddedEvent; - /** * A list of all customers */ @@ -107,40 +98,13 @@ public class PizzaCustomerWebSessionBean implements PizzaCustomerWebSessionContr } } - @Override - public void addCustomer (final Customer customer) { - // The contact must be valid - if (null == customer) { - // Throw NPE - throw new NullPointerException("customer is null"); //NOI18N - } else if (customer.getCustomerId() == null) { - // Throw again ... - throw new NullPointerException("customer.customerId is null"); //NOI18N - } else if (customer.getCustomerId() < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("customer.customerId={0} is not valid", customer.getCustomerId())); //NOI18N - } else if (customer.getCustomerContact() == null) { - // Throw NPE - throw new NullPointerException("customer.customerContact is null"); //NOI18N - } else if (customer.getCustomerContact().getContactId() == null) { - // Throw again ... - throw new NullPointerException("customer.customerContact.contactId is null"); //NOI18N - } else if (customer.getCustomerContact().getContactId() < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("customer.customerContact.contactId={0} is not valid", customer.getCustomerContact().getContactId())); //NOI18N - } - - // Add to list - this.customerList.add(customer); - } - @Override public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) { // The event must be valid if (null == event) { // Throw NPE throw new NullPointerException("event is null"); //NOI18N - } else if (event.getAddedContact()== null) { + } else if (event.getAddedContact() == null) { // Throw again ... throw new NullPointerException("event.addedContact is null"); //NOI18N } else if (event.getAddedContact().getContactId() == null) { @@ -170,6 +134,15 @@ public class PizzaCustomerWebSessionBean implements PizzaCustomerWebSessionContr } else if (event.getAddedCustomer().getCustomerId() < 1) { // Not valid throw new IllegalArgumentException(MessageFormat.format("event.addedCustomer.customerId={0} is not valid", event.getAddedCustomer().getCustomerId())); //NOI18N //NOI18N + } else if (event.getAddedCustomer().getCustomerContact() == null) { + // Throw NPE + throw new NullPointerException("event.addedCustomer.customerContact is null"); //NOI18N + } else if (event.getAddedCustomer().getCustomerContact().getContactId() == null) { + // Throw again ... + throw new NullPointerException("event.addedCustomer.customerContact.contactId is null"); //NOI18N + } else if (event.getAddedCustomer().getCustomerContact().getContactId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("event.addedCustomer.customerContact.contactId={0} is not valid", event.getAddedCustomer().getCustomerContact().getContactId())); //NOI18N } else if (!this.selectableContacts.contains(event.getAddedCustomer().getCustomerContact())) { // Contact not in selectable list found throw new IllegalStateException(MessageFormat.format("event.addedCustomer.customerId={0} is not in selectableContacts list.", event.getAddedCustomer().getCustomerContact().getContactId())); @@ -275,4 +248,36 @@ public class PizzaCustomerWebSessionBean implements PizzaCustomerWebSessionContr return Collections.unmodifiableList(this.selectableContacts); } + /** + * Adds given customer instance to this controller. The customer should be + * an updated instance (with id number). + *

+ * @param customer Customer instance + */ + private void addCustomer (final Customer customer) { + // The contact must be valid + if (null == customer) { + // Throw NPE + throw new NullPointerException("customer is null"); //NOI18N + } else if (customer.getCustomerId() == null) { + // Throw again ... + throw new NullPointerException("customer.customerId is null"); //NOI18N + } else if (customer.getCustomerId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("customer.customerId={0} is not valid", customer.getCustomerId())); //NOI18N + } else if (customer.getCustomerContact() == null) { + // Throw NPE + throw new NullPointerException("customer.customerContact is null"); //NOI18N + } else if (customer.getCustomerContact().getContactId() == null) { + // Throw again ... + throw new NullPointerException("customer.customerContact.contactId is null"); //NOI18N + } else if (customer.getCustomerContact().getContactId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("customer.customerContact.contactId={0} is not valid", customer.getCustomerContact().getContactId())); //NOI18N + } + + // Add to list + this.customerList.add(customer); + } + } diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionController.java index 42be4d49..5fc2464c 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionController.java @@ -30,14 +30,6 @@ import org.mxchange.jcustomercore.model.customer.Customer; */ public interface PizzaCustomerWebSessionController extends Serializable { - /** - * Adds customer instance to list. The customer should be an updated - * instance (with id number). - *

- * @param customer Customer instance - */ - void addCustomer (final Customer customer); - /** * Observes events being fired when an administrator has added a new * contact. -- 2.39.5