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.jjobs.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.AdminAddedContactEvent;
41 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
42 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
43 import org.mxchange.jcountry.data.Country;
44 import org.mxchange.jjobs.beans.BaseJobsController;
45 import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
46 import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
47 import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
48 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
49 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
50 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
51 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
52 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
53 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
54 import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
55 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
56 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
57 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
58 import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
59 import org.mxchange.jusercore.model.user.User;
62 * A general contact controller (bean)
64 * @author Roland Haeder<roland@mxchange.org>
66 @Named ("contactController")
68 public class JobsContactWebSessionBean extends BaseJobsController implements JobsContactWebSessionController {
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 final List<Contact> contactList;
113 private Country country;
118 private String emailAddress;
123 private final 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;
213 private String title;
216 * Regular user controller
219 private JobsUserWebSessionController userController;
222 * Login controller (bean)
225 private JobsUserLoginWebSessionController userLoginController;
230 private Integer zipCode;
233 * Default constructor
235 public JobsContactWebSessionBean () {
238 // Get initial context
239 Context context = new InitialContext();
242 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
243 } catch (final NamingException e) {
245 throw new FaceletException(e);
249 this.contactList = new LinkedList<>();
250 this.emailAddressList = new LinkedList<>();
254 public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) {
255 // The event must be valid
258 throw new NullPointerException("event is null"); //NOI18N
259 } else if (event.getAddedContact() == null) {
261 throw new NullPointerException("event.addedContact is null"); //NOI18N
262 } else if (event.getAddedContact().getContactId() == null) {
264 throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
265 } else if (event.getAddedContact().getContactId() < 1) {
267 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
274 this.uniqueAddContact(event.getAddedContact());
276 // Add to selectable contacts
277 this.selectableContacts.add(event.getAddedContact());
281 public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
282 // event should not be null
285 throw new NullPointerException("event is null"); //NOI18N
286 } else if (event.getAddedUser() == null) {
288 throw new NullPointerException("event.addedUser is null"); //NOI18N
289 } else if (event.getAddedUser().getUserId() == null) {
291 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
292 } else if (event.getAddedUser().getUserId() < 1) {
294 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
302 public void afterAdminLinkedUser (@Observes final AdminLinkedUserEvent event) {
303 // event should not be null
306 throw new NullPointerException("event is null"); //NOI18N
307 } else if (event.getLinkedUser() == null) {
309 throw new NullPointerException("event.linkedUser is null"); //NOI18N
310 } else if (event.getLinkedUser().getUserContact() == null) {
312 throw new NullPointerException("event.linkedUser.userContact is null"); //NOI18N
313 } else if (event.getLinkedUser().getUserContact().getContactId() == null) {
315 throw new NullPointerException("event.linkedUser.userContact.contactId is null"); //NOI18N
316 } else if (event.getLinkedUser().getUserContact().getContactId() < 1) {
318 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N
321 // Remove contact from list available contacts list
322 this.selectableContacts.remove(event.getLinkedUser().getUserContact());
329 public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
330 // event should not be null
333 throw new NullPointerException("event is null"); //NOI18N
334 } else if (event.getUpdatedContact() == null) {
336 throw new NullPointerException("event.updatedContact is null"); //NOI18N
337 } else if (event.getUpdatedContact().getContactId() == null) {
339 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
340 } else if (event.getUpdatedContact().getContactId() < 1) {
342 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
345 // Add contact instance only once
346 this.uniqueAddContact(event.getUpdatedContact());
348 // Add email address to list
349 this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
353 public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
354 // event should not be null
357 throw new NullPointerException("event is null"); //NOI18N
358 } else if (event.getRegisteredUser() == null) {
360 throw new NullPointerException("event.registeredUser is null"); //NOI18N
361 } else if (event.getRegisteredUser().getUserId() == null) {
363 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
364 } else if (event.getRegisteredUser().getUserId() < 1) {
366 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
370 Contact registeredContact = event.getRegisteredUser().getUserContact();
372 // Copy all data from registered->user
373 this.copyContact(registeredContact);
375 // Add contact instance only once
376 this.uniqueAddContact(registeredContact);
378 // Add user name and email address
379 this.addUserNameEmailAddress(registeredContact);
386 public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) {
387 // event should not be null
390 throw new NullPointerException("event is null"); //NOI18N
391 } else if (event.getConfirmedUser() == null) {
393 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
394 } else if (event.getConfirmedUser().getUserId() == null) {
396 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
397 } else if (event.getConfirmedUser().getUserId() < 1) {
399 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
402 // Add contact instance only once
403 this.uniqueAddContact(event.getConfirmedUser().getUserContact());
407 public void afterUserLogin (@Observes final UserLoggedInEvent event) {
408 // event should not be null
411 throw new NullPointerException("event is null"); //NOI18N
412 } else if (event.getLoggedInUser() == null) {
414 throw new NullPointerException("event.loggedInUser is null"); //NOI18N
415 } else if (event.getLoggedInUser().getUserId() == null) {
417 throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
418 } else if (event.getLoggedInUser().getUserId() < 1) {
420 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
423 // Copy all data to this bean
424 this.copyContact(event.getLoggedInUser().getUserContact());
428 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
429 public List<Contact> allContacts () {
431 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size()));
433 // Return un-modified list
434 return this.contactList;
438 public Contact createContactInstance () {
440 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName()));
442 // Is all required data set?
443 if (!this.isRequiredPersonalDataSet()) {
444 // No, then abort here
445 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
448 // Generate phone number
449 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
450 DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
451 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
453 // Create new contact
454 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
455 contact.setContactStreet(this.getStreet());
456 contact.setContactHouseNumber(this.getHouseNumber());
457 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
458 contact.setContactZipCode(this.getZipCode());
459 contact.setContactCity(this.getCity());
460 contact.setContactCountry(this.getCountry());
461 contact.setContactEmailAddress(this.getEmailAddress());
462 contact.setContactBirthday(this.getBirthday());
463 contact.setContactComment(this.getComment());
466 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
467 // Don't set null or wrong references
468 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
469 // Now the number must be given
470 if (phone.getPhoneAreaCode() == null) {
472 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
473 } else if (phone.getPhoneAreaCode() < 1) {
475 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
476 } else if (phone.getPhoneNumber() == null) {
478 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
479 } else if (phone.getPhoneNumber() < 1) {
481 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
485 contact.setContactLandLineNumber(phone);
488 // Don't set null or wrong references
489 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
490 // Now the number must be given
491 if (fax.getPhoneAreaCode() == null) {
493 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
494 } else if (fax.getPhoneAreaCode() < 1) {
496 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
497 } else if (fax.getPhoneNumber() == null) {
499 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
500 } else if (fax.getPhoneNumber() < 1) {
502 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
506 contact.setContactFaxNumber(fax);
509 // Is the provider set?
510 if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
511 // Is the number set?
512 if (cellphone.getPhoneNumber() == null) {
514 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
515 } else if (cellphone.getPhoneNumber() < 1) {
517 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
520 // Set cellphone number
521 contact.setContactCellphoneNumber(cellphone);
525 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
531 public String doChangePersonalContactData () {
532 // This method shall only be called if the user is logged-in
533 if (!this.userLoginController.isUserLoggedIn()) {
535 throw new IllegalStateException("User is not logged-in"); //NOI18N
536 } else if (!this.isRequiredChangePersonalDataSet()) {
537 // Not all required fields are set
538 throw new FaceletException("Not all required fields are set."); //NOI18N
539 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
540 // Password not matching
541 this.showFacesMessage("form_login_change_personal:currentPassword", "ERROR_USER_CURRENT_PASSWORD_MISMATCHING"); //NOI18N
545 // Get contact instance
546 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
548 // It should be there, so run some tests on it
549 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
550 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
551 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
554 contact.setContactGender(this.getGender());
555 contact.setContactFirstName(this.getFirstName());
556 contact.setContactFamilyName(this.getFamilyName());
557 contact.setContactStreet(this.getStreet());
558 contact.setContactHouseNumber(this.getHouseNumber());
559 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
560 contact.setContactZipCode(this.getZipCode());
561 contact.setContactCity(this.getCity());
562 contact.setContactCountry(this.getCountry());
564 // Update contact's cellphone number
565 this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
567 // Update contact's land-line number
568 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
570 // Update contact's fax number
571 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
573 // Send it to the EJB
574 this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
577 return "contact_data_saved"; //NOI18N
581 @SuppressWarnings ("ReturnOfDateField")
582 public Date getBirthday () {
583 return this.birthday;
587 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
588 public void setBirthday (final Date birthday) {
589 this.birthday = birthday;
593 public MobileProvider getCellphoneCarrier () {
594 return this.cellphoneCarrier;
598 public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
599 this.cellphoneCarrier = cellphoneCarrier;
603 public Long getCellphoneNumber () {
604 return this.cellphoneNumber;
608 public void setCellphoneNumber (Long cellphoneNumber) {
609 this.cellphoneNumber = cellphoneNumber;
613 public String getCity () {
618 public void setCity (final String city) {
623 public String getComment () {
628 public void setComment (final String comment) {
629 this.comment = comment;
633 public String getControllerType () {
634 return "general"; //NOI18N
639 public void setControllerType (final String controllerType) {
640 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
644 public Country getCountry () {
649 public void setCountry (final Country country) {
650 this.country = country;
654 public String getEmailAddress () {
655 return this.emailAddress;
659 public void setEmailAddress (final String emailAddress) {
660 this.emailAddress = emailAddress;
664 public String getEmailAddressRepeat () {
665 return this.emailAddressRepeat;
669 public void setEmailAddressRepeat (final String emailAddressRepeat) {
670 this.emailAddressRepeat = emailAddressRepeat;
674 public String getFamilyName () {
675 return this.familyName;
679 public void setFamilyName (final String familyName) {
680 this.familyName = familyName;
684 public Integer getFaxAreaCode () {
685 return this.faxAreaCode;
689 public void setFaxAreaCode (final Integer faxAreaCode) {
690 this.faxAreaCode = faxAreaCode;
694 public Country getFaxCountry () {
695 return this.faxCountry;
699 public void setFaxCountry (final Country faxCountry) {
700 this.faxCountry = faxCountry;
704 public Long getFaxNumber () {
705 return this.faxNumber;
709 public void setFaxNumber (final Long faxNumber) {
710 this.faxNumber = faxNumber;
714 public String getFirstName () {
715 return this.firstName;
719 public void setFirstName (final String firstName) {
720 this.firstName = firstName;
724 public Gender getGender () {
729 public void setGender (final Gender gender) {
730 this.gender = gender;
734 public Short getHouseNumber () {
735 return this.houseNumber;
739 public void setHouseNumber (final Short houseNumber) {
740 this.houseNumber = houseNumber;
744 public String getHouseNumberExtension () {
745 return this.houseNumberExtension;
749 public void setHouseNumberExtension (final String houseNumberExtension) {
750 this.houseNumberExtension = houseNumberExtension;
754 public Integer getPhoneAreaCode () {
755 return this.phoneAreaCode;
759 public void setPhoneAreaCode (final Integer phoneAreaCode) {
760 this.phoneAreaCode = phoneAreaCode;
764 public Country getPhoneCountry () {
765 return this.phoneCountry;
769 public void setPhoneCountry (final Country phoneCountry) {
770 this.phoneCountry = phoneCountry;
774 public Long getPhoneNumber () {
775 return this.phoneNumber;
779 public void setPhoneNumber (final Long phoneNumber) {
780 this.phoneNumber = phoneNumber;
784 public String getStreet () {
789 public void setStreet (final String street) {
790 this.street = street;
794 public String getTitle () {
799 public void setTitle (final String title) {
804 public Integer getZipCode () {
809 public void setZipCode (final Integer zipCode) {
810 this.zipCode = zipCode;
814 * Post-initialization of this class
817 public void init () {
818 // Get full email address list for reducing EJB calls
819 this.emailAddressList.addAll(this.contactBean.getEmailAddressList());
821 // Get full contact list
822 this.contactList.addAll(this.contactBean.getAllContacts());
825 List<User> allUsers = this.userController.allUsers();
828 List<Contact> allContacts = this.contactBean.getAllContacts();
831 Iterator<Contact> iterator = allContacts.iterator();
834 while (iterator.hasNext()) {
836 Contact next = iterator.next();
839 Iterator<User> userIterator = allUsers.iterator();
841 // Loop through all users
842 while (userIterator.hasNext()) {
844 User nextUser = userIterator.next();
847 if (Objects.equals(next, nextUser.getUserContact())) {
856 this.selectableContacts = allContacts;
860 public boolean isEmailAddressRegistered (final Contact contact) {
862 if (null == contact) {
864 throw new NullPointerException("contact is null"); //NOI18N
865 } else if (contact.getContactEmailAddress() == null) {
867 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
868 } else if (contact.getContactEmailAddress().isEmpty()) {
870 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
874 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
878 public boolean isRequiredChangePersonalDataSet () {
879 return ((this.getGender() != null) &&
880 (this.getFirstName() != null) &&
881 (this.getFamilyName() != null) &&
882 (this.getStreet() != null) &&
883 (this.getHouseNumber() != null) &&
884 (this.getZipCode() != null) &&
885 (this.getCity() != null));
889 public boolean isRequiredPersonalDataSet () {
890 return ((this.getGender() != null) &&
891 (this.getFirstName() != null) &&
892 (this.getFamilyName() != null) &&
893 (this.getStreet() != null) &&
894 (this.getHouseNumber() != null) &&
895 (this.getZipCode() != null) &&
896 (this.getCity() != null) &&
897 (this.getEmailAddress() != null) &&
898 (this.getEmailAddressRepeat() != null));
902 public boolean isSameEmailAddressEntered () {
903 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
907 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
909 Contact localContact = null;
914 // Try to lookup it in visible user list
915 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
917 Contact next = iterator.next();
919 // Is the user id found?
920 if (Objects.equals(next.getContactId(), contactId)) {
921 // Copy to other variable
928 if (null == localContact) {
929 // Not visible for the current user
930 throw new ContactNotFoundException(contactId);
933 // Copy all data to this bean
934 this.copyContact(localContact);
941 public List<Contact> selectableContacts () {
942 return Collections.unmodifiableList(this.selectableContacts);
946 public void updateContactDataFromController (final Contact contact) {
947 // Is the instance valid?
948 if (null == contact) {
950 throw new NullPointerException("contact is null"); //NOI18N
951 } else if (contact.getContactId() == null) {
953 throw new NullPointerException("contact.contactId is null"); //NOI18N
954 } else if (contact.getContactId() < 1) {
955 // Not valid id number
956 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
960 this.copyContact(contact);
964 * Adds email address to bean's internal list.
966 * @param contact Contact instance
968 private void addUserNameEmailAddress (final Contact contact) {
969 // Make sure the entry is not added yet
970 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
972 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
976 this.emailAddressList.add(contact.getContactEmailAddress());
982 private void clear () {
985 this.setGender(null);
987 this.setFirstName(null);
988 this.setFamilyName(null);
989 this.setStreet(null);
990 this.setHouseNumber(null);
991 this.setHouseNumberExtension(null);
992 this.setZipCode(null);
994 this.setCountry(null);
997 this.setEmailAddress(null);
998 this.setEmailAddressRepeat(null);
999 this.setPhoneAreaCode(null);
1000 this.setPhoneCountry(null);
1001 this.setPhoneNumber(null);
1002 this.setCellphoneCarrier(null);
1003 this.setCellphoneNumber(null);
1004 this.setFaxAreaCode(null);
1005 this.setFaxCountry(null);
1006 this.setFaxNumber(null);
1009 this.setBirthday(null);
1010 this.setComment(null);
1014 * Copies given contact into the controller
1016 * @param contact Contact instance
1018 private void copyContact (final Contact contact) {
1019 // Is the instance valid?
1020 if (null == contact) {
1022 throw new NullPointerException("contact is null"); //NOI18N
1023 } else if (contact.getContactId() == null) {
1025 throw new NullPointerException("contact.contactId is null"); //NOI18N
1026 } else if (contact.getContactId() < 1) {
1027 // Not valid id number
1028 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1033 this.setGender(contact.getContactGender());
1034 this.setTitle(contact.getContactTitle());
1035 this.setFirstName(contact.getContactFirstName());
1036 this.setFamilyName(contact.getContactFamilyName());
1037 this.setStreet(contact.getContactStreet());
1038 this.setHouseNumber(contact.getContactHouseNumber());
1039 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
1040 this.setZipCode(contact.getContactZipCode());
1041 this.setCity(contact.getContactCity());
1042 this.setCountry(contact.getContactCountry());
1043 this.setEmailAddress(contact.getContactEmailAddress());
1044 this.setBirthday(contact.getContactBirthday());
1045 this.setComment(contact.getContactComment());
1047 // Get cellphone, phone and fax instance
1048 DialableCellphoneNumber cellphone = contact.getContactCellphoneNumber();
1049 DialableFaxNumber fax = contact.getContactFaxNumber();
1050 DialableLandLineNumber phone = contact.getContactLandLineNumber();
1053 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
1054 this.setPhoneCountry(phone.getPhoneCountry());
1055 this.setPhoneAreaCode(phone.getPhoneAreaCode());
1056 this.setPhoneNumber(phone.getPhoneNumber());
1059 if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) {
1060 this.setCellphoneCarrier(cellphone.getCellphoneProvider());
1061 this.setCellphoneNumber(cellphone.getPhoneNumber());
1064 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
1065 this.setFaxCountry(fax.getPhoneCountry());
1066 this.setFaxAreaCode(fax.getPhoneAreaCode());
1067 this.setFaxNumber(fax.getPhoneNumber());
1072 * Removes given contact from all lists
1074 * @param contact Contact instance to remove
1076 private void removeContact (final Contact contact) {
1077 // Is the instance valid?
1078 if (null == contact) {
1080 throw new NullPointerException("contact is null"); //NOI18N
1081 } else if (contact.getContactId() == null) {
1083 throw new NullPointerException("contact.contactId is null"); //NOI18N
1084 } else if (contact.getContactId() < 1) {
1085 // Not valid id number
1086 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1089 // Remove from general list
1090 if (!this.contactList.remove(contact)) {
1091 // Did not remove contact
1092 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
1095 // Remove from other lists
1096 this.emailAddressList.remove(contact.getContactEmailAddress());
1100 * Adds unique instance to contact list. First any existing instance is
1101 * being removed, then the new instance is added.
1103 * @param contact Contact instance to add uniquely
1105 private void uniqueAddContact (final Contact contact) {
1106 // Is the instance valid?
1107 if (null == contact) {
1109 throw new NullPointerException("contact is null"); //NOI18N
1110 } else if (contact.getContactId() == null) {
1112 throw new NullPointerException("contact.contactId is null"); //NOI18N
1113 } else if (contact.getContactId() < 1) {
1114 // Not valid id number
1115 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1118 // Get iterator from list
1119 Iterator<Contact> iterator = this.contactList.iterator();
1121 // "Walk" through all entries
1122 while (iterator.hasNext()) {
1124 Contact next = iterator.next();
1126 // Is id number the same?
1127 if (Objects.equals(contact.getContactId(), next.getContactId())) {
1128 // Found entry, so remove it and abort
1129 this.removeContact(next);
1134 // Add contact to list
1135 this.contactList.add(contact);