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) {
247 /* NOISY-DEBUG: */ System.out.println(MessageFormat.format("contactController.afterAdminAddedContact(): event={0} - CALLED!", event)); //NOI18N
249 // The event must be valid
252 throw new NullPointerException("event is null"); //NOI18N
253 } else if (event.getAddedContact() == null) {
255 throw new NullPointerException("event.addedContact is null"); //NOI18N
256 } else if (event.getAddedContact().getContactId() == null) {
258 throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
259 } else if (event.getAddedContact().getContactId() < 1) {
261 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
268 this.contactList.add(event.getAddedContact());
271 this.selectableContacts.add(event.getAddedContact());
275 public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
276 // event should not be null
279 throw new NullPointerException("event is null"); //NOI18N
280 } else if (event.getAddedUser() == null) {
282 throw new NullPointerException("event.addedUser is null"); //NOI18N
283 } else if (event.getAddedUser().getUserId() == null) {
285 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
286 } else if (event.getAddedUser().getUserId() < 1) {
288 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
296 public void afterAdminLinkedUser (@Observes final AdminLinkedUserEvent event) {
297 // event should not be null
300 throw new NullPointerException("event is null"); //NOI18N
301 } else if (event.getLinkedUser() == null) {
303 throw new NullPointerException("event.linkedUser is null"); //NOI18N
304 } else if (event.getLinkedUser().getUserContact() == null) {
306 throw new NullPointerException("event.linkedUser.userContact is null"); //NOI18N
307 } else if (event.getLinkedUser().getUserContact().getContactId() == null) {
309 throw new NullPointerException("event.linkedUser.userContact.contactId is null"); //NOI18N
310 } else if (event.getLinkedUser().getUserContact().getContactId() < 1) {
312 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N
315 // Remove contact from list available contacts list
316 this.selectableContacts.remove(event.getLinkedUser().getUserContact());
323 public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
324 // event should not be null
327 throw new NullPointerException("event is null"); //NOI18N
328 } else if (event.getUpdatedContact() == null) {
330 throw new NullPointerException("event.updatedContact is null"); //NOI18N
331 } else if (event.getUpdatedContact().getContactId() == null) {
333 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
334 } else if (event.getUpdatedContact().getContactId() < 1) {
336 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
339 // Get iterator from list
340 Iterator<Contact> iterator = this.contactList.iterator();
342 // "Walk" through all entries
343 while (iterator.hasNext()) {
345 Contact next = iterator.next();
347 // Is id number the same?
348 if (Objects.equals(event.getUpdatedContact().getContactId(), next.getContactId())) {
349 // Found entry, so remove it and abort
350 this.contactList.remove(next);
352 // Remove also email from list
353 this.emailAddressList.remove(next.getContactEmailAddress());
358 // Add contact to list
359 this.contactList.add(event.getUpdatedContact());
361 // Add email address to list
362 this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
366 public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
367 // event should not be null
370 throw new NullPointerException("event is null"); //NOI18N
371 } else if (event.getRegisteredUser() == null) {
373 throw new NullPointerException("event.registeredUser is null"); //NOI18N
374 } else if (event.getRegisteredUser().getUserId() == null) {
376 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
377 } else if (event.getRegisteredUser().getUserId() < 1) {
379 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
383 Contact registeredContact = event.getRegisteredUser().getUserContact();
385 // Copy all data from registered->user
386 this.copyContact(registeredContact);
388 // Add user name and email address
389 this.addUserNameEmailAddress(registeredContact);
396 public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) {
397 // event should not be null
400 throw new NullPointerException("event is null"); //NOI18N
401 } else if (event.getConfirmedUser() == null) {
403 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
404 } else if (event.getConfirmedUser().getUserId() == null) {
406 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
407 } else if (event.getConfirmedUser().getUserId() < 1) {
409 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
412 // "Cache" contact instance
413 Contact contact = event.getConfirmedUser().getUserContact();
415 // Get iterator from list
416 Iterator<Contact> iterator = this.contactList.iterator();
418 // "Walk" through all entries
419 while (iterator.hasNext()) {
421 Contact next = iterator.next();
423 // Is id number the same?
424 if (Objects.equals(contact.getContactId(), next.getContactId())) {
425 // Found entry, so remove it and abort
426 this.removeContact(next);
431 // Add contact to list
432 this.contactList.add(contact);
436 public void afterUserLogin (@Observes final UserLoggedInEvent event) {
437 // event should not be null
440 throw new NullPointerException("event is null"); //NOI18N
441 } else if (event.getLoggedInUser() == null) {
443 throw new NullPointerException("event.loggedInUser is null"); //NOI18N
444 } else if (event.getLoggedInUser().getUserId() == null) {
446 throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
447 } else if (event.getLoggedInUser().getUserId() < 1) {
449 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
452 // Copy all data to this bean
453 this.copyContact(event.getLoggedInUser().getUserContact());
457 public List<Contact> allContacts () {
459 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size()));
461 // Return un-modified list
462 return Collections.unmodifiableList(this.contactList);
466 public Contact createContactInstance () {
468 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName()));
470 // Is all required data set?
471 if (!this.isRequiredPersonalDataSet()) {
472 // No, then abort here
473 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
476 // Generate phone number
477 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
478 DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
479 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
481 // Create new contact
482 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
483 contact.setContactStreet(this.getStreet());
484 contact.setContactHouseNumber(this.getHouseNumber());
485 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
486 contact.setContactZipCode(this.getZipCode());
487 contact.setContactCity(this.getCity());
488 contact.setContactCountry(this.getCountry());
489 contact.setContactEmailAddress(this.getEmailAddress());
490 contact.setContactBirthday(this.getBirthday());
491 contact.setContactComment(this.getComment());
494 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
496 // Don't set null or wrong references
497 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
498 // Now the number must be given
499 if (phone.getPhoneAreaCode() == null) {
501 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
502 } else if (phone.getPhoneAreaCode() < 1) {
504 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
505 } else if (phone.getPhoneNumber() == null) {
507 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
508 } else if (phone.getPhoneNumber() < 1) {
510 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
514 contact.setContactLandLineNumber(phone);
517 // Don't set null or wrong references
518 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
519 // Now the number must be given
520 if (fax.getPhoneAreaCode() == null) {
522 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
523 } else if (fax.getPhoneAreaCode() < 1) {
525 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
526 } else if (fax.getPhoneNumber() == null) {
528 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
529 } else if (fax.getPhoneNumber() < 1) {
531 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
535 contact.setContactFaxNumber(fax);
538 // Is the provider set?
539 if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
540 // Is the number set?
541 if (cellphone.getPhoneNumber() == null) {
543 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
544 } else if (cellphone.getPhoneNumber() < 1) {
546 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
549 // Set cellphone number
550 contact.setContactCellphoneNumber(cellphone);
554 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
561 public String doChangePersonalContactData () {
562 // This method shall only be called if the user is logged-in
563 if (!this.userLoginController.isUserLoggedIn()) {
565 throw new IllegalStateException("User is not logged-in"); //NOI18N
566 } else if (!this.isRequiredChangePersonalDataSet()) {
567 // Not all required fields are set
568 throw new FaceletException("Not all required fields are set."); //NOI18N
569 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
570 // Password not matching
571 this.showFacesMessage("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
575 // Get contact instance
576 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
578 // It should be there, so run some tests on it
579 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
580 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
581 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
584 contact.setContactGender(this.getGender());
585 contact.setContactFirstName(this.getFirstName());
586 contact.setContactFamilyName(this.getFamilyName());
587 contact.setContactStreet(this.getStreet());
588 contact.setContactHouseNumber(this.getHouseNumber());
589 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
590 contact.setContactZipCode(this.getZipCode());
591 contact.setContactCity(this.getCity());
592 contact.setContactCountry(this.getCountry());
594 // Update contact's cellphone number
595 this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
597 // Update contact's land-line number
598 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
600 // Update contact's fax number
601 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
603 // Send it to the EJB
604 this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
607 return "contact_data_saved"; //NOI18N
611 @SuppressWarnings ("ReturnOfDateField")
612 public Date getBirthday () {
613 return this.birthday;
617 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
618 public void setBirthday (final Date birthday) {
619 this.birthday = birthday;
623 public MobileProvider getCellphoneCarrier () {
624 return this.cellphoneCarrier;
628 public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
629 this.cellphoneCarrier = cellphoneCarrier;
633 public Long getCellphoneNumber () {
634 return this.cellphoneNumber;
638 public void setCellphoneNumber (Long cellphoneNumber) {
639 this.cellphoneNumber = cellphoneNumber;
643 public String getCity () {
648 public void setCity (final String city) {
653 public String getComment () {
658 public void setComment (final String comment) {
659 this.comment = comment;
663 public String getControllerType () {
664 return "general"; //NOI18N
669 public void setControllerType (final String controllerType) {
670 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
674 public Country getCountry () {
679 public void setCountry (final Country country) {
680 this.country = country;
684 public String getEmailAddress () {
685 return this.emailAddress;
689 public void setEmailAddress (final String emailAddress) {
690 this.emailAddress = emailAddress;
694 public String getEmailAddressRepeat () {
695 return this.emailAddressRepeat;
699 public void setEmailAddressRepeat (final String emailAddressRepeat) {
700 this.emailAddressRepeat = emailAddressRepeat;
704 public String getFamilyName () {
705 return this.familyName;
709 public void setFamilyName (final String familyName) {
710 this.familyName = familyName;
714 public Integer getFaxAreaCode () {
715 return this.faxAreaCode;
719 public void setFaxAreaCode (final Integer faxAreaCode) {
720 this.faxAreaCode = faxAreaCode;
724 public Country getFaxCountry () {
725 return this.faxCountry;
729 public void setFaxCountry (final Country faxCountry) {
730 this.faxCountry = faxCountry;
734 public Long getFaxNumber () {
735 return this.faxNumber;
739 public void setFaxNumber (final Long faxNumber) {
740 this.faxNumber = faxNumber;
744 public String getFirstName () {
745 return this.firstName;
749 public void setFirstName (final String firstName) {
750 this.firstName = firstName;
754 public Gender getGender () {
759 public void setGender (final Gender gender) {
760 this.gender = gender;
764 public Short getHouseNumber () {
765 return this.houseNumber;
769 public void setHouseNumber (final Short houseNumber) {
770 this.houseNumber = houseNumber;
774 public String getHouseNumberExtension () {
775 return this.houseNumberExtension;
779 public void setHouseNumberExtension (final String houseNumberExtension) {
780 this.houseNumberExtension = houseNumberExtension;
784 public Integer getPhoneAreaCode () {
785 return this.phoneAreaCode;
789 public void setPhoneAreaCode (final Integer phoneAreaCode) {
790 this.phoneAreaCode = phoneAreaCode;
794 public Country getPhoneCountry () {
795 return this.phoneCountry;
799 public void setPhoneCountry (final Country phoneCountry) {
800 this.phoneCountry = phoneCountry;
804 public Long getPhoneNumber () {
805 return this.phoneNumber;
809 public void setPhoneNumber (final Long phoneNumber) {
810 this.phoneNumber = phoneNumber;
814 public String getStreet () {
819 public void setStreet (final String street) {
820 this.street = street;
824 public Integer getZipCode () {
829 public void setZipCode (final Integer zipCode) {
830 this.zipCode = zipCode;
834 public boolean hasContacts () {
835 return (!this.contactList.isEmpty());
839 * Post-initialization of this class
842 public void init () {
843 // Get full email address list for reducing EJB calls
844 this.emailAddressList = this.contactBean.getEmailAddressList();
846 // Get full contact list
847 this.contactList = this.contactBean.getAllContacts();
850 List<User> allUsers = this.userController.allUsers();
853 List<Contact> allContacts = this.contactBean.getAllContacts();
856 Iterator<Contact> iterator = allContacts.iterator();
859 while (iterator.hasNext()) {
861 Contact next = iterator.next();
864 Iterator<User> userIterator = allUsers.iterator();
866 // Loop through all users
867 while (userIterator.hasNext()) {
869 User nextUser = userIterator.next();
872 if (Objects.equals(next, nextUser.getUserContact())) {
881 this.selectableContacts = allContacts;
885 public boolean isEmailAddressRegistered (final Contact contact) {
887 if (null == contact) {
889 throw new NullPointerException("contact is null"); //NOI18N
890 } else if (contact.getContactEmailAddress() == null) {
892 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
893 } else if (contact.getContactEmailAddress().isEmpty()) {
895 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
899 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
903 public boolean isRequiredChangePersonalDataSet () {
904 return ((this.getGender() != null) &&
905 (this.getFirstName() != null) &&
906 (this.getFamilyName() != null) &&
907 (this.getStreet() != null) &&
908 (this.getHouseNumber() != null) &&
909 (this.getZipCode() != null) &&
910 (this.getCity() != null));
914 public boolean isRequiredPersonalDataSet () {
915 return ((this.getGender() != null) &&
916 (this.getFirstName() != null) &&
917 (this.getFamilyName() != null) &&
918 (this.getStreet() != null) &&
919 (this.getHouseNumber() != null) &&
920 (this.getZipCode() != null) &&
921 (this.getCity() != null) &&
922 (this.getEmailAddress() != null) &&
923 (this.getEmailAddressRepeat() != null));
927 public boolean isSameEmailAddressEntered () {
928 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
932 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
934 Contact localContact = null;
939 // Try to lookup it in visible user list
940 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
942 Contact next = iterator.next();
944 // Is the user id found?
945 if (Objects.equals(next.getContactId(), contactId)) {
946 // Copy to other variable
953 if (null == localContact) {
954 // Not visible for the current user
955 throw new ContactNotFoundException(contactId);
958 // Copy all data to this bean
959 this.copyContact(localContact);
966 public List<Contact> selectableContacts () {
967 return Collections.unmodifiableList(this.selectableContacts);
971 public void updateContactDataFromController (final Contact contact) {
972 // Is the instance valid?
973 if (null == contact) {
975 throw new NullPointerException("contact is null"); //NOI18N
976 } else if (contact.getContactId() == null) {
978 throw new NullPointerException("contact.contactId is null"); //NOI18N
979 } else if (contact.getContactId() < 1) {
980 // Not valid id number
981 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
985 this.copyContact(contact);
989 * Adds email address to bean's internal list.
991 * @param contact Contact instance
993 private void addUserNameEmailAddress (final Contact contact) {
994 // Make sure the entry is not added yet
995 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
997 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
1001 this.emailAddressList.add(contact.getContactEmailAddress());
1007 private void clear () {
1010 this.setGender(null);
1011 // TODO: Unfinished this.setTitle(null);
1012 this.setFirstName(null);
1013 this.setFamilyName(null);
1014 this.setStreet(null);
1015 this.setHouseNumber(null);
1016 this.setHouseNumberExtension(null);
1017 this.setZipCode(null);
1019 this.setCountry(null);
1022 this.setEmailAddress(null);
1023 this.setEmailAddressRepeat(null);
1024 this.setPhoneAreaCode(null);
1025 this.setPhoneCountry(null);
1026 this.setPhoneNumber(null);
1027 this.setCellphoneCarrier(null);
1028 this.setCellphoneNumber(null);
1029 this.setFaxAreaCode(null);
1030 this.setFaxCountry(null);
1031 this.setFaxNumber(null);
1034 this.setBirthday(null);
1035 this.setComment(null);
1039 * Copies given contact into the controller
1041 * @param contact Contact instance
1043 private void copyContact (final Contact contact) {
1044 // Is the instance valid?
1045 if (null == contact) {
1047 throw new NullPointerException("contact is null"); //NOI18N
1048 } else if (contact.getContactId() == null) {
1050 throw new NullPointerException("contact.contactId is null"); //NOI18N
1051 } else if (contact.getContactId() < 1) {
1052 // Not valid id number
1053 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1058 this.setGender(contact.getContactGender());
1059 this.setFirstName(contact.getContactFirstName());
1060 this.setFamilyName(contact.getContactFamilyName());
1061 this.setStreet(contact.getContactStreet());
1062 this.setHouseNumber(contact.getContactHouseNumber());
1063 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
1064 this.setZipCode(contact.getContactZipCode());
1065 this.setCity(contact.getContactCity());
1066 this.setCountry(contact.getContactCountry());
1067 this.setEmailAddress(contact.getContactEmailAddress());
1068 this.setBirthday(contact.getContactBirthday());
1069 this.setComment(contact.getContactComment());
1071 // Get cellphone, phone and fax instance
1072 DialableCellphoneNumber cellphone = contact.getContactCellphoneNumber();
1073 DialableFaxNumber fax = contact.getContactFaxNumber();
1074 DialableLandLineNumber phone = contact.getContactLandLineNumber();
1077 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
1078 this.setPhoneCountry(phone.getPhoneCountry());
1079 this.setPhoneAreaCode(phone.getPhoneAreaCode());
1080 this.setPhoneNumber(phone.getPhoneNumber());
1083 if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) {
1084 this.setCellphoneCarrier(cellphone.getCellphoneProvider());
1085 this.setCellphoneNumber(cellphone.getPhoneNumber());
1088 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
1089 this.setFaxCountry(fax.getPhoneCountry());
1090 this.setFaxAreaCode(fax.getPhoneAreaCode());
1091 this.setFaxNumber(fax.getPhoneNumber());
1096 * Removes given contact from all lists
1098 * @param contact Contact instance to remove
1100 private void removeContact (final Contact contact) {
1101 // Is the instance valid?
1102 if (null == contact) {
1104 throw new NullPointerException("contact is null"); //NOI18N
1105 } else if (contact.getContactId() == null) {
1107 throw new NullPointerException("contact.contactId is null"); //NOI18N
1108 } else if (contact.getContactId() < 1) {
1109 // Not valid id number
1110 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1113 // Remove from general list
1114 if (!this.contactList.remove(contact)) {
1115 // Did not remove contact
1116 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
1119 // Remove from other lists
1120 this.emailAddressList.remove(contact.getContactEmailAddress());