From 9ae755de45ca44003f48967e6d59722d2d9387d8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 26 Apr 2016 11:45:23 +0200 Subject: [PATCH] Continued with adding customers: - addCustomer() is now "basicly finished" - it fires an event when a new customer has been added MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../PizzaAdminCustomerWebRequestBean.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java index bde39ab1..d643aaff 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java @@ -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 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 -- 2.39.5