/*
- * Copyright (C) 2016 Roland Haeder
+ * Copyright (C) 2016 Roland Häder
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import javax.annotation.PostConstruct;
import org.mxchange.jcontacts.contact.UserContact;
import org.mxchange.jcontacts.contact.gender.Gender;
import org.mxchange.jcontacts.contact.utils.ContactUtils;
-import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
-import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
+import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
+import org.mxchange.jcontacts.events.contact.deleted.ObservableAdminDeletedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
+import org.mxchange.jcontacts.events.fax.unlinked.ObservableAdminUnlinkedFaxNumberEvent;
+import org.mxchange.jcontacts.events.landline.unlinked.ObservableAdminUnlinkedLandLineNumberEvent;
+import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent;
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.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;
-import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
-import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
-import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
-import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
+import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent;
+import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
+import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent;
+import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
+import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
import org.mxchange.jusercore.model.user.User;
/**
- * A general contact bean (controller)
+ * A general contact controller (bean)
* <p>
- * @author Roland Haeder<roland@mxchange.org>
+ * @author Roland Häder<roland@mxchange.org>
*/
@Named ("contactController")
@SessionScoped
*/
private Date birthday;
- /**
- * Cellphone number's carrier
- */
- private MobileProvider cellphoneCarrier;
-
- /**
- * Cellphone number
- */
- private Long cellphoneNumber;
-
/**
* City
*/
/**
* Contact list
*/
- private List<Contact> contactList;
+ private final List<Contact> contacts;
/**
* Country instance
private String emailAddress;
/**
- * Email address list
+ * Email address repeated
*/
- private List<String> emailAddressList;
+ private String emailAddressRepeat;
/**
- * Email address repeated
+ * Email address list
*/
- private String emailAddressRepeat;
+ private final List<String> emailAddresses;
/**
* Family name
*/
private String houseNumberExtension;
- /**
- * Whether a cellphone entry has been unlinked
- */
- private boolean isCellphoneUnlinked;
-
/**
* Whether a fax entry has been unlinked
*/
private boolean isLandLineUnlinked;
/**
- * Phone number area code
+ * Whether a mobile entry has been unlinked
+ */
+ private boolean isMobileUnlinked;
+
+ /**
+ * Land-line number area code
+ */
+ private Integer landLineAreaCode;
+
+ /**
+ * Country instance for land-line number
*/
- private Integer phoneAreaCode;
+ private Country landLineCountry;
/**
- * Country instance for phone number
+ * Land-line number
*/
- private Country phoneCountry;
+ private Long landLineNumber;
/**
- * Phone number
+ * Mobile number
*/
- private Long phoneNumber;
+ private Long mobileNumber;
+
+ /**
+ * Mobile provider
+ */
+ private MobileProvider mobileProvider;
/**
* A list of all selectable contacts
private JobsUserWebSessionController userController;
/**
- * Login bean (controller)
+ * Login controller (bean)
*/
@Inject
private JobsUserLoginWebSessionController userLoginController;
Context context = new InitialContext();
// Try to lookup
- this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
+ this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jjobs-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
} catch (final NamingException e) {
// Throw again
throw new FaceletException(e);
}
+
+ // Init lists/maps
+ this.contacts = new LinkedList<>();
+ this.emailAddresses = new LinkedList<>();
}
@Override
- public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) {
- // Trace message
- /* NOISY-DEBUG: */ System.out.println(MessageFormat.format("contactController.afterAdminAddedContact(): event={0} - CALLED!", event)); //NOI18N
-
+ public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
// The event must be valid
if (null == event) {
// Throw NPE
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 //NOI18N
+ throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
}
// Clear this bean
}
@Override
- public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
+ public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
// event should not be null
if (null == event) {
// Throw NPE
}
@Override
- public void afterAdminLinkedUser (@Observes final AdminLinkedUserEvent event) {
+ public void afterAdminDeletedContactEvent (@Observes final ObservableAdminDeletedContactEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getDeletedContact() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.deletedContact is null"); //NOI18N
+ } else if (event.getDeletedContact().getContactId() == null) {
+ // userId is null
+ throw new NullPointerException("event.deletedContact.contactId is null"); //NOI18N
+ } else if (event.getDeletedContact().getContactId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getDeletedContact(), event.getDeletedContact().getContactId())); //NOI18N
+ }
+
+ // Remove from both lists
+ this.contacts.remove(event.getDeletedContact());
+ this.selectableContacts.remove(event.getDeletedContact());
+
+ // Clear all data
+ this.clear();
+ }
+
+ @Override
+ public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent event) {
// event should not be null
if (null == event) {
// Throw NPE
}
@Override
- public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
+ public void afterAdminUnlinkedFaxContactDataEvent (@Observes final ObservableAdminUnlinkedFaxNumberEvent event) {
// event should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getUpdatedContact() == null) {
+ } else if (event.getUnlinkedFaxNumber() == null) {
// Throw NPE again
- throw new NullPointerException("event.updatedContact is null"); //NOI18N
- } else if (event.getUpdatedContact().getContactId() == null) {
+ throw new NullPointerException("event.unlinkedFaxNumber is null"); //NOI18N
+ } else if (event.getUnlinkedFaxNumber().getPhoneId() == null) {
// userId is null
- throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
- } else if (event.getUpdatedContact().getContactId() < 1) {
+ 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.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
+ throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedFaxNumber(), event.getUnlinkedFaxNumber().getPhoneId())); //NOI18N
}
- // Add contact instance only once
- this.uniqueAddContact(event.getUpdatedContact());
+ // Remove it from list
+ this.removeFromContacts(event.getUnlinkedFaxNumber());
- // Add email address to list
- this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
+ // Clear all data
+ this.clear();
}
@Override
- public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
+ public void afterAdminUnlinkedLandLineContactDataEvent (@Observes final ObservableAdminUnlinkedLandLineNumberEvent event) {
// event should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getRegisteredUser() == null) {
+ } else if (event.getUnlinkedLandLineNumber() == null) {
// Throw NPE again
- throw new NullPointerException("event.registeredUser is null"); //NOI18N
- } else if (event.getRegisteredUser().getUserId() == null) {
+ throw new NullPointerException("event.unlinkedLandLineNumber is null"); //NOI18N
+ } else if (event.getUnlinkedLandLineNumber().getPhoneId() == null) {
// userId is null
- throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
- } else if (event.getRegisteredUser().getUserId() < 1) {
+ throw new NullPointerException("event.unlinkedLandLineNumber.contactId is null"); //NOI18N
+ } else if (event.getUnlinkedLandLineNumber().getPhoneId() < 1) {
// Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
+ throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedLandLineNumber(), event.getUnlinkedLandLineNumber().getPhoneId())); //NOI18N
}
- // Get user instance
- Contact registeredContact = event.getRegisteredUser().getUserContact();
+ // Remove it from list
+ this.removeFromContacts(event.getUnlinkedLandLineNumber());
- // Copy all data from registered->user
- this.copyContact(registeredContact);
+ // Clear all data
+ this.clear();
+ }
- // Add contact instance only once
- this.uniqueAddContact(registeredContact);
+ @Override
+ public void afterAdminUnlinkedMobileContactDataEvent (@Observes final ObservableAdminUnlinkedMobileNumberEvent 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
+ }
- // Add user name and email address
- this.addUserNameEmailAddress(registeredContact);
+ // Remove it from list
+ this.removeFromContacts(event.getUnlinkedMobileNumber());
// Clear all data
this.clear();
}
@Override
- public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) {
+ 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
+ }
+
+ // Add contact instance only once
+ this.uniqueAddContact(event.getUpdatedContact());
+
+ // Add email address to list
+ this.emailAddresses.add(event.getUpdatedContact().getContactEmailAddress());
+ }
+
+ @Override
+ public void afterUserConfirmedAccountEventEvent (@Observes final ObservableUserConfirmedAccountEvent event) {
// event should not be null
if (null == event) {
// Throw NPE
}
@Override
- public void afterUserLogin (@Observes final UserLoggedInEvent event) {
+ public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
// event should not be null
if (null == event) {
// Throw NPE
}
@Override
+ public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getRegisteredUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.registeredUser is null"); //NOI18N
+ } else if (event.getRegisteredUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
+ } else if (event.getRegisteredUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
+ }
+
+ // Get user instance
+ Contact registeredContact = event.getRegisteredUser().getUserContact();
+
+ // Copy all data from registered->user
+ this.copyContact(registeredContact);
+
+ // Add user name and email address
+ this.addUserNameEmailAddress(registeredContact);
+
+ // Clear all data
+ this.clear();
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
public List<Contact> allContacts () {
// Debug message
//* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size()));
// Return un-modified list
- return Collections.unmodifiableList(this.contactList);
+ return this.contacts;
}
@Override
}
// 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
// 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
}
// 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
//* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
-
// Return it
return contact;
}
throw new FaceletException("Not all required fields are set."); //NOI18N
} else if (!this.userLoginController.ifCurrentPasswordMatches()) {
// Password not matching
- this.showFacesMessage("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
+ this.showFacesMessage("form_login_change_personal:currentPassword", "ERROR_USER_CURRENT_PASSWORD_MISMATCHING"); //NOI18N
return ""; //NOI18N
}
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.updateMobileNumber(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
+ return "user_contact_data_saved"; //NOI18N
}
@Override
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;
}
@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 Long getLandLineNumber () {
+ return this.landLineNumber;
}
@Override
- public void setPhoneAreaCode (final Integer phoneAreaCode) {
- this.phoneAreaCode = phoneAreaCode;
+ public void setLandLineNumber (final Long landLineNumber) {
+ this.landLineNumber = landLineNumber;
}
@Override
- public Country getPhoneCountry () {
- return this.phoneCountry;
+ public Long getMobileNumber () {
+ return this.mobileNumber;
}
@Override
- public void setPhoneCountry (final Country phoneCountry) {
- this.phoneCountry = phoneCountry;
+ public void setMobileNumber (Long mobileNumber) {
+ this.mobileNumber = mobileNumber;
}
@Override
- public Long getPhoneNumber () {
- return this.phoneNumber;
+ public MobileProvider getMobileProvider () {
+ return this.mobileProvider;
}
@Override
- public void setPhoneNumber (final Long phoneNumber) {
- this.phoneNumber = phoneNumber;
+ public void setMobileProvider (final MobileProvider mobileProvider) {
+ this.mobileProvider = mobileProvider;
}
@Override
this.zipCode = zipCode;
}
- @Override
- public boolean hasContacts () {
- return (!this.contactList.isEmpty());
- }
-
/**
* Post-initialization of this class
*/
@PostConstruct
public void init () {
// Get full email address list for reducing EJB calls
- this.emailAddressList = this.contactBean.getEmailAddressList();
+ this.emailAddresses.addAll(this.contactBean.getEmailAddressList());
+
+ // Get all contacts
+ List<Contact> allContacts = this.contactBean.getAllContacts();
// Get full contact list
- this.contactList = this.contactBean.getAllContacts();
+ this.contacts.addAll(allContacts);
// Get all users
List<User> allUsers = this.userController.allUsers();
- // Get all contacts
- List<Contact> allContacts = this.contactBean.getAllContacts();
-
// Get iterator
Iterator<Contact> iterator = allContacts.iterator();
}
// 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();
return localContact;
}
+ @Override
+ 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.getMobileNumberList() == null) {
+ // Throw NPE again
+ 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.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.getMobileNumberList().remove(contact.getContactMobileNumber());
+ }
+ }
+ }
+
@Override
public List<Contact> selectableContacts () {
return Collections.unmodifiableList(this.selectableContacts);
*/
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());
}
/**
// - 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);
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)) {
}
// 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) {
+ // Log message
+ System.out.println(MessageFormat.format("{0}.removeFromContacts: faxNumber={1} - CALLED!", this.getClass().getSimpleName(), faxNumber)); //NOI18N
+
+ // 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) {
+ // Log message
+ System.out.println(MessageFormat.format("{0}.removeFromContacts: contact={1},contact.contactFaxNumber={2}", this.getClass().getSimpleName(), contact, contact.getContactFaxNumber())); //NOI18N
+
+ // Is the number set?
+ if (Objects.equals(contact.getContactFaxNumber(), faxNumber)) {
+ // Log message
+ System.out.println(MessageFormat.format("{0}.removeFromContacts: Unsetting faxNumber={1} ...", this.getClass().getSimpleName(), faxNumber)); //NOI18N
+
+ // 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) {
+ // Log message
+ System.out.println(MessageFormat.format("{0}.removeFromContacts: landLineNumber={1} - CALLED!", this.getClass().getSimpleName(), landLineNumber)); //NOI18N
+
+ // 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) {
+ // Log message
+ System.out.println(MessageFormat.format("{0}.removeFromContacts: contact={1},contact.contactLandLineNumber={2}", this.getClass().getSimpleName(), contact, contact.getContactLandLineNumber())); //NOI18N
+
+ // Is the number set?
+ if (Objects.equals(contact.getContactLandLineNumber(), landLineNumber)) {
+ // Log message
+ System.out.println(MessageFormat.format("{0}.removeFromContacts: Unsetting landLineNumber={1} ...", this.getClass().getSimpleName(), landLineNumber)); //NOI18N
+
+ // 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) {
+ // Log message
+ System.out.println(MessageFormat.format("{0}.removeFromContacts: mobileNumber={1} - CALLED!", this.getClass().getSimpleName(), mobileNumber)); //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},contact.contactMobileNumber={2}", this.getClass().getSimpleName(), contact, contact.getContactMobileNumber())); //NOI18N
+
+ // Is the number set?
+ if (Objects.equals(contact.getContactMobileNumber(), mobileNumber)) {
+ // Log message
+ System.out.println(MessageFormat.format("{0}.removeFromContacts: Unsetting mobileNumber={1} ...", this.getClass().getSimpleName(), mobileNumber)); //NOI18N
+
+ // Unset 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);
}
}