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.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("contactId of contact={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 // Generate phone number
452 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
453 DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
454 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
456 // Create new contact
457 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
458 contact.setContactStreet(this.getStreet());
459 contact.setContactHouseNumber(this.getHouseNumber());
460 contact.setContactZipCode(this.getZipCode());
461 contact.setContactCity(this.getCity());
462 contact.setContactCountry(this.getCountry());
463 contact.setContactEmailAddress(this.getEmailAddress());
464 contact.setContactBirthday(this.getBirthday());
465 contact.setContactComment(this.getComment());
468 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
470 // Don't set null or wrong references
471 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
472 // Now the number must be given
473 if (phone.getPhoneAreaCode() == null) {
475 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
476 } else if (phone.getPhoneAreaCode() < 1) {
478 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
479 } else if (phone.getPhoneNumber() == null) {
481 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
482 } else if (phone.getPhoneNumber() < 1) {
484 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
488 contact.setContactLandLineNumber(phone);
491 // Don't set null or wrong references
492 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
493 // Now the number must be given
494 if (fax.getPhoneAreaCode() == null) {
496 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
497 } else if (fax.getPhoneAreaCode() < 1) {
499 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
500 } else if (fax.getPhoneNumber() == null) {
502 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
503 } else if (fax.getPhoneNumber() < 1) {
505 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
509 contact.setContactFaxNumber(fax);
512 // Is the provider set?
513 if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
514 // Is the number set?
515 if (cellphone.getPhoneNumber() == null) {
517 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
518 } else if (cellphone.getPhoneNumber() < 1) {
520 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
523 // Set cellphone number
524 contact.setContactCellphoneNumber(cellphone);
528 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
535 public String doChangePersonalContactData () {
536 // This method shall only be called if the user is logged-in
537 if (!this.userLoginController.isUserLoggedIn()) {
539 throw new IllegalStateException("User is not logged-in"); //NOI18N
540 } else if (!this.isRequiredChangePersonalDataSet()) {
541 // Not all required fields are set
542 throw new FaceletException("Not all required fields are set."); //NOI18N
543 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
544 // Password not matching
545 this.showFacesMessage("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
549 // Get contact instance
550 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
552 // It should be there, so run some tests on it
553 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
554 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
555 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
558 contact.setContactGender(this.getGender());
559 contact.setContactFirstName(this.getFirstName());
560 contact.setContactFamilyName(this.getFamilyName());
561 contact.setContactStreet(this.getStreet());
562 contact.setContactHouseNumber(this.getHouseNumber());
563 contact.setContactZipCode(this.getZipCode());
564 contact.setContactCity(this.getCity());
565 contact.setContactCountry(this.getCountry());
567 // Update contact's cellphone number
568 this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
570 // Update contact's land-line number
571 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
573 // Update contact's fax number
574 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
576 // Send it to the EJB
577 this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
580 return "contact_data_saved"; //NOI18N
584 @SuppressWarnings ("ReturnOfDateField")
585 public Date getBirthday () {
586 return this.birthday;
590 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
591 public void setBirthday (final Date birthday) {
592 this.birthday = birthday;
596 public MobileProvider getCellphoneCarrier () {
597 return this.cellphoneCarrier;
601 public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
602 this.cellphoneCarrier = cellphoneCarrier;
606 public Long getCellphoneNumber () {
607 return this.cellphoneNumber;
611 public void setCellphoneNumber (Long cellphoneNumber) {
612 this.cellphoneNumber = cellphoneNumber;
616 public String getCity () {
621 public void setCity (final String city) {
626 public String getComment () {
631 public void setComment (final String comment) {
632 this.comment = comment;
636 public Country getCountry () {
641 public void setCountry (final Country country) {
642 this.country = country;
646 public String getEmailAddress () {
647 return this.emailAddress;
651 public void setEmailAddress (final String emailAddress) {
652 this.emailAddress = emailAddress;
656 public String getEmailAddressRepeat () {
657 return this.emailAddressRepeat;
661 public void setEmailAddressRepeat (final String emailAddressRepeat) {
662 this.emailAddressRepeat = emailAddressRepeat;
666 public String getFamilyName () {
667 return this.familyName;
671 public void setFamilyName (final String familyName) {
672 this.familyName = familyName;
676 public Integer getFaxAreaCode () {
677 return this.faxAreaCode;
681 public void setFaxAreaCode (final Integer faxAreaCode) {
682 this.faxAreaCode = faxAreaCode;
686 public Country getFaxCountry () {
687 return this.faxCountry;
691 public void setFaxCountry (final Country faxCountry) {
692 this.faxCountry = faxCountry;
696 public Long getFaxNumber () {
697 return this.faxNumber;
701 public void setFaxNumber (final Long faxNumber) {
702 this.faxNumber = faxNumber;
706 public String getFirstName () {
707 return this.firstName;
711 public void setFirstName (final String firstName) {
712 this.firstName = firstName;
716 public Gender getGender () {
721 public void setGender (final Gender gender) {
722 this.gender = gender;
726 public Short getHouseNumber () {
727 return this.houseNumber;
731 public void setHouseNumber (final Short houseNumber) {
732 this.houseNumber = houseNumber;
736 public Integer getPhoneAreaCode () {
737 return this.phoneAreaCode;
741 public void setPhoneAreaCode (final Integer phoneAreaCode) {
742 this.phoneAreaCode = phoneAreaCode;
746 public Country getPhoneCountry () {
747 return this.phoneCountry;
751 public void setPhoneCountry (final Country phoneCountry) {
752 this.phoneCountry = phoneCountry;
756 public Long getPhoneNumber () {
757 return this.phoneNumber;
761 public void setPhoneNumber (final Long phoneNumber) {
762 this.phoneNumber = phoneNumber;
766 public String getStreet () {
771 public void setStreet (final String street) {
772 this.street = street;
776 public Integer getZipCode () {
781 public void setZipCode (final Integer zipCode) {
782 this.zipCode = zipCode;
786 public boolean hasContacts () {
787 return (!this.contactList.isEmpty());
791 * Post-initialization of this class
794 public void init () {
795 // Get full email address list for reducing EJB calls
796 this.emailAddressList = this.contactBean.getEmailAddressList();
798 // Get full contact list
799 this.contactList = this.contactBean.getAllContacts();
803 public boolean isEmailAddressRegistered (final Contact contact) {
805 if (null == contact) {
807 throw new NullPointerException("contact is null"); //NOI18N
808 } else if (contact.getContactEmailAddress() == null) {
810 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
811 } else if (contact.getContactEmailAddress().isEmpty()) {
813 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
817 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
821 public boolean isRequiredChangePersonalDataSet () {
822 return ((this.getGender() != null) &&
823 (this.getFirstName() != null) &&
824 (this.getFamilyName() != null) &&
825 (this.getStreet() != null) &&
826 (this.getHouseNumber() != null) &&
827 (this.getZipCode() != null) &&
828 (this.getCity() != null));
832 public boolean isRequiredPersonalDataSet () {
833 return ((this.getGender() != null) &&
834 (this.getFirstName() != null) &&
835 (this.getFamilyName() != null) &&
836 (this.getStreet() != null) &&
837 (this.getHouseNumber() != null) &&
838 (this.getZipCode() != null) &&
839 (this.getCity() != null) &&
840 (this.getEmailAddress() != null) &&
841 (this.getEmailAddressRepeat() != null));
845 public boolean isSameEmailAddressEntered () {
846 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
850 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
852 Contact localContact = null;
857 // Try to lookup it in visible user list
858 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
860 Contact next = iterator.next();
862 // Is the user id found?
863 if (Objects.equals(next.getContactId(), contactId)) {
864 // Copy to other variable
871 if (null == localContact) {
872 // Not visible for the current user
873 throw new ContactNotFoundException(contactId);
876 // Copy all data to this bean
877 this.copyContact(localContact);
884 public void updateContactDataFromController (final Contact contact) {
885 // Is the instance valid?
886 if (null == contact) {
888 throw new NullPointerException("contact is null"); //NOI18N
889 } else if (contact.getContactId() == null) {
891 throw new NullPointerException("contact.contactId is null"); //NOI18N
892 } else if (contact.getContactId() < 1) {
893 // Not valid id number
894 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
898 this.copyContact(contact);
902 * Adds email address to bean's internal list.
904 * @param contact Contact instance
906 private void addUserNameEmailAddress (final Contact contact) {
907 // Make sure the entry is not added yet
908 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
910 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
914 this.emailAddressList.add(contact.getContactEmailAddress());
920 private void clear () {
923 this.setGender(Gender.UNKNOWN);
924 this.setFirstName(null);
925 this.setFamilyName(null);
926 this.setStreet(null);
927 this.setHouseNumber(null);
928 this.setZipCode(null);
930 this.setCountry(null);
933 this.setEmailAddress(null);
934 this.setEmailAddressRepeat(null);
935 this.setPhoneAreaCode(null);
936 this.setPhoneCountry(null);
937 this.setPhoneNumber(null);
938 this.setCellphoneCarrier(null);
939 this.setCellphoneNumber(null);
940 this.setFaxAreaCode(null);
941 this.setFaxCountry(null);
942 this.setFaxNumber(null);
945 this.setBirthday(null);
946 this.setComment(null);
950 * Copies given contact into the controller
952 * @param contact Contact instance
954 private void copyContact (final Contact contact) {
955 // Is the instance valid?
956 if (null == contact) {
958 throw new NullPointerException("contact is null"); //NOI18N
959 } else if (contact.getContactId() == null) {
961 throw new NullPointerException("contact.contactId is null"); //NOI18N
962 } else if (contact.getContactId() < 1) {
963 // Not valid id number
964 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
969 this.setGender(contact.getContactGender());
970 this.setFirstName(contact.getContactFirstName());
971 this.setFamilyName(contact.getContactFamilyName());
972 this.setStreet(contact.getContactStreet());
973 this.setHouseNumber(contact.getContactHouseNumber());
974 this.setZipCode(contact.getContactZipCode());
975 this.setCity(contact.getContactCity());
976 this.setCountry(contact.getContactCountry());
977 this.setEmailAddress(contact.getContactEmailAddress());
978 this.setBirthday(contact.getContactBirthday());
979 this.setComment(contact.getContactComment());
981 // Get cellphone, phone and fax instance
982 DialableCellphoneNumber cellphone = contact.getContactCellphoneNumber();
983 DialableFaxNumber fax = contact.getContactFaxNumber();
984 DialableLandLineNumber phone = contact.getContactLandLineNumber();
987 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
988 this.setPhoneCountry(phone.getPhoneCountry());
989 this.setPhoneAreaCode(phone.getPhoneAreaCode());
990 this.setPhoneNumber(phone.getPhoneNumber());
993 if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) {
994 this.setCellphoneCarrier(cellphone.getCellphoneProvider());
995 this.setCellphoneNumber(cellphone.getPhoneNumber());
998 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
999 this.setFaxCountry(fax.getPhoneCountry());
1000 this.setFaxAreaCode(fax.getPhoneAreaCode());
1001 this.setFaxNumber(fax.getPhoneNumber());
1006 * Removes given contact from all lists
1008 * @param contact Contact instance to remove
1010 private void removeContact (final Contact contact) {
1011 // Is the instance valid?
1012 if (null == contact) {
1014 throw new NullPointerException("contact is null"); //NOI18N
1015 } else if (contact.getContactId() == null) {
1017 throw new NullPointerException("contact.contactId is null"); //NOI18N
1018 } else if (contact.getContactId() < 1) {
1019 // Not valid id number
1020 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1023 // Remove from general list
1024 if (!this.contactList.remove(contact)) {
1025 // Did not remove contact
1026 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
1029 // Remove from other lists
1030 this.emailAddressList.remove(contact.getContactEmailAddress());