]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Continued with adding customers:
authorRoland Häder <roland@mxchange.org>
Tue, 26 Apr 2016 09:45:23 +0000 (11:45 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 27 Apr 2016 20:06:18 +0000 (22:06 +0200)
- addCustomer() is now "basicly finished"
- it fires an event when a new customer has been added

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java

index bde39ab1fe2ea60d133c9e7945682a5d6baffa62..d643aaffc250b59cff346ef11584ddab8f1027e7 100644 (file)
@@ -20,6 +20,8 @@ import java.util.Collections;
 import java.util.List;
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.RequestScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Any;
 import javax.faces.view.facelets.FaceletException;
 import javax.inject.Inject;
 import javax.inject.Named;
@@ -28,6 +30,9 @@ import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jcontacts.contact.gender.Gender;
+import org.mxchange.jcustomercore.events.AdminAddedCustomerEvent;
+import org.mxchange.jcustomercore.events.CustomerAdminAddedEvent;
+import org.mxchange.jcustomercore.exceptions.CustomerAlreadyRegisteredException;
 import org.mxchange.jcustomercore.model.customer.Customer;
 import org.mxchange.jcustomercore.model.customer.status.CustomerAccountStatus;
 import org.mxchange.pizzaapplication.beans.contact.PizzaAdminContactWebRequestController;
@@ -58,6 +63,13 @@ public class PizzaAdminCustomerWebRequestBean implements PizzaAdminCustomerWebRe
         */
        private PizzaAdminCustomerSessionBeanRemote adminCustomerBean;
 
+       /**
+        * An event being fired when an administrator has added a new customer
+        */
+       @Inject
+       @Any
+       private Event<AdminAddedCustomerEvent> customerAddedEvent;
+
        /**
         * A list of all customers
         */
@@ -85,7 +97,7 @@ public class PizzaAdminCustomerWebRequestBean implements PizzaAdminCustomerWebRe
                // Are at least some fields added?
                if (!this.isCustomerDataSet()) {
                        // Not all customer data is set
-                       throw new FaceletException("PLease provide minimum personal data: gender, first_name, family_name");
+                       throw new FaceletException("Please provide minimum personal data: gender, first_name, family_name"); //NOI18N
                }
 
                // Get contact instance
@@ -96,6 +108,26 @@ public class PizzaAdminCustomerWebRequestBean implements PizzaAdminCustomerWebRe
 
                // Create new customer instance
                Customer customer = new PizzaCustomer(CustomerAccountStatus.CONFIRMED, contact, customerNumber);
+
+               // Init instance
+               Customer updatedCustomer;
+
+               try {
+                       // Add customer and return updated
+                       updatedCustomer = this.adminCustomerBean.addCustomer(customer);
+               } catch (final CustomerAlreadyRegisteredException ex) {
+                       // Throw again
+                       throw new FaceletException(ex);
+               }
+
+               // Add customer to list
+               this.customerList.add(updatedCustomer);
+
+               // Fire event
+               this.customerAddedEvent.fire(new CustomerAdminAddedEvent(updatedCustomer));
+
+               // Redirect
+               return "admin_list_customer"; //NOI18N
        }
 
        @Override