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.addressbook.beans.contact;
19 import java.text.MessageFormat;
20 import java.util.Collections;
21 import java.util.Date;
22 import java.util.Iterator;
23 import java.util.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.addressbook.beans.BaseAddressbookController;
35 import org.mxchange.addressbook.beans.login.AddressbookUserLoginWebSessionController;
36 import org.mxchange.jcontacts.contact.Contact;
37 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
38 import org.mxchange.jcontacts.contact.UserContact;
39 import org.mxchange.jcontacts.contact.gender.Gender;
40 import org.mxchange.jcontacts.contact.utils.ContactUtils;
41 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
42 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
43 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
44 import org.mxchange.jcountry.data.Country;
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 AddressbookContactWebSessionBean extends BaseAddressbookController implements AddressbookContactWebSessionController {
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 AddressbookUserLoginWebSessionController userLoginController;
206 private Integer zipCode;
209 * Default constructor
211 public AddressbookContactWebSessionBean () {
214 // Get initial context
215 Context context = new InitialContext();
218 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/addressbook-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.contactList.add(event.getAddedContact());
250 public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
252 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminAddedUserEvent: event={0} - CALLED!", event)); //NOI18N
254 // event should not be null
257 throw new NullPointerException("event is null"); //NOI18N
258 } else if (event.getAddedUser() == null) {
260 throw new NullPointerException("event.addedUser is null"); //NOI18N
261 } else if (event.getAddedUser().getUserId() == null) {
263 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
264 } else if (event.getAddedUser().getUserId() < 1) {
266 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
273 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminAddedUserEvent: EXIT!"); //NOI18N
277 public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
279 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
281 // event should not be null
284 throw new NullPointerException("event is null"); //NOI18N
285 } else if (event.getUpdatedContact() == null) {
287 throw new NullPointerException("event.updatedContact is null"); //NOI18N
288 } else if (event.getUpdatedContact().getContactId() == null) {
290 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
291 } else if (event.getUpdatedContact().getContactId() < 1) {
293 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
296 // Get iterator from list
297 Iterator<Contact> iterator = this.contactList.iterator();
299 // "Walk" through all entries
300 while (iterator.hasNext()) {
302 Contact next = iterator.next();
304 // Is id number the same?
305 if (Objects.equals(event.getUpdatedContact().getContactId(), next.getContactId())) {
306 // Found entry, so remove it and abort
307 this.contactList.remove(next);
309 // Remove also email from list
310 this.emailAddressList.remove(next.getContactEmailAddress());
315 // Add contact to list
316 this.contactList.add(event.getUpdatedContact());
318 // Add email address to list
319 this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
323 public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
325 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
327 // event should not be null
330 throw new NullPointerException("event is null"); //NOI18N
331 } else if (event.getRegisteredUser() == null) {
333 throw new NullPointerException("event.registeredUser is null"); //NOI18N
334 } else if (event.getRegisteredUser().getUserId() == null) {
336 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
337 } else if (event.getRegisteredUser().getUserId() < 1) {
339 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
343 Contact registeredContact = event.getRegisteredUser().getUserContact();
346 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: registeredContact={0}", registeredContact)); //NOI18N
348 // Copy all data from registered->user
349 this.copyContact(registeredContact);
351 // Add user name and email address
352 this.addUserNameEmailAddress(registeredContact);
358 //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterRegistration: EXIT!"); //NOI18N
362 public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) {
364 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
366 // event should not be null
369 throw new NullPointerException("event is null"); //NOI18N
370 } else if (event.getConfirmedUser() == null) {
372 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
373 } else if (event.getConfirmedUser().getUserId() == null) {
375 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
376 } else if (event.getConfirmedUser().getUserId() < 1) {
378 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
381 // "Cache" contact instance
382 Contact contact = event.getConfirmedUser().getUserContact();
384 // Get iterator from list
385 Iterator<Contact> iterator = this.contactList.iterator();
387 // "Walk" through all entries
388 while (iterator.hasNext()) {
390 Contact next = iterator.next();
392 // Is id number the same?
393 if (Objects.equals(contact.getContactId(), next.getContactId())) {
394 // Found entry, so remove it and abort
395 this.contactList.remove(next);
400 // Add contact to list
401 this.contactList.add(contact);
405 public void afterUserLogin (@Observes final UserLoggedInEvent event) {
407 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
409 // event should not be null
412 throw new NullPointerException("event is null"); //NOI18N
413 } else if (event.getLoggedInUser() == null) {
415 throw new NullPointerException("event.loggedInUser is null"); //NOI18N
416 } else if (event.getLoggedInUser().getUserId() == null) {
418 throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
419 } else if (event.getLoggedInUser().getUserId() < 1) {
421 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
424 // Copy all data to this bean
425 this.copyContact(event.getLoggedInUser().getUserContact());
428 //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N
432 public List<Contact> allContacts () {
434 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size()));
436 // Return un-modified list
437 return Collections.unmodifiableList(this.contactList);
441 public Contact createContactInstance () {
443 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName()));
445 // Is all required data set?
446 if (!this.isRequiredPersonalDataSet()) {
447 // No, then abort here
448 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
451 // Required personal data must be set
452 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
454 // Generate phone number
455 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
456 DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
457 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
459 // Create new contact
460 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
461 contact.setContactStreet(this.getStreet());
462 contact.setContactHouseNumber(this.getHouseNumber());
463 contact.setContactZipCode(this.getZipCode());
464 contact.setContactCity(this.getCity());
465 contact.setContactCountry(this.getCountry());
466 contact.setContactEmailAddress(this.getEmailAddress());
467 contact.setContactBirthday(this.getBirthday());
468 contact.setContactComment(this.getComment());
471 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
472 // Don't set null or wrong references
473 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
474 // Now the number must be given
475 if (phone.getPhoneAreaCode() == null) {
477 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
478 } else if (phone.getPhoneAreaCode() < 1) {
480 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
481 } else if (phone.getPhoneNumber() == null) {
483 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
484 } else if (phone.getPhoneNumber() < 1) {
486 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
490 contact.setContactLandLineNumber(phone);
493 // Don't set null or wrong references
494 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
495 // Now the number must be given
496 if (fax.getPhoneAreaCode() == null) {
498 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
499 } else if (fax.getPhoneAreaCode() < 1) {
501 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
502 } else if (fax.getPhoneNumber() == null) {
504 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
505 } else if (fax.getPhoneNumber() < 1) {
507 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
511 contact.setContactFaxNumber(fax);
514 // Is the provider set?
515 if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
516 // Is the number set?
517 if (cellphone.getPhoneNumber() == null) {
519 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
520 } else if (cellphone.getPhoneNumber() < 1) {
522 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
525 // Set cellphone number
526 contact.setContactCellphoneNumber(cellphone);
530 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
537 public String doChangePersonalContactData () {
538 // This method shall only be called if the user is logged-in
539 if (!this.userLoginController.isUserLoggedIn()) {
541 throw new IllegalStateException("User is not logged-in"); //NOI18N
542 } else if (!this.isRequiredChangePersonalDataSet()) {
543 // Not all required fields are set
544 throw new FaceletException("Not all required fields are set."); //NOI18N
545 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
546 // Password not matching
547 throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()));
550 // Get contact instance
551 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
553 // It should be there, so run some tests on it
554 assert (contact instanceof Contact) : "Instance loginController.loggedInUser.userContact is null"; //NOI18N
555 assert (contact.getContactId() instanceof Long) : "Instance loginController.userContact.contactId is null"; //NOI18N
556 assert (contact.getContactId() > 0) : MessageFormat.format("Instance loginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
559 contact.setContactGender(this.getGender());
560 contact.setContactFirstName(this.getFirstName());
561 contact.setContactFamilyName(this.getFamilyName());
562 contact.setContactStreet(this.getStreet());
563 contact.setContactHouseNumber(this.getHouseNumber());
564 contact.setContactZipCode(this.getZipCode());
565 contact.setContactCity(this.getCity());
566 contact.setContactCountry(this.getCountry());
568 // Update contact's cellphone number
569 this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
571 // Update contact's land-line number
572 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
574 // Update contact's fax number
575 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
577 // Send it to the EJB
578 this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
581 return "contact_data_saved"; //NOI18N
585 @SuppressWarnings ("ReturnOfDateField")
586 public Date getBirthday () {
587 return this.birthday;
591 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
592 public void setBirthday (final Date birthday) {
593 this.birthday = birthday;
597 public MobileProvider getCellphoneCarrier () {
598 return this.cellphoneCarrier;
602 public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
603 this.cellphoneCarrier = cellphoneCarrier;
607 public Long getCellphoneNumber () {
608 return this.cellphoneNumber;
612 public void setCellphoneNumber (Long cellphoneNumber) {
613 this.cellphoneNumber = cellphoneNumber;
617 public String getCity () {
622 public void setCity (final String city) {
627 public String getComment () {
632 public void setComment (final String comment) {
633 this.comment = comment;
637 public Country getCountry () {
642 public void setCountry (final Country country) {
643 this.country = country;
647 public String getEmailAddress () {
648 return this.emailAddress;
652 public void setEmailAddress (final String emailAddress) {
653 this.emailAddress = emailAddress;
657 public String getEmailAddressRepeat () {
658 return this.emailAddressRepeat;
662 public void setEmailAddressRepeat (final String emailAddressRepeat) {
663 this.emailAddressRepeat = emailAddressRepeat;
667 public String getFamilyName () {
668 return this.familyName;
672 public void setFamilyName (final String familyName) {
673 this.familyName = familyName;
677 public Integer getFaxAreaCode () {
678 return this.faxAreaCode;
682 public void setFaxAreaCode (final Integer faxAreaCode) {
683 this.faxAreaCode = faxAreaCode;
687 public Country getFaxCountry () {
688 return this.faxCountry;
692 public void setFaxCountry (final Country faxCountry) {
693 this.faxCountry = faxCountry;
697 public Long getFaxNumber () {
698 return this.faxNumber;
702 public void setFaxNumber (final Long faxNumber) {
703 this.faxNumber = faxNumber;
707 public String getFirstName () {
708 return this.firstName;
712 public void setFirstName (final String firstName) {
713 this.firstName = firstName;
717 public Gender getGender () {
722 public void setGender (final Gender gender) {
723 this.gender = gender;
727 public Short getHouseNumber () {
728 return this.houseNumber;
732 public void setHouseNumber (final Short houseNumber) {
733 this.houseNumber = houseNumber;
737 public Integer getPhoneAreaCode () {
738 return this.phoneAreaCode;
742 public void setPhoneAreaCode (final Integer phoneAreaCode) {
743 this.phoneAreaCode = phoneAreaCode;
747 public Country getPhoneCountry () {
748 return this.phoneCountry;
752 public void setPhoneCountry (final Country phoneCountry) {
753 this.phoneCountry = phoneCountry;
757 public Long getPhoneNumber () {
758 return this.phoneNumber;
762 public void setPhoneNumber (final Long phoneNumber) {
763 this.phoneNumber = phoneNumber;
767 public String getStreet () {
772 public void setStreet (final String street) {
773 this.street = street;
777 public Integer getZipCode () {
782 public void setZipCode (final Integer zipCode) {
783 this.zipCode = zipCode;
787 public boolean hasContacts () {
788 return (!this.contactList.isEmpty());
792 * Post-initialization of this class
795 public void init () {
796 // Get full email address list for reducing EJB calls
797 this.emailAddressList = this.contactBean.getEmailAddressList();
799 // Get full contact list
800 this.contactList = this.contactBean.getAllContacts();
804 public boolean isEmailAddressRegistered (final Contact contact) {
806 if (null == contact) {
808 throw new NullPointerException("contact is null"); //NOI18N
809 } else if (contact.getContactEmailAddress() == null) {
811 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
812 } else if (contact.getContactEmailAddress().isEmpty()) {
814 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
818 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
822 public boolean isRequiredChangePersonalDataSet () {
823 return ((this.getGender() != null) &&
824 (this.getFirstName() != null) &&
825 (this.getFamilyName() != null) &&
826 (this.getStreet() != null) &&
827 (this.getHouseNumber() != null) &&
828 (this.getZipCode() != null) &&
829 (this.getCity() != null));
833 public boolean isRequiredPersonalDataSet () {
834 return ((this.getGender() != null) &&
835 (this.getFirstName() != null) &&
836 (this.getFamilyName() != null) &&
837 (this.getStreet() != null) &&
838 (this.getHouseNumber() != null) &&
839 (this.getZipCode() != null) &&
840 (this.getCity() != null) &&
841 (this.getEmailAddress() != null) &&
842 (this.getEmailAddressRepeat() != null));
846 public boolean isSameEmailAddressEntered () {
847 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
851 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
853 Contact localContact = null;
858 // Try to lookup it in visible user list
859 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
861 Contact next = iterator.next();
863 // Is the user id found?
864 if (Objects.equals(next.getContactId(), contactId)) {
865 // Copy to other variable
872 if (null == localContact) {
873 // Not visible for the current user
874 throw new ContactNotFoundException(contactId);
877 // Copy all data to this bean
878 this.copyContact(localContact);
885 public void updateContactDataFromController (final Contact contact) {
886 // Is the instance valid?
887 if (null == contact) {
889 throw new NullPointerException("contact is null"); //NOI18N
890 } else if (contact.getContactId() == null) {
892 throw new NullPointerException("contact.contactId is null"); //NOI18N
893 } else if (contact.getContactId() < 1) {
894 // Not valid id number
895 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
899 this.copyContact(contact);
903 * Adds email address to bean's internal list.
905 * @param contact Contact instance
907 private void addUserNameEmailAddress (final Contact contact) {
908 // Make sure the entry is not added yet
909 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
911 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
915 this.emailAddressList.add(contact.getContactEmailAddress());
921 private void clear () {
924 this.setGender(Gender.UNKNOWN);
925 this.setFirstName(null);
926 this.setFamilyName(null);
927 this.setStreet(null);
928 this.setHouseNumber(null);
929 this.setZipCode(null);
931 this.setCountry(null);
934 this.setEmailAddress(null);
935 this.setEmailAddressRepeat(null);
936 this.setPhoneAreaCode(null);
937 this.setPhoneCountry(null);
938 this.setPhoneNumber(null);
939 this.setCellphoneCarrier(null);
940 this.setCellphoneNumber(null);
941 this.setFaxAreaCode(null);
942 this.setFaxCountry(null);
943 this.setFaxNumber(null);
946 this.setBirthday(null);
947 this.setComment(null);
951 * Copies given contact into the controller
953 * @param contact Contact instance
955 private void copyContact (final Contact contact) {
956 // Is the instance valid?
957 if (null == contact) {
959 throw new NullPointerException("contact is null"); //NOI18N
960 } else if (contact.getContactId() == null) {
962 throw new NullPointerException("contact.contactId is null"); //NOI18N
963 } else if (contact.getContactId() < 1) {
964 // Not valid id number
965 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
970 this.setGender(contact.getContactGender());
971 this.setFirstName(contact.getContactFirstName());
972 this.setFamilyName(contact.getContactFamilyName());
973 this.setStreet(contact.getContactStreet());
974 this.setHouseNumber(contact.getContactHouseNumber());
975 this.setZipCode(contact.getContactZipCode());
976 this.setCity(contact.getContactCity());
977 this.setCountry(contact.getContactCountry());
978 this.setEmailAddress(contact.getContactEmailAddress());
979 this.setBirthday(contact.getContactBirthday());
980 this.setComment(contact.getContactComment());
982 // Get cellphone, phone and fax instance
983 DialableCellphoneNumber cellphone = contact.getContactCellphoneNumber();
984 DialableFaxNumber fax = contact.getContactFaxNumber();
985 DialableLandLineNumber phone = contact.getContactLandLineNumber();
988 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
989 this.setPhoneCountry(phone.getPhoneCountry());
990 this.setPhoneAreaCode(phone.getPhoneAreaCode());
991 this.setPhoneNumber(phone.getPhoneNumber());
994 if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) {
995 this.setCellphoneCarrier(cellphone.getCellphoneProvider());
996 this.setCellphoneNumber(cellphone.getPhoneNumber());
999 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
1000 this.setFaxCountry(fax.getPhoneCountry());
1001 this.setFaxAreaCode(fax.getPhoneAreaCode());
1002 this.setFaxNumber(fax.getPhoneNumber());
1007 * Removes given contact from all lists
1009 * @param contact Contact instance to remove
1011 private void removeContact (final Contact contact) {
1012 // Is the instance valid?
1013 if (null == contact) {
1015 throw new NullPointerException("contact is null"); //NOI18N
1016 } else if (contact.getContactId() == null) {
1018 throw new NullPointerException("contact.contactId is null"); //NOI18N
1019 } else if (contact.getContactId() < 1) {
1020 // Not valid id number
1021 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1024 // Remove from general list
1025 if (!this.contactList.remove(contact)) {
1026 // Did not remove contact
1027 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
1030 // Remove from other lists
1031 this.emailAddressList.remove(contact.getContactEmailAddress());