]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
The customer is now differently created, first you need to get the contact-relevant...
authorRoland Haeder <roland@mxchange.org>
Fri, 29 Apr 2016 20:16:04 +0000 (22:16 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 29 Apr 2016 20:16:04 +0000 (22:16 +0200)
Method addCustomer(customer) was no need for calling external as the event does the same job.

Remove event from general customer controller.

src/java/org/mxchange/pizzaapplication/beans/checkout/PizzaCheckoutWebSessionBean.java
src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionBean.java
src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionController.java

index e325da560ed67b6457731101cd91e887b8e83d66..f4df60872245f44a3d26b5a58285e0d912b6262b 100644 (file)
@@ -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!");
 
index 2be7b522762af5dfc0b0ad16feef036baebc1b9e..23cbe5a3fb5224201a8568f5039ae41c3a9ea337 100644 (file)
@@ -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<AdminAddedCustomerEvent> 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).
+        * <p>
+        * @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);
+       }
+
 }
index 42be4d49aa687af8292268fde2afcfbbc4f0fcc1..5fc2464c219a7a9b3869f315aaf64018bebb1928 100644 (file)
@@ -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).
-        * <p>
-        * @param customer Customer instance
-        */
-       void addCustomer (final Customer customer);
-
        /**
         * Observes events being fired when an administrator has added a new
         * contact.