2 * Copyright (C) 2016 Roland Häder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.pizzaapplication.beans.contact;
19 import java.text.MessageFormat;
20 import java.util.Collections;
21 import java.util.Date;
22 import java.util.Iterator;
23 import java.util.LinkedList;
24 import java.util.List;
25 import java.util.Objects;
26 import javax.annotation.PostConstruct;
27 import javax.enterprise.context.SessionScoped;
28 import javax.enterprise.event.Observes;
29 import javax.faces.view.facelets.FaceletException;
30 import javax.inject.Inject;
31 import javax.inject.Named;
32 import javax.naming.Context;
33 import javax.naming.InitialContext;
34 import javax.naming.NamingException;
35 import org.mxchange.jcontacts.contact.Contact;
36 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
37 import org.mxchange.jcontacts.contact.UserContact;
38 import org.mxchange.jcontacts.contact.gender.Gender;
39 import org.mxchange.jcontacts.contact.utils.ContactUtils;
40 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
41 import org.mxchange.jcountry.data.Country;
42 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
43 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
44 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
45 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
46 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
47 import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
48 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
49 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
50 import org.mxchange.jusercore.model.user.User;
51 import org.mxchange.pizzaapplication.beans.BasePizzaController;
52 import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController;
53 import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
54 import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent;
55 import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
56 import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent;
57 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
58 import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
59 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
60 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
63 * A general contact bean (controller)
65 * @author Roland Häder<roland@mxchange.org>
67 @Named ("contactController")
69 public class PizzaContactWebSessionBean extends BasePizzaController implements PizzaContactWebSessionController {
74 private static final long serialVersionUID = 542_145_347_916L;
79 private Date birthday;
82 * Mobile number's carrier
84 private MobileProvider cellphoneCarrier;
89 private Long cellphoneNumber;
99 private String comment;
102 * Remote contact bean
104 private final ContactSessionBeanRemote contactBean;
109 private final List<Contact> contactList;
114 private Country country;
119 private String emailAddress;
124 private final List<String> emailAddressList;
127 * Email address repeated
129 private String emailAddressRepeat;
134 private String familyName;
137 * Fax number's area code
139 private Integer faxAreaCode;
142 * Country instance for fax number
144 private Country faxCountry;
149 private Long faxNumber;
154 private String firstName;
159 private Gender gender;
164 private Short houseNumber;
167 * House number extension
169 private String houseNumberExtension;
172 * Whether a cellphone entry has been unlinked
174 private boolean isMobileUnlinked;
177 * Whether a fax entry has been unlinked
179 private boolean isFaxUnlinked;
182 * Whether a land-line number has been unlinked
184 private boolean isLandLineUnlinked;
187 * Phone number area code
189 private Integer phoneAreaCode;
192 * Country instance for phone number
194 private Country phoneCountry;
199 private Long phoneNumber;
202 * A list of all selectable contacts
204 private List<Contact> selectableContacts;
209 private String street;
214 private String title;
217 * Regular user controller
220 private PizzaUserWebSessionController userController;
223 * Login bean (controller)
226 private PizzaUserLoginWebSessionController userLoginController;
231 private Integer zipCode;
234 * Default constructor
236 public PizzaContactWebSessionBean () {
239 // Get initial context
240 Context context = new InitialContext();
243 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
244 } catch (final NamingException e) {
246 throw new FaceletException(e);
250 this.contactList = new LinkedList<>();
251 this.emailAddressList = new LinkedList<>();
255 public void afterAdminAddedContact (@Observes final ObservableAdminAddedContactEvent event) {
257 /* NOISY-DEBUG: */ System.out.println(MessageFormat.format("contactController.afterAdminAddedContact(): event={0} - CALLED!", event)); //NOI18N
259 // The event must be valid
262 throw new NullPointerException("event is null"); //NOI18N
263 } else if (event.getAddedContact() == null) {
265 throw new NullPointerException("event.addedContact is null"); //NOI18N
266 } else if (event.getAddedContact().getContactId() == null) {
268 throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
269 } else if (event.getAddedContact().getContactId() < 1) {
271 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
278 this.uniqueAddContact(event.getAddedContact());
280 // Add to selectable contacts
281 this.selectableContacts.add(event.getAddedContact());
285 public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
286 // event should not be null
289 throw new NullPointerException("event is null"); //NOI18N
290 } else if (event.getAddedUser() == null) {
292 throw new NullPointerException("event.addedUser is null"); //NOI18N
293 } else if (event.getAddedUser().getUserId() == null) {
295 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
296 } else if (event.getAddedUser().getUserId() < 1) {
298 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
306 public void afterAdminLinkedUser (@Observes final ObservableAdminLinkedUserEvent event) {
307 // event should not be null
310 throw new NullPointerException("event is null"); //NOI18N
311 } else if (event.getLinkedUser() == null) {
313 throw new NullPointerException("event.linkedUser is null"); //NOI18N
314 } else if (event.getLinkedUser().getUserContact() == null) {
316 throw new NullPointerException("event.linkedUser.userContact is null"); //NOI18N
317 } else if (event.getLinkedUser().getUserContact().getContactId() == null) {
319 throw new NullPointerException("event.linkedUser.userContact.contactId is null"); //NOI18N
320 } else if (event.getLinkedUser().getUserContact().getContactId() < 1) {
322 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N
325 // Remove contact from list available contacts list
326 this.selectableContacts.remove(event.getLinkedUser().getUserContact());
333 public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
334 // event should not be null
337 throw new NullPointerException("event is null"); //NOI18N
338 } else if (event.getUpdatedContact() == null) {
340 throw new NullPointerException("event.updatedContact is null"); //NOI18N
341 } else if (event.getUpdatedContact().getContactId() == null) {
343 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
344 } else if (event.getUpdatedContact().getContactId() < 1) {
346 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
349 // Add contact instance only once
350 this.uniqueAddContact(event.getUpdatedContact());
352 // Add email address to list
353 this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
357 public void afterRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
358 // event should not be null
361 throw new NullPointerException("event is null"); //NOI18N
362 } else if (event.getRegisteredUser() == null) {
364 throw new NullPointerException("event.registeredUser is null"); //NOI18N
365 } else if (event.getRegisteredUser().getUserId() == null) {
367 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
368 } else if (event.getRegisteredUser().getUserId() < 1) {
370 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
374 Contact registeredContact = event.getRegisteredUser().getUserContact();
376 // Copy all data from registered->user
377 this.copyContact(registeredContact);
379 // Add contact instance only once
380 this.uniqueAddContact(registeredContact);
382 // Add user name and email address
383 this.addUserNameEmailAddress(registeredContact);
390 public void afterUserConfirmedAccount (@Observes final ObservableUserConfirmedAccountEvent event) {
391 // event should not be null
394 throw new NullPointerException("event is null"); //NOI18N
395 } else if (event.getConfirmedUser() == null) {
397 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
398 } else if (event.getConfirmedUser().getUserId() == null) {
400 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
401 } else if (event.getConfirmedUser().getUserId() < 1) {
403 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
406 // Add contact instance only once
407 this.uniqueAddContact(event.getConfirmedUser().getUserContact());
411 public void afterUserLogin (@Observes final ObservableUserLoggedInEvent event) {
412 // event should not be null
415 throw new NullPointerException("event is null"); //NOI18N
416 } else if (event.getLoggedInUser() == null) {
418 throw new NullPointerException("event.loggedInUser is null"); //NOI18N
419 } else if (event.getLoggedInUser().getUserId() == null) {
421 throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
422 } else if (event.getLoggedInUser().getUserId() < 1) {
424 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
427 // Copy all data to this bean
428 this.copyContact(event.getLoggedInUser().getUserContact());
432 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
433 public List<Contact> allContacts () {
435 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size()));
437 // Return un-modified list
438 return this.contactList;
442 public Contact createContactInstance () {
444 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName()));
446 // Is all required data set?
447 if (!this.isRequiredPersonalDataSet()) {
448 // No, then abort here
449 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
452 // Generate phone number
453 DialableLandLineNumber landLineNumber = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
454 DialableMobileNumber mobileNumber = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
455 DialableFaxNumber faxNumber = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
457 // Create new contact
458 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
459 contact.setContactStreet(this.getStreet());
460 contact.setContactHouseNumber(this.getHouseNumber());
461 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
462 contact.setContactZipCode(this.getZipCode());
463 contact.setContactCity(this.getCity());
464 contact.setContactCountry(this.getCountry());
465 contact.setContactEmailAddress(this.getEmailAddress());
466 contact.setContactBirthday(this.getBirthday());
467 contact.setContactComment(this.getComment());
470 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
472 // Don't set null or wrong references
473 if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
474 // Now the number must be given
475 if (landLineNumber.getPhoneAreaCode() == null) {
477 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
478 } else if (landLineNumber.getPhoneAreaCode() < 1) {
480 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
481 } else if (landLineNumber.getPhoneNumber() == null) {
483 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
484 } else if (landLineNumber.getPhoneNumber() < 1) {
486 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
490 contact.setContactLandLineNumber(landLineNumber);
493 // Don't set null or wrong references
494 if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
495 // Now the number must be given
496 if (faxNumber.getPhoneAreaCode() == null) {
498 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
499 } else if (faxNumber.getPhoneAreaCode() < 1) {
501 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
502 } else if (faxNumber.getPhoneNumber() == null) {
504 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
505 } else if (faxNumber.getPhoneNumber() < 1) {
507 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
511 contact.setContactFaxNumber(faxNumber);
514 // Is the provider set?
515 if ((mobileNumber instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
516 // Is the number set?
517 if (mobileNumber.getPhoneNumber() == null) {
519 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
520 } else if (mobileNumber.getPhoneNumber() < 1) {
522 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
525 // Set cellphone number
526 contact.setContactMobileNumber(mobileNumber);
530 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
537 public String doChangePersonalContactData () {
538 // This method shall only be called if the user is logged-in
539 if (!this.userLoginController.isUserLoggedIn()) {
541 throw new IllegalStateException("User is not logged-in"); //NOI18N
542 } else if (!this.isRequiredChangePersonalDataSet()) {
543 // Not all required fields are set
544 throw new FaceletException("Not all required fields are set."); //NOI18N
545 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
546 // Password not matching
547 this.showFacesMessage("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
551 // Get contact instance
552 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
554 // It should be there, so run some tests on it
555 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
556 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
557 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
560 contact.setContactGender(this.getGender());
561 contact.setContactFirstName(this.getFirstName());
562 contact.setContactFamilyName(this.getFamilyName());
563 contact.setContactStreet(this.getStreet());
564 contact.setContactHouseNumber(this.getHouseNumber());
565 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
566 contact.setContactZipCode(this.getZipCode());
567 contact.setContactCity(this.getCity());
568 contact.setContactCountry(this.getCountry());
570 // Update contact's cellphone number
571 this.isMobileUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
573 // Update contact's land-line number
574 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
576 // Update contact's fax number
577 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
579 // Send it to the EJB
580 this.contactBean.updateContactData(contact, this.isMobileUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
583 return "contact_data_saved"; //NOI18N
587 @SuppressWarnings ("ReturnOfDateField")
588 public Date getBirthday () {
589 return this.birthday;
593 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
594 public void setBirthday (final Date birthday) {
595 this.birthday = birthday;
599 public MobileProvider getMobileProvider () {
600 return this.cellphoneCarrier;
604 public void setMobileProvider (final MobileProvider mobileProvider) {
605 this.cellphoneCarrier = mobileProvider;
609 public Long getMobileNumber () {
610 return this.cellphoneNumber;
614 public void setMobileNumber (Long cellphoneNumber) {
615 this.cellphoneNumber = cellphoneNumber;
619 public String getCity () {
624 public void setCity (final String city) {
629 public String getComment () {
634 public void setComment (final String comment) {
635 this.comment = comment;
639 public String getControllerType () {
640 return "general"; //NOI18N
645 public void setControllerType (final String controllerType) {
646 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
650 public Country getCountry () {
655 public void setCountry (final Country country) {
656 this.country = country;
660 public String getEmailAddress () {
661 return this.emailAddress;
665 public void setEmailAddress (final String emailAddress) {
666 this.emailAddress = emailAddress;
670 public String getEmailAddressRepeat () {
671 return this.emailAddressRepeat;
675 public void setEmailAddressRepeat (final String emailAddressRepeat) {
676 this.emailAddressRepeat = emailAddressRepeat;
680 public String getFamilyName () {
681 return this.familyName;
685 public void setFamilyName (final String familyName) {
686 this.familyName = familyName;
690 public Integer getFaxAreaCode () {
691 return this.faxAreaCode;
695 public void setFaxAreaCode (final Integer faxAreaCode) {
696 this.faxAreaCode = faxAreaCode;
700 public Country getFaxCountry () {
701 return this.faxCountry;
705 public void setFaxCountry (final Country faxCountry) {
706 this.faxCountry = faxCountry;
710 public Long getFaxNumber () {
711 return this.faxNumber;
715 public void setFaxNumber (final Long faxNumber) {
716 this.faxNumber = faxNumber;
720 public String getFirstName () {
721 return this.firstName;
725 public void setFirstName (final String firstName) {
726 this.firstName = firstName;
730 public Gender getGender () {
735 public void setGender (final Gender gender) {
736 this.gender = gender;
740 public Short getHouseNumber () {
741 return this.houseNumber;
745 public void setHouseNumber (final Short houseNumber) {
746 this.houseNumber = houseNumber;
750 public String getHouseNumberExtension () {
751 return this.houseNumberExtension;
755 public void setHouseNumberExtension (final String houseNumberExtension) {
756 this.houseNumberExtension = houseNumberExtension;
760 public Integer getPhoneAreaCode () {
761 return this.phoneAreaCode;
765 public void setPhoneAreaCode (final Integer phoneAreaCode) {
766 this.phoneAreaCode = phoneAreaCode;
770 public Country getPhoneCountry () {
771 return this.phoneCountry;
775 public void setPhoneCountry (final Country phoneCountry) {
776 this.phoneCountry = phoneCountry;
780 public Long getPhoneNumber () {
781 return this.phoneNumber;
785 public void setPhoneNumber (final Long phoneNumber) {
786 this.phoneNumber = phoneNumber;
790 public String getStreet () {
795 public void setStreet (final String street) {
796 this.street = street;
800 public String getTitle () {
805 public void setTitle (final String title) {
810 public Integer getZipCode () {
815 public void setZipCode (final Integer zipCode) {
816 this.zipCode = zipCode;
820 * Post-initialization of this class
823 public void init () {
824 // Get full email address list for reducing EJB calls
825 this.emailAddressList.addAll(this.contactBean.getEmailAddressList());
827 // Get full contact list
828 this.contactList.addAll(this.contactBean.getAllContacts());
831 List<User> allUsers = this.userController.allUsers();
834 List<Contact> allContacts = this.contactBean.getAllContacts();
837 Iterator<Contact> iterator = allContacts.iterator();
840 while (iterator.hasNext()) {
842 Contact next = iterator.next();
845 Iterator<User> userIterator = allUsers.iterator();
847 // Loop through all users
848 while (userIterator.hasNext()) {
850 User nextUser = userIterator.next();
853 if (Objects.equals(next, nextUser.getUserContact())) {
862 this.selectableContacts = allContacts;
866 public boolean isEmailAddressRegistered (final Contact contact) {
868 if (null == contact) {
870 throw new NullPointerException("contact is null"); //NOI18N
871 } else if (contact.getContactEmailAddress() == null) {
873 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
874 } else if (contact.getContactEmailAddress().isEmpty()) {
876 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
880 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
884 public boolean isRequiredChangePersonalDataSet () {
885 return ((this.getGender() != null) &&
886 (this.getFirstName() != null) &&
887 (this.getFamilyName() != null) &&
888 (this.getStreet() != null) &&
889 (this.getHouseNumber() != null) &&
890 (this.getZipCode() != null) &&
891 (this.getCity() != null));
895 public boolean isRequiredPersonalDataSet () {
896 return ((this.getGender() != null) &&
897 (this.getFirstName() != null) &&
898 (this.getFamilyName() != null) &&
899 (this.getStreet() != null) &&
900 (this.getHouseNumber() != null) &&
901 (this.getZipCode() != null) &&
902 (this.getCity() != null) &&
903 (this.getEmailAddress() != null) &&
904 (this.getEmailAddressRepeat() != null));
908 public boolean isSameEmailAddressEntered () {
909 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
913 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
915 Contact localContact = null;
920 // Try to lookup it in visible user list
921 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
923 Contact next = iterator.next();
925 // Is the user id found?
926 if (Objects.equals(next.getContactId(), contactId)) {
927 // Copy to other variable
934 if (null == localContact) {
935 // Not visible for the current user
936 throw new ContactNotFoundException(contactId);
939 // Copy all data to this bean
940 this.copyContact(localContact);
947 public List<Contact> selectableContacts () {
948 return Collections.unmodifiableList(this.selectableContacts);
952 public void updateContactDataFromController (final Contact contact) {
953 // Is the instance valid?
954 if (null == contact) {
956 throw new NullPointerException("contact is null"); //NOI18N
957 } else if (contact.getContactId() == null) {
959 throw new NullPointerException("contact.contactId is null"); //NOI18N
960 } else if (contact.getContactId() < 1) {
961 // Not valid id number
962 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
966 this.copyContact(contact);
970 * Adds email address to bean's internal list.
972 * @param contact Contact instance
974 private void addUserNameEmailAddress (final Contact contact) {
975 // Make sure the entry is not added yet
976 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
978 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
982 this.emailAddressList.add(contact.getContactEmailAddress());
988 private void clear () {
991 this.setGender(null);
993 this.setFirstName(null);
994 this.setFamilyName(null);
995 this.setStreet(null);
996 this.setHouseNumber(null);
997 this.setHouseNumberExtension(null);
998 this.setZipCode(null);
1000 this.setCountry(null);
1003 this.setEmailAddress(null);
1004 this.setEmailAddressRepeat(null);
1005 this.setPhoneAreaCode(null);
1006 this.setPhoneCountry(null);
1007 this.setPhoneNumber(null);
1008 this.setMobileProvider(null);
1009 this.setMobileNumber(null);
1010 this.setFaxAreaCode(null);
1011 this.setFaxCountry(null);
1012 this.setFaxNumber(null);
1015 this.setBirthday(null);
1016 this.setComment(null);
1020 * Copies given contact into the controller
1022 * @param contact Contact instance
1024 private void copyContact (final Contact contact) {
1025 // Is the instance valid?
1026 if (null == contact) {
1028 throw new NullPointerException("contact is null"); //NOI18N
1029 } else if (contact.getContactId() == null) {
1031 throw new NullPointerException("contact.contactId is null"); //NOI18N
1032 } else if (contact.getContactId() < 1) {
1033 // Not valid id number
1034 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1039 this.setGender(contact.getContactGender());
1040 this.setTitle(contact.getContactTitle());
1041 this.setFirstName(contact.getContactFirstName());
1042 this.setFamilyName(contact.getContactFamilyName());
1043 this.setStreet(contact.getContactStreet());
1044 this.setHouseNumber(contact.getContactHouseNumber());
1045 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
1046 this.setZipCode(contact.getContactZipCode());
1047 this.setCity(contact.getContactCity());
1048 this.setCountry(contact.getContactCountry());
1049 this.setEmailAddress(contact.getContactEmailAddress());
1050 this.setBirthday(contact.getContactBirthday());
1051 this.setComment(contact.getContactComment());
1053 // Get cellphone, phone and fax instance
1054 DialableMobileNumber cellphone = contact.getContactMobileNumber();
1055 DialableFaxNumber fax = contact.getContactFaxNumber();
1056 DialableLandLineNumber phone = contact.getContactLandLineNumber();
1059 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
1060 this.setPhoneCountry(phone.getPhoneCountry());
1061 this.setPhoneAreaCode(phone.getPhoneAreaCode());
1062 this.setPhoneNumber(phone.getPhoneNumber());
1065 if ((cellphone instanceof DialableMobileNumber) && (cellphone.getMobileProvider() instanceof MobileProvider)) {
1066 this.setMobileProvider(cellphone.getMobileProvider());
1067 this.setMobileNumber(cellphone.getPhoneNumber());
1070 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
1071 this.setFaxCountry(fax.getPhoneCountry());
1072 this.setFaxAreaCode(fax.getPhoneAreaCode());
1073 this.setFaxNumber(fax.getPhoneNumber());
1078 * Removes given contact from all lists
1080 * @param contact Contact instance to remove
1082 private void removeContact (final Contact contact) {
1083 // Is the instance valid?
1084 if (null == contact) {
1086 throw new NullPointerException("contact is null"); //NOI18N
1087 } else if (contact.getContactId() == null) {
1089 throw new NullPointerException("contact.contactId is null"); //NOI18N
1090 } else if (contact.getContactId() < 1) {
1091 // Not valid id number
1092 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1095 // Remove from general list
1096 if (!this.contactList.remove(contact)) {
1097 // Did not remove contact
1098 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
1101 // Remove from other lists
1102 this.emailAddressList.remove(contact.getContactEmailAddress());
1106 * Adds unique instance to contact list. First any existing instance is
1107 * being removed, then the new instance is added.
1109 * @param contact Contact instance to add uniquely
1111 private void uniqueAddContact (final Contact contact) {
1112 // Is the instance valid?
1113 if (null == contact) {
1115 throw new NullPointerException("contact is null"); //NOI18N
1116 } else if (contact.getContactId() == null) {
1118 throw new NullPointerException("contact.contactId is null"); //NOI18N
1119 } else if (contact.getContactId() < 1) {
1120 // Not valid id number
1121 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1124 // Get iterator from list
1125 Iterator<Contact> iterator = this.contactList.iterator();
1127 // "Walk" through all entries
1128 while (iterator.hasNext()) {
1130 Contact next = iterator.next();
1132 // Is id number the same?
1133 if (Objects.equals(contact.getContactId(), next.getContactId())) {
1134 // Found entry, so remove it and abort
1135 this.removeContact(next);
1140 // Add contact to list
1141 this.contactList.add(contact);