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.jphone.phonenumbers.cellphone.CellphoneNumber;
46 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
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.mobileprovider.MobileProvider;
52 import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
53 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
54 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
55 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
56 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
59 * A general contact bean (controller)
61 * @author Roland Haeder<roland@mxchange.org>
63 @Named ("contactController")
65 public class JobsContactWebSessionBean extends BaseJobsController implements JobsContactWebSessionController {
70 private static final long serialVersionUID = 542_145_347_916L;
75 private Date birthday;
78 * Cellphone number's carrier
80 private MobileProvider cellphoneCarrier;
85 private Long cellphoneNumber;
95 private String comment;
100 private final ContactSessionBeanRemote contactBean;
105 private List<Contact> contactList;
110 private Country country;
115 private String emailAddress;
120 private List<String> emailAddressList;
123 * Email address repeated
125 private String emailAddressRepeat;
130 private String familyName;
133 * Fax number's area code
135 private Integer faxAreaCode;
138 * Country instance for fax number
140 private Country faxCountry;
145 private Long faxNumber;
150 private String firstName;
155 private Gender gender;
160 private Short houseNumber;
163 * Whether a cellphone entry has been unlinked
165 private boolean isCellphoneUnlinked;
168 * Whether a fax entry has been unlinked
170 private boolean isFaxUnlinked;
173 * Whether a land-line number has been unlinked
175 private boolean isLandLineUnlinked;
178 * Phone number area code
180 private Integer phoneAreaCode;
183 * Country instance for phone number
185 private Country phoneCountry;
190 private Long phoneNumber;
195 private String street;
198 * Login bean (controller)
201 private JobsUserLoginWebSessionController userLoginController;
206 private Integer zipCode;
209 * Default constructor
211 public JobsContactWebSessionBean () {
214 // Get initial context
215 Context context = new InitialContext();
218 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
219 } catch (final NamingException e) {
221 throw new FaceletException(e);
226 public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) {
227 // The event must be valid
230 throw new NullPointerException("event is null"); //NOI18N
231 } else if (event.getAddedContact() == null) {
233 throw new NullPointerException("event.addedContact is null"); //NOI18N
234 } else if (event.getAddedContact().getContactId() == null) {
236 throw new NullPointerException("event.addedContact.customerId is null"); //NOI18N
237 } else if (event.getAddedContact().getContactId() < 1) {
239 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.customerId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
246 this.uniqueAddContact(event.getAddedContact());
248 // Add to selectable contacts
249 this.selectableContacts.add(event.getAddedContact());
253 public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
255 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminAddedUserEvent: event={0} - CALLED!", event)); //NOI18N
257 // event should not be null
260 throw new NullPointerException("event is null"); //NOI18N
261 } else if (event.getAddedUser() == null) {
263 throw new NullPointerException("event.addedUser is null"); //NOI18N
264 } else if (event.getAddedUser().getUserId() == null) {
266 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
267 } else if (event.getAddedUser().getUserId() < 1) {
269 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
276 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminAddedUserEvent: EXIT!"); //NOI18N
280 public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
282 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
284 // event should not be null
287 throw new NullPointerException("event is null"); //NOI18N
288 } else if (event.getUpdatedContact() == null) {
290 throw new NullPointerException("event.updatedContact is null"); //NOI18N
291 } else if (event.getUpdatedContact().getContactId() == null) {
293 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
294 } else if (event.getUpdatedContact().getContactId() < 1) {
296 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
299 // Add contact instance only once
300 this.uniqueAddContact(event.getUpdatedContact());
302 // Add email address to list
303 this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
307 public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
309 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
311 // event should not be null
314 throw new NullPointerException("event is null"); //NOI18N
315 } else if (event.getRegisteredUser() == null) {
317 throw new NullPointerException("event.registeredUser is null"); //NOI18N
318 } else if (event.getRegisteredUser().getUserId() == null) {
320 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
321 } else if (event.getRegisteredUser().getUserId() < 1) {
323 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
327 Contact registeredContact = event.getRegisteredUser().getUserContact();
330 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: registeredContact={0}", registeredContact)); //NOI18N
332 // Copy all data from registered->user
333 this.copyContact(registeredContact);
335 // Add contact instance only once
336 this.uniqueAddContact(registeredContact);
338 // Add user name and email address
339 this.addUserNameEmailAddress(registeredContact);
345 //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterRegistration: EXIT!"); //NOI18N
349 public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) {
351 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
353 // event should not be null
356 throw new NullPointerException("event is null"); //NOI18N
357 } else if (event.getConfirmedUser() == null) {
359 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
360 } else if (event.getConfirmedUser().getUserId() == null) {
362 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
363 } else if (event.getConfirmedUser().getUserId() < 1) {
365 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
368 // Add contact instance only once
369 this.uniqueAddContact(event.getConfirmedUser().getUserContact());
373 public void afterUserLogin (@Observes final UserLoggedInEvent event) {
375 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
377 // event should not be null
380 throw new NullPointerException("event is null"); //NOI18N
381 } else if (event.getLoggedInUser() == null) {
383 throw new NullPointerException("event.loggedInUser is null"); //NOI18N
384 } else if (event.getLoggedInUser().getUserId() == null) {
386 throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
387 } else if (event.getLoggedInUser().getUserId() < 1) {
389 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
392 // Copy all data to this bean
393 this.copyContact(event.getLoggedInUser().getUserContact());
396 //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N
400 public List<Contact> allContacts () {
402 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size()));
404 // Return un-modified list
405 return Collections.unmodifiableList(this.contactList);
409 public Contact createContactInstance () {
411 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName()));
413 // Is all required data set?
414 if (!this.isRequiredPersonalDataSet()) {
415 // No, then abort here
416 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
419 // Generate phone number
420 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
421 DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
422 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
424 // Create new contact
425 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
426 contact.setContactStreet(this.getStreet());
427 contact.setContactHouseNumber(this.getHouseNumber());
428 contact.setContactZipCode(this.getZipCode());
429 contact.setContactCity(this.getCity());
430 contact.setContactCountry(this.getCountry());
431 contact.setContactEmailAddress(this.getEmailAddress());
432 contact.setContactBirthday(this.getBirthday());
433 contact.setContactComment(this.getComment());
436 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
438 // Don't set null or wrong references
439 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
440 // Now the number must be given
441 if (phone.getPhoneAreaCode() == null) {
443 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
444 } else if (phone.getPhoneAreaCode() < 1) {
446 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
447 } else if (phone.getPhoneNumber() == null) {
449 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
450 } else if (phone.getPhoneNumber() < 1) {
452 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
456 contact.setContactLandLineNumber(phone);
459 // Don't set null or wrong references
460 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
461 // Now the number must be given
462 if (fax.getPhoneAreaCode() == null) {
464 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
465 } else if (fax.getPhoneAreaCode() < 1) {
467 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
468 } else if (fax.getPhoneNumber() == null) {
470 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
471 } else if (fax.getPhoneNumber() < 1) {
473 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
477 contact.setContactFaxNumber(fax);
480 // Is the provider set?
481 if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
482 // Is the number set?
483 if (cellphone.getPhoneNumber() == null) {
485 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
486 } else if (cellphone.getPhoneNumber() < 1) {
488 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
491 // Set cellphone number
492 contact.setContactCellphoneNumber(cellphone);
496 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
503 public String doChangePersonalContactData () {
504 // This method shall only be called if the user is logged-in
505 if (!this.userLoginController.isUserLoggedIn()) {
507 throw new IllegalStateException("User is not logged-in"); //NOI18N
508 } else if (!this.isRequiredChangePersonalDataSet()) {
509 // Not all required fields are set
510 throw new FaceletException("Not all required fields are set."); //NOI18N
511 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
512 // Password not matching
513 this.showFacesMessage("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
517 // Get contact instance
518 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
520 // It should be there, so run some tests on it
521 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
522 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
523 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
526 contact.setContactGender(this.getGender());
527 contact.setContactFirstName(this.getFirstName());
528 contact.setContactFamilyName(this.getFamilyName());
529 contact.setContactStreet(this.getStreet());
530 contact.setContactHouseNumber(this.getHouseNumber());
531 contact.setContactZipCode(this.getZipCode());
532 contact.setContactCity(this.getCity());
533 contact.setContactCountry(this.getCountry());
535 // Update contact's cellphone number
536 this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
538 // Update contact's land-line number
539 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
541 // Update contact's fax number
542 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
544 // Send it to the EJB
545 this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
548 return "contact_data_saved"; //NOI18N
552 @SuppressWarnings ("ReturnOfDateField")
553 public Date getBirthday () {
554 return this.birthday;
558 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
559 public void setBirthday (final Date birthday) {
560 this.birthday = birthday;
564 public MobileProvider getCellphoneCarrier () {
565 return this.cellphoneCarrier;
569 public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
570 this.cellphoneCarrier = cellphoneCarrier;
574 public Long getCellphoneNumber () {
575 return this.cellphoneNumber;
579 public void setCellphoneNumber (Long cellphoneNumber) {
580 this.cellphoneNumber = cellphoneNumber;
584 public String getCity () {
589 public void setCity (final String city) {
594 public String getComment () {
599 public void setComment (final String comment) {
600 this.comment = comment;
604 public Country getCountry () {
609 public void setCountry (final Country country) {
610 this.country = country;
614 public String getEmailAddress () {
615 return this.emailAddress;
619 public void setEmailAddress (final String emailAddress) {
620 this.emailAddress = emailAddress;
624 public String getEmailAddressRepeat () {
625 return this.emailAddressRepeat;
629 public void setEmailAddressRepeat (final String emailAddressRepeat) {
630 this.emailAddressRepeat = emailAddressRepeat;
634 public String getFamilyName () {
635 return this.familyName;
639 public void setFamilyName (final String familyName) {
640 this.familyName = familyName;
644 public Integer getFaxAreaCode () {
645 return this.faxAreaCode;
649 public void setFaxAreaCode (final Integer faxAreaCode) {
650 this.faxAreaCode = faxAreaCode;
654 public Country getFaxCountry () {
655 return this.faxCountry;
659 public void setFaxCountry (final Country faxCountry) {
660 this.faxCountry = faxCountry;
664 public Long getFaxNumber () {
665 return this.faxNumber;
669 public void setFaxNumber (final Long faxNumber) {
670 this.faxNumber = faxNumber;
674 public String getFirstName () {
675 return this.firstName;
679 public void setFirstName (final String firstName) {
680 this.firstName = firstName;
684 public Gender getGender () {
689 public void setGender (final Gender gender) {
690 this.gender = gender;
694 public Short getHouseNumber () {
695 return this.houseNumber;
699 public void setHouseNumber (final Short houseNumber) {
700 this.houseNumber = houseNumber;
704 public Integer getPhoneAreaCode () {
705 return this.phoneAreaCode;
709 public void setPhoneAreaCode (final Integer phoneAreaCode) {
710 this.phoneAreaCode = phoneAreaCode;
714 public Country getPhoneCountry () {
715 return this.phoneCountry;
719 public void setPhoneCountry (final Country phoneCountry) {
720 this.phoneCountry = phoneCountry;
724 public Long getPhoneNumber () {
725 return this.phoneNumber;
729 public void setPhoneNumber (final Long phoneNumber) {
730 this.phoneNumber = phoneNumber;
734 public String getStreet () {
739 public void setStreet (final String street) {
740 this.street = street;
744 public Integer getZipCode () {
749 public void setZipCode (final Integer zipCode) {
750 this.zipCode = zipCode;
754 public boolean hasContacts () {
755 return (!this.contactList.isEmpty());
759 * Post-initialization of this class
762 public void init () {
763 // Get full email address list for reducing EJB calls
764 this.emailAddressList = this.contactBean.getEmailAddressList();
766 // Get full contact list
767 this.contactList = this.contactBean.getAllContacts();
771 public boolean isEmailAddressRegistered (final Contact contact) {
773 if (null == contact) {
775 throw new NullPointerException("contact is null"); //NOI18N
776 } else if (contact.getContactEmailAddress() == null) {
778 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
779 } else if (contact.getContactEmailAddress().isEmpty()) {
781 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
785 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
789 public boolean isRequiredChangePersonalDataSet () {
790 return ((this.getGender() != null) &&
791 (this.getFirstName() != null) &&
792 (this.getFamilyName() != null) &&
793 (this.getStreet() != null) &&
794 (this.getHouseNumber() != null) &&
795 (this.getZipCode() != null) &&
796 (this.getCity() != null));
800 public boolean isRequiredPersonalDataSet () {
801 return ((this.getGender() != null) &&
802 (this.getFirstName() != null) &&
803 (this.getFamilyName() != null) &&
804 (this.getStreet() != null) &&
805 (this.getHouseNumber() != null) &&
806 (this.getZipCode() != null) &&
807 (this.getCity() != null) &&
808 (this.getEmailAddress() != null) &&
809 (this.getEmailAddressRepeat() != null));
813 public boolean isSameEmailAddressEntered () {
814 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
818 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
820 Contact localContact = null;
825 // Try to lookup it in visible user list
826 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
828 Contact next = iterator.next();
830 // Is the user id found?
831 if (Objects.equals(next.getContactId(), contactId)) {
832 // Copy to other variable
839 if (null == localContact) {
840 // Not visible for the current user
841 throw new ContactNotFoundException(contactId);
844 // Copy all data to this bean
845 this.copyContact(localContact);
852 public void updateContactDataFromController (final Contact contact) {
853 // Is the instance valid?
854 if (null == contact) {
856 throw new NullPointerException("contact is null"); //NOI18N
857 } else if (contact.getContactId() == null) {
859 throw new NullPointerException("contact.contactId is null"); //NOI18N
860 } else if (contact.getContactId() < 1) {
861 // Not valid id number
862 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
866 this.copyContact(contact);
870 * Adds email address to bean's internal list.
872 * @param contact Contact instance
874 private void addUserNameEmailAddress (final Contact contact) {
875 // Make sure the entry is not added yet
876 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
878 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
882 this.emailAddressList.add(contact.getContactEmailAddress());
888 private void clear () {
891 this.setGender(Gender.UNKNOWN);
892 this.setFirstName(null);
893 this.setFamilyName(null);
894 this.setStreet(null);
895 this.setHouseNumber(null);
896 this.setZipCode(null);
898 this.setCountry(null);
901 this.setEmailAddress(null);
902 this.setEmailAddressRepeat(null);
903 this.setPhoneAreaCode(null);
904 this.setPhoneCountry(null);
905 this.setPhoneNumber(null);
906 this.setCellphoneCarrier(null);
907 this.setCellphoneNumber(null);
908 this.setFaxAreaCode(null);
909 this.setFaxCountry(null);
910 this.setFaxNumber(null);
913 this.setBirthday(null);
914 this.setComment(null);
918 * Copies given contact into the controller
920 * @param contact Contact instance
922 private void copyContact (final Contact contact) {
923 // Is the instance valid?
924 if (null == contact) {
926 throw new NullPointerException("contact is null"); //NOI18N
927 } else if (contact.getContactId() == null) {
929 throw new NullPointerException("contact.contactId is null"); //NOI18N
930 } else if (contact.getContactId() < 1) {
931 // Not valid id number
932 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
937 this.setGender(contact.getContactGender());
938 this.setFirstName(contact.getContactFirstName());
939 this.setFamilyName(contact.getContactFamilyName());
940 this.setStreet(contact.getContactStreet());
941 this.setHouseNumber(contact.getContactHouseNumber());
942 this.setZipCode(contact.getContactZipCode());
943 this.setCity(contact.getContactCity());
944 this.setCountry(contact.getContactCountry());
945 this.setEmailAddress(contact.getContactEmailAddress());
946 this.setBirthday(contact.getContactBirthday());
947 this.setComment(contact.getContactComment());
949 // Get cellphone, phone and fax instance
950 DialableCellphoneNumber cellphone = contact.getContactCellphoneNumber();
951 DialableFaxNumber fax = contact.getContactFaxNumber();
952 DialableLandLineNumber phone = contact.getContactLandLineNumber();
955 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
956 this.setPhoneCountry(phone.getPhoneCountry());
957 this.setPhoneAreaCode(phone.getPhoneAreaCode());
958 this.setPhoneNumber(phone.getPhoneNumber());
961 if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) {
962 this.setCellphoneCarrier(cellphone.getCellphoneProvider());
963 this.setCellphoneNumber(cellphone.getPhoneNumber());
966 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
967 this.setFaxCountry(fax.getPhoneCountry());
968 this.setFaxAreaCode(fax.getPhoneAreaCode());
969 this.setFaxNumber(fax.getPhoneNumber());
974 * Removes given contact from all lists
976 * @param contact Contact instance to remove
978 private void removeContact (final Contact contact) {
979 // Is the instance valid?
980 if (null == contact) {
982 throw new NullPointerException("contact is null"); //NOI18N
983 } else if (contact.getContactId() == null) {
985 throw new NullPointerException("contact.contactId is null"); //NOI18N
986 } else if (contact.getContactId() < 1) {
987 // Not valid id number
988 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
991 // Remove from general list
992 if (!this.contactList.remove(contact)) {
993 // Did not remove contact
994 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
997 // Remove from other lists
998 this.emailAddressList.remove(contact.getContactEmailAddress());
1002 * Adds unique instance to contact list. First any existing instance is
1003 * being removed, then the new instance is added.
1005 * @param contact Contact instance to add uniquely
1007 private void uniqueAddContact (final Contact contact) {
1008 // Is the instance valid?
1009 if (null == contact) {
1011 throw new NullPointerException("contact is null"); //NOI18N
1012 } else if (contact.getContactId() == null) {
1014 throw new NullPointerException("contact.contactId is null"); //NOI18N
1015 } else if (contact.getContactId() < 1) {
1016 // Not valid id number
1017 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1020 // Get iterator from list
1021 Iterator<Contact> iterator = this.contactList.iterator();
1023 // "Walk" through all entries
1024 while (iterator.hasNext()) {
1026 Contact next = iterator.next();
1028 // Is id number the same?
1029 if (Objects.equals(contact.getContactId(), next.getContactId())) {
1030 // Found entry, so remove it and abort
1031 this.removeContact(next);
1036 // Add contact to list
1037 this.contactList.add(contact);