*/
package org.mxchange.jjobs.beans.phone;
-import fish.payara.cdi.jsr107.impl.NamedCache;
-import java.text.MessageFormat;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Objects;
-import javax.annotation.PostConstruct;
-import javax.cache.Cache;
-import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
-import javax.enterprise.event.Observes;
-import javax.inject.Inject;
import javax.inject.Named;
-import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
-import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
-import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent;
-import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent;
-import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent;
-import org.mxchange.jcontacts.model.contact.Contact;
import org.mxchange.jjobs.beans.BaseJobsBean;
-import org.mxchange.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent;
-import org.mxchange.jphone.events.fax.updated.AdminUpdatedFaxNumberEvent;
-import org.mxchange.jphone.events.landline.deleted.AdminDeletedLandLineNumberEvent;
-import org.mxchange.jphone.events.landline.updated.AdminUpdatedLandLineNumberEvent;
-import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent;
-import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent;
-import org.mxchange.jphone.exceptions.phone.PhoneEntityNotFoundException;
-import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
-import org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote;
-import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
/**
* Regular controller (bean) for phone numbers
*/
private static final long serialVersionUID = 491_058_674_675_690_105L;
- /**
- * All fax numbers
- */
- @Inject
- @NamedCache (cacheName = "faxNumberCache")
- private Cache<Long, DialableFaxNumber> faxNumberCache;
-
- /**
- * All land-line numbers
- */
- @Inject
- @NamedCache (cacheName = "landLineNumberCache")
- private Cache<Long, DialableLandLineNumber> landLineNumberCache;
-
- /**
- * All mobile numbers
- */
- @Inject
- @NamedCache (cacheName = "mobileNumberCache")
- private Cache<Long, DialableMobileNumber> mobileNumberCache;
-
- /**
- * General EJB for phone numbers
- */
- @EJB (lookup = "java:global/jjobs-ejb/phone!org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote")
- private PhoneSessionBeanRemote phoneBean;
-
/**
* Default constructor
*/
super();
}
- /**
- * Observes events being fired when an administrator has added a new
- * contact.
- * <p>
- * @param event Event being fired
- */
- public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent 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.contactId is null"); //NOI18N
- } else if (event.getAddedContact().getContactId() < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
- }
-
- // Update contact's mobile, land-line and fax number
- this.updateContactPhoneNumbers(event.getAddedContact());
-
- // Clear this bean
- this.clear();
- }
-
- /**
- * Event observer for newly added users by administrator
- * <p>
- * @param event Event being fired
- */
- public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
- // event should not be null
- 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
- }
-
- // Update contact's mobile, land-line and fax number
- this.updateContactPhoneNumbers(event.getAddedUser().getUserContact());
-
- // Clear all data
- this.clear();
- }
-
- /**
- * Observes events being fired when an administrator has deleted a fax
- * number
- * <p>
- * @param event Event being fired
- */
- public void afterAdminDeletedFaxNumberEvent (@Observes final AdminDeletedFaxNumberEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getDeletedFaxNumber() == null) {
- // Throw NPE again
- throw new NullPointerException("event.deletedFaxNumber is null"); //NOI18N
- } else if (event.getDeletedFaxNumber().getPhoneId() == null) {
- // userId is null
- throw new NullPointerException("event.deletedFaxNumber.phoneId is null"); //NOI18N
- } else if (event.getDeletedFaxNumber().getPhoneId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedFaxNumber(), event.getDeletedFaxNumber().getPhoneId())); //NOI18N
- }
-
- // Update contact's mobile, land-line and fax number
- this.allFaxNumbers().remove(event.getDeletedFaxNumber());
-
- // Clear all data
- this.clear();
- }
-
- /**
- * Observes events being fired when an administrator has deleted a land-line
- * number
- * <p>
- * @param event Event being fired
- */
- public void afterAdminDeletedLandLineNumberEvent (@Observes final AdminDeletedLandLineNumberEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getDeletedLandLineNumber() == null) {
- // Throw NPE again
- throw new NullPointerException("event.deletedLandLineNumber is null"); //NOI18N
- } else if (event.getDeletedLandLineNumber().getPhoneId() == null) {
- // userId is null
- throw new NullPointerException("event.deletedLandLineNumber.phoneId is null"); //NOI18N
- } else if (event.getDeletedLandLineNumber().getPhoneId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedLandLineNumber(), event.getDeletedLandLineNumber().getPhoneId())); //NOI18N
- }
-
- // Update contact's mobile, land-line and fax number
- this.allLandLineNumbers().remove(event.getDeletedLandLineNumber());
-
- // Clear all data
- this.clear();
- }
-
- /**
- * Observes events being fired when an administrator has deleted a mobile
- * number
- * <p>
- * @param event Event being fired
- */
- public void afterAdminDeletedMobileNumberEvent (@Observes final AdminDeletedMobileNumberEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getDeletedMobileNumber() == null) {
- // Throw NPE again
- throw new NullPointerException("event.deletedMobileNumber is null"); //NOI18N
- } else if (event.getDeletedMobileNumber().getPhoneId() == null) {
- // userId is null
- throw new NullPointerException("event.deletedMobileNumber.phoneId is null"); //NOI18N
- } else if (event.getDeletedMobileNumber().getPhoneId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedMobileNumber(), event.getDeletedMobileNumber().getPhoneId())); //NOI18N
- }
-
- // Update contact's mobile, land-line and fax number
- this.allMobileNumbers().remove(event.getDeletedMobileNumber());
-
- // Clear all data
- this.clear();
- }
-
- /**
- * Observes events being fired when an administrator has a linked a fax
- * number
- * <p>
- * @param event Event being fired
- */
- public void afterAdminLinkedFaxNumberEvent (@Observes final ObservableAdminLinkedFaxNumberEvent event) {
- // Is the event fine?
- if (event == null) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getContact() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact is null"); //NOI18N
- } else if (event.getContact().getContactId() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactId is null"); //NOI18N
- } else if (event.getContact().getContactId() < 1) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactId=" + event.getContact().getContactId() + " is invalid"); //NOI18N
- } else if (event.getContact().getContactFaxNumber() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactFaxNumber is null"); //NOI18N
- } else if (event.getContact().getContactFaxNumber().getPhoneId() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactFaxNumber.phoneId is null"); //NOI18N
- } else if (event.getContact().getContactFaxNumber().getPhoneId() < 1) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactFaxNumber.phoneId=" + event.getContact().getContactFaxNumber().getPhoneId() + " is invalid"); //NOI18N
- } else if (event.getLinkedFaxNumber() == null) {
- // Throw again ...
- throw new NullPointerException("event.linkedFaxNumer is null"); //NOI18N
- }
-
- // Is the id number in linked number not set?
- if (event.getLinkedFaxNumber().getPhoneId() == null) {
- // Then it is a new number, so add it from contact as there the id number has been set
- this.uniqueAddFaxNumber(event.getContact().getContactFaxNumber());
- }
- }
-
- /**
- * Observes events being fired when an administrator has a linked a
- * land-line number
- * <p>
- * @param event Event being fired
- */
- public void afterAdminLinkedLandLineNumberEvent (@Observes final ObservableAdminLinkedLandLineNumberEvent event) {
- // Is the event fine?
- if (event == null) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getContact() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact is null"); //NOI18N
- } else if (event.getContact().getContactId() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactId is null"); //NOI18N
- } else if (event.getContact().getContactId() < 1) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactId=" + event.getContact().getContactId() + " is invalid"); //NOI18N
- } else if (event.getContact().getContactLandLineNumber() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactLandLineNumber is null"); //NOI18N
- } else if (event.getContact().getContactLandLineNumber().getPhoneId() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactLandLineNumber.phoneId is null"); //NOI18N
- } else if (event.getContact().getContactLandLineNumber().getPhoneId() < 1) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactLandLineNumber.phoneId=" + event.getContact().getContactLandLineNumber().getPhoneId() + " is invalid"); //NOI18N
- } else if (event.getLinkedLandLineNumber() == null) {
- // Throw again ...
- throw new NullPointerException("event.linkedLandLineNumer is null"); //NOI18N
- }
-
- // Is the id number in linked number not set?
- if (event.getLinkedLandLineNumber().getPhoneId() == null) {
- // Then it is a new number, so add it from contact as there the id number has been set
- this.uniqueAddLandLineNumber(event.getContact().getContactLandLineNumber());
- }
- }
-
- /**
- * Observes events being fired when an administrator has a linked a mobile
- * number
- * <p>
- * @param event Event being fired
- */
- public void afterAdminLinkedMobileNumberEvent (@Observes final ObservableAdminLinkedMobileNumberEvent event) {
- // Is the event fine?
- if (event == null) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getContact() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact is null"); //NOI18N
- } else if (event.getContact().getContactId() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactId is null"); //NOI18N
- } else if (event.getContact().getContactId() < 1) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactId=" + event.getContact().getContactId() + " is invalid"); //NOI18N
- } else if (event.getContact().getContactMobileNumber() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactMobileNumber is null"); //NOI18N
- } else if (event.getContact().getContactMobileNumber().getPhoneId() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactMobileNumber.phoneId is null"); //NOI18N
- } else if (event.getContact().getContactMobileNumber().getPhoneId() < 1) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactMobileNumber.phoneId=" + event.getContact().getContactMobileNumber().getPhoneId() + " is invalid"); //NOI18N
- } else if (event.getLinkedMobileNumber() == null) {
- // Throw again ...
- throw new NullPointerException("event.linkedMobileNumer is null"); //NOI18N
- }
-
- // Is the id number in linked number not set?
- if (event.getLinkedMobileNumber().getPhoneId() == null) {
- // Then it is a new number, so add it from contact as there the id number has been set
- this.uniqueAddMobileNumber(event.getContact().getContactMobileNumber());
- }
- }
-
- /**
- * Observes events being fired when an administrator has updated contact
- * data.
- * <p>
- * @param event Event being fired
- */
- public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
- // 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.updatedContact is null"); //NOI18N
- } else if (event.getUpdatedContact().getContactId() == null) {
- // userId is null
- throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
- } else if (event.getUpdatedContact().getContactId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
- }
-
- // Update contact's mobile, land-line and fax number
- this.updateContactPhoneNumbers(event.getUpdatedContact());
-
- // Clear all data
- this.clear();
- }
-
- /**
- * Observes events being fired when an administrator has updated a fax
- * number.
- * <p>
- * @param event Event being fired
- */
- public void afterAdminUpdatedFaxNumberEvent (@Observes final AdminUpdatedFaxNumberEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getUpdatedFaxNumber() == null) {
- // Throw NPE again
- throw new NullPointerException("event.updatedFaxNumber is null"); //NOI18N
- } else if (event.getUpdatedFaxNumber().getPhoneId() == null) {
- // userId is null
- throw new NullPointerException("event.updatedFaxNumber.phoneId is null"); //NOI18N
- } else if (event.getUpdatedFaxNumber().getPhoneId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedFaxNumber(), event.getUpdatedFaxNumber().getPhoneId())); //NOI18N
- }
-
- // Uniquely add it
- this.uniqueAddFaxNumber(event.getUpdatedFaxNumber());
-
- // Clear it
- this.clear();
- }
-
- /**
- * Observes events being fired when an administrator has updated a land-line
- * number.
- * <p>
- * @param event Event being fired
- */
- public void afterAdminUpdatedLandLineNumberEvent (@Observes final AdminUpdatedLandLineNumberEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getUpdatedLandLineNumber() == null) {
- // Throw NPE again
- throw new NullPointerException("event.updatedLandLineNumber is null"); //NOI18N
- } else if (event.getUpdatedLandLineNumber().getPhoneId() == null) {
- // userId is null
- throw new NullPointerException("event.updatedLandLineNumber.phoneId is null"); //NOI18N
- } else if (event.getUpdatedLandLineNumber().getPhoneId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedLandLineNumber(), event.getUpdatedLandLineNumber().getPhoneId())); //NOI18N
- }
-
- // Uniquely add it
- this.uniqueAddLandLineNumber(event.getUpdatedLandLineNumber());
-
- // Clear it
- this.clear();
- }
-
- /**
- * Observes events being fired when an administrator has updated a mobile
- * number.
- * <p>
- * @param event Event being fired
- */
- public void afterAdminUpdatedMobileNumberEvent (@Observes final AdminUpdatedMobileNumberEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getUpdatedMobileNumber() == null) {
- // Throw NPE again
- throw new NullPointerException("event.updatedMobileNumber is null"); //NOI18N
- } else if (event.getUpdatedMobileNumber().getPhoneId() == null) {
- // userId is null
- throw new NullPointerException("event.updatedMobileNumber.phoneId is null"); //NOI18N
- } else if (event.getUpdatedMobileNumber().getPhoneId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedMobileNumber(), event.getUpdatedMobileNumber().getPhoneId())); //NOI18N
- }
-
- // Uniquely add it
- this.uniqueAddMobileNumber(event.getUpdatedMobileNumber());
-
- // Clear it
- this.clear();
- }
-
- @Override
- @SuppressWarnings ("ReturnOfCollectionOrArrayField")
- public List<DialableFaxNumber> allFaxNumbers () {
- // Init list
- final List<DialableFaxNumber> list = new LinkedList<>();
-
- // Get iterator
- final Iterator<Cache.Entry<Long, DialableFaxNumber>> iterator = this.faxNumberCache.iterator();
-
- // Loop over all
- while (iterator.hasNext()) {
- // Get next entry
- final Cache.Entry<Long, DialableFaxNumber> next = iterator.next();
-
- // Add value to list
- list.add(next.getValue());
- }
-
- // Return it
- return list;
- }
-
- @Override
- @SuppressWarnings ("ReturnOfCollectionOrArrayField")
- public List<DialableLandLineNumber> allLandLineNumbers () {
- // Init list
- final List<DialableLandLineNumber> list = new LinkedList<>();
-
- // Get iterator
- final Iterator<Cache.Entry<Long, DialableLandLineNumber>> iterator = this.landLineNumberCache.iterator();
-
- // Loop over all
- while (iterator.hasNext()) {
- // Get next entry
- final Cache.Entry<Long, DialableLandLineNumber> next = iterator.next();
-
- // Add value to list
- list.add(next.getValue());
- }
-
- // Return it
- return list;
- }
-
- @Override
- @SuppressWarnings ("ReturnOfCollectionOrArrayField")
- public List<DialableMobileNumber> allMobileNumbers () {
- // Init list
- final List<DialableMobileNumber> list = new LinkedList<>();
-
- // Get iterator
- final Iterator<Cache.Entry<Long, DialableMobileNumber>> iterator = this.mobileNumberCache.iterator();
-
- // Loop over all
- while (iterator.hasNext()) {
- // Get next entry
- final Cache.Entry<Long, DialableMobileNumber> next = iterator.next();
-
- // Add value to list
- list.add(next.getValue());
- }
-
- // Return it
- return list;
- }
-
- @Override
- public DialableFaxNumber findFaxNumberById (final Long faxNumberId) throws PhoneEntityNotFoundException {
- // Validate paramter
- if (null == faxNumberId) {
- // Throw NPE
- throw new NullPointerException("faxNumberId is null"); //NOI18N
- } else if (faxNumberId < 1) {
- // Throw IAE
- throw new IllegalArgumentException("faxNumberId=" + faxNumberId + " is invalid."); //NOI18N
- } else if (!this.faxNumberCache.containsKey(faxNumberId)) {
- // Not found
- throw new PhoneEntityNotFoundException(faxNumberId);
- }
-
- // Get it from cache
- final DialableFaxNumber faxNumber = this.faxNumberCache.get(faxNumberId);
-
- // Return it
- return faxNumber;
- }
-
- @Override
- public DialableLandLineNumber findLandLineNumberById (final Long landLineNumberId) throws PhoneEntityNotFoundException {
- // Validate paramter
- if (null == landLineNumberId) {
- // Throw NPE
- throw new NullPointerException("landLineNumberId is null"); //NOI18N
- } else if (landLineNumberId < 1) {
- // Throw IAE
- throw new IllegalArgumentException("landLineNumberId=" + landLineNumberId + " is invalid."); //NOI18N
- } else if (!this.landLineNumberCache.containsKey(landLineNumberId)) {
- // Not found
- throw new PhoneEntityNotFoundException(landLineNumberId);
- }
-
- // Get it from cache
- final DialableLandLineNumber landLineNumber = this.landLineNumberCache.get(landLineNumberId);
-
- // Return it
- return landLineNumber;
- }
-
- @Override
- public DialableMobileNumber findMobileNumberById (final Long mobileNumberId) throws PhoneEntityNotFoundException {
- // Validate paramter
- if (null == mobileNumberId) {
- // Throw NPE
- throw new NullPointerException("mobileNumberId is null"); //NOI18N
- } else if (mobileNumberId < 1) {
- // Throw IAE
- throw new IllegalArgumentException("mobileNumberId=" + mobileNumberId + " is invalid."); //NOI18N
- } else if (!this.mobileNumberCache.containsKey(mobileNumberId)) {
- // Not found
- throw new PhoneEntityNotFoundException(mobileNumberId);
- }
-
- // Get it from cache
- final DialableMobileNumber mobileNumber = this.mobileNumberCache.get(mobileNumberId);
-
- // Return it
- return mobileNumber;
- }
-
- /**
- * Post-construction method
- */
- @PostConstruct
- public void init () {
- // Is cache there?
- if (!this.faxNumberCache.iterator().hasNext()) {
- // Get whole list from EJB
- final List<DialableFaxNumber> faxNumbers = this.phoneBean.allFaxNumbers();
-
- // Add all
- for (final DialableFaxNumber faxNumber : faxNumbers) {
- // Add it to cache
- this.faxNumberCache.put(faxNumber.getPhoneId(), faxNumber);
- }
- }
-
- // Is cache there?
- if (!this.landLineNumberCache.iterator().hasNext()) {
- // Get whole list from EJB
- final List<DialableLandLineNumber> lineNumbers = this.phoneBean.allLandLineNumbers();
-
- // Add all
- for (final DialableLandLineNumber lineNumber : lineNumbers) {
- // Add it to cache
- this.landLineNumberCache.put(lineNumber.getPhoneId(), lineNumber);
- }
- }
-
- // Is cache there?
- if (!this.mobileNumberCache.iterator().hasNext()) {
- // Get whole list from EJB
- final List<DialableMobileNumber> mobileNumbers = this.phoneBean.allMobileNumbers();
-
- // Add all
- for (final DialableMobileNumber mobileNumber : mobileNumbers) {
- // Add it to cache
- this.mobileNumberCache.put(mobileNumber.getPhoneId(), mobileNumber);
- }
- }
- }
-
- /**
- * Clears this bean
- */
- private void clear () {
- // Clear all data
- }
-
- /**
- * Uniquely add given fax number to this bean's list. First remove the old
- * instance (by id number), then re-add it again.
- * <p>
- * @param faxNumber number to add
- */
- private void uniqueAddFaxNumber (final DialableFaxNumber faxNumber) {
- // Make sure the parameter is valid
- if (null == faxNumber) {
- // Throw NPE
- throw new NullPointerException("faxNumber is null"); //NOI18N
- } else if (faxNumber.getPhoneId() == null) {
- // Throw again ...
- throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
- } else if (faxNumber.getPhoneId() < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid.", faxNumber.getPhoneId())); //NOI18N
- }
-
- // First remove it
- if (!this.allFaxNumbers().remove(faxNumber)) {
- // Did not work, try by id number
- for (final DialableFaxNumber fax : this.allFaxNumbers()) {
- // Is id number the same?
- if (Objects.equals(fax.getPhoneId(), faxNumber.getPhoneId())) {
- // Found it
- this.allFaxNumbers().remove(fax);
- break;
- }
- }
- }
-
- // ... then add it
- this.allFaxNumbers().add(faxNumber);
- }
-
- /**
- * Uniquely add given land-line number to this bean's list. First remove the
- * old instance (by id number), then re-add it again.
- * <p>
- * @param landLineNumber Land-line number to add
- */
- private void uniqueAddLandLineNumber (final DialableLandLineNumber landLineNumber) {
- // Make sure the parameter is valid
- if (null == landLineNumber) {
- // Throw NPE
- throw new NullPointerException("landLineNumber is null"); //NOI18N
- } else if (landLineNumber.getPhoneId() == null) {
- // Throw again ...
- throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
- } else if (landLineNumber.getPhoneId() < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid.", landLineNumber.getPhoneId())); //NOI18N
- }
-
- // First remove it
- if (!this.allLandLineNumbers().remove(landLineNumber)) {
- // Did not work, try by id number
- for (final DialableLandLineNumber landLine : this.allLandLineNumbers()) {
- // Is id number the same?
- if (Objects.equals(landLine.getPhoneId(), landLineNumber.getPhoneId())) {
- // Found it
- this.allLandLineNumbers().remove(landLine);
- break;
- }
- }
- }
-
- // ... then add it
- this.allLandLineNumbers().add(landLineNumber);
- }
-
- /**
- * Uniquely add given mobile number to this bean's list. First remove the
- * old instance (by id number), then re-add it again.
- * <p>
- * @param mobileNumber Mobile number to add
- */
- private void uniqueAddMobileNumber (final DialableMobileNumber mobileNumber) {
- // Make sure the parameter is valid
- if (null == mobileNumber) {
- // Throw NPE
- throw new NullPointerException("mobileNumber is null"); //NOI18N
- } else if (mobileNumber.getPhoneId() == null) {
- // Throw again ...
- throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N
- } else if (mobileNumber.getPhoneId() < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid.", mobileNumber.getPhoneId())); //NOI18N
- }
-
- // First remove it by object
- if (!this.allMobileNumbers().remove(mobileNumber)) {
- // Did not work, try by id number
- for (final DialableMobileNumber cell : this.allMobileNumbers()) {
- // Is id number the same?
- if (Objects.equals(cell.getPhoneId(), mobileNumber.getPhoneId())) {
- // Found it
- this.allMobileNumbers().remove(cell);
- break;
- }
- }
- }
-
- // ... then add it
- this.allMobileNumbers().add(mobileNumber);
- }
-
- /**
- * Updates given contact's mobile, land-line and fax number
- * <p>
- * @param contact Contact instance
- */
- private void updateContactPhoneNumbers (final Contact contact) {
- // Parameter must be valid
- if (null == contact) {
- // Throw NPE
- throw new NullPointerException("contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
- // Throw again
- throw new NullPointerException("contact.contactId is null"); //NOI18N
- } else if (contact.getContactId() < 1) {
- // Id number is not valid
- }
-
- // Is mobile set?
- if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
- // Unique-add it
- this.uniqueAddMobileNumber(contact.getContactMobileNumber());
- }
-
- // Is land-line set?
- if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
- // Unique-add it
- this.uniqueAddLandLineNumber(contact.getContactLandLineNumber());
- }
-
- // Is fax set?
- if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
- // Unique-add it
- this.uniqueAddFaxNumber(contact.getContactFaxNumber());
- }
- }
-
}