]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Continued with observers:
authorRoland Häder <roland@mxchange.org>
Wed, 27 Apr 2016 12:15:17 +0000 (14:15 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 27 Apr 2016 20:21:47 +0000 (22:21 +0200)
- 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

src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java
src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionController.java
src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaAdminMobileProviderWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java

index ec0e666b60ef3819a1514856608e63343c0b8d68..591b52f209da8b0ed2993c52887360f8a54ddb6e 100644 (file)
@@ -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;
        }
index 4223b78eb10823428c1e01df8c12331ed8d64026..381330ef2638770697f7dc67a1c77ecc6cb190ed 100644 (file)
@@ -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
+        * <p>
+        * @param event Event being fired
+        */
+       void afterAdminAddedCustomer (final AdminAddedCustomerEvent event);
+
+       /**
+        * Event observer for newly added users by an administrator
+        * <p>
+        * @param event Event being fired
+        */
+       void afterAdminAddedUserEvent (final AdminAddedUserEvent event);
+
        /**
         * Event observer for updated contact data by admins
         * <p>
index 1e587dc6387c50c5397774f5da6ac7865921f815..a43f0631d562d42da9e31705034a62ccc6f9433b 100644 (file)
@@ -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.
index 088d747a2dc0fc976fcb21ab41e981d753e84930..c92a4cc986557534acb6638944056127db828b81 100644 (file)
@@ -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
        }
index ec7f0e4539afb9e1daf2392b1b91554b7491dc53..a47626a3c509ddcb86723479c26444370e0ccb46 100644 (file)
@@ -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;
        }