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.naming.InitialContext;
import javax.naming.NamingException;
import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
import org.mxchange.jcustomercore.events.AdminAddedCustomerEvent;
import org.mxchange.jcustomercore.model.customer.Customer;
import org.mxchange.pizzaapplication.beans.contact.PizzaAdminContactWebRequestController;
*/
private PizzaAdminCustomerSessionBeanRemote adminCustomerBean;
+ /**
+ * Remote user bean
+ */
+ private final ContactSessionBeanRemote contactBean;
+
/**
* An event being fired when an administrator has added a new customer
*/
*/
private List<Customer> customerList;
+ /**
+ * A list of all selectable contacts
+ */
+ private List<Contact> selectableContacts;
+
/**
* Default constructor
*/
// Try to lookup
this.adminCustomerBean = (PizzaAdminCustomerSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/admincustomer!de.chotime.jratecalc.model.customer.PizzaAdminCustomerSessionBeanRemote"); //NOI18N
+
+ // Try to lookup
+ this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
} catch (final NamingException e) {
// Throw again
throw new FaceletException(e);
} 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 afterAdminAddedCustomer (@Observes final AdminAddedCustomerEvent event) {
+ // The event must be valid
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getAddedCustomer() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.addedCustomer is null"); //NOI18N
+ } else if (event.getAddedCustomer().getCustomerId() == null) {
+ // ... and again
+ throw new NullPointerException("event.addedCustomer.customerId is null"); //NOI18N
+ } 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
+ }
+
+ // Call other method
+ this.addCustomer(event.getAddedCustomer());
+ }
+
@Override
public List<Customer> allCustomers () {
// Return it
public void init () {
// Initialize customer list
this.customerList = this.adminCustomerBean.allCustomers();
+
+ // Get all contacts
+ List<Contact> allContacts = this.contactBean.getAllContacts();
+
+ // Get iterator
+ Iterator<Contact> iterator = allContacts.iterator();
+
+ // Loop through it
+ while (iterator.hasNext()) {
+ // Get next element
+ Contact next = iterator.next();
+
+ // Get iterator
+ Iterator<Customer> userIterator = this.customerList.iterator();
+
+ // Loop through all users
+ while (userIterator.hasNext()) {
+ // Get user instance
+ Customer nextCustomer = userIterator.next();
+
+ // Is contact same?
+ if (Objects.equals(next, nextCustomer.getCustomerContact())) {
+ // Found same
+ iterator.remove();
+ break;
+ }
+ }
+ }
+
+ // Set contact list
+ this.selectableContacts = allContacts;
}
@Override