X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Fjava%2Forg%2Fmxchange%2Fjjobs%2Fbeans%2Fcontact%2FJobsContactWebSessionBean.java;h=b6cd5ee002f9d6e40d226e05c950f466a30894be;hb=09d2137f89da9234cd2fed7af9021b24c3934662;hp=657e980b9cd0019140c9a8ce0e34c6b359ed1bb0;hpb=ed09ef91eda455ee6e60bbdf98a09477d35cb6fa;p=jjobs-war.git diff --git a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java index 657e980b..b6cd5ee0 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java @@ -40,18 +40,21 @@ 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; import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController; import org.mxchange.jjobs.beans.user.JobsUserWebSessionController; -import org.mxchange.jphone.events.cellphone.remove.AdminRemoveCellphoneNumberFromListEvent; -import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber; -import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber; +import org.mxchange.jphone.events.mobile.remove.AdminRemoveMobileNumberFromListEvent; import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; import org.mxchange.jphone.phonenumbers.fax.FaxNumber; import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; import org.mxchange.jphone.phonenumbers.landline.LandLineNumber; +import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jphone.phonenumbers.mobile.MobileNumber; import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent; import org.mxchange.jusercore.events.login.UserLoggedInEvent; @@ -79,16 +82,6 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job */ private Date birthday; - /** - * Cellphone number's carrier - */ - private MobileProvider cellphoneCarrier; - - /** - * Cellphone number - */ - private Long cellphoneNumber; - /** * City */ @@ -107,7 +100,7 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job /** * Contact list */ - private final List contactList; + private final List contacts; /** * Country instance @@ -120,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 @@ -169,11 +162,6 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job */ private String houseNumberExtension; - /** - * Whether a cellphone entry has been unlinked - */ - private boolean isCellphoneUnlinked; - /** * Whether a fax entry has been unlinked */ @@ -185,19 +173,34 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job private boolean isLandLineUnlinked; /** - * Phone number area code + * Whether a mobile entry has been unlinked + */ + private boolean isMobileUnlinked; + + /** + * Land-line number area code */ - private Integer phoneAreaCode; + private Integer landLineAreaCode; /** - * Country instance for phone number + * Country instance for land-line number */ - private Country phoneCountry; + private Country landLineCountry; /** - * Phone number + * Land-line number */ - private Long phoneNumber; + private Long landLineNumber; + + /** + * Mobile number + */ + private Long mobileNumber; + + /** + * Mobile provider + */ + private MobileProvider mobileProvider; /** * A list of all selectable contacts @@ -248,12 +251,12 @@ 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 - public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) { + public void afterAdminAddedContactEvent (@Observes final AdminAddedContactEvent event) { // The event must be valid if (null == event) { // Throw NPE @@ -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 @@ -326,7 +329,7 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job } @Override - public void afterAdminLinkedUser (@Observes final AdminLinkedUserEvent event) { + public void afterAdminLinkedUserEvent (@Observes final AdminLinkedUserEvent event) { // event should not be null if (null == event) { // Throw NPE @@ -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,11 +448,11 @@ 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 - public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) { + public void afterUserRegistrationEvent (@Observes final UserRegisteredEvent event) { // event should not be null if (null == event) { // Throw NPE @@ -410,7 +485,7 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job } @Override - public void afterUserConfirmedAccountEvent (@Observes final UserConfirmedAccountEvent event) { + public void afterUserConfirmedAccountEventEvent (@Observes final UserConfirmedAccountEvent event) { // event should not be null if (null == event) { // Throw NPE @@ -431,7 +506,7 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job } @Override - public void afterUserLogin (@Observes final UserLoggedInEvent event) { + public void afterUserLoginEvent (@Observes final UserLoggedInEvent event) { // event should not be null if (null == event) { // Throw NPE @@ -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 @@ -473,8 +548,8 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job } // Generate phone number - DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber()); - DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber()); + DialableLandLineNumber phone = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber()); + DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber()); DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber()); // Create new contact @@ -492,7 +567,7 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job // Debug message //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress())); // Don't set null or wrong references - if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) { + if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) { // Now the number must be given if (phone.getPhoneAreaCode() == null) { // Is null @@ -534,18 +609,18 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job } // Is the provider set? - if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) { + if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) { // Is the number set? - if (cellphone.getPhoneNumber() == null) { + if (mobile.getPhoneNumber() == null) { // Is null - throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N - } else if (cellphone.getPhoneNumber() < 1) { + throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N + } else if (mobile.getPhoneNumber() < 1) { // Abort here - throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N + throw new IllegalArgumentException("mobileNumber.phoneNumber is zero or below."); //NOI18N } - // Set cellphone number - contact.setContactCellphoneNumber(cellphone); + // Set mobile number + contact.setContactMobileNumber(mobile); } // Trace message @@ -588,17 +663,17 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job contact.setContactCity(this.getCity()); contact.setContactCountry(this.getCountry()); - // Update contact's cellphone number - this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber()); + // Update contact's mobile number + this.isMobileUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getMobileProvider(), this.getMobileNumber()); // Update contact's land-line number - this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber()); + this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber()); // Update contact's fax number this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber()); // Send it to the EJB - this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked); + this.contactBean.updateContactData(contact, this.isMobileUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked); // All fine return "contact_data_saved"; //NOI18N @@ -616,26 +691,6 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job this.birthday = birthday; } - @Override - public MobileProvider getCellphoneCarrier () { - return this.cellphoneCarrier; - } - - @Override - public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) { - this.cellphoneCarrier = cellphoneCarrier; - } - - @Override - public Long getCellphoneNumber () { - return this.cellphoneNumber; - } - - @Override - public void setCellphoneNumber (Long cellphoneNumber) { - this.cellphoneNumber = cellphoneNumber; - } - @Override public String getCity () { return this.city; @@ -778,33 +833,53 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job } @Override - public Integer getPhoneAreaCode () { - return this.phoneAreaCode; + public Integer getLandLineAreaCode () { + return this.landLineAreaCode; + } + + @Override + public void setLandLineAreaCode (final Integer landLineAreaCode) { + this.landLineAreaCode = landLineAreaCode; + } + + @Override + public Country getLandLineCountry () { + return this.landLineCountry; + } + + @Override + public void setLandLineCountry (final Country landLineCountry) { + this.landLineCountry = landLineCountry; } @Override - public void setPhoneAreaCode (final Integer phoneAreaCode) { - this.phoneAreaCode = phoneAreaCode; + public Long getLandLineNumber () { + return this.landLineNumber; } @Override - public Country getPhoneCountry () { - return this.phoneCountry; + public void setLandLineNumber (final Long landLineNumber) { + this.landLineNumber = landLineNumber; } @Override - public void setPhoneCountry (final Country phoneCountry) { - this.phoneCountry = phoneCountry; + public Long getMobileNumber () { + return this.mobileNumber; } @Override - public Long getPhoneNumber () { - return this.phoneNumber; + public void setMobileNumber (Long mobileNumber) { + this.mobileNumber = mobileNumber; } @Override - public void setPhoneNumber (final Long phoneNumber) { - this.phoneNumber = phoneNumber; + public MobileProvider getMobileProvider () { + return this.mobileProvider; + } + + @Override + public void setMobileProvider (final MobileProvider mobileProvider) { + this.mobileProvider = mobileProvider; } @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(); @@ -965,25 +1040,25 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job } @Override - public void removeCellphoneNumberFromListEvent (@Observes final AdminRemoveCellphoneNumberFromListEvent event) { + public void removeMobileNumberFromListEvent (@Observes final AdminRemoveMobileNumberFromListEvent event) { // event should not be null if (null == event) { // Throw NPE throw new NullPointerException("event is null"); //NOI18N - } else if (event.getCellphoneList()== null) { + } else if (event.getMobileNumberList() == null) { // Throw NPE again - throw new NullPointerException("event.cellphoneList is null"); //NOI18N - } else if (event.getCellphoneList().isEmpty()) { + throw new NullPointerException("event.mobileList is null"); //NOI18N + } else if (event.getMobileNumberList().isEmpty()) { // List is empty, no need to check return; } // Check all entries - for (final Contact contact : this.contactList) { - // Is the cell phone instance set and in list? - if ((contact.getContactCellphoneNumber() instanceof DialableCellphoneNumber) && (event.getCellphoneList().contains(contact.getContactCellphoneNumber()))) { + 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 - event.getCellphoneList().remove(contact.getContactCellphoneNumber()); + event.getMobileNumberList().remove(contact.getContactMobileNumber()); } } } @@ -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()); } /** @@ -1047,11 +1122,11 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job // - contact data this.setEmailAddress(null); this.setEmailAddressRepeat(null); - this.setPhoneAreaCode(null); - this.setPhoneCountry(null); - this.setPhoneNumber(null); - this.setCellphoneCarrier(null); - this.setCellphoneNumber(null); + this.setLandLineAreaCode(null); + this.setLandLineCountry(null); + this.setLandLineNumber(null); + this.setMobileProvider(null); + this.setMobileNumber(null); this.setFaxAreaCode(null); this.setFaxCountry(null); this.setFaxNumber(null); @@ -1095,21 +1170,21 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job this.setBirthday(contact.getContactBirthday()); this.setComment(contact.getContactComment()); - // Get cellphone, phone and fax instance - DialableCellphoneNumber cellphone = contact.getContactCellphoneNumber(); + // Get mobile, phone and fax instance + DialableMobileNumber mobile = contact.getContactMobileNumber(); DialableFaxNumber fax = contact.getContactFaxNumber(); DialableLandLineNumber phone = contact.getContactLandLineNumber(); // - contact data if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) { - this.setPhoneCountry(phone.getPhoneCountry()); - this.setPhoneAreaCode(phone.getPhoneAreaCode()); - this.setPhoneNumber(phone.getPhoneNumber()); + this.setLandLineCountry(phone.getPhoneCountry()); + this.setLandLineAreaCode(phone.getPhoneAreaCode()); + this.setLandLineNumber(phone.getPhoneNumber()); } - if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) { - this.setCellphoneCarrier(cellphone.getCellphoneProvider()); - this.setCellphoneNumber(cellphone.getPhoneNumber()); + if ((mobile instanceof DialableMobileNumber) && (mobile.getMobileProvider() instanceof MobileProvider)) { + this.setMobileProvider(mobile.getMobileProvider()); + this.setMobileNumber(mobile.getPhoneNumber()); } if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) { @@ -1138,13 +1213,106 @@ 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"); //NOI18N + } else if (faxNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N + } else if (faxNumber.getPhoneId() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N + } + + // 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"); //NOI18N + } else if (landLineNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N + } else if (landLineNumber.getPhoneId() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N + } + + // 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) { + // Log message + System.out.println(MessageFormat.format("{0}.removeFromContacts: CALLED!", this.getClass().getSimpleName())); //NOI18N + + // Is it valid? + if (null == mobileNumber) { + // Throw NPE + throw new NullPointerException("mobileNumber is null"); //NOI18N + } else if (mobileNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N + } else if (mobileNumber.getPhoneId() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N + } + + // Loop through all contacts + for (final Contact contact : this.contacts) { + // Log message + System.out.println(MessageFormat.format("{0}.removeFromContacts: contact={1}", this.getClass().getSimpleName(), contact)); //NOI18N + + // Is the number set? + if (Objects.equals(contact.getContactMobileNumber(), mobileNumber)) { + // Log message + System.out.println(MessageFormat.format("{0}.removeFromContacts: Unsetting ...", this.getClass().getSimpleName())); //NOI18N + + // Unset it + contact.setContactMobileNumber(null); + } + } } /** @@ -1167,7 +1335,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 +1351,7 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job } // Add contact to list - this.contactList.add(contact); + this.contacts.add(contact); } }