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.addressbook.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.addressbook.beans.BaseAddressbookController;
36 import org.mxchange.addressbook.beans.login.AddressbookUserLoginWebSessionController;
37 import org.mxchange.addressbook.beans.user.AddressbookUserWebSessionController;
38 import org.mxchange.jcontacts.contact.Contact;
39 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
40 import org.mxchange.jcontacts.contact.UserContact;
41 import org.mxchange.jcontacts.contact.gender.Gender;
42 import org.mxchange.jcontacts.contact.utils.ContactUtils;
43 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
44 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
45 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
46 import org.mxchange.jcountry.data.Country;
47 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
48 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
49 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
50 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
51 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
52 import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
53 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
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.jusercore.exceptions.UserPasswordMismatchException;
60 import org.mxchange.jusercore.model.user.User;
63 * A general contact bean (controller)
65 * @author Roland Häder<roland@mxchange.org>
67 @Named ("contactController")
69 public class AddressbookContactWebSessionBean extends BaseAddressbookController implements AddressbookContactWebSessionController {
74 private static final long serialVersionUID = 542_145_347_916L;
79 private Date birthday;
82 * Mobile number's carrier
84 private MobileProvider mobileCarrier;
89 private Long mobileNumber;
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 mobile 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 AddressbookUserWebSessionController userController;
223 * Login bean (controller)
226 private AddressbookUserLoginWebSessionController userLoginController;
231 private Integer zipCode;
234 * Default constructor
236 public AddressbookContactWebSessionBean () {
239 // Get initial context
240 Context context = new InitialContext();
243 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/addressbook-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) {
287 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("contactController.afterAdminAddedUserEvent(): event={0} - CALLED!", event)); //NOI18N
289 // event should not be null
292 throw new NullPointerException("event is null"); //NOI18N
293 } else if (event.getAddedUser() == null) {
295 throw new NullPointerException("event.addedUser is null"); //NOI18N
296 } else if (event.getAddedUser().getUserId() == null) {
298 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
299 } else if (event.getAddedUser().getUserId() < 1) {
301 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
309 public void afterAdminLinkedUser (@Observes final ObservableAdminLinkedUserEvent event) {
310 // event should not be null
313 throw new NullPointerException("event is null"); //NOI18N
314 } else if (event.getLinkedUser() == null) {
316 throw new NullPointerException("event.linkedUser is null"); //NOI18N
317 } else if (event.getLinkedUser().getUserContact() == null) {
319 throw new NullPointerException("event.linkedUser.userContact is null"); //NOI18N
320 } else if (event.getLinkedUser().getUserContact().getContactId() == null) {
322 throw new NullPointerException("event.linkedUser.userContact.contactId is null"); //NOI18N
323 } else if (event.getLinkedUser().getUserContact().getContactId() < 1) {
325 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N
328 // Remove contact from list available contacts list
329 this.selectableContacts.remove(event.getLinkedUser().getUserContact());
336 public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
337 // event should not be null
340 throw new NullPointerException("event is null"); //NOI18N
341 } else if (event.getUpdatedContact() == null) {
343 throw new NullPointerException("event.updatedContact is null"); //NOI18N
344 } else if (event.getUpdatedContact().getContactId() == null) {
346 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
347 } else if (event.getUpdatedContact().getContactId() < 1) {
349 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
352 // Add contact instance only once
353 this.uniqueAddContact(event.getUpdatedContact());
355 // Add email address to list
356 this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
359 //* NOISY-DEBUG: */ System.out.println("contactController.afterAdminUpdatedContactDataEvent(): EXIT!"); //NOI18N
363 public void afterRegistrationEvent (@Observes final ObservableUserRegisteredEvent 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 contact instance only once
386 this.uniqueAddContact(registeredContact);
388 // Add user name and email address
389 this.addUserNameEmailAddress(registeredContact);
396 public void afterUserConfirmedAccount (@Observes final ObservableUserConfirmedAccountEvent 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 // Add contact instance only once
413 this.uniqueAddContact(event.getConfirmedUser().getUserContact());
417 public void afterUserLogin (@Observes final ObservableUserLoggedInEvent event) {
418 // event should not be null
421 throw new NullPointerException("event is null"); //NOI18N
422 } else if (event.getLoggedInUser() == null) {
424 throw new NullPointerException("event.loggedInUser is null"); //NOI18N
425 } else if (event.getLoggedInUser().getUserId() == null) {
427 throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
428 } else if (event.getLoggedInUser().getUserId() < 1) {
430 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
433 // Copy all data to this bean
434 this.copyContact(event.getLoggedInUser().getUserContact());
438 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
439 public List<Contact> allContacts () {
441 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size()));
443 // Return un-modified list
444 return this.contactList;
448 public Contact createContactInstance () {
450 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName()));
452 // Is all required data set?
453 if (!this.isRequiredPersonalDataSet()) {
454 // No, then abort here
455 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
458 // Required personal data must be set
459 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
461 // Generate phone number
462 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
463 DialableMobileNumber mobile = new MobileNumber(this.getMobileCarrier(), this.getMobileNumber());
464 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
466 // Create new contact
467 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
468 contact.setContactStreet(this.getStreet());
469 contact.setContactHouseNumber(this.getHouseNumber());
470 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
471 contact.setContactZipCode(this.getZipCode());
472 contact.setContactCity(this.getCity());
473 contact.setContactCountry(this.getCountry());
474 contact.setContactEmailAddress(this.getEmailAddress());
475 contact.setContactBirthday(this.getBirthday());
476 contact.setContactComment(this.getComment());
479 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
481 // Don't set null or wrong references
482 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
483 // Now the number must be given
484 if (phone.getPhoneAreaCode() == null) {
486 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
487 } else if (phone.getPhoneAreaCode() < 1) {
489 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
490 } else if (phone.getPhoneNumber() == null) {
492 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
493 } else if (phone.getPhoneNumber() < 1) {
495 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
499 contact.setContactLandLineNumber(phone);
502 // Don't set null or wrong references
503 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
504 // Now the number must be given
505 if (fax.getPhoneAreaCode() == null) {
507 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
508 } else if (fax.getPhoneAreaCode() < 1) {
510 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
511 } else if (fax.getPhoneNumber() == null) {
513 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
514 } else if (fax.getPhoneNumber() < 1) {
516 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
520 contact.setContactFaxNumber(fax);
523 // Is the provider set?
524 if ((mobile instanceof DialableMobileNumber) && (this.getMobileCarrier() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
525 // Is the number set?
526 if (mobile.getPhoneNumber() == null) {
528 throw new NullPointerException("mobile.phoneNumber is null"); //NOI18N
529 } else if (mobile.getPhoneNumber() < 1) {
531 throw new IllegalArgumentException("mobile.phoneNumber is zero or below."); //NOI18N
535 contact.setContactMobileNumber(mobile);
539 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
546 public String doChangePersonalContactData () {
547 // This method shall only be called if the user is logged-in
548 if (!this.userLoginController.isUserLoggedIn()) {
550 throw new IllegalStateException("User is not logged-in"); //NOI18N
551 } else if (!this.isRequiredChangePersonalDataSet()) {
552 // Not all required fields are set
553 throw new FaceletException("Not all required fields are set."); //NOI18N
554 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
555 // Password not matching
556 this.showFacesMessage("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
560 // Get contact instance
561 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
563 // It should be there, so run some tests on it
564 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
565 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
566 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
569 contact.setContactGender(this.getGender());
570 contact.setContactFirstName(this.getFirstName());
571 contact.setContactFamilyName(this.getFamilyName());
572 contact.setContactStreet(this.getStreet());
573 contact.setContactHouseNumber(this.getHouseNumber());
574 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
575 contact.setContactZipCode(this.getZipCode());
576 contact.setContactCity(this.getCity());
577 contact.setContactCountry(this.getCountry());
579 // Update contact's mobile number
580 this.isMobileUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileCarrier(), this.getMobileNumber());
582 // Update contact's land-line number
583 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
585 // Update contact's fax number
586 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
588 // Send it to the EJB
589 this.contactBean.updateContactData(contact, this.isMobileUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
592 return "contact_data_saved"; //NOI18N
596 @SuppressWarnings ("ReturnOfDateField")
597 public Date getBirthday () {
598 return this.birthday;
602 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
603 public void setBirthday (final Date birthday) {
604 this.birthday = birthday;
608 public MobileProvider getMobileCarrier () {
609 return this.mobileCarrier;
613 public void setMobileCarrier (final MobileProvider mobileCarrier) {
614 this.mobileCarrier = mobileCarrier;
618 public Long getMobileNumber () {
619 return this.mobileNumber;
623 public void setMobileNumber (final Long mobileNumber) {
624 this.mobileNumber = mobileNumber;
628 public String getCity () {
633 public void setCity (final String city) {
638 public String getComment () {
643 public void setComment (final String comment) {
644 this.comment = comment;
648 public String getControllerType () {
649 return "general"; //NOI18N
654 public void setControllerType (final String controllerType) {
655 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
659 public Country getCountry () {
664 public void setCountry (final Country country) {
665 this.country = country;
669 public String getEmailAddress () {
670 return this.emailAddress;
674 public void setEmailAddress (final String emailAddress) {
675 this.emailAddress = emailAddress;
679 public String getEmailAddressRepeat () {
680 return this.emailAddressRepeat;
684 public void setEmailAddressRepeat (final String emailAddressRepeat) {
685 this.emailAddressRepeat = emailAddressRepeat;
689 public String getFamilyName () {
690 return this.familyName;
694 public void setFamilyName (final String familyName) {
695 this.familyName = familyName;
699 public Integer getFaxAreaCode () {
700 return this.faxAreaCode;
704 public void setFaxAreaCode (final Integer faxAreaCode) {
705 this.faxAreaCode = faxAreaCode;
709 public Country getFaxCountry () {
710 return this.faxCountry;
714 public void setFaxCountry (final Country faxCountry) {
715 this.faxCountry = faxCountry;
719 public Long getFaxNumber () {
720 return this.faxNumber;
724 public void setFaxNumber (final Long faxNumber) {
725 this.faxNumber = faxNumber;
729 public String getFirstName () {
730 return this.firstName;
734 public void setFirstName (final String firstName) {
735 this.firstName = firstName;
739 public Gender getGender () {
744 public void setGender (final Gender gender) {
745 this.gender = gender;
749 public Short getHouseNumber () {
750 return this.houseNumber;
754 public void setHouseNumber (final Short houseNumber) {
755 this.houseNumber = houseNumber;
759 public String getHouseNumberExtension () {
760 return this.houseNumberExtension;
764 public void setHouseNumberExtension (final String houseNumberExtension) {
765 this.houseNumberExtension = houseNumberExtension;
769 public Integer getPhoneAreaCode () {
770 return this.phoneAreaCode;
774 public void setPhoneAreaCode (final Integer phoneAreaCode) {
775 this.phoneAreaCode = phoneAreaCode;
779 public Country getPhoneCountry () {
780 return this.phoneCountry;
784 public void setPhoneCountry (final Country phoneCountry) {
785 this.phoneCountry = phoneCountry;
789 public Long getPhoneNumber () {
790 return this.phoneNumber;
794 public void setPhoneNumber (final Long phoneNumber) {
795 this.phoneNumber = phoneNumber;
799 public String getStreet () {
804 public void setStreet (final String street) {
805 this.street = street;
809 public String getTitle () {
814 public void setTitle (final String title) {
819 public Integer getZipCode () {
824 public void setZipCode (final Integer zipCode) {
825 this.zipCode = zipCode;
829 * Post-initialization of this class
832 public void init () {
833 // Get full email address list for reducing EJB calls
834 this.emailAddressList.addAll(this.contactBean.getEmailAddressList());
837 List<Contact> allContacts = this.contactBean.getAllContacts();
839 // Get full contact list
840 this.contactList.addAll(allContacts);
843 List<User> allUsers = this.userController.allUsers();
846 Iterator<Contact> iterator = allContacts.iterator();
849 while (iterator.hasNext()) {
851 Contact next = iterator.next();
854 Iterator<User> userIterator = allUsers.iterator();
856 // Loop through all users
857 while (userIterator.hasNext()) {
859 User nextUser = userIterator.next();
862 if (Objects.equals(next, nextUser.getUserContact())) {
871 this.selectableContacts = allContacts;
875 public boolean isEmailAddressRegistered (final Contact contact) {
877 if (null == contact) {
879 throw new NullPointerException("contact is null"); //NOI18N
880 } else if (contact.getContactEmailAddress() == null) {
882 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
883 } else if (contact.getContactEmailAddress().isEmpty()) {
885 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
889 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
893 public boolean isRequiredChangePersonalDataSet () {
894 return ((this.getGender() != null) &&
895 (this.getFirstName() != null) &&
896 (this.getFamilyName() != null) &&
897 (this.getStreet() != null) &&
898 (this.getHouseNumber() != null) &&
899 (this.getZipCode() != null) &&
900 (this.getCity() != null));
904 public boolean isRequiredPersonalDataSet () {
905 return ((this.getGender() != null) &&
906 (this.getFirstName() != null) &&
907 (this.getFamilyName() != null) &&
908 (this.getStreet() != null) &&
909 (this.getHouseNumber() != null) &&
910 (this.getZipCode() != null) &&
911 (this.getCity() != null) &&
912 (this.getEmailAddress() != null) &&
913 (this.getEmailAddressRepeat() != null));
917 public boolean isSameEmailAddressEntered () {
918 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
922 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
924 Contact localContact = null;
929 // Try to lookup it in visible user list
930 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
932 Contact next = iterator.next();
934 // Is the user id found?
935 if (Objects.equals(next.getContactId(), contactId)) {
936 // Copy to other variable
943 if (null == localContact) {
944 // Not visible for the current user
945 throw new ContactNotFoundException(contactId);
948 // Copy all data to this bean
949 this.copyContact(localContact);
956 public List<Contact> selectableContacts () {
957 return Collections.unmodifiableList(this.selectableContacts);
961 public void updateContactDataFromController (final Contact contact) {
962 // Is the instance valid?
963 if (null == contact) {
965 throw new NullPointerException("contact is null"); //NOI18N
966 } else if (contact.getContactId() == null) {
968 throw new NullPointerException("contact.contactId is null"); //NOI18N
969 } else if (contact.getContactId() < 1) {
970 // Not valid id number
971 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
975 this.copyContact(contact);
979 * Adds email address to bean's internal list.
981 * @param contact Contact instance
983 private void addUserNameEmailAddress (final Contact contact) {
984 // Make sure the entry is not added yet
985 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
987 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
991 this.emailAddressList.add(contact.getContactEmailAddress());
997 private void clear () {
1000 this.setGender(null);
1001 this.setTitle(null);
1002 this.setFirstName(null);
1003 this.setFamilyName(null);
1004 this.setStreet(null);
1005 this.setHouseNumber(null);
1006 this.setHouseNumberExtension(null);
1007 this.setZipCode(null);
1009 this.setCountry(null);
1012 this.setEmailAddress(null);
1013 this.setEmailAddressRepeat(null);
1014 this.setPhoneAreaCode(null);
1015 this.setPhoneCountry(null);
1016 this.setPhoneNumber(null);
1017 this.setMobileCarrier(null);
1018 this.setMobileNumber(null);
1019 this.setFaxAreaCode(null);
1020 this.setFaxCountry(null);
1021 this.setFaxNumber(null);
1024 this.setBirthday(null);
1025 this.setComment(null);
1029 * Copies given contact into the controller
1031 * @param contact Contact instance
1033 private void copyContact (final Contact contact) {
1034 // Is the instance valid?
1035 if (null == contact) {
1037 throw new NullPointerException("contact is null"); //NOI18N
1038 } else if (contact.getContactId() == null) {
1040 throw new NullPointerException("contact.contactId is null"); //NOI18N
1041 } else if (contact.getContactId() < 1) {
1042 // Not valid id number
1043 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1048 this.setGender(contact.getContactGender());
1049 this.setTitle(contact.getContactTitle());
1050 this.setFirstName(contact.getContactFirstName());
1051 this.setFamilyName(contact.getContactFamilyName());
1052 this.setStreet(contact.getContactStreet());
1053 this.setHouseNumber(contact.getContactHouseNumber());
1054 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
1055 this.setZipCode(contact.getContactZipCode());
1056 this.setCity(contact.getContactCity());
1057 this.setCountry(contact.getContactCountry());
1058 this.setEmailAddress(contact.getContactEmailAddress());
1059 this.setBirthday(contact.getContactBirthday());
1060 this.setComment(contact.getContactComment());
1062 // Get mobile, phone and fax instance
1063 DialableMobileNumber mobile = contact.getContactMobileNumber();
1064 DialableFaxNumber fax = contact.getContactFaxNumber();
1065 DialableLandLineNumber phone = contact.getContactLandLineNumber();
1068 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
1069 this.setPhoneCountry(phone.getPhoneCountry());
1070 this.setPhoneAreaCode(phone.getPhoneAreaCode());
1071 this.setPhoneNumber(phone.getPhoneNumber());
1074 if ((mobile instanceof DialableMobileNumber) && (mobile.getMobileProvider() instanceof MobileProvider)) {
1075 this.setMobileCarrier(mobile.getMobileProvider());
1076 this.setMobileNumber(mobile.getPhoneNumber());
1079 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
1080 this.setFaxCountry(fax.getPhoneCountry());
1081 this.setFaxAreaCode(fax.getPhoneAreaCode());
1082 this.setFaxNumber(fax.getPhoneNumber());
1087 * Removes given contact from all lists
1089 * @param contact Contact instance to remove
1091 private void removeContact (final Contact contact) {
1092 // Is the instance valid?
1093 if (null == contact) {
1095 throw new NullPointerException("contact is null"); //NOI18N
1096 } else if (contact.getContactId() == null) {
1098 throw new NullPointerException("contact.contactId is null"); //NOI18N
1099 } else if (contact.getContactId() < 1) {
1100 // Not valid id number
1101 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1104 // Remove from general list
1105 if (!this.contactList.remove(contact)) {
1106 // Did not remove contact
1107 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
1110 // Remove from other lists
1111 this.emailAddressList.remove(contact.getContactEmailAddress());
1115 * Adds unique instance to contact list. First any existing instance is
1116 * being removed, then the new instance is added.
1118 * @param contact Contact instance to add uniquely
1120 private void uniqueAddContact (final Contact contact) {
1121 // Is the instance valid?
1122 if (null == contact) {
1124 throw new NullPointerException("contact is null"); //NOI18N
1125 } else if (contact.getContactId() == null) {
1127 throw new NullPointerException("contact.contactId is null"); //NOI18N
1128 } else if (contact.getContactId() < 1) {
1129 // Not valid id number
1130 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1133 // Get iterator from list
1134 Iterator<Contact> iterator = this.contactList.iterator();
1136 // "Walk" through all entries
1137 while (iterator.hasNext()) {
1139 Contact next = iterator.next();
1141 // Is id number the same?
1142 if (Objects.equals(contact.getContactId(), next.getContactId())) {
1143 // Found entry, so remove it and abort
1144 this.removeContact(next);
1149 // Add contact to list
1150 this.contactList.add(contact);