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;
*/
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
*/
}
}
- @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) {
} 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()));
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);
+ }
+
}