2 * Copyright (C) 2016 Roland Haeder
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.List;
24 import java.util.Objects;
25 import javax.annotation.PostConstruct;
26 import javax.enterprise.context.SessionScoped;
27 import javax.enterprise.event.Observes;
28 import javax.faces.view.facelets.FaceletException;
29 import javax.inject.Inject;
30 import javax.inject.Named;
31 import javax.naming.Context;
32 import javax.naming.InitialContext;
33 import javax.naming.NamingException;
34 import org.mxchange.jcontacts.contact.Contact;
35 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
36 import org.mxchange.jcontacts.contact.UserContact;
37 import org.mxchange.jcontacts.contact.gender.Gender;
38 import org.mxchange.jcontacts.contact.utils.ContactUtils;
39 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
40 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
41 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
42 import org.mxchange.jcountry.data.Country;
43 import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
44 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
45 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
46 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
47 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
48 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
49 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
50 import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
51 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
52 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
53 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
54 import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
55 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
56 import org.mxchange.jusercore.model.user.User;
57 import org.mxchange.pizzaapplication.beans.BasePizzaController;
58 import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController;
59 import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
62 * A general contact bean (controller)
64 * @author Roland Haeder<roland@mxchange.org>
66 @Named ("contactController")
68 public class PizzaContactWebSessionBean extends BasePizzaController implements PizzaContactWebSessionController {
73 private static final long serialVersionUID = 542_145_347_916L;
78 private Date birthday;
81 * Cellphone number's carrier
83 private MobileProvider cellphoneCarrier;
88 private Long cellphoneNumber;
98 private String comment;
101 * Remote contact bean
103 private final ContactSessionBeanRemote contactBean;
108 private List<Contact> contactList;
113 private Country country;
118 private String emailAddress;
123 private List<String> emailAddressList;
126 * Email address repeated
128 private String emailAddressRepeat;
133 private String familyName;
136 * Fax number's area code
138 private Integer faxAreaCode;
141 * Country instance for fax number
143 private Country faxCountry;
148 private Long faxNumber;
153 private String firstName;
158 private Gender gender;
163 private Short houseNumber;
166 * House number extension
168 private String houseNumberExtension;
171 * Whether a cellphone entry has been unlinked
173 private boolean isCellphoneUnlinked;
176 * Whether a fax entry has been unlinked
178 private boolean isFaxUnlinked;
181 * Whether a land-line number has been unlinked
183 private boolean isLandLineUnlinked;
186 * Phone number area code
188 private Integer phoneAreaCode;
191 * Country instance for phone number
193 private Country phoneCountry;
198 private Long phoneNumber;
201 * A list of all selectable contacts
203 private List<Contact> selectableContacts;
208 private String street;
211 * Regular user controller
214 private PizzaUserWebSessionController userController;
217 * Login bean (controller)
220 private PizzaUserLoginWebSessionController userLoginController;
225 private Integer zipCode;
228 * Default constructor
230 public PizzaContactWebSessionBean () {
233 // Get initial context
234 Context context = new InitialContext();
237 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
238 } catch (final NamingException e) {
240 throw new FaceletException(e);
245 public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) {
246 // The event must be valid
249 throw new NullPointerException("event is null"); //NOI18N
250 } else if (event.getAddedContact() == null) {
252 throw new NullPointerException("event.addedContact is null"); //NOI18N
253 } else if (event.getAddedContact().getContactId() == null) {
255 throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
256 } else if (event.getAddedContact().getContactId() < 1) {
258 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
265 this.contactList.add(event.getAddedContact());
268 this.selectableContacts.add(event.getAddedContact());
272 public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
273 // event should not be null
276 throw new NullPointerException("event is null"); //NOI18N
277 } else if (event.getAddedUser() == null) {
279 throw new NullPointerException("event.addedUser is null"); //NOI18N
280 } else if (event.getAddedUser().getUserId() == null) {
282 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
283 } else if (event.getAddedUser().getUserId() < 1) {
285 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
293 public void afterAdminLinkedUser (@Observes final AdminLinkedUserEvent event) {
294 // event should not be null
297 throw new NullPointerException("event is null"); //NOI18N
298 } else if (event.getLinkedUser() == null) {
300 throw new NullPointerException("event.linkedUser is null"); //NOI18N
301 } else if (event.getLinkedUser().getUserContact() == null) {
303 throw new NullPointerException("event.linkedUser.userContact is null"); //NOI18N
304 } else if (event.getLinkedUser().getUserContact().getContactId() == null) {
306 throw new NullPointerException("event.linkedUser.userContact.contactId is null"); //NOI18N
307 } else if (event.getLinkedUser().getUserContact().getContactId() < 1) {
309 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N
312 // Remove contact from list available contacts list
313 this.selectableContacts.remove(event.getLinkedUser().getUserContact());
320 public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
321 // event should not be null
324 throw new NullPointerException("event is null"); //NOI18N
325 } else if (event.getUpdatedContact() == null) {
327 throw new NullPointerException("event.updatedContact is null"); //NOI18N
328 } else if (event.getUpdatedContact().getContactId() == null) {
330 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
331 } else if (event.getUpdatedContact().getContactId() < 1) {
333 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
336 // Get iterator from list
337 Iterator<Contact> iterator = this.contactList.iterator();
339 // "Walk" through all entries
340 while (iterator.hasNext()) {
342 Contact next = iterator.next();
344 // Is id number the same?
345 if (Objects.equals(event.getUpdatedContact().getContactId(), next.getContactId())) {
346 // Found entry, so remove it and abort
347 this.contactList.remove(next);
349 // Remove also email from list
350 this.emailAddressList.remove(next.getContactEmailAddress());
355 // Add contact to list
356 this.contactList.add(event.getUpdatedContact());
358 // Add email address to list
359 this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
363 public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
364 // event should not be null
367 throw new NullPointerException("event is null"); //NOI18N
368 } else if (event.getRegisteredUser() == null) {
370 throw new NullPointerException("event.registeredUser is null"); //NOI18N
371 } else if (event.getRegisteredUser().getUserId() == null) {
373 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
374 } else if (event.getRegisteredUser().getUserId() < 1) {
376 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
380 Contact registeredContact = event.getRegisteredUser().getUserContact();
382 // Copy all data from registered->user
383 this.copyContact(registeredContact);
385 // Add user name and email address
386 this.addUserNameEmailAddress(registeredContact);
393 public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) {
394 // event should not be null
397 throw new NullPointerException("event is null"); //NOI18N
398 } else if (event.getConfirmedUser() == null) {
400 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
401 } else if (event.getConfirmedUser().getUserId() == null) {
403 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
404 } else if (event.getConfirmedUser().getUserId() < 1) {
406 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
409 // "Cache" contact instance
410 Contact contact = event.getConfirmedUser().getUserContact();
412 // Get iterator from list
413 Iterator<Contact> iterator = this.contactList.iterator();
415 // "Walk" through all entries
416 while (iterator.hasNext()) {
418 Contact next = iterator.next();
420 // Is id number the same?
421 if (Objects.equals(contact.getContactId(), next.getContactId())) {
422 // Found entry, so remove it and abort
423 this.removeContact(next);
428 // Add contact to list
429 this.contactList.add(contact);
433 public void afterUserLogin (@Observes final UserLoggedInEvent event) {
434 // event should not be null
437 throw new NullPointerException("event is null"); //NOI18N
438 } else if (event.getLoggedInUser() == null) {
440 throw new NullPointerException("event.loggedInUser is null"); //NOI18N
441 } else if (event.getLoggedInUser().getUserId() == null) {
443 throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
444 } else if (event.getLoggedInUser().getUserId() < 1) {
446 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
449 // Copy all data to this bean
450 this.copyContact(event.getLoggedInUser().getUserContact());
454 public List<Contact> allContacts () {
456 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size()));
458 // Return un-modified list
459 return Collections.unmodifiableList(this.contactList);
463 public Contact createContactInstance () {
465 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName()));
467 // Is all required data set?
468 if (!this.isRequiredPersonalDataSet()) {
469 // No, then abort here
470 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
473 // Generate phone number
474 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
475 DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
476 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
478 // Create new contact
479 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
480 contact.setContactStreet(this.getStreet());
481 contact.setContactHouseNumber(this.getHouseNumber());
482 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
483 contact.setContactZipCode(this.getZipCode());
484 contact.setContactCity(this.getCity());
485 contact.setContactCountry(this.getCountry());
486 contact.setContactEmailAddress(this.getEmailAddress());
487 contact.setContactBirthday(this.getBirthday());
488 contact.setContactComment(this.getComment());
491 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
492 // Don't set null or wrong references
493 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
494 // Now the number must be given
495 if (phone.getPhoneAreaCode() == null) {
497 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
498 } else if (phone.getPhoneAreaCode() < 1) {
500 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
501 } else if (phone.getPhoneNumber() == null) {
503 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
504 } else if (phone.getPhoneNumber() < 1) {
506 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
510 contact.setContactLandLineNumber(phone);
513 // Don't set null or wrong references
514 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
515 // Now the number must be given
516 if (fax.getPhoneAreaCode() == null) {
518 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
519 } else if (fax.getPhoneAreaCode() < 1) {
521 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
522 } else if (fax.getPhoneNumber() == null) {
524 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
525 } else if (fax.getPhoneNumber() < 1) {
527 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
531 contact.setContactFaxNumber(fax);
534 // Is the provider set?
535 if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
536 // Is the number set?
537 if (cellphone.getPhoneNumber() == null) {
539 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
540 } else if (cellphone.getPhoneNumber() < 1) {
542 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
545 // Set cellphone number
546 contact.setContactCellphoneNumber(cellphone);
550 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
556 public String doChangePersonalContactData () {
557 // This method shall only be called if the user is logged-in
558 if (!this.userLoginController.isUserLoggedIn()) {
560 throw new IllegalStateException("User is not logged-in"); //NOI18N
561 } else if (!this.isRequiredChangePersonalDataSet()) {
562 // Not all required fields are set
563 throw new FaceletException("Not all required fields are set."); //NOI18N
564 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
565 // Password not matching
566 this.showFacesMessage("login_change_personal_form:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
570 // Get contact instance
571 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
573 // It should be there, so run some tests on it
574 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
575 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
576 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
579 contact.setContactGender(this.getGender());
580 contact.setContactFirstName(this.getFirstName());
581 contact.setContactFamilyName(this.getFamilyName());
582 contact.setContactStreet(this.getStreet());
583 contact.setContactHouseNumber(this.getHouseNumber());
584 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
585 contact.setContactZipCode(this.getZipCode());
586 contact.setContactCity(this.getCity());
587 contact.setContactCountry(this.getCountry());
589 // Update contact's cellphone number
590 this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
592 // Update contact's land-line number
593 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
595 // Update contact's fax number
596 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
598 // Send it to the EJB
599 this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
602 return "contact_data_saved"; //NOI18N
606 @SuppressWarnings ("ReturnOfDateField")
607 public Date getBirthday () {
608 return this.birthday;
612 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
613 public void setBirthday (final Date birthday) {
614 this.birthday = birthday;
618 public MobileProvider getCellphoneCarrier () {
619 return this.cellphoneCarrier;
623 public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
624 this.cellphoneCarrier = cellphoneCarrier;
628 public Long getCellphoneNumber () {
629 return this.cellphoneNumber;
633 public void setCellphoneNumber (Long cellphoneNumber) {
634 this.cellphoneNumber = cellphoneNumber;
638 public String getCity () {
643 public void setCity (final String city) {
648 public String getComment () {
653 public void setComment (final String comment) {
654 this.comment = comment;
658 public String getControllerType () {
659 return "general"; //NOI18N
664 public void setControllerType (final String controllerType) {
665 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
669 public Country getCountry () {
674 public void setCountry (final Country country) {
675 this.country = country;
679 public String getEmailAddress () {
680 return this.emailAddress;
684 public void setEmailAddress (final String emailAddress) {
685 this.emailAddress = emailAddress;
689 public String getEmailAddressRepeat () {
690 return this.emailAddressRepeat;
694 public void setEmailAddressRepeat (final String emailAddressRepeat) {
695 this.emailAddressRepeat = emailAddressRepeat;
699 public String getFamilyName () {
700 return this.familyName;
704 public void setFamilyName (final String familyName) {
705 this.familyName = familyName;
709 public Integer getFaxAreaCode () {
710 return this.faxAreaCode;
714 public void setFaxAreaCode (final Integer faxAreaCode) {
715 this.faxAreaCode = faxAreaCode;
719 public Country getFaxCountry () {
720 return this.faxCountry;
724 public void setFaxCountry (final Country faxCountry) {
725 this.faxCountry = faxCountry;
729 public Long getFaxNumber () {
730 return this.faxNumber;
734 public void setFaxNumber (final Long faxNumber) {
735 this.faxNumber = faxNumber;
739 public String getFirstName () {
740 return this.firstName;
744 public void setFirstName (final String firstName) {
745 this.firstName = firstName;
749 public Gender getGender () {
754 public void setGender (final Gender gender) {
755 this.gender = gender;
759 public Short getHouseNumber () {
760 return this.houseNumber;
764 public void setHouseNumber (final Short houseNumber) {
765 this.houseNumber = houseNumber;
769 public String getHouseNumberExtension () {
770 return this.houseNumberExtension;
774 public void setHouseNumberExtension (final String houseNumberExtension) {
775 this.houseNumberExtension = houseNumberExtension;
779 public Integer getPhoneAreaCode () {
780 return this.phoneAreaCode;
784 public void setPhoneAreaCode (final Integer phoneAreaCode) {
785 this.phoneAreaCode = phoneAreaCode;
789 public Country getPhoneCountry () {
790 return this.phoneCountry;
794 public void setPhoneCountry (final Country phoneCountry) {
795 this.phoneCountry = phoneCountry;
799 public Long getPhoneNumber () {
800 return this.phoneNumber;
804 public void setPhoneNumber (final Long phoneNumber) {
805 this.phoneNumber = phoneNumber;
809 public String getStreet () {
814 public void setStreet (final String street) {
815 this.street = street;
819 public Integer getZipCode () {
824 public void setZipCode (final Integer zipCode) {
825 this.zipCode = zipCode;
829 public boolean hasContacts () {
830 return (!this.contactList.isEmpty());
834 * Post-initialization of this class
837 public void init () {
838 // Get full email address list for reducing EJB calls
839 this.emailAddressList = this.contactBean.getEmailAddressList();
841 // Get full contact list
842 this.contactList = this.contactBean.getAllContacts();
845 List<User> allUsers = this.userController.allUsers();
848 List<Contact> allContacts = this.contactBean.getAllContacts();
851 Iterator<Contact> iterator = allContacts.iterator();
854 while (iterator.hasNext()) {
856 Contact next = iterator.next();
859 Iterator<User> userIterator = allUsers.iterator();
861 // Loop through all users
862 while (userIterator.hasNext()) {
864 User nextUser = userIterator.next();
867 if (Objects.equals(next, nextUser.getUserContact())) {
876 this.selectableContacts = allContacts;
880 public boolean isEmailAddressRegistered (final Contact contact) {
882 if (null == contact) {
884 throw new NullPointerException("contact is null"); //NOI18N
885 } else if (contact.getContactEmailAddress() == null) {
887 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
888 } else if (contact.getContactEmailAddress().isEmpty()) {
890 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
894 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
898 public boolean isRequiredChangePersonalDataSet () {
899 return ((this.getGender() != null) &&
900 (this.getFirstName() != null) &&
901 (this.getFamilyName() != null) &&
902 (this.getStreet() != null) &&
903 (this.getHouseNumber() != null) &&
904 (this.getZipCode() != null) &&
905 (this.getCity() != null));
909 public boolean isRequiredPersonalDataSet () {
910 return ((this.getGender() != null) &&
911 (this.getFirstName() != null) &&
912 (this.getFamilyName() != null) &&
913 (this.getStreet() != null) &&
914 (this.getHouseNumber() != null) &&
915 (this.getZipCode() != null) &&
916 (this.getCity() != null) &&
917 (this.getEmailAddress() != null) &&
918 (this.getEmailAddressRepeat() != null));
922 public boolean isSameEmailAddressEntered () {
923 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
927 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
929 Contact localContact = null;
934 // Try to lookup it in visible user list
935 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
937 Contact next = iterator.next();
939 // Is the user id found?
940 if (Objects.equals(next.getContactId(), contactId)) {
941 // Copy to other variable
948 if (null == localContact) {
949 // Not visible for the current user
950 throw new ContactNotFoundException(contactId);
953 // Copy all data to this bean
954 this.copyContact(localContact);
961 public List<Contact> selectableContacts () {
962 return Collections.unmodifiableList(this.selectableContacts);
966 public void updateContactDataFromController (final Contact contact) {
967 // Is the instance valid?
968 if (null == contact) {
970 throw new NullPointerException("contact is null"); //NOI18N
971 } else if (contact.getContactId() == null) {
973 throw new NullPointerException("contact.contactId is null"); //NOI18N
974 } else if (contact.getContactId() < 1) {
975 // Not valid id number
976 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
980 this.copyContact(contact);
984 * Adds email address to bean's internal list.
986 * @param contact Contact instance
988 private void addUserNameEmailAddress (final Contact contact) {
989 // Make sure the entry is not added yet
990 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
992 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
996 this.emailAddressList.add(contact.getContactEmailAddress());
1002 private void clear () {
1005 this.setGender(null);
1006 // TODO: Unfinished this.setTitle(null);
1007 this.setFirstName(null);
1008 this.setFamilyName(null);
1009 this.setStreet(null);
1010 this.setHouseNumber(null);
1011 this.setHouseNumberExtension(null);
1012 this.setZipCode(null);
1014 this.setCountry(null);
1017 this.setEmailAddress(null);
1018 this.setEmailAddressRepeat(null);
1019 this.setPhoneAreaCode(null);
1020 this.setPhoneCountry(null);
1021 this.setPhoneNumber(null);
1022 this.setCellphoneCarrier(null);
1023 this.setCellphoneNumber(null);
1024 this.setFaxAreaCode(null);
1025 this.setFaxCountry(null);
1026 this.setFaxNumber(null);
1029 this.setBirthday(null);
1030 this.setComment(null);
1034 * Copies given contact into the controller
1036 * @param contact Contact instance
1038 private void copyContact (final Contact contact) {
1039 // Is the instance valid?
1040 if (null == contact) {
1042 throw new NullPointerException("contact is null"); //NOI18N
1043 } else if (contact.getContactId() == null) {
1045 throw new NullPointerException("contact.contactId is null"); //NOI18N
1046 } else if (contact.getContactId() < 1) {
1047 // Not valid id number
1048 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1053 this.setGender(contact.getContactGender());
1054 this.setFirstName(contact.getContactFirstName());
1055 this.setFamilyName(contact.getContactFamilyName());
1056 this.setStreet(contact.getContactStreet());
1057 this.setHouseNumber(contact.getContactHouseNumber());
1058 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
1059 this.setZipCode(contact.getContactZipCode());
1060 this.setCity(contact.getContactCity());
1061 this.setCountry(contact.getContactCountry());
1062 this.setEmailAddress(contact.getContactEmailAddress());
1063 this.setBirthday(contact.getContactBirthday());
1064 this.setComment(contact.getContactComment());
1066 // Get cellphone, phone and fax instance
1067 DialableCellphoneNumber cellphone = contact.getContactCellphoneNumber();
1068 DialableFaxNumber fax = contact.getContactFaxNumber();
1069 DialableLandLineNumber phone = contact.getContactLandLineNumber();
1072 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
1073 this.setPhoneCountry(phone.getPhoneCountry());
1074 this.setPhoneAreaCode(phone.getPhoneAreaCode());
1075 this.setPhoneNumber(phone.getPhoneNumber());
1078 if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) {
1079 this.setCellphoneCarrier(cellphone.getCellphoneProvider());
1080 this.setCellphoneNumber(cellphone.getPhoneNumber());
1083 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
1084 this.setFaxCountry(fax.getPhoneCountry());
1085 this.setFaxAreaCode(fax.getPhoneAreaCode());
1086 this.setFaxNumber(fax.getPhoneNumber());
1091 * Removes given contact from all lists
1093 * @param contact Contact instance to remove
1095 private void removeContact (final Contact contact) {
1096 // Is the instance valid?
1097 if (null == contact) {
1099 throw new NullPointerException("contact is null"); //NOI18N
1100 } else if (contact.getContactId() == null) {
1102 throw new NullPointerException("contact.contactId is null"); //NOI18N
1103 } else if (contact.getContactId() < 1) {
1104 // Not valid id number
1105 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1108 // Remove from general list
1109 if (!this.contactList.remove(contact)) {
1110 // Did not remove contact
1111 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
1114 // Remove from other lists
1115 this.emailAddressList.remove(contact.getContactEmailAddress());