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;
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;
*/
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
*/
// 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
// 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