From: Roland Häder Date: Tue, 23 Aug 2016 13:55:49 +0000 (+0200) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a05307951035afa92eda8a8ad91848b126a9982f;p=jjobs-war.git Please cherry-pick: - renamed fields as List as suffix is redundant - observed events for unlinked fax, land-line and mobile numbers --- diff --git a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java index 2022b318..e087f813 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java @@ -40,6 +40,9 @@ import org.mxchange.jcontacts.contact.utils.ContactUtils; import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent; import org.mxchange.jcontacts.events.contact.deleted.AdminDeletedContactEvent; import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent; +import org.mxchange.jcontacts.events.fax.unlinked.AdminUnlinkedFaxNumberEvent; +import org.mxchange.jcontacts.events.landline.unlinked.AdminUnlinkedLandLineNumberEvent; +import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent; import org.mxchange.jcontacts.exceptions.ContactNotFoundException; import org.mxchange.jcountry.data.Country; import org.mxchange.jjobs.beans.BaseJobsController; @@ -97,7 +100,7 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job /** * Contact list */ - private final List contactList; + private final List contacts; /** * Country instance @@ -110,14 +113,14 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job private String emailAddress; /** - * Email address list + * Email address repeated */ - private final List emailAddressList; + private String emailAddressRepeat; /** - * Email address repeated + * Email address list */ - private String emailAddressRepeat; + private final List emailAddresses; /** * Family name @@ -248,8 +251,8 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job } // Init lists/maps - this.contactList = new LinkedList<>(); - this.emailAddressList = new LinkedList<>(); + this.contacts = new LinkedList<>(); + this.emailAddresses = new LinkedList<>(); } @Override @@ -318,7 +321,7 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job } // Remove from both lists - this.contactList.remove(event.getDeletedContact()); + this.contacts.remove(event.getDeletedContact()); this.selectableContacts.remove(event.getDeletedContact()); // Clear all data @@ -352,6 +355,78 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job this.clear(); } + @Override + public void afterAdminUnlinkedFaxContactDataEvent (@Observes final AdminUnlinkedFaxNumberEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUnlinkedFaxNumber() == null) { + // Throw NPE again + throw new NullPointerException("event.unlinkedFaxNumber is null"); //NOI18N + } else if (event.getUnlinkedFaxNumber().getPhoneId() == null) { + // userId is null + throw new NullPointerException("event.unlinkedFaxNumber.contactId is null"); //NOI18N + } else if (event.getUnlinkedFaxNumber().getPhoneId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedFaxNumber(), event.getUnlinkedFaxNumber().getPhoneId())); //NOI18N + } + + // Remove it from list + this.removeFromContacts(event.getUnlinkedFaxNumber()); + + // Clear all data + this.clear(); + } + + @Override + public void afterAdminUnlinkedLandLineContactDataEvent (@Observes final AdminUnlinkedLandLineNumberEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUnlinkedLandLineNumber() == null) { + // Throw NPE again + throw new NullPointerException("event.unlinkedLandLineNumber is null"); //NOI18N + } else if (event.getUnlinkedLandLineNumber().getPhoneId() == null) { + // userId is null + throw new NullPointerException("event.unlinkedLandLineNumber.contactId is null"); //NOI18N + } else if (event.getUnlinkedLandLineNumber().getPhoneId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedLandLineNumber(), event.getUnlinkedLandLineNumber().getPhoneId())); //NOI18N + } + + // Remove it from list + this.removeFromContacts(event.getUnlinkedLandLineNumber()); + + // Clear all data + this.clear(); + } + + @Override + public void afterAdminUnlinkedMobileContactDataEvent (@Observes final AdminUnlinkedMobileNumberEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUnlinkedMobileNumber() == null) { + // Throw NPE again + throw new NullPointerException("event.unlinkedMobileNumber is null"); //NOI18N + } else if (event.getUnlinkedMobileNumber().getPhoneId() == null) { + // userId is null + throw new NullPointerException("event.unlinkedMobileNumber.contactId is null"); //NOI18N + } else if (event.getUnlinkedMobileNumber().getPhoneId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedMobileNumber(), event.getUnlinkedMobileNumber().getPhoneId())); //NOI18N + } + + // Remove it from list + this.removeFromContacts(event.getUnlinkedMobileNumber()); + + // Clear all data + this.clear(); + } + @Override public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) { // event should not be null @@ -373,7 +448,7 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job this.uniqueAddContact(event.getUpdatedContact()); // Add email address to list - this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress()); + this.emailAddresses.add(event.getUpdatedContact().getContactEmailAddress()); } @Override @@ -458,7 +533,7 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size())); // Return un-modified list - return this.contactList; + return this.contacts; } @Override @@ -843,10 +918,10 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job @PostConstruct public void init () { // Get full email address list for reducing EJB calls - this.emailAddressList.addAll(this.contactBean.getEmailAddressList()); + this.emailAddresses.addAll(this.contactBean.getEmailAddressList()); // Get full contact list - this.contactList.addAll(this.contactBean.getAllContacts()); + this.contacts.addAll(this.contactBean.getAllContacts()); // Get all users List allUsers = this.userController.allUsers(); @@ -898,7 +973,7 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job } // Determine it - return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress()))); + return ((this.emailAddresses instanceof List) && (this.emailAddresses.contains(contact.getContactEmailAddress()))); } @Override @@ -939,7 +1014,7 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job this.clear(); // Try to lookup it in visible user list - for (final Iterator iterator = this.contactList.iterator(); iterator.hasNext();) { + for (final Iterator iterator = this.contacts.iterator(); iterator.hasNext();) { // Get next user Contact next = iterator.next(); @@ -979,7 +1054,7 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job } // Check all entries - for (final Contact contact : this.contactList) { + for (final Contact contact : this.contacts) { // Is the mobile instance set and in list? if ((contact.getContactMobileNumber() instanceof DialableMobileNumber) && (event.getMobileNumberList().contains(contact.getContactMobileNumber()))) { // Found it, so remvoe it from list @@ -1018,13 +1093,13 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job */ private void addUserNameEmailAddress (final Contact contact) { // Make sure the entry is not added yet - if (this.emailAddressList.contains(contact.getContactEmailAddress())) { + if (this.emailAddresses.contains(contact.getContactEmailAddress())) { // Already added throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N } // Add email addres - this.emailAddressList.add(contact.getContactEmailAddress()); + this.emailAddresses.add(contact.getContactEmailAddress()); } /** @@ -1138,13 +1213,97 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job } // Remove from general list - if (!this.contactList.remove(contact)) { + if (!this.contacts.remove(contact)) { // Did not remove contact throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N } // Remove from other lists - this.emailAddressList.remove(contact.getContactEmailAddress()); + this.emailAddresses.remove(contact.getContactEmailAddress()); + } + + /** + * Removes given fax number from all contacts + *

+ * @param faxNumber Fax number to remove + */ + private void removeFromContacts (final DialableFaxNumber faxNumber) { + // Is it valid? + if (null == faxNumber) { + // Throw NPE + throw new NullPointerException("faxNumber is null"); + } else if (faxNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("faxNumber.phoneId is null"); + } else if (faxNumber.getPhoneId() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); + } + + // Loop through all contacts + for (final Contact contact : this.contacts) { + // Is the number set? + if (Objects.equals(contact.getContactFaxNumber(), faxNumber)) { + // Found it + contact.setContactFaxNumber(null); + } + } + } + + /** + * Removes given land-line number from all contacts + *

+ * @param landLineNumber Land-line number to remove + */ + private void removeFromContacts (final DialableLandLineNumber landLineNumber) { + // Is it valid? + if (null == landLineNumber) { + // Throw NPE + throw new NullPointerException("landLineNumber is null"); + } else if (landLineNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("landLineNumber.phoneId is null"); + } else if (landLineNumber.getPhoneId() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); + } + + // Loop through all contacts + for (final Contact contact : this.contacts) { + // Is the number set? + if (Objects.equals(contact.getContactLandLineNumber(), landLineNumber)) { + // Found it + contact.setContactLandLineNumber(null); + } + } + } + + /** + * Removes given mobile number from all contacts + *

+ * @param mobileNumber Mobile number to remove + */ + private void removeFromContacts (final DialableMobileNumber mobileNumber) { + // Is it valid? + if (null == mobileNumber) { + // Throw NPE + throw new NullPointerException("mobileNumber is null"); + } else if (mobileNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.phoneId is null"); + } else if (mobileNumber.getPhoneId() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); + } + + // Loop through all contacts + for (final Contact contact : this.contacts) { + // Is the number set? + if (Objects.equals(contact.getContactMobileNumber(), mobileNumber)) { + // Found it + contact.setContactMobileNumber(null); + } + } } /** @@ -1167,7 +1326,7 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job } // Get iterator from list - Iterator iterator = this.contactList.iterator(); + Iterator iterator = this.contacts.iterator(); // "Walk" through all entries while (iterator.hasNext()) { @@ -1183,7 +1342,7 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job } // Add contact to list - this.contactList.add(contact); + this.contacts.add(contact); } } diff --git a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionController.java b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionController.java index ee3c6a00..70e20315 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionController.java +++ b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionController.java @@ -25,6 +25,9 @@ import org.mxchange.jcontacts.contact.gender.Gender; import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent; import org.mxchange.jcontacts.events.contact.deleted.AdminDeletedContactEvent; import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent; +import org.mxchange.jcontacts.events.fax.unlinked.AdminUnlinkedFaxNumberEvent; +import org.mxchange.jcontacts.events.landline.unlinked.AdminUnlinkedLandLineNumberEvent; +import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent; import org.mxchange.jcontacts.exceptions.ContactNotFoundException; import org.mxchange.jcountry.data.Country; import org.mxchange.jphone.events.mobile.remove.AdminRemoveMobileNumberFromListEvent; @@ -64,6 +67,27 @@ public interface JobsContactWebSessionController extends Serializable { */ void afterAdminDeletedContactEvent (final AdminDeletedContactEvent event); + /** + * Event observer for unlinked fax contact by administrators + *

+ * @param event Unlinked fax contact event + */ + void afterAdminUnlinkedFaxContactDataEvent (final AdminUnlinkedFaxNumberEvent event); + + /** + * Event observer for unlinked land-line contact by administrators + *

+ * @param event Unlinked land-line contact event + */ + void afterAdminUnlinkedLandLineContactDataEvent (final AdminUnlinkedLandLineNumberEvent event); + + /** + * Event observer for unlinked mobile contact by administrators + *

+ * @param event Unlinked mobile contact event + */ + void afterAdminUnlinkedMobileContactDataEvent (final AdminUnlinkedMobileNumberEvent event); + /** * Event observer when user confirmed account. *