From 416ce0cd0fe2b5249404dc64ca983be919f646ef Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 22 Apr 2016 09:52:57 +0200 Subject: [PATCH] Continued a bit: - added observer method afterAdminUpdatedContactDataEvent() to update contact and email lists - no contact list in admin controller as the same exists in general controller - imports cleaned up MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- ...AddressbookAdminContactWebRequestBean.java | 5 +- .../AddressbookContactWebSessionBean.java | 48 +++++++++++++++++++ ...ddressbookContactWebSessionController.java | 8 ++++ 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java index 51a4c047..554d404b 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java @@ -238,11 +238,8 @@ public class AddressbookAdminContactWebRequestBean implements AddressbookAdminCo // Call EJB for updating contact data Contact updatedContact = this.contactBean.updateContactPersonalData(contact); - // Update list - this.updateList(updatedContact); - // Fire event - this.updatedContactDataEvent.fire(new AdminContactUpdatedEvent(updatedContact)); + this.updatedContactEvent.fire(new AdminContactUpdatedEvent(updatedContact)); // Return to contact list (for now) 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 7e2c94d6..66295f55 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java @@ -35,6 +35,7 @@ import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jcontacts.contact.ContactSessionBeanRemote; import org.mxchange.jcontacts.contact.UserContact; 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.jphone.phonenumbers.cellphone.CellphoneNumber; @@ -209,6 +210,52 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe this.emailAddressList.add(contactEmailAddress); } + @Override + public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) { + // Trace message + System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N + + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUpdatedContact()== null) { + // Throw NPE again + throw new NullPointerException("event.user is null"); //NOI18N + } else if (event.getUpdatedContact().getContactId() == null) { + // userId is null + throw new NullPointerException("event.user.userId is null"); //NOI18N + } else if (event.getUpdatedContact().getContactId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N + } + + // Get iterator from list + Iterator iterator = this.contactList.iterator(); + + // "Walk" through all entries + while (iterator.hasNext()) { + // Get next element + Contact next = iterator.next(); + + // Is id number the same? + if (Objects.equals(event.getUpdatedContact().getContactId(), next.getContactId())) { + // Found entry, so remove it and abort + this.contactList.remove(next); + + // Remove also email from list + this.emailAddressList.remove(next.getContactEmailAddress()); + break; + } + } + + // Add contact to list + this.contactList.add(event.getUpdatedContact()); + + // Add email address to list + this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress()); + } + @Override public void afterRegistrationEvent (final @Observes UserRegisteredEvent event) { // Trace message @@ -393,6 +440,7 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe // Trace message //this.getLogger().logTrace(MessageFormat.format("createContactInstance: localContact={0} - EXIT!", localContact)); + // Return it return localContact; } diff --git a/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionController.java b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionController.java index 757b8273..39998c6c 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionController.java +++ b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionController.java @@ -20,6 +20,7 @@ import java.io.Serializable; import java.util.Date; import org.mxchange.jcontacts.contact.Contact; 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.jphone.phonenumbers.mobileprovider.MobileProvider; @@ -76,6 +77,13 @@ public interface AddressbookContactWebSessionController extends Serializable { */ void afterRegistrationEvent (final UserRegisteredEvent event); + /** + * Event observer for updated contact data by admins + *

+ * @param event Updated contact data event + */ + void afterAdminUpdatedContactDataEvent (final AdminUpdatedContactEvent event); + /** * Event observer for logged-in user *

-- 2.39.5