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.List;
24 import java.util.Objects;
25 import javax.annotation.PostConstruct;
26 import javax.enterprise.context.SessionScoped;
27 import javax.enterprise.event.Observes;
28 import javax.faces.view.facelets.FaceletException;
29 import javax.inject.Inject;
30 import javax.inject.Named;
31 import javax.naming.Context;
32 import javax.naming.InitialContext;
33 import javax.naming.NamingException;
34 import org.mxchange.jcontacts.contact.Contact;
35 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
36 import org.mxchange.jcontacts.contact.UserContact;
37 import org.mxchange.jcontacts.contact.gender.Gender;
38 import org.mxchange.jcontacts.contact.utils.ContactUtils;
39 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
40 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
41 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
42 import org.mxchange.jcountry.data.Country;
43 import org.mxchange.jjobs.beans.BaseJobsController;
44 import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
45 import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
46 import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
47 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
48 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
49 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
50 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
51 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
52 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
53 import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
54 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
55 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
56 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
57 import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
58 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
59 import org.mxchange.jusercore.model.user.User;
62 * A general contact bean (controller)
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 List<Contact> contactList;
113 private Country country;
118 private String emailAddress;
123 private List<String> emailAddressList;
126 * Email address repeated
128 private String emailAddressRepeat;
133 private String familyName;
136 * Fax number's area code
138 private Integer faxAreaCode;
141 * Country instance for fax number
143 private Country faxCountry;
148 private Long faxNumber;
153 private String firstName;
158 private Gender gender;
163 private Short houseNumber;
166 * Whether a cellphone entry has been unlinked
168 private boolean isCellphoneUnlinked;
171 * Whether a fax entry has been unlinked
173 private boolean isFaxUnlinked;
176 * Whether a land-line number has been unlinked
178 private boolean isLandLineUnlinked;
181 * Phone number area code
183 private Integer phoneAreaCode;
186 * Country instance for phone number
188 private Country phoneCountry;
193 private Long phoneNumber;
196 * A list of all selectable contacts
198 private List<Contact> selectableContacts;
203 private String street;
206 * Regular user controller
209 private JobsUserWebSessionController userController;
212 * Login bean (controller)
215 private JobsUserLoginWebSessionController userLoginController;
220 private Integer zipCode;
223 * Default constructor
225 public JobsContactWebSessionBean () {
228 // Get initial context
229 Context context = new InitialContext();
232 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
233 } catch (final NamingException e) {
235 throw new FaceletException(e);
240 public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) {
241 // The event must be valid
244 throw new NullPointerException("event is null"); //NOI18N
245 } else if (event.getAddedContact() == null) {
247 throw new NullPointerException("event.addedContact is null"); //NOI18N
248 } else if (event.getAddedContact().getContactId() == null) {
250 throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
251 } else if (event.getAddedContact().getContactId() < 1) {
253 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
260 this.uniqueAddContact(event.getAddedContact());
262 // Add to selectable contacts
263 this.selectableContacts.add(event.getAddedContact());
267 public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
268 // event should not be null
271 throw new NullPointerException("event is null"); //NOI18N
272 } else if (event.getAddedUser() == null) {
274 throw new NullPointerException("event.addedUser is null"); //NOI18N
275 } else if (event.getAddedUser().getUserId() == null) {
277 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
278 } else if (event.getAddedUser().getUserId() < 1) {
280 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
288 public void afterAdminLinkedUser (@Observes final AdminLinkedUserEvent event) {
289 // event should not be null
292 throw new NullPointerException("event is null"); //NOI18N
293 } else if (event.getLinkedUser() == null) {
295 throw new NullPointerException("event.linkedUser is null"); //NOI18N
296 } else if (event.getLinkedUser().getUserContact() == null) {
298 throw new NullPointerException("event.linkedUser.userContact is null"); //NOI18N
299 } else if (event.getLinkedUser().getUserContact().getContactId() == null) {
301 throw new NullPointerException("event.linkedUser.userContact.contactId is null"); //NOI18N
302 } else if (event.getLinkedUser().getUserContact().getContactId() < 1) {
304 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N
307 // Remove contact from list available contacts list
308 this.selectableContacts.remove(event.getLinkedUser().getUserContact());
315 public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
316 // event should not be null
319 throw new NullPointerException("event is null"); //NOI18N
320 } else if (event.getUpdatedContact() == null) {
322 throw new NullPointerException("event.updatedContact is null"); //NOI18N
323 } else if (event.getUpdatedContact().getContactId() == null) {
325 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
326 } else if (event.getUpdatedContact().getContactId() < 1) {
328 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
331 // Add contact instance only once
332 this.uniqueAddContact(event.getUpdatedContact());
334 // Add email address to list
335 this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
339 public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
340 // event should not be null
343 throw new NullPointerException("event is null"); //NOI18N
344 } else if (event.getRegisteredUser() == null) {
346 throw new NullPointerException("event.registeredUser is null"); //NOI18N
347 } else if (event.getRegisteredUser().getUserId() == null) {
349 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
350 } else if (event.getRegisteredUser().getUserId() < 1) {
352 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
356 Contact registeredContact = event.getRegisteredUser().getUserContact();
358 // Copy all data from registered->user
359 this.copyContact(registeredContact);
361 // Add contact instance only once
362 this.uniqueAddContact(registeredContact);
364 // Add user name and email address
365 this.addUserNameEmailAddress(registeredContact);
372 public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) {
373 // event should not be null
376 throw new NullPointerException("event is null"); //NOI18N
377 } else if (event.getConfirmedUser() == null) {
379 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
380 } else if (event.getConfirmedUser().getUserId() == null) {
382 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
383 } else if (event.getConfirmedUser().getUserId() < 1) {
385 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
388 // Add contact instance only once
389 this.uniqueAddContact(event.getConfirmedUser().getUserContact());
393 public void afterUserLogin (@Observes final UserLoggedInEvent event) {
394 // event should not be null
397 throw new NullPointerException("event is null"); //NOI18N
398 } else if (event.getLoggedInUser() == null) {
400 throw new NullPointerException("event.loggedInUser is null"); //NOI18N
401 } else if (event.getLoggedInUser().getUserId() == null) {
403 throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
404 } else if (event.getLoggedInUser().getUserId() < 1) {
406 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
409 // Copy all data to this bean
410 this.copyContact(event.getLoggedInUser().getUserContact());
414 public List<Contact> allContacts () {
416 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size()));
418 // Return un-modified list
419 return Collections.unmodifiableList(this.contactList);
423 public Contact createContactInstance () {
425 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName()));
427 // Is all required data set?
428 if (!this.isRequiredPersonalDataSet()) {
429 // No, then abort here
430 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
433 // Generate phone number
434 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
435 DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
436 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
438 // Create new contact
439 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
440 contact.setContactStreet(this.getStreet());
441 contact.setContactHouseNumber(this.getHouseNumber());
442 contact.setContactZipCode(this.getZipCode());
443 contact.setContactCity(this.getCity());
444 contact.setContactCountry(this.getCountry());
445 contact.setContactEmailAddress(this.getEmailAddress());
446 contact.setContactBirthday(this.getBirthday());
447 contact.setContactComment(this.getComment());
450 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
452 // Don't set null or wrong references
453 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
454 // Now the number must be given
455 if (phone.getPhoneAreaCode() == null) {
457 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
458 } else if (phone.getPhoneAreaCode() < 1) {
460 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
461 } else if (phone.getPhoneNumber() == null) {
463 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
464 } else if (phone.getPhoneNumber() < 1) {
466 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
470 contact.setContactLandLineNumber(phone);
473 // Don't set null or wrong references
474 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
475 // Now the number must be given
476 if (fax.getPhoneAreaCode() == null) {
478 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
479 } else if (fax.getPhoneAreaCode() < 1) {
481 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
482 } else if (fax.getPhoneNumber() == null) {
484 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
485 } else if (fax.getPhoneNumber() < 1) {
487 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
491 contact.setContactFaxNumber(fax);
494 // Is the provider set?
495 if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
496 // Is the number set?
497 if (cellphone.getPhoneNumber() == null) {
499 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
500 } else if (cellphone.getPhoneNumber() < 1) {
502 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
505 // Set cellphone number
506 contact.setContactCellphoneNumber(cellphone);
510 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
517 public String doChangePersonalContactData () {
518 // This method shall only be called if the user is logged-in
519 if (!this.userLoginController.isUserLoggedIn()) {
521 throw new IllegalStateException("User is not logged-in"); //NOI18N
522 } else if (!this.isRequiredChangePersonalDataSet()) {
523 // Not all required fields are set
524 throw new FaceletException("Not all required fields are set."); //NOI18N
525 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
526 // Password not matching
527 this.showFacesMessage("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
531 // Get contact instance
532 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
534 // It should be there, so run some tests on it
535 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
536 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
537 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
540 contact.setContactGender(this.getGender());
541 contact.setContactFirstName(this.getFirstName());
542 contact.setContactFamilyName(this.getFamilyName());
543 contact.setContactStreet(this.getStreet());
544 contact.setContactHouseNumber(this.getHouseNumber());
545 contact.setContactZipCode(this.getZipCode());
546 contact.setContactCity(this.getCity());
547 contact.setContactCountry(this.getCountry());
549 // Update contact's cellphone number
550 this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
552 // Update contact's land-line number
553 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
555 // Update contact's fax number
556 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
558 // Send it to the EJB
559 this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
562 return "contact_data_saved"; //NOI18N
566 @SuppressWarnings ("ReturnOfDateField")
567 public Date getBirthday () {
568 return this.birthday;
572 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
573 public void setBirthday (final Date birthday) {
574 this.birthday = birthday;
578 public MobileProvider getCellphoneCarrier () {
579 return this.cellphoneCarrier;
583 public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
584 this.cellphoneCarrier = cellphoneCarrier;
588 public Long getCellphoneNumber () {
589 return this.cellphoneNumber;
593 public void setCellphoneNumber (Long cellphoneNumber) {
594 this.cellphoneNumber = cellphoneNumber;
598 public String getCity () {
603 public void setCity (final String city) {
608 public String getComment () {
613 public void setComment (final String comment) {
614 this.comment = comment;
618 public Country getCountry () {
623 public void setCountry (final Country country) {
624 this.country = country;
628 public String getEmailAddress () {
629 return this.emailAddress;
633 public void setEmailAddress (final String emailAddress) {
634 this.emailAddress = emailAddress;
638 public String getEmailAddressRepeat () {
639 return this.emailAddressRepeat;
643 public void setEmailAddressRepeat (final String emailAddressRepeat) {
644 this.emailAddressRepeat = emailAddressRepeat;
648 public String getFamilyName () {
649 return this.familyName;
653 public void setFamilyName (final String familyName) {
654 this.familyName = familyName;
658 public Integer getFaxAreaCode () {
659 return this.faxAreaCode;
663 public void setFaxAreaCode (final Integer faxAreaCode) {
664 this.faxAreaCode = faxAreaCode;
668 public Country getFaxCountry () {
669 return this.faxCountry;
673 public void setFaxCountry (final Country faxCountry) {
674 this.faxCountry = faxCountry;
678 public Long getFaxNumber () {
679 return this.faxNumber;
683 public void setFaxNumber (final Long faxNumber) {
684 this.faxNumber = faxNumber;
688 public String getFirstName () {
689 return this.firstName;
693 public void setFirstName (final String firstName) {
694 this.firstName = firstName;
698 public Gender getGender () {
703 public void setGender (final Gender gender) {
704 this.gender = gender;
708 public Short getHouseNumber () {
709 return this.houseNumber;
713 public void setHouseNumber (final Short houseNumber) {
714 this.houseNumber = houseNumber;
718 public Integer getPhoneAreaCode () {
719 return this.phoneAreaCode;
723 public void setPhoneAreaCode (final Integer phoneAreaCode) {
724 this.phoneAreaCode = phoneAreaCode;
728 public Country getPhoneCountry () {
729 return this.phoneCountry;
733 public void setPhoneCountry (final Country phoneCountry) {
734 this.phoneCountry = phoneCountry;
738 public Long getPhoneNumber () {
739 return this.phoneNumber;
743 public void setPhoneNumber (final Long phoneNumber) {
744 this.phoneNumber = phoneNumber;
748 public String getStreet () {
753 public void setStreet (final String street) {
754 this.street = street;
758 public Integer getZipCode () {
763 public void setZipCode (final Integer zipCode) {
764 this.zipCode = zipCode;
768 public boolean hasContacts () {
769 return (!this.contactList.isEmpty());
773 * Post-initialization of this class
776 public void init () {
777 // Get full email address list for reducing EJB calls
778 this.emailAddressList = this.contactBean.getEmailAddressList();
780 // Get full contact list
781 this.contactList = this.contactBean.getAllContacts();
784 List<User> allUsers = this.userController.allUsers();
787 List<Contact> allContacts = this.contactBean.getAllContacts();
790 Iterator<Contact> iterator = allContacts.iterator();
793 while (iterator.hasNext()) {
795 Contact next = iterator.next();
798 Iterator<User> userIterator = allUsers.iterator();
800 // Loop through all users
801 while (userIterator.hasNext()) {
803 User nextUser = userIterator.next();
806 if (Objects.equals(next, nextUser.getUserContact())) {
815 this.selectableContacts = allContacts;
819 public boolean isEmailAddressRegistered (final Contact contact) {
821 if (null == contact) {
823 throw new NullPointerException("contact is null"); //NOI18N
824 } else if (contact.getContactEmailAddress() == null) {
826 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
827 } else if (contact.getContactEmailAddress().isEmpty()) {
829 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
833 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
837 public boolean isRequiredChangePersonalDataSet () {
838 return ((this.getGender() != null) &&
839 (this.getFirstName() != null) &&
840 (this.getFamilyName() != null) &&
841 (this.getStreet() != null) &&
842 (this.getHouseNumber() != null) &&
843 (this.getZipCode() != null) &&
844 (this.getCity() != null));
848 public boolean isRequiredPersonalDataSet () {
849 return ((this.getGender() != null) &&
850 (this.getFirstName() != null) &&
851 (this.getFamilyName() != null) &&
852 (this.getStreet() != null) &&
853 (this.getHouseNumber() != null) &&
854 (this.getZipCode() != null) &&
855 (this.getCity() != null) &&
856 (this.getEmailAddress() != null) &&
857 (this.getEmailAddressRepeat() != null));
861 public boolean isSameEmailAddressEntered () {
862 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
866 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
868 Contact localContact = null;
873 // Try to lookup it in visible user list
874 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
876 Contact next = iterator.next();
878 // Is the user id found?
879 if (Objects.equals(next.getContactId(), contactId)) {
880 // Copy to other variable
887 if (null == localContact) {
888 // Not visible for the current user
889 throw new ContactNotFoundException(contactId);
892 // Copy all data to this bean
893 this.copyContact(localContact);
900 public List<Contact> selectableContacts () {
901 return Collections.unmodifiableList(this.selectableContacts);
905 public void updateContactDataFromController (final Contact contact) {
906 // Is the instance valid?
907 if (null == contact) {
909 throw new NullPointerException("contact is null"); //NOI18N
910 } else if (contact.getContactId() == null) {
912 throw new NullPointerException("contact.contactId is null"); //NOI18N
913 } else if (contact.getContactId() < 1) {
914 // Not valid id number
915 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
919 this.copyContact(contact);
923 * Adds email address to bean's internal list.
925 * @param contact Contact instance
927 private void addUserNameEmailAddress (final Contact contact) {
928 // Make sure the entry is not added yet
929 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
931 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
935 this.emailAddressList.add(contact.getContactEmailAddress());
941 private void clear () {
944 this.setGender(null);
945 // TODO: Unfinished this.setTitle(null);
946 this.setFirstName(null);
947 this.setFamilyName(null);
948 this.setStreet(null);
949 this.setHouseNumber(null);
950 this.setZipCode(null);
952 this.setCountry(null);
955 this.setEmailAddress(null);
956 this.setEmailAddressRepeat(null);
957 this.setPhoneAreaCode(null);
958 this.setPhoneCountry(null);
959 this.setPhoneNumber(null);
960 this.setCellphoneCarrier(null);
961 this.setCellphoneNumber(null);
962 this.setFaxAreaCode(null);
963 this.setFaxCountry(null);
964 this.setFaxNumber(null);
967 this.setBirthday(null);
968 this.setComment(null);
972 * Copies given contact into the controller
974 * @param contact Contact instance
976 private void copyContact (final Contact contact) {
977 // Is the instance valid?
978 if (null == contact) {
980 throw new NullPointerException("contact is null"); //NOI18N
981 } else if (contact.getContactId() == null) {
983 throw new NullPointerException("contact.contactId is null"); //NOI18N
984 } else if (contact.getContactId() < 1) {
985 // Not valid id number
986 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
991 this.setGender(contact.getContactGender());
992 this.setFirstName(contact.getContactFirstName());
993 this.setFamilyName(contact.getContactFamilyName());
994 this.setStreet(contact.getContactStreet());
995 this.setHouseNumber(contact.getContactHouseNumber());
996 this.setZipCode(contact.getContactZipCode());
997 this.setCity(contact.getContactCity());
998 this.setCountry(contact.getContactCountry());
999 this.setEmailAddress(contact.getContactEmailAddress());
1000 this.setBirthday(contact.getContactBirthday());
1001 this.setComment(contact.getContactComment());
1003 // Get cellphone, phone and fax instance
1004 DialableCellphoneNumber cellphone = contact.getContactCellphoneNumber();
1005 DialableFaxNumber fax = contact.getContactFaxNumber();
1006 DialableLandLineNumber phone = contact.getContactLandLineNumber();
1009 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
1010 this.setPhoneCountry(phone.getPhoneCountry());
1011 this.setPhoneAreaCode(phone.getPhoneAreaCode());
1012 this.setPhoneNumber(phone.getPhoneNumber());
1015 if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) {
1016 this.setCellphoneCarrier(cellphone.getCellphoneProvider());
1017 this.setCellphoneNumber(cellphone.getPhoneNumber());
1020 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
1021 this.setFaxCountry(fax.getPhoneCountry());
1022 this.setFaxAreaCode(fax.getPhoneAreaCode());
1023 this.setFaxNumber(fax.getPhoneNumber());
1028 * Removes given contact from all lists
1030 * @param contact Contact instance to remove
1032 private void removeContact (final Contact contact) {
1033 // Is the instance valid?
1034 if (null == contact) {
1036 throw new NullPointerException("contact is null"); //NOI18N
1037 } else if (contact.getContactId() == null) {
1039 throw new NullPointerException("contact.contactId is null"); //NOI18N
1040 } else if (contact.getContactId() < 1) {
1041 // Not valid id number
1042 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1045 // Remove from general list
1046 if (!this.contactList.remove(contact)) {
1047 // Did not remove contact
1048 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
1051 // Remove from other lists
1052 this.emailAddressList.remove(contact.getContactEmailAddress());
1056 * Adds unique instance to contact list. First any existing instance is
1057 * being removed, then the new instance is added.
1059 * @param contact Contact instance to add uniquely
1061 private void uniqueAddContact (final Contact contact) {
1062 // Is the instance valid?
1063 if (null == contact) {
1065 throw new NullPointerException("contact is null"); //NOI18N
1066 } else if (contact.getContactId() == null) {
1068 throw new NullPointerException("contact.contactId is null"); //NOI18N
1069 } else if (contact.getContactId() < 1) {
1070 // Not valid id number
1071 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1074 // Get iterator from list
1075 Iterator<Contact> iterator = this.contactList.iterator();
1077 // "Walk" through all entries
1078 while (iterator.hasNext()) {
1080 Contact next = iterator.next();
1082 // Is id number the same?
1083 if (Objects.equals(contact.getContactId(), next.getContactId())) {
1084 // Found entry, so remove it and abort
1085 this.removeContact(next);
1090 // Add contact to list
1091 this.contactList.add(contact);