2 * Copyright (C) 2016 Roland Häder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.pizzaapplication.beans.contact;
19 import java.text.MessageFormat;
20 import java.util.Collections;
21 import java.util.Date;
22 import java.util.Iterator;
23 import java.util.LinkedList;
24 import java.util.List;
25 import java.util.Objects;
26 import javax.annotation.PostConstruct;
27 import javax.enterprise.context.SessionScoped;
28 import javax.enterprise.event.Observes;
29 import javax.faces.view.facelets.FaceletException;
30 import javax.inject.Inject;
31 import javax.inject.Named;
32 import javax.naming.Context;
33 import javax.naming.InitialContext;
34 import javax.naming.NamingException;
35 import org.mxchange.jcontacts.contact.Contact;
36 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
37 import org.mxchange.jcontacts.contact.UserContact;
38 import org.mxchange.jcontacts.contact.gender.Gender;
39 import org.mxchange.jcontacts.contact.utils.ContactUtils;
40 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
41 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
42 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
43 import org.mxchange.jcountry.data.Country;
44 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
45 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
46 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
47 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
48 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
49 import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
50 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
51 import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent;
52 import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
53 import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent;
54 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
55 import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
56 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
57 import org.mxchange.jusercore.model.user.User;
58 import org.mxchange.pizzaapplication.beans.BasePizzaController;
59 import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController;
60 import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
63 * A general contact bean (controller)
65 * @author Roland Häder<roland@mxchange.org>
67 @Named ("contactController")
69 public class PizzaContactWebSessionBean extends BasePizzaController implements PizzaContactWebSessionController {
74 private static final long serialVersionUID = 542_145_347_916L;
79 private Date birthday;
89 private String comment;
94 private ContactSessionBeanRemote contactBean;
99 private final List<Contact> contactList;
104 private Country country;
109 private String emailAddress;
114 private final List<String> emailAddressList;
117 * Email address repeated
119 private String emailAddressRepeat;
124 private String familyName;
127 * Fax number's area code
129 private Integer faxAreaCode;
132 * Country instance for fax number
134 private Country faxCountry;
139 private Long faxNumber;
144 private String firstName;
149 private Gender gender;
154 private Short houseNumber;
157 * House number extension
159 private String houseNumberExtension;
162 * Whether a fax entry has been unlinked
164 private boolean isFaxUnlinked;
167 * Whether a land-line number has been unlinked
169 private boolean isLandLineUnlinked;
172 * Whether a mobile entry has been unlinked
174 private boolean isMobileUnlinked;
177 * Mobile number's carrier
179 private MobileProvider mobileCarrier;
184 private Long mobileNumber;
187 * Phone number area code
189 private Integer phoneAreaCode;
192 * Country instance for phone number
194 private Country phoneCountry;
199 private Long phoneNumber;
202 * A list of all selectable contacts
204 private List<Contact> selectableContacts;
209 private String street;
214 private String title;
217 * Regular user controller
220 private PizzaUserWebSessionController userController;
223 * Login bean (controller)
226 private PizzaUserLoginWebSessionController userLoginController;
231 private Integer zipCode;
234 * Default constructor
236 public PizzaContactWebSessionBean () {
238 this.contactList = new LinkedList<>();
239 this.emailAddressList = new LinkedList<>();
243 * Observes events being fired when an administrator has added a new
246 * @param event Event being fired
248 public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
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.uniqueAddContact(event.getAddedContact());
270 // Add to selectable contacts
271 this.selectableContacts.add(event.getAddedContact());
275 * Event observer for newly added users by adminstrator
277 * @param event Event being fired
279 public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
280 // event should not be null
283 throw new NullPointerException("event is null"); //NOI18N
284 } else if (event.getAddedUser() == null) {
286 throw new NullPointerException("event.addedUser is null"); //NOI18N
287 } else if (event.getAddedUser().getUserId() == null) {
289 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
290 } else if (event.getAddedUser().getUserId() < 1) {
292 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
300 * Observes events being fired when an administrator has linked a new user
301 * with existing contact data.
303 * @param event Event being fired
305 public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent event) {
306 // event should not be null
309 throw new NullPointerException("event is null"); //NOI18N
310 } else if (event.getLinkedUser() == null) {
312 throw new NullPointerException("event.linkedUser is null"); //NOI18N
313 } else if (event.getLinkedUser().getUserContact() == null) {
315 throw new NullPointerException("event.linkedUser.userContact is null"); //NOI18N
316 } else if (event.getLinkedUser().getUserContact().getContactId() == null) {
318 throw new NullPointerException("event.linkedUser.userContact.contactId is null"); //NOI18N
319 } else if (event.getLinkedUser().getUserContact().getContactId() < 1) {
321 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N
324 // Remove contact from list available contacts list
325 this.selectableContacts.remove(event.getLinkedUser().getUserContact());
332 * Event observer for updated contact data by administrators
334 * @param event Updated contact data event
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());
360 * Event observer when user confirmed account.
362 * @param event Event being fired
364 public void afterUserConfirmedAccount (@Observes final ObservableUserConfirmedAccountEvent event) {
365 // event should not be null
368 throw new NullPointerException("event is null"); //NOI18N
369 } else if (event.getConfirmedUser() == null) {
371 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
372 } else if (event.getConfirmedUser().getUserId() == null) {
374 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
375 } else if (event.getConfirmedUser().getUserId() < 1) {
377 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
380 // Add contact instance only once
381 this.uniqueAddContact(event.getConfirmedUser().getUserContact());
385 * Event observer for logged-in user
387 * @param event Event instance
389 public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
390 // event should not be null
393 throw new NullPointerException("event is null"); //NOI18N
394 } else if (event.getLoggedInUser() == null) {
396 throw new NullPointerException("event.loggedInUser is null"); //NOI18N
397 } else if (event.getLoggedInUser().getUserId() == null) {
399 throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
400 } else if (event.getLoggedInUser().getUserId() < 1) {
402 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
405 // Copy all data to this bean
406 this.copyContact(event.getLoggedInUser().getUserContact());
410 * Event observer for new user registrations
412 * @param event User registration event
414 public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
415 // event should not be null
418 throw new NullPointerException("event is null"); //NOI18N
419 } else if (event.getRegisteredUser() == null) {
421 throw new NullPointerException("event.registeredUser is null"); //NOI18N
422 } else if (event.getRegisteredUser().getUserId() == null) {
424 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
425 } else if (event.getRegisteredUser().getUserId() < 1) {
427 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
431 Contact registeredContact = event.getRegisteredUser().getUserContact();
433 // Copy all data from registered->user
434 this.copyContact(registeredContact);
436 // Add contact instance only once
437 this.uniqueAddContact(registeredContact);
439 // Add user name and email address
440 this.addUserNameEmailAddress(registeredContact);
447 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
448 public List<Contact> allContacts () {
449 // Return un-modified list
450 return this.contactList;
454 public Contact createContactInstance () {
455 // Is all required data set?
456 if (!this.isRequiredPersonalDataSet()) {
457 // No, then abort here
458 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
461 // Required personal data must be set
462 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
464 // Generate phone number
465 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
466 DialableMobileNumber mobile = new MobileNumber(this.getMobileCarrier(), this.getMobileNumber());
467 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
469 // Create new contact
470 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
471 contact.setContactStreet(this.getStreet());
472 contact.setContactHouseNumber(this.getHouseNumber());
473 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
474 contact.setContactZipCode(this.getZipCode());
475 contact.setContactCity(this.getCity());
476 contact.setContactCountry(this.getCountry());
477 contact.setContactEmailAddress(this.getEmailAddress());
478 contact.setContactBirthday(this.getBirthday());
479 contact.setContactComment(this.getComment());
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);
543 public String doChangePersonalContactData () {
544 // This method shall only be called if the user is logged-in
545 if (!this.userLoginController.isUserLoggedIn()) {
547 throw new IllegalStateException("User is not logged-in"); //NOI18N
548 } else if (!this.isRequiredChangePersonalDataSet()) {
549 // Not all required fields are set
550 throw new FaceletException("Not all required fields are set."); //NOI18N
551 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
552 // Password not matching
553 this.showFacesMessage("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
557 // Get contact instance
558 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
560 // It should be there, so run some tests on it
561 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
562 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
563 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
566 contact.setContactGender(this.getGender());
567 contact.setContactFirstName(this.getFirstName());
568 contact.setContactFamilyName(this.getFamilyName());
569 contact.setContactStreet(this.getStreet());
570 contact.setContactHouseNumber(this.getHouseNumber());
571 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
572 contact.setContactZipCode(this.getZipCode());
573 contact.setContactCity(this.getCity());
574 contact.setContactCountry(this.getCountry());
576 // Update contact's mobile number
577 this.isMobileUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileCarrier(), this.getMobileNumber());
579 // Update contact's land-line number
580 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
582 // Update contact's fax number
583 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
585 // Send it to the EJB
586 this.contactBean.updateContactData(contact, this.isMobileUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
589 return "contact_data_saved"; //NOI18N
593 @SuppressWarnings ("ReturnOfDateField")
594 public Date getBirthday () {
595 return this.birthday;
599 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
600 public void setBirthday (final Date birthday) {
601 this.birthday = birthday;
605 public String getCity () {
610 public void setCity (final String city) {
615 public String getComment () {
620 public void setComment (final String comment) {
621 this.comment = comment;
625 public String getControllerType () {
626 return "general"; //NOI18N
631 public void setControllerType (final String controllerType) {
632 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
636 public Country getCountry () {
641 public void setCountry (final Country country) {
642 this.country = country;
646 public String getEmailAddress () {
647 return this.emailAddress;
651 public void setEmailAddress (final String emailAddress) {
652 this.emailAddress = emailAddress;
656 public String getEmailAddressRepeat () {
657 return this.emailAddressRepeat;
661 public void setEmailAddressRepeat (final String emailAddressRepeat) {
662 this.emailAddressRepeat = emailAddressRepeat;
666 public String getFamilyName () {
667 return this.familyName;
671 public void setFamilyName (final String familyName) {
672 this.familyName = familyName;
676 public Integer getFaxAreaCode () {
677 return this.faxAreaCode;
681 public void setFaxAreaCode (final Integer faxAreaCode) {
682 this.faxAreaCode = faxAreaCode;
686 public Country getFaxCountry () {
687 return this.faxCountry;
691 public void setFaxCountry (final Country faxCountry) {
692 this.faxCountry = faxCountry;
696 public Long getFaxNumber () {
697 return this.faxNumber;
701 public void setFaxNumber (final Long faxNumber) {
702 this.faxNumber = faxNumber;
706 public String getFirstName () {
707 return this.firstName;
711 public void setFirstName (final String firstName) {
712 this.firstName = firstName;
716 public Gender getGender () {
721 public void setGender (final Gender gender) {
722 this.gender = gender;
726 public Short getHouseNumber () {
727 return this.houseNumber;
731 public void setHouseNumber (final Short houseNumber) {
732 this.houseNumber = houseNumber;
736 public String getHouseNumberExtension () {
737 return this.houseNumberExtension;
741 public void setHouseNumberExtension (final String houseNumberExtension) {
742 this.houseNumberExtension = houseNumberExtension;
746 public MobileProvider getMobileCarrier () {
747 return this.mobileCarrier;
751 public void setMobileCarrier (final MobileProvider mobileCarrier) {
752 this.mobileCarrier = mobileCarrier;
756 public Long getMobileNumber () {
757 return this.mobileNumber;
761 public void setMobileNumber (final Long mobileNumber) {
762 this.mobileNumber = mobileNumber;
766 public Integer getPhoneAreaCode () {
767 return this.phoneAreaCode;
771 public void setPhoneAreaCode (final Integer phoneAreaCode) {
772 this.phoneAreaCode = phoneAreaCode;
776 public Country getPhoneCountry () {
777 return this.phoneCountry;
781 public void setPhoneCountry (final Country phoneCountry) {
782 this.phoneCountry = phoneCountry;
786 public Long getPhoneNumber () {
787 return this.phoneNumber;
791 public void setPhoneNumber (final Long phoneNumber) {
792 this.phoneNumber = phoneNumber;
796 public String getStreet () {
801 public void setStreet (final String street) {
802 this.street = street;
806 public String getTitle () {
811 public void setTitle (final String title) {
816 public Integer getZipCode () {
821 public void setZipCode (final Integer zipCode) {
822 this.zipCode = zipCode;
826 * Post-construction method
829 public void init () {
832 // Get initial context
833 Context context = new InitialContext();
836 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
837 } catch (final NamingException e) {
839 throw new FaceletException(e);
842 // Get full email address list for reducing EJB calls
843 this.emailAddressList.addAll(this.contactBean.getEmailAddressList());
846 List<Contact> allContacts = this.contactBean.getAllContacts();
848 // Get full contact list
849 this.contactList.addAll(allContacts);
852 List<User> allUsers = this.userController.allUsers();
855 Iterator<Contact> iterator = allContacts.iterator();
858 while (iterator.hasNext()) {
860 Contact next = iterator.next();
863 Iterator<User> userIterator = allUsers.iterator();
865 // Loop through all users
866 while (userIterator.hasNext()) {
868 User nextUser = userIterator.next();
871 if (Objects.equals(next, nextUser.getUserContact())) {
880 this.selectableContacts = allContacts;
884 public boolean isEmailAddressRegistered (final Contact contact) {
886 if (null == contact) {
888 throw new NullPointerException("contact is null"); //NOI18N
889 } else if (contact.getContactEmailAddress() == null) {
891 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
892 } else if (contact.getContactEmailAddress().isEmpty()) {
894 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
898 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
902 public boolean isRequiredChangePersonalDataSet () {
903 return ((this.getGender() != null) &&
904 (this.getFirstName() != null) &&
905 (this.getFamilyName() != null) &&
906 (this.getStreet() != null) &&
907 (this.getHouseNumber() != null) &&
908 (this.getZipCode() != null) &&
909 (this.getCity() != null));
913 public boolean isRequiredPersonalDataSet () {
914 return ((this.getGender() != null) &&
915 (this.getFirstName() != null) &&
916 (this.getFamilyName() != null) &&
917 (this.getStreet() != null) &&
918 (this.getHouseNumber() != null) &&
919 (this.getZipCode() != null) &&
920 (this.getCity() != null) &&
921 (this.getEmailAddress() != null) &&
922 (this.getEmailAddressRepeat() != null));
926 public boolean isSameEmailAddressEntered () {
927 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
931 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
933 Contact localContact = null;
938 // Try to lookup it in visible user list
939 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
941 Contact next = iterator.next();
943 // Is the user id found?
944 if (Objects.equals(next.getContactId(), contactId)) {
945 // Copy to other variable
952 if (null == localContact) {
953 // Not visible for the current user
954 throw new ContactNotFoundException(contactId);
957 // Copy all data to this bean
958 this.copyContact(localContact);
965 public List<Contact> selectableContacts () {
966 return Collections.unmodifiableList(this.selectableContacts);
970 public void updateContactDataFromController (final Contact contact) {
971 // Is the instance valid?
972 if (null == contact) {
974 throw new NullPointerException("contact is null"); //NOI18N
975 } else if (contact.getContactId() == null) {
977 throw new NullPointerException("contact.contactId is null"); //NOI18N
978 } else if (contact.getContactId() < 1) {
979 // Not valid id number
980 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
984 this.copyContact(contact);
988 * Adds email address to bean's internal list.
990 * @param contact Contact instance
992 private void addUserNameEmailAddress (final Contact contact) {
993 // Make sure the entry is not added yet
994 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
996 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
1000 this.emailAddressList.add(contact.getContactEmailAddress());
1006 private void clear () {
1009 this.setGender(null);
1010 this.setTitle(null);
1011 this.setFirstName(null);
1012 this.setFamilyName(null);
1013 this.setStreet(null);
1014 this.setHouseNumber(null);
1015 this.setHouseNumberExtension(null);
1016 this.setZipCode(null);
1018 this.setCountry(null);
1021 this.setEmailAddress(null);
1022 this.setEmailAddressRepeat(null);
1023 this.setPhoneAreaCode(null);
1024 this.setPhoneCountry(null);
1025 this.setPhoneNumber(null);
1026 this.setMobileCarrier(null);
1027 this.setMobileNumber(null);
1028 this.setFaxAreaCode(null);
1029 this.setFaxCountry(null);
1030 this.setFaxNumber(null);
1033 this.setBirthday(null);
1034 this.setComment(null);
1038 * Copies given contact into the controller
1040 * @param contact Contact instance
1042 private void copyContact (final Contact contact) {
1043 // Is the instance valid?
1044 if (null == contact) {
1046 throw new NullPointerException("contact is null"); //NOI18N
1047 } else if (contact.getContactId() == null) {
1049 throw new NullPointerException("contact.contactId is null"); //NOI18N
1050 } else if (contact.getContactId() < 1) {
1051 // Not valid id number
1052 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1057 this.setGender(contact.getContactGender());
1058 this.setTitle(contact.getContactTitle());
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 mobile, phone and fax instance
1072 DialableMobileNumber mobile = contact.getContactMobileNumber();
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 ((mobile instanceof DialableMobileNumber) && (mobile.getMobileProvider() instanceof MobileProvider)) {
1084 this.setMobileCarrier(mobile.getMobileProvider());
1085 this.setMobileNumber(mobile.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());
1124 * Adds unique instance to contact list. First any existing instance is
1125 * being removed, then the new instance is added.
1127 * @param contact Contact instance to add uniquely
1129 private void uniqueAddContact (final Contact contact) {
1130 // Is the instance valid?
1131 if (null == contact) {
1133 throw new NullPointerException("contact is null"); //NOI18N
1134 } else if (contact.getContactId() == null) {
1136 throw new NullPointerException("contact.contactId is null"); //NOI18N
1137 } else if (contact.getContactId() < 1) {
1138 // Not valid id number
1139 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1142 // Get iterator from list
1143 Iterator<Contact> iterator = this.contactList.iterator();
1145 // "Walk" through all entries
1146 while (iterator.hasNext()) {
1148 Contact next = iterator.next();
1150 // Is id number the same?
1151 if (Objects.equals(contact.getContactId(), next.getContactId())) {
1152 // Found entry, so remove it and abort
1153 this.removeContact(next);
1158 // Add contact to list
1159 this.contactList.add(contact);