From: Roland Häder Date: Wed, 27 Apr 2016 15:51:06 +0000 (+0200) Subject: Continued with contact: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=15ee0569d8d8b9e2889e3328e4816de50cf7feb4;p=addressbook-war.git Continued with contact: - added observers for events being fired when admin added new contact - cleared admin contact bean after adding contact Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java index bb46862f..917234ba 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java @@ -285,6 +285,9 @@ public class AddressbookAdminContactWebRequestBean implements AddressbookAdminCo // Fire event this.addedContactEvent.fire(new AdminContactAddedEvent(updatedContact)); + // Clear this bean + this.clear(); + // Return outcome return "admin_list_contact"; //NOI18N } diff --git a/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java index 725b928f..ed9c740f 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java @@ -37,6 +37,7 @@ import org.mxchange.jcontacts.contact.ContactSessionBeanRemote; import org.mxchange.jcontacts.contact.UserContact; import org.mxchange.jcontacts.contact.gender.Gender; import org.mxchange.jcontacts.contact.utils.ContactUtils; +import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent; import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent; import org.mxchange.jcontacts.exceptions.ContactNotFoundException; import org.mxchange.jcountry.data.Country; diff --git a/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionController.java b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionController.java index 1f402a86..a7ab2756 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionController.java +++ b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionController.java @@ -21,6 +21,7 @@ import java.util.Date; import java.util.List; import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jcontacts.contact.gender.Gender; +import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent; import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent; import org.mxchange.jcontacts.exceptions.ContactNotFoundException; import org.mxchange.jcountry.data.Country; @@ -46,7 +47,7 @@ public interface AddressbookContactWebSessionController extends Serializable { *

* @return A list of all contacts. */ - List allContacts(); + List allContacts (); /** * Checks whether there are contacts. @@ -69,13 +70,6 @@ public interface AddressbookContactWebSessionController extends Serializable { */ void updateContactDataFromController (final Contact userContact); - /** - * Adds given email address to list - *

- * @param contactEmailAddress Email address to add - */ - void addEmailAddress (final String contactEmailAddress); - /** * Tries to lookup contact by given id number. If the user is not found a * proper exceptions are thrown. @@ -96,7 +90,15 @@ public interface AddressbookContactWebSessionController extends Serializable { void afterRegistrationEvent (final UserRegisteredEvent event); /** - * Event observer for updated contact data by admins + * Observes events being fired when an administrator has added a new + * contact. + *

+ * @param event Event being fired + */ + void afterAdminAddedContact (final AdminAddedContactEvent event); + + /** + * Event observer for updated contact data by administrators *

* @param event Updated contact data event */ diff --git a/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java index 2d13c89d..405d133a 100644 --- a/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java @@ -35,10 +35,7 @@ import javax.naming.NamingException; import org.mxchange.addressbook.beans.contact.AddressbookContactWebSessionController; import org.mxchange.addressbook.beans.login.AddressbookUserLoginWebSessionController; import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jcontacts.contact.ContactSessionBeanRemote; +import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent; import org.mxchange.jusercore.events.login.UserLoggedInEvent; import org.mxchange.jusercore.events.registration.UserRegisteredEvent; import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; @@ -158,6 +155,27 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC } } + @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) { + // Throw again ... + throw new NullPointerException("event.addedContact is null"); //NOI18N + } else if (event.getAddedContact().getContactId() == null) { + // ... and again + throw new NullPointerException("event.addedContact.customerId is null"); //NOI18N + } else if (event.getAddedContact().getContactId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("event.addedContact.customerId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N + } + + // Call other method + this.selectableContacts.add(event.getAddedContact()); + } + @Override public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) { // Trace message diff --git a/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionController.java b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionController.java index edac6cce..c5eb1ade 100644 --- a/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionController.java +++ b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionController.java @@ -19,6 +19,7 @@ package org.mxchange.addressbook.beans.user; import java.io.Serializable; import java.util.List; import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent; import org.mxchange.jusercore.events.login.UserLoggedInEvent; import org.mxchange.jusercore.events.registration.UserRegisteredEvent; import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; @@ -105,6 +106,14 @@ public interface AddressbookUserWebSessionController extends Serializable { */ boolean isContactFound (final Contact contact); + /** + * Observes events being fired when an administrator has added a new + * contact. + *

+ * @param event Event being fired + */ + void afterAdminAddedContact (final AdminAddedContactEvent event); + /** * Checks whether a public user account is registered. This means that at * least one user profile has its flag "public user profile" enabled.