From e4f374a7024dfed9c14413652263204153349749 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 27 Apr 2016 14:15:17 +0200 Subject: [PATCH] Continued with observers: - added afterAdminAddedCustomer() to add contact to list - commented out noisy debug lines - clear() is still needed for request-scoped to remove the form data - no need for explicit clear() call as the observer does it - removed some commented out log messages --- .../contact/PizzaContactWebSessionBean.java | 74 ++++++++++++++++--- .../PizzaContactWebSessionController.java | 17 +++++ ...izzaAdminMobileProviderWebRequestBean.java | 14 ++++ .../user/PizzaAdminUserWebRequestBean.java | 3 - .../beans/user/PizzaUserWebSessionBean.java | 17 ++--- 5 files changed, 99 insertions(+), 26 deletions(-) diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java index ec0e666b..591b52f2 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java @@ -38,6 +38,7 @@ import org.mxchange.jcontacts.contact.utils.ContactUtils; import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent; import org.mxchange.jcontacts.exceptions.ContactNotFoundException; import org.mxchange.jcountry.data.Country; +import org.mxchange.jcustomercore.events.AdminAddedCustomerEvent; import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber; import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber; import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; @@ -47,6 +48,7 @@ import org.mxchange.jphone.phonenumbers.landline.LandLineNumber; import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; import org.mxchange.jusercore.events.login.UserLoggedInEvent; import org.mxchange.jusercore.events.registration.UserRegisteredEvent; +import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; import org.mxchange.jusercore.exceptions.UserPasswordMismatchException; import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController; @@ -226,10 +228,64 @@ public class PizzaContactWebSessionBean implements PizzaContactWebSessionControl this.emailAddressList.add(contactEmailAddress); } + @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 + } + + // Clear this bean + this.clear(); + + // Call other method + this.contactList.add(event.getAddedCustomer().getCustomerContact()); + } + + @Override + public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) { + // The event must be valid + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getAddedUser() == null) { + // Throw NPE again + throw new NullPointerException("event.addedUser is null"); //NOI18N + } else if (event.getAddedUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.addedUser.userId is null"); //NOI18N + } else if (event.getAddedUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N + } else if (event.getAddedUser().getUserContact() == null) { + // userId is null + throw new NullPointerException("event.addedUser.userContact is null"); //NOI18N + } else if (event.getAddedUser().getUserContact().getContactId() == null) { + // userId is null + throw new NullPointerException("event.addedUser.userContact.contactId is null"); //NOI18N + } else if (event.getAddedUser().getUserContact().getContactId() < 1) { + // userId is null + throw new IllegalArgumentException(MessageFormat.format("event.addedUser.userContact.contactId={0} is not valid", event.getAddedUser().getUserContact().getContactId())); //NOI18N + } + + // Add user to local list + this.contactList.add(event.getAddedUser().getUserContact()); + } + @Override public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) { // Trace message - System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N // event should not be null if (null == event) { @@ -275,7 +331,7 @@ public class PizzaContactWebSessionBean implements PizzaContactWebSessionControl @Override public void afterRegistrationEvent (final @Observes UserRegisteredEvent event) { // Trace message - System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N // event should not be null if (null == event) { @@ -296,7 +352,7 @@ public class PizzaContactWebSessionBean implements PizzaContactWebSessionControl Contact registeredContact = event.getRegisteredUser().getUserContact(); // Debug message - System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: registeredContact={0}", registeredContact)); //NOI18N + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: registeredContact={0}", registeredContact)); //NOI18N // Copy all data from registered->user this.copyContact(registeredContact); @@ -308,13 +364,13 @@ public class PizzaContactWebSessionBean implements PizzaContactWebSessionControl this.clear(); // Trace message - System.out.println("ContactWebBean:afterRegistration: EXIT!"); //NOI18N + //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterRegistration: EXIT!"); //NOI18N } @Override public void afterUserLogin (final @Observes UserLoggedInEvent event) { // Trace message - System.out.println(MessageFormat.format("ContactWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N // event should not be null if (null == event) { @@ -335,7 +391,7 @@ public class PizzaContactWebSessionBean implements PizzaContactWebSessionControl this.copyContact(event.getLoggedInUser().getUserContact()); // Trace message - System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N + //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N } @Override @@ -373,9 +429,6 @@ public class PizzaContactWebSessionBean implements PizzaContactWebSessionControl @Override public Contact createContactInstance () { - // User message - //this.getLogger().logTrace("createContactInstance: CALLED!"); - // Required personal data must be set assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N @@ -455,9 +508,6 @@ public class PizzaContactWebSessionBean implements PizzaContactWebSessionControl contact.setContactCellphoneNumber(cellphone); } - // Trace message - //this.getLogger().logTrace(MessageFormat.format("createContactInstance: localContact={0} - EXIT!", localContact)); - // Return it return contact; } diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionController.java index 4223b78e..381330ef 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionController.java @@ -24,9 +24,11 @@ import org.mxchange.jcontacts.contact.gender.Gender; import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent; import org.mxchange.jcontacts.exceptions.ContactNotFoundException; import org.mxchange.jcountry.data.Country; +import org.mxchange.jcustomercore.events.AdminAddedCustomerEvent; import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; import org.mxchange.jusercore.events.login.UserLoggedInEvent; import org.mxchange.jusercore.events.registration.UserRegisteredEvent; +import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; /** * An interface for user beans @@ -85,6 +87,21 @@ public interface PizzaContactWebSessionController extends Serializable { */ void afterRegistrationEvent (final UserRegisteredEvent event); + /** + * Observes events being fired when an administrator has added a new + * customer + *

+ * @param event Event being fired + */ + void afterAdminAddedCustomer (final AdminAddedCustomerEvent event); + + /** + * Event observer for newly added users by an administrator + *

+ * @param event Event being fired + */ + void afterAdminAddedUserEvent (final AdminAddedUserEvent event); + /** * Event observer for updated contact data by admins *

diff --git a/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaAdminMobileProviderWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaAdminMobileProviderWebRequestBean.java index 1e587dc6..a43f0631 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaAdminMobileProviderWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaAdminMobileProviderWebRequestBean.java @@ -130,6 +130,9 @@ public class PizzaAdminMobileProviderWebRequestBean implements PizzaAdminMobileP // Fire event this.providerAddedEvent.fire(new AdminMobileProviderAddedEvent(updatedProvider)); + // Clear this bean + this.clear(); + // Redirect to list return "admin_list_mobile_provider"; //NOI18N } @@ -184,6 +187,17 @@ public class PizzaAdminMobileProviderWebRequestBean implements PizzaAdminMobileP return (!this.allMobileProvider().isEmpty()); } + /** + * Clears this bean + */ + private void clear () { + // Set all vaues to null + this.setProviderCountry(null); + this.setProviderDialPrefix(null); + this.setProviderMailPattern(null); + this.setProviderName(null); + } + /** * Checks whether if the given mobile provider is already created by * checking both dial prefix and country. diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java index 088d747a..c92a4cc9 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java @@ -245,9 +245,6 @@ public class PizzaAdminUserWebRequestBean implements PizzaAdminUserWebRequestCon // Fire event this.addedUserEvent.fire(new AdminUserAddedEvent(updatedUser)); - // Clear contact instance - this.contactController.clear(); - // Return to user list (for now) return "admin_list_user"; //NOI18N } diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java index ec7f0e45..a47626a3 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java @@ -168,7 +168,7 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController { @Override public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) { // Trace message - System.out.println(MessageFormat.format("ContactWebBean:afterAdminAddedUserEvent: event={0} - CALLED!", event)); //NOI18N + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminAddedUserEvent: event={0} - CALLED!", event)); //NOI18N // The event must be valid if (null == event) { @@ -207,7 +207,7 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController { @Override public void afterRegistrationEvent (final @Observes UserRegisteredEvent event) { // Trace message - System.out.println(MessageFormat.format("UserWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N // event should not be null if (null == event) { @@ -228,7 +228,7 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController { User registeredUser = event.getRegisteredUser(); // Debug message - System.out.println(MessageFormat.format("UserWebBean:afterRegistration: registeredUser={0}", registeredUser)); //NOI18N + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: registeredUser={0}", registeredUser)); //NOI18N // Copy all data from registered->user this.copyUser(registeredUser); @@ -252,13 +252,13 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController { } // Trace message - System.out.println("UserWebBean:afterRegistration: EXIT!"); //NOI18N + //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterRegistration: EXIT!"); //NOI18N } @Override public void afterUserLogin (final @Observes UserLoggedInEvent event) { // Trace message - System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N // event should not be null if (null == event) { @@ -282,7 +282,7 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController { this.copyUser(event.getLoggedInUser()); // Trace message - System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: this.visibleUserList.size()={0} - EXIT!", this.visibleUserList.size())); //NOI18N + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: this.visibleUserList.size()={0} - EXIT!", this.visibleUserList.size())); //NOI18N } @Override @@ -320,9 +320,6 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController { @Override public User createUserInstance () { - // User message - //this.getLogger().logTrace("createUserInstance: CALLED!"); - // Required personal data must be set assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N @@ -339,8 +336,6 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController { // Set contact in user localUser.setUserContact(contact); - // Trace message - //this.getLogger().logTrace(MessageFormat.format("createUserInstance: user={0} - EXIT!", user)); // Return it return localUser; } -- 2.39.5