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;
/**
* Contact list
*/
- private final List<Contact> contactList;
+ private final List<Contact> contacts;
/**
* Country instance
private String emailAddress;
/**
- * Email address list
+ * Email address repeated
*/
- private final List<String> emailAddressList;
+ private String emailAddressRepeat;
/**
- * Email address repeated
+ * Email address list
*/
- private String emailAddressRepeat;
+ private final List<String> emailAddresses;
/**
* Family name
}
// Init lists/maps
- this.contactList = new LinkedList<>();
- this.emailAddressList = new LinkedList<>();
+ this.contacts = new LinkedList<>();
+ this.emailAddresses = new LinkedList<>();
}
@Override
}
// Remove from both lists
- this.contactList.remove(event.getDeletedContact());
+ this.contacts.remove(event.getDeletedContact());
this.selectableContacts.remove(event.getDeletedContact());
// Clear all data
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
this.uniqueAddContact(event.getUpdatedContact());
// Add email address to list
- this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
+ this.emailAddresses.add(event.getUpdatedContact().getContactEmailAddress());
}
@Override
//* 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
@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<User> allUsers = this.userController.allUsers();
}
// Determine it
- return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
+ return ((this.emailAddresses instanceof List) && (this.emailAddresses.contains(contact.getContactEmailAddress())));
}
@Override
this.clear();
// Try to lookup it in visible user list
- for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
+ for (final Iterator<Contact> iterator = this.contacts.iterator(); iterator.hasNext();) {
// Get next user
Contact next = iterator.next();
}
// 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
*/
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());
}
/**
}
// 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
+ * <p>
+ * @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
+ * <p>
+ * @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
+ * <p>
+ * @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);
+ }
+ }
}
/**
}
// Get iterator from list
- Iterator<Contact> iterator = this.contactList.iterator();
+ Iterator<Contact> iterator = this.contacts.iterator();
// "Walk" through all entries
while (iterator.hasNext()) {
}
// Add contact to list
- this.contactList.add(contact);
+ this.contacts.add(contact);
}
}