/*
- * Copyright (C) 2016 Roland Haeder
+ * Copyright (C) 2016, 2017 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
package org.mxchange.pizzaapplication.beans.contact;
import java.text.MessageFormat;
+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 javax.naming.NamingException;
import org.mxchange.jcontacts.contact.Contact;
import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
+import org.mxchange.jcontacts.contact.ContactUtils;
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.update.AdminUpdatedContactEvent;
+import org.mxchange.jcontacts.contact.title.PersonalTitle;
+import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
import org.mxchange.jcountry.data.Country;
-import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
-import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
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.login.UserLoggedInEvent;
-import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
-import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
-import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController;
+import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
+import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.juserlogincore.events.confirmation.ObservableUserConfirmedAccountEvent;
+import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent;
+import org.mxchange.juserlogincore.events.registration.ObservableUserRegisteredEvent;
+import org.mxchange.juserlogincore.exceptions.UserPasswordMismatchException;
+import org.mxchange.pizzaapplication.beans.BasePizzaController;
+import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
+import org.mxchange.pizzaapplication.beans.user.login.PizzaUserLoginWebSessionController;
/**
* A general contact bean (controller)
* <p>
- * @author Roland Haeder<roland@mxchange.org>
+ * @author Roland Häder<roland@mxchange.org>
*/
@Named ("contactController")
@SessionScoped
-public class PizzaContactWebSessionBean implements PizzaContactWebSessionController {
+public class PizzaContactWebSessionBean extends BasePizzaController implements PizzaContactWebSessionController {
/**
* Serial number
private static final long serialVersionUID = 542_145_347_916L;
/**
- * Birth day
- */
- private Date birthday;
-
- /**
- * Cellphone number's carrier
+ * Academic academicTitle
*/
- private MobileProvider cellphoneCarrier;
+ private String academicTitle;
/**
- * Cellphone number
+ * Birth day
*/
- private Long cellphoneNumber;
+ private Date birthday;
/**
* City
/**
* Remote contact bean
*/
- private final ContactSessionBeanRemote contactBean;
+ private ContactSessionBeanRemote contactBean;
/**
* Contact list
*/
- private List<Contact> contactList;
+ private final List<Contact> contactList;
/**
* Country instance
/**
* Email address list
*/
- private List<String> emailAddressList;
+ private final List<String> emailAddressList;
/**
* Email address repeated
*/
private String firstName;
- /**
- * Gender instance
- */
- private Gender gender;
-
/**
* House number
*/
private Short houseNumber;
/**
- * Whether a cellphone entry has been unlinked
+ * House number extension
*/
- private boolean isCellphoneUnlinked;
+ private String houseNumberExtension;
/**
* Whether a fax entry has been unlinked
private boolean isLandLineUnlinked;
/**
- * Login bean (controller)
+ * Whether a mobile entry has been unlinked
*/
- @Inject
- private PizzaUserLoginWebSessionController loginController;
+ private boolean isMobileUnlinked;
/**
* Phone number area code
*/
- private Integer phoneAreaCode;
+ private Integer landLineAreaCode;
/**
* Country instance for phone number
*/
- private Country phoneCountry;
+ private Country landLineCountry;
/**
* Phone number
*/
- private Long phoneNumber;
+ private Long landLineNumber;
+
+ /**
+ * Mobile number
+ */
+ private Long mobileNumber;
+
+ /**
+ * Mobile number's carrier
+ */
+ private MobileProvider mobileProvider;
+
+ /**
+ * Personal academicTitle
+ */
+ private PersonalTitle personalTitle;
+
+ /**
+ * A list of all selectable contacts
+ */
+ private List<Contact> selectableContacts;
/**
* Street
*/
private String street;
+ /**
+ * Regular user controller
+ */
+ @Inject
+ private PizzaUserWebSessionController userController;
+
+ /**
+ * Login bean (controller)
+ */
+ @Inject
+ private PizzaUserLoginWebSessionController userLoginController;
+
/**
* ZIP code
*/
* Default constructor
*/
public PizzaContactWebSessionBean () {
- // Set gender to UNKNOWN
- this.gender = Gender.UNKNOWN;
+ // Call super constructor
+ super();
- // Try it
- try {
- // Get initial context
- Context context = new InitialContext();
+ // Init lists/maps
+ this.contactList = new LinkedList<>();
+ this.emailAddressList = new LinkedList<>();
+ }
- // Try to lookup
- this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/PizzaService-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
- } catch (final NamingException e) {
- // Throw again
- throw new FaceletException(e);
+ /**
+ * 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 //NOI18N
}
- }
- @Override
- public void addEmailAddress (final String contactEmailAddress) {
- // Add it
- this.emailAddressList.add(contactEmailAddress);
- }
+ // Clear this bean
+ this.clear();
- @Override
- public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
- // Trace message
- System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
+ // Call other method
+ this.uniqueAddContact(event.getAddedContact());
+ // Add to selectable contacts
+ this.selectableContacts.add(event.getAddedContact());
+ }
+
+ /**
+ * 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.getUpdatedContact()== null) {
+ } else if (event.getAddedUser() == null) {
// Throw NPE again
- throw new NullPointerException("event.updatedUser is null"); //NOI18N
- } else if (event.getUpdatedContact().getContactId() == null) {
+ throw new NullPointerException("event.addedUser is null"); //NOI18N
+ } else if (event.getAddedUser().getUserId() == null) {
// userId is null
- throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
- } else if (event.getUpdatedContact().getContactId() < 1) {
+ throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
+ } else if (event.getAddedUser().getUserId() < 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("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
}
- // Get iterator from list
- Iterator<Contact> iterator = this.contactList.iterator();
+ // Clear all data
+ this.clear();
+ }
- // "Walk" through all entries
- while (iterator.hasNext()) {
- // Get next element
- Contact next = iterator.next();
+ /**
+ * Observes events being fired when an administrator has linked a new user
+ * with existing contact data.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getLinkedUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.linkedUser is null"); //NOI18N
+ } else if (event.getLinkedUser().getUserContact() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.linkedUser.userContact is null"); //NOI18N
+ } else if (event.getLinkedUser().getUserContact().getContactId() == null) {
+ // userId is null
+ throw new NullPointerException("event.linkedUser.userContact.contactId is null"); //NOI18N
+ } else if (event.getLinkedUser().getUserContact().getContactId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N
+ }
- // Is id number the same?
- if (Objects.equals(event.getUpdatedContact().getContactId(), next.getContactId())) {
- // Found entry, so remove it and abort
- this.contactList.remove(next);
+ // Remove contact from list available contacts list
+ this.selectableContacts.remove(event.getLinkedUser().getUserContact());
- // Remove also email from list
- this.emailAddressList.remove(next.getContactEmailAddress());
- break;
- }
+ // Clear all data
+ this.clear();
+ }
+
+ /**
+ * Event observer for updated contact data by administrators
+ * <p>
+ * @param event Updated contact data 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("userId of user={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
}
- // Add contact to list
- this.contactList.add(event.getUpdatedContact());
+ // Add contact instance only once
+ this.uniqueAddContact(event.getUpdatedContact());
// Add email address to list
this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
}
- @Override
- public void afterRegistrationEvent (final @Observes UserRegisteredEvent event) {
- // Trace message
- System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
-
+ /**
+ * Event observer when user confirmed account.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterUserConfirmedAccount (@Observes final ObservableUserConfirmedAccountEvent 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.getConfirmedUser() == null) {
// Throw NPE again
- throw new NullPointerException("event.user is null"); //NOI18N
- } else if (event.getRegisteredUser().getUserId() == null) {
+ throw new NullPointerException("event.confirmedUser is null"); //NOI18N
+ } else if (event.getConfirmedUser().getUserId() == null) {
// userId is null
- throw new NullPointerException("event.user.userId is null"); //NOI18N
- } else if (event.getRegisteredUser().getUserId() < 1) {
+ throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
+ } else if (event.getConfirmedUser().getUserId() < 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("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
}
- // Get user instance
- Contact registeredContact = event.getRegisteredUser().getUserContact();
-
- // Debug message
- System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: registeredContact={0}", registeredContact)); //NOI18N
-
- // Copy all data from registered->user
- this.copyContact(registeredContact);
-
- // Add user name and email address
- this.addUserNameEmailAddress(registeredContact);
-
- // Clear all data
- this.clear();
-
- // Trace message
- System.out.println("ContactWebBean:afterRegistration: EXIT!"); //NOI18N
+ // Add contact instance only once
+ this.uniqueAddContact(event.getConfirmedUser().getUserContact());
}
- @Override
- public void afterUserLogin (final @Observes UserLoggedInEvent event) {
- // Trace message
- System.out.println(MessageFormat.format("ContactWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
-
+ /**
+ * Event observer for logged-in user
+ * <p>
+ * @param event Event instance
+ */
+ public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
// event should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
} else if (event.getLoggedInUser() == null) {
// Throw NPE again
- throw new NullPointerException("event.user is null"); //NOI18N
+ throw new NullPointerException("event.loggedInUser is null"); //NOI18N
} else if (event.getLoggedInUser().getUserId() == null) {
// userId is null
- throw new NullPointerException("event.user.userId is null"); //NOI18N
+ throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
} else if (event.getLoggedInUser().getUserId() < 1) {
// Not avalid id
throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
// Copy all data to this bean
this.copyContact(event.getLoggedInUser().getUserContact());
+ }
+
+ /**
+ * Event observer for new user registrations
+ * <p>
+ * @param event User registration event
+ */
+ 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 contact instance only once
+ this.uniqueAddContact(registeredContact);
+
+ // Add user name and email address
+ this.addUserNameEmailAddress(registeredContact);
- // Trace message
- System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N
+ // Clear all data
+ this.clear();
}
@Override
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
public List<Contact> allContacts () {
+ // Return un-modified list
return this.contactList;
}
- /**
- * Clears this bean
- */
@Override
- public void clear () {
- // Clear all data
- // - personal data
- this.setGender(Gender.UNKNOWN);
- this.setFirstName(null);
- this.setFamilyName(null);
- this.setStreet(null);
- this.setHouseNumber(null);
- this.setZipCode(null);
- this.setCity(null);
- this.setCountry(null);
-
- // - contact data
+ public void clearEmailAddresses () {
+ // Clear both
this.setEmailAddress(null);
this.setEmailAddressRepeat(null);
- this.setPhoneAreaCode(null);
- this.setCellphoneCarrier(null);
- this.setFaxAreaCode(null);
-
- // - other data
- this.setBirthday(null);
- this.setComment(null);
}
@Override
public Contact createContactInstance () {
- // User message
- //this.getLogger().logTrace("createContactInstance: CALLED!");
+ // Is all required data set?
+ if (!this.isRequiredPersonalDataSet()) {
+ // No, then abort here
+ throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
+ }
// Required personal data must be set
assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
// 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
- Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
+ Contact contact = new UserContact(this.getPersonalTitle(), this.getFirstName(), this.getFamilyName());
contact.setContactStreet(this.getStreet());
contact.setContactHouseNumber(this.getHouseNumber());
+ contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
contact.setContactZipCode(this.getZipCode());
contact.setContactCity(this.getCity());
contact.setContactCountry(this.getCountry());
contact.setContactBirthday(this.getBirthday());
contact.setContactComment(this.getComment());
- // Set ownContact
- contact.setContactOwnContact(Boolean.TRUE);
-
// 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("mobile.phoneNumber is null"); //NOI18N
+ } else if (mobile.getPhoneNumber() < 1) {
// Abort here
- throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
+ throw new IllegalArgumentException("mobile.phoneNumber is zero or below."); //NOI18N
}
- // Set cellphone number
- contact.setContactCellphoneNumber(cellphone);
+ // Set mobile number
+ contact.setContactMobileNumber(mobile);
}
- // Trace message
- //this.getLogger().logTrace(MessageFormat.format("createContactInstance: localContact={0} - EXIT!", localContact));
-
// Return it
return contact;
}
@Override
public String doChangePersonalContactData () {
// This method shall only be called if the user is logged-in
- if (!this.loginController.isUserLoggedIn()) {
+ if (!this.userLoginController.isUserLoggedIn()) {
// Not logged-in
throw new IllegalStateException("User is not logged-in"); //NOI18N
} else if (!this.isRequiredChangePersonalDataSet()) {
// Not all required fields are set
throw new FaceletException("Not all required fields are set."); //NOI18N
- } else if (!this.loginController.ifCurrentPasswordMatches()) {
+ } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
// Password not matching
- throw new FaceletException(new UserPasswordMismatchException(this.loginController.getLoggedInUser()));
+ this.showFacesMessage("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
+ return ""; //NOI18N
}
// Get contact instance
- Contact contact = this.loginController.getLoggedInUser().getUserContact();
+ Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
// It should be there, so run some tests on it
- assert (contact instanceof Contact) : "Instance loginController.loggedInUser.userContact is null"; //NOI18N
- assert (contact.getContactId() instanceof Long) : "Instance loginController.userContact.contactId is null"; //NOI18N
- assert (contact.getContactId() > 0) : MessageFormat.format("Instance loginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
+ assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
+ assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
+ assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
// Update all fields
- contact.setContactGender(this.getGender());
+ contact.setContactPersonalTitle(this.getPersonalTitle());
contact.setContactFirstName(this.getFirstName());
contact.setContactFamilyName(this.getFamilyName());
contact.setContactStreet(this.getStreet());
contact.setContactHouseNumber(this.getHouseNumber());
+ contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
contact.setContactZipCode(this.getZipCode());
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
}
- @Override
- public Date getBirthday () {
- return this.birthday;
- }
-
- @Override
- public void setBirthday (final Date birthday) {
- this.birthday = birthday;
- }
-
- @Override
- public MobileProvider getCellphoneCarrier () {
- return this.cellphoneCarrier;
+ /**
+ * Getter for academic title
+ * <p>
+ * @return Academic title
+ */
+ public String getAcademicTitle () {
+ return this.academicTitle;
}
- @Override
- public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
- this.cellphoneCarrier = cellphoneCarrier;
+ /**
+ * Setter for academic title
+ * <p>
+ * @param academicTitle Academic title
+ */
+ public void setAcademicTitle (final String academicTitle) {
+ this.academicTitle = academicTitle;
}
- @Override
- public Long getCellphoneNumber () {
- return this.cellphoneNumber;
+ /**
+ * Getter for birth day
+ * <p>
+ * @return Birth day
+ */
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getBirthday () {
+ return this.birthday;
}
- @Override
- public void setCellphoneNumber (Long cellphoneNumber) {
- this.cellphoneNumber = cellphoneNumber;
+ /**
+ * Setter for birth day
+ * <p>
+ * @param birthday Birth day
+ */
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setBirthday (final Date birthday) {
+ this.birthday = birthday;
}
- @Override
+ /**
+ * Getter for city name
+ * <p>
+ * @return City name
+ */
public String getCity () {
return this.city;
}
- @Override
+ /**
+ * Setter for city name
+ * <p>
+ * @param city City name
+ */
public void setCity (final String city) {
this.city = city;
}
- @Override
+ /**
+ * Getter for comments
+ * <p>
+ * @return Comments
+ */
public String getComment () {
return this.comment;
}
- @Override
+ /**
+ * Setter for comment
+ * <p>
+ * @param comment Comments
+ */
public void setComment (final String comment) {
this.comment = comment;
}
@Override
+ public String getControllerType () {
+ return "general"; //NOI18N
+ }
+
+ @Override
+ @Deprecated
+ public void setControllerType (final String controllerType) {
+ throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
+ }
+
+ /**
+ * Getter for country instance
+ * <p>
+ * @return Country instance
+ */
public Country getCountry () {
return this.country;
}
- @Override
+ /**
+ * Setter for country instance
+ * <p>
+ * @param country Country instance
+ */
public void setCountry (final Country country) {
this.country = country;
}
return this.emailAddress;
}
- @Override
+ /**
+ * Setter for email address
+ * <p>
+ * @param emailAddress Email address
+ */
public void setEmailAddress (final String emailAddress) {
this.emailAddress = emailAddress;
}
- @Override
+ /**
+ * Getter for email address, repeated
+ * <p>
+ * @return the emailAddress, repeated
+ */
public String getEmailAddressRepeat () {
return this.emailAddressRepeat;
}
- @Override
+ /**
+ * Setter for email address repeated
+ * <p>
+ * @param emailAddressRepeat the emailAddress to set
+ */
public void setEmailAddressRepeat (final String emailAddressRepeat) {
this.emailAddressRepeat = emailAddressRepeat;
}
- @Override
+ /**
+ * Family name
+ * <p>
+ * @return the familyName
+ */
public String getFamilyName () {
return this.familyName;
}
- @Override
+ /**
+ * Family name
+ * <p>
+ * @param familyName the familyName to set
+ */
public void setFamilyName (final String familyName) {
this.familyName = familyName;
}
- @Override
+ /**
+ * Getter for fax number's area code
+ * <p>
+ * @return Fax number's area code
+ */
public Integer getFaxAreaCode () {
return this.faxAreaCode;
}
- @Override
+ /**
+ * Setter for fax number's area code
+ * <p>
+ * @param faxAreaCode Fax number's area code
+ */
public void setFaxAreaCode (final Integer faxAreaCode) {
this.faxAreaCode = faxAreaCode;
}
- @Override
+ /**
+ * Getter for fax's country instance
+ * <p>
+ * @return Fax' country instance
+ */
public Country getFaxCountry () {
return this.faxCountry;
}
- @Override
+ /**
+ * Setter for fax's country instance
+ * <p>
+ * @param faxCountry Fax' country instance
+ */
public void setFaxCountry (final Country faxCountry) {
this.faxCountry = faxCountry;
}
- @Override
+ /**
+ * Getter for fax number
+ * <p>
+ * @return Fax number
+ */
public Long getFaxNumber () {
return this.faxNumber;
}
- @Override
+ /**
+ * Setter for fax number
+ * <p>
+ * @param faxNumber Fax number
+ */
public void setFaxNumber (final Long faxNumber) {
this.faxNumber = faxNumber;
}
- @Override
+ /**
+ * First name
+ * <p>
+ * @return the first name
+ */
public String getFirstName () {
return this.firstName;
}
- @Override
+ /**
+ * First name
+ * <p>
+ * @param firstName the first name to set
+ */
public void setFirstName (final String firstName) {
this.firstName = firstName;
}
- @Override
- public Gender getGender () {
- return this.gender;
- }
-
- @Override
- public void setGender (final Gender gender) {
- this.gender = gender;
- }
-
- @Override
+ /**
+ * House number
+ * <p>
+ * @return the houseNumber
+ */
public Short getHouseNumber () {
return this.houseNumber;
}
- @Override
+ /**
+ * House number
+ * <p>
+ * @param houseNumber the houseNumber to set
+ */
public void setHouseNumber (final Short houseNumber) {
this.houseNumber = houseNumber;
}
- @Override
- public Integer getPhoneAreaCode () {
- return this.phoneAreaCode;
+ /**
+ * Getter for house number extension, example: 123a 'a' is then the
+ * extension and 123 is the house number.
+ * <p>
+ * @return House number extension
+ */
+ public String getHouseNumberExtension () {
+ return this.houseNumberExtension;
}
- @Override
- public void setPhoneAreaCode (final Integer phoneAreaCode) {
- this.phoneAreaCode = phoneAreaCode;
+ /**
+ * Setter for house number extension
+ * <p>
+ * @param houseNumberExtension House number extension
+ */
+ public void setHouseNumberExtension (final String houseNumberExtension) {
+ this.houseNumberExtension = houseNumberExtension;
}
- @Override
- public Country getPhoneCountry () {
- return this.phoneCountry;
+ /**
+ * Getter for land-line number's area code
+ * <p>
+ * @return Land-line number's area code
+ */
+ public Integer getLandLineAreaCode () {
+ return this.landLineAreaCode;
}
- @Override
- public void setPhoneCountry (final Country phoneCountry) {
- this.phoneCountry = phoneCountry;
+ /**
+ * Setter for land-line number's area code
+ * <p>
+ * @param landLineAreaCode Land-line number's area code
+ */
+ public void setLandLineAreaCode (final Integer landLineAreaCode) {
+ this.landLineAreaCode = landLineAreaCode;
}
- @Override
- public Long getPhoneNumber () {
- return this.phoneNumber;
+ /**
+ * Getter for land-line number's country instance
+ * <p>
+ * @return Land-line number's country instance
+ */
+ public Country getLandLineCountry () {
+ return this.landLineCountry;
}
- @Override
- public void setPhoneNumber (final Long phoneNumber) {
- this.phoneNumber = phoneNumber;
+ /**
+ * Setter for land-line number's country instance
+ * <p>
+ * @param landLineCountry Land-line number's country instance
+ */
+ public void setLandLineCountry (final Country landLineCountry) {
+ this.landLineCountry = landLineCountry;
}
- @Override
+ /**
+ * Getter for land-line number
+ * <p>
+ * @return Land-line number
+ */
+ public Long getLandLineNumber () {
+ return this.landLineNumber;
+ }
+
+ /**
+ * Setter for land-line number
+ * <p>
+ * @param landLineNumber Land-line number
+ */
+ public void setLandLineNumber (final Long landLineNumber) {
+ this.landLineNumber = landLineNumber;
+ }
+
+ /**
+ * Getter for mobile number
+ * <p>
+ * @return Mobile number
+ */
+ public Long getMobileNumber () {
+ return this.mobileNumber;
+ }
+
+ /**
+ * Setter for mobile number
+ * <p>
+ * @param mobileNumber Mobile number
+ */
+ public void setMobileNumber (final Long mobileNumber) {
+ this.mobileNumber = mobileNumber;
+ }
+
+ /**
+ * Getter for mobile number's carrier
+ * <p>
+ * @return Mobile number's carrier
+ */
+ public MobileProvider getMobileProvider () {
+ return this.mobileProvider;
+ }
+
+ /**
+ * Setter for mobile number's provider
+ * <p>
+ * @param mobileProvider Mobile number's provider
+ */
+ public void setMobileProvider (final MobileProvider mobileProvider) {
+ this.mobileProvider = mobileProvider;
+ }
+
+ /**
+ * Getter for personal title
+ * <p>
+ * @return Personal title
+ */
+ public PersonalTitle getPersonalTitle () {
+ return this.personalTitle;
+ }
+
+ /**
+ * Setter for personal title
+ * <p>
+ * @param personalTitle Personal title
+ */
+ public void setPersonalTitle (final PersonalTitle personalTitle) {
+ this.personalTitle = personalTitle;
+ }
+
+ /**
+ * Getter for street
+ * <p>
+ * @return Street
+ */
public String getStreet () {
return this.street;
}
- @Override
+ /**
+ * Setter for street
+ * <p>
+ * @param street Street
+ */
public void setStreet (final String street) {
this.street = street;
}
- @Override
+ /**
+ * Getter for ZIP code
+ * <p>
+ * @return ZIP code
+ */
public Integer getZipCode () {
return this.zipCode;
}
- @Override
+ /**
+ * Setter for ZIP code
+ * <p>
+ * @param zipCode ZIP code
+ */
public void setZipCode (final Integer zipCode) {
this.zipCode = zipCode;
}
/**
- * Post-initialization of this class
+ * Post-construction method
*/
@PostConstruct
public void init () {
+ // Try it
+ try {
+ // Get initial context
+ Context context = new InitialContext();
+
+ // Try to lookup
+ this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
+ } catch (final NamingException e) {
+ // Throw again
+ throw new FaceletException(e);
+ }
+
// Get full email address list for reducing EJB calls
- this.emailAddressList = this.contactBean.getEmailAddressList();
+ this.emailAddressList.addAll(this.contactBean.getEmailAddressList());
+
+ // Get all contacts
+ List<Contact> allContacts = this.contactBean.getAllContacts();
// Get full contact list
- this.contactList = this.contactBean.getAllContacts();
+ this.contactList.addAll(allContacts);
+
+ // Get all users
+ List<User> allUsers = this.userController.allUsers();
+
+ // Get iterator
+ Iterator<Contact> iterator = allContacts.iterator();
+
+ // Loop through it
+ while (iterator.hasNext()) {
+ // Get next element
+ Contact next = iterator.next();
+
+ // Get iterator
+ Iterator<User> userIterator = allUsers.iterator();
+
+ // Loop through all users
+ while (userIterator.hasNext()) {
+ // Get user instance
+ User nextUser = userIterator.next();
+
+ // Is contact same?
+ if (Objects.equals(next, nextUser.getUserContact())) {
+ // Found same
+ iterator.remove();
+ break;
+ }
+ }
+ }
+
+ // Set contact list
+ this.selectableContacts = allContacts;
}
@Override
public boolean isEmailAddressRegistered (final Contact contact) {
+ // Cherck parameter
+ if (null == contact) {
+ // Throw NPE
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (contact.getContactEmailAddress() == null) {
+ // Throw again
+ throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
+ } else if (contact.getContactEmailAddress().isEmpty()) {
+ // Is empty
+ throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
+ }
+
+ // Determine it
return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
}
@Override
public boolean isRequiredChangePersonalDataSet () {
- return ((this.getGender() != null) &&
+ return ((this.getPersonalTitle() != null) &&
(this.getFirstName() != null) &&
(this.getFamilyName() != null) &&
(this.getStreet() != null) &&
@Override
public boolean isRequiredPersonalDataSet () {
- return ((this.getGender() != null) &&
+ return ((this.getPersonalTitle() != null) &&
(this.getFirstName() != null) &&
(this.getFamilyName() != null) &&
(this.getStreet() != null) &&
}
@Override
- public void updateContactDataFromController (final Contact userContact) {
+ public List<Contact> selectableContacts () {
+ return Collections.unmodifiableList(this.selectableContacts);
+ }
+
+ @Override
+ public void updateContactDataFromController (final Contact contact) {
// Is the instance valid?
- if (null == userContact) {
+ if (null == contact) {
// Throw NPE
- throw new NullPointerException("userContact is null"); //NOI18N
- } else if (userContact.getContactId() == null) {
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (contact.getContactId() == null) {
// Throw NPE
- throw new NullPointerException("userContact.contactId is null"); //NOI18N
- } else if (userContact.getContactId() < 1) {
+ throw new NullPointerException("contact.contactId is null"); //NOI18N
+ } else if (contact.getContactId() < 1) {
// Not valid id number
- throw new IllegalArgumentException(MessageFormat.format("userContact.contactId={0} is not valid.", userContact.getContactId())); //NOI18N
+ throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
}
// Set all
- this.copyContact(userContact);
+ this.copyContact(contact);
}
/**
this.emailAddressList.add(contact.getContactEmailAddress());
}
+ /**
+ * Clears this bean
+ */
+ private void clear () {
+ // Clear all data
+ // - personal data
+ this.setPersonalTitle(null);
+ this.setAcademicTitle(null);
+ this.setFirstName(null);
+ this.setFamilyName(null);
+ this.setStreet(null);
+ this.setHouseNumber(null);
+ this.setHouseNumberExtension(null);
+ this.setZipCode(null);
+ this.setCity(null);
+ this.setCountry(null);
+
+ // - contact data
+ this.clearEmailAddresses();
+ this.setLandLineAreaCode(null);
+ this.setLandLineCountry(null);
+ this.setLandLineNumber(null);
+ this.setMobileProvider(null);
+ this.setMobileNumber(null);
+ this.setFaxAreaCode(null);
+ this.setFaxCountry(null);
+ this.setFaxNumber(null);
+
+ // - other data
+ this.setBirthday(null);
+ this.setComment(null);
+ }
+
/**
* Copies given contact into the controller
* <p>
* @param contact Contact instance
*/
private void copyContact (final Contact contact) {
+ // Is the instance valid?
+ if (null == contact) {
+ // Throw NPE
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (contact.getContactId() == null) {
+ // Throw NPE
+ throw new NullPointerException("contact.contactId is null"); //NOI18N
+ } else if (contact.getContactId() < 1) {
+ // Not valid id number
+ throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
+ }
+
// Copy all fields:
// - base data
- this.setGender(contact.getContactGender());
+ this.setPersonalTitle(contact.getContactPersonalTitle());
+ this.setAcademicTitle(contact.getContactTitle());
this.setFirstName(contact.getContactFirstName());
this.setFamilyName(contact.getContactFamilyName());
this.setStreet(contact.getContactStreet());
this.setHouseNumber(contact.getContactHouseNumber());
+ this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
this.setZipCode(contact.getContactZipCode());
this.setCity(contact.getContactCity());
this.setCountry(contact.getContactCountry());
+ this.setEmailAddress(contact.getContactEmailAddress());
+ 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)) {
this.setFaxCountry(fax.getPhoneCountry());
this.setFaxAreaCode(fax.getPhoneAreaCode());
this.setFaxNumber(fax.getPhoneNumber());
}
- this.setEmailAddress(contact.getContactEmailAddress());
+ }
- // -- other data
- this.setBirthday(contact.getContactBirthday());
- this.setComment(contact.getContactComment());
+ /**
+ * Removes given contact from all lists
+ * <p>
+ * @param contact Contact instance to remove
+ */
+ private void removeContact (final Contact contact) {
+ // Is the instance valid?
+ if (null == contact) {
+ // Throw NPE
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (contact.getContactId() == null) {
+ // Throw NPE
+ throw new NullPointerException("contact.contactId is null"); //NOI18N
+ } else if (contact.getContactId() < 1) {
+ // Not valid id number
+ throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
+ }
+
+ // Remove from general list
+ if (!this.contactList.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());
+ }
+
+ /**
+ * Adds unique instance to contact list. First any existing instance is
+ * being removed, then the new instance is added.
+ * <p>
+ * @param contact Contact instance to add uniquely
+ */
+ private void uniqueAddContact (final Contact contact) {
+ // Is the instance valid?
+ if (null == contact) {
+ // Throw NPE
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (contact.getContactId() == null) {
+ // Throw NPE
+ throw new NullPointerException("contact.contactId is null"); //NOI18N
+ } else if (contact.getContactId() < 1) {
+ // Not valid id number
+ throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
+ }
+
+ // Get iterator from list
+ Iterator<Contact> iterator = this.contactList.iterator();
+
+ // "Walk" through all entries
+ while (iterator.hasNext()) {
+ // Get next element
+ Contact next = iterator.next();
+
+ // Is id number the same?
+ if (Objects.equals(contact.getContactId(), next.getContactId())) {
+ // Found entry, so remove it and abort
+ this.removeContact(next);
+ break;
+ }
+ }
+
+ // Add contact to list
+ this.contactList.add(contact);
}
}