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.pizzaapplication.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.jcustomercore.events.customer.added.AdminAddedCustomerEvent;
44 import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
45 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
46 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
47 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
48 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
49 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
50 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
51 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
52 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
53 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
54 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
55 import org.mxchange.pizzaapplication.beans.BasePizzaController;
56 import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController;
59 * A general contact bean (controller)
61 * @author Roland Haeder<roland@mxchange.org>
63 @Named ("contactController")
65 public class PizzaContactWebSessionBean extends BasePizzaController implements PizzaContactWebSessionController {
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 PizzaUserLoginWebSessionController userLoginController;
206 private Integer zipCode;
209 * Default constructor
211 public PizzaContactWebSessionBean () {
214 // Get initial context
215 Context context = new InitialContext();
218 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/PizzaService-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 afterAdminAddedCustomer (@Observes final AdminAddedCustomerEvent event) {
251 // The event must be valid
254 throw new NullPointerException("event is null"); //NOI18N
255 } else if (event.getAddedCustomer() == null) {
257 throw new NullPointerException("event.addedCustomer is null"); //NOI18N
258 } else if (event.getAddedCustomer().getCustomerId() == null) {
260 throw new NullPointerException("event.addedCustomer.customerId is null"); //NOI18N
261 } else if (event.getAddedCustomer().getCustomerId() < 1) {
263 throw new IllegalArgumentException(MessageFormat.format("event.addedCustomer.customerId={0} is not valid", event.getAddedCustomer().getCustomerId())); //NOI18N //NOI18N
270 this.contactList.add(event.getAddedCustomer().getCustomerContact());
274 public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
276 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminAddedUserEvent: event={0} - CALLED!", event)); //NOI18N
278 // event should not be null
281 throw new NullPointerException("event is null"); //NOI18N
282 } else if (event.getAddedUser() == null) {
284 throw new NullPointerException("event.addedUser is null"); //NOI18N
285 } else if (event.getAddedUser().getUserId() == null) {
287 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
288 } else if (event.getAddedUser().getUserId() < 1) {
290 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
297 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminAddedUserEvent: EXIT!"); //NOI18N
301 public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
303 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
305 // event should not be null
308 throw new NullPointerException("event is null"); //NOI18N
309 } else if (event.getUpdatedContact() == null) {
311 throw new NullPointerException("event.updatedUser is null"); //NOI18N
312 } else if (event.getUpdatedContact().getContactId() == null) {
314 throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
315 } else if (event.getUpdatedContact().getContactId() < 1) {
317 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
320 // Get iterator from list
321 Iterator<Contact> iterator = this.contactList.iterator();
323 // "Walk" through all entries
324 while (iterator.hasNext()) {
326 Contact next = iterator.next();
328 // Is id number the same?
329 if (Objects.equals(event.getUpdatedContact().getContactId(), next.getContactId())) {
330 // Found entry, so remove it and abort
331 this.contactList.remove(next);
333 // Remove also email from list
334 this.emailAddressList.remove(next.getContactEmailAddress());
339 // Add contact to list
340 this.contactList.add(event.getUpdatedContact());
342 // Add email address to list
343 this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
347 public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
349 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
351 // event should not be null
354 throw new NullPointerException("event is null"); //NOI18N
355 } else if (event.getRegisteredUser() == null) {
357 throw new NullPointerException("event.user is null"); //NOI18N
358 } else if (event.getRegisteredUser().getUserId() == null) {
360 throw new NullPointerException("event.user.userId is null"); //NOI18N
361 } else if (event.getRegisteredUser().getUserId() < 1) {
363 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
367 Contact registeredContact = event.getRegisteredUser().getUserContact();
370 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: registeredContact={0}", registeredContact)); //NOI18N
371 // Copy all data from registered->user
372 this.copyContact(registeredContact);
374 // Add user name and email address
375 this.addUserNameEmailAddress(registeredContact);
381 //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterRegistration: EXIT!"); //NOI18N
385 public void afterUserLogin (@Observes final UserLoggedInEvent event) {
387 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
389 // event should not be null
392 throw new NullPointerException("event is null"); //NOI18N
393 } else if (event.getLoggedInUser() == null) {
395 throw new NullPointerException("event.user is null"); //NOI18N
396 } else if (event.getLoggedInUser().getUserId() == null) {
398 throw new NullPointerException("event.user.userId is null"); //NOI18N
399 } else if (event.getLoggedInUser().getUserId() < 1) {
401 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
404 // Copy all data to this bean
405 this.copyContact(event.getLoggedInUser().getUserContact());
408 //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N
412 public List<Contact> allContacts () {
414 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size()));
416 // Return un-modified list
417 return Collections.unmodifiableList(this.contactList);
421 public Contact createContactInstance () {
423 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName()));
425 // Is all required data set?
426 if (!this.isRequiredPersonalDataSet()) {
427 // No, then abort here
428 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
431 // Generate phone number
432 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
433 DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
434 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
436 // Create new contact
437 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
438 contact.setContactStreet(this.getStreet());
439 contact.setContactHouseNumber(this.getHouseNumber());
440 contact.setContactZipCode(this.getZipCode());
441 contact.setContactCity(this.getCity());
442 contact.setContactCountry(this.getCountry());
443 contact.setContactEmailAddress(this.getEmailAddress());
444 contact.setContactBirthday(this.getBirthday());
445 contact.setContactComment(this.getComment());
448 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
449 // Don't set null or wrong references
450 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
451 // Now the number must be given
452 if (phone.getPhoneAreaCode() == null) {
454 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
455 } else if (phone.getPhoneAreaCode() < 1) {
457 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
458 } else if (phone.getPhoneNumber() == null) {
460 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
461 } else if (phone.getPhoneNumber() < 1) {
463 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
467 contact.setContactLandLineNumber(phone);
470 // Don't set null or wrong references
471 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
472 // Now the number must be given
473 if (fax.getPhoneAreaCode() == null) {
475 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
476 } else if (fax.getPhoneAreaCode() < 1) {
478 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
479 } else if (fax.getPhoneNumber() == null) {
481 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
482 } else if (fax.getPhoneNumber() < 1) {
484 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
488 contact.setContactFaxNumber(fax);
491 // Is the provider set?
492 if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
493 // Is the number set?
494 if (cellphone.getPhoneNumber() == null) {
496 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
497 } else if (cellphone.getPhoneNumber() < 1) {
499 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
502 // Set cellphone number
503 contact.setContactCellphoneNumber(cellphone);
507 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
513 public String doChangePersonalContactData () {
514 // This method shall only be called if the user is logged-in
515 if (!this.userLoginController.isUserLoggedIn()) {
517 throw new IllegalStateException("User is not logged-in"); //NOI18N
518 } else if (!this.isRequiredChangePersonalDataSet()) {
519 // Not all required fields are set
520 throw new FaceletException("Not all required fields are set."); //NOI18N
521 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
522 // Password not matching
523 throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()));
526 // Get contact instance
527 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
529 // It should be there, so run some tests on it
530 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
531 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
532 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
535 contact.setContactGender(this.getGender());
536 contact.setContactFirstName(this.getFirstName());
537 contact.setContactFamilyName(this.getFamilyName());
538 contact.setContactStreet(this.getStreet());
539 contact.setContactHouseNumber(this.getHouseNumber());
540 contact.setContactZipCode(this.getZipCode());
541 contact.setContactCity(this.getCity());
542 contact.setContactCountry(this.getCountry());
544 // Update contact's cellphone number
545 this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
547 // Update contact's land-line number
548 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
550 // Update contact's fax number
551 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
553 // Send it to the EJB
554 this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
557 return "contact_data_saved"; //NOI18N
561 @SuppressWarnings ("ReturnOfDateField")
562 public Date getBirthday () {
563 return this.birthday;
567 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
568 public void setBirthday (final Date birthday) {
569 this.birthday = birthday;
573 public MobileProvider getCellphoneCarrier () {
574 return this.cellphoneCarrier;
578 public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
579 this.cellphoneCarrier = cellphoneCarrier;
583 public Long getCellphoneNumber () {
584 return this.cellphoneNumber;
588 public void setCellphoneNumber (Long cellphoneNumber) {
589 this.cellphoneNumber = cellphoneNumber;
593 public String getCity () {
598 public void setCity (final String city) {
603 public String getComment () {
608 public void setComment (final String comment) {
609 this.comment = comment;
613 public Country getCountry () {
618 public void setCountry (final Country country) {
619 this.country = country;
623 public String getEmailAddress () {
624 return this.emailAddress;
628 public void setEmailAddress (final String emailAddress) {
629 this.emailAddress = emailAddress;
633 public String getEmailAddressRepeat () {
634 return this.emailAddressRepeat;
638 public void setEmailAddressRepeat (final String emailAddressRepeat) {
639 this.emailAddressRepeat = emailAddressRepeat;
643 public String getFamilyName () {
644 return this.familyName;
648 public void setFamilyName (final String familyName) {
649 this.familyName = familyName;
653 public Integer getFaxAreaCode () {
654 return this.faxAreaCode;
658 public void setFaxAreaCode (final Integer faxAreaCode) {
659 this.faxAreaCode = faxAreaCode;
663 public Country getFaxCountry () {
664 return this.faxCountry;
668 public void setFaxCountry (final Country faxCountry) {
669 this.faxCountry = faxCountry;
673 public Long getFaxNumber () {
674 return this.faxNumber;
678 public void setFaxNumber (final Long faxNumber) {
679 this.faxNumber = faxNumber;
683 public String getFirstName () {
684 return this.firstName;
688 public void setFirstName (final String firstName) {
689 this.firstName = firstName;
693 public Gender getGender () {
698 public void setGender (final Gender gender) {
699 this.gender = gender;
703 public Short getHouseNumber () {
704 return this.houseNumber;
708 public void setHouseNumber (final Short houseNumber) {
709 this.houseNumber = houseNumber;
713 public Integer getPhoneAreaCode () {
714 return this.phoneAreaCode;
718 public void setPhoneAreaCode (final Integer phoneAreaCode) {
719 this.phoneAreaCode = phoneAreaCode;
723 public Country getPhoneCountry () {
724 return this.phoneCountry;
728 public void setPhoneCountry (final Country phoneCountry) {
729 this.phoneCountry = phoneCountry;
733 public Long getPhoneNumber () {
734 return this.phoneNumber;
738 public void setPhoneNumber (final Long phoneNumber) {
739 this.phoneNumber = phoneNumber;
743 public String getStreet () {
748 public void setStreet (final String street) {
749 this.street = street;
753 public Integer getZipCode () {
758 public void setZipCode (final Integer zipCode) {
759 this.zipCode = zipCode;
763 public boolean hasContacts () {
764 return (!this.contactList.isEmpty());
768 * Post-initialization of this class
771 public void init () {
772 // Get full email address list for reducing EJB calls
773 this.emailAddressList = this.contactBean.getEmailAddressList();
775 // Get full contact list
776 this.contactList = this.contactBean.getAllContacts();
780 public boolean isEmailAddressRegistered (final Contact contact) {
782 if (null == contact) {
784 throw new NullPointerException("contact is null"); //NOI18N
785 } else if (contact.getContactEmailAddress() == null) {
787 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
788 } else if (contact.getContactEmailAddress().isEmpty()) {
790 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
794 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
798 public boolean isRequiredChangePersonalDataSet () {
799 return ((this.getGender() != null) &&
800 (this.getFirstName() != null) &&
801 (this.getFamilyName() != null) &&
802 (this.getStreet() != null) &&
803 (this.getHouseNumber() != null) &&
804 (this.getZipCode() != null) &&
805 (this.getCity() != null));
809 public boolean isRequiredPersonalDataSet () {
810 return ((this.getGender() != null) &&
811 (this.getFirstName() != null) &&
812 (this.getFamilyName() != null) &&
813 (this.getStreet() != null) &&
814 (this.getHouseNumber() != null) &&
815 (this.getZipCode() != null) &&
816 (this.getCity() != null) &&
817 (this.getEmailAddress() != null) &&
818 (this.getEmailAddressRepeat() != null));
822 public boolean isSameEmailAddressEntered () {
823 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
827 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
829 Contact localContact = null;
834 // Try to lookup it in visible user list
835 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
837 Contact next = iterator.next();
839 // Is the user id found?
840 if (Objects.equals(next.getContactId(), contactId)) {
841 // Copy to other variable
848 if (null == localContact) {
849 // Not visible for the current user
850 throw new ContactNotFoundException(contactId);
853 // Copy all data to this bean
854 this.copyContact(localContact);
861 public void updateContactDataFromController (final Contact contact) {
862 // Is the instance valid?
863 if (null == contact) {
865 throw new NullPointerException("contact is null"); //NOI18N
866 } else if (contact.getContactId() == null) {
868 throw new NullPointerException("contact.contactId is null"); //NOI18N
869 } else if (contact.getContactId() < 1) {
870 // Not valid id number
871 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
875 this.copyContact(contact);
879 * Adds email address to bean's internal list.
881 * @param contact Contact instance
883 private void addUserNameEmailAddress (final Contact contact) {
884 // Make sure the entry is not added yet
885 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
887 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
891 this.emailAddressList.add(contact.getContactEmailAddress());
897 private void clear () {
900 this.setGender(Gender.UNKNOWN);
901 this.setFirstName(null);
902 this.setFamilyName(null);
903 this.setStreet(null);
904 this.setHouseNumber(null);
905 this.setZipCode(null);
907 this.setCountry(null);
910 this.setEmailAddress(null);
911 this.setEmailAddressRepeat(null);
912 this.setPhoneCountry(null);
913 this.setPhoneAreaCode(null);
914 this.setPhoneCountry(null);
915 this.setPhoneNumber(null);
916 this.setCellphoneCarrier(null);
917 this.setCellphoneNumber(null);
918 this.setFaxAreaCode(null);
919 this.setFaxCountry(null);
920 this.setFaxNumber(null);
923 this.setBirthday(null);
924 this.setComment(null);
928 * Copies given contact into the controller
930 * @param contact Contact instance
932 private void copyContact (final Contact contact) {
933 // Is the instance valid?
934 if (null == contact) {
936 throw new NullPointerException("contact is null"); //NOI18N
937 } else if (contact.getContactId() == null) {
939 throw new NullPointerException("contact.contactId is null"); //NOI18N
940 } else if (contact.getContactId() < 1) {
941 // Not valid id number
942 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
947 this.setGender(contact.getContactGender());
948 this.setFirstName(contact.getContactFirstName());
949 this.setFamilyName(contact.getContactFamilyName());
950 this.setStreet(contact.getContactStreet());
951 this.setHouseNumber(contact.getContactHouseNumber());
952 this.setZipCode(contact.getContactZipCode());
953 this.setCity(contact.getContactCity());
954 this.setCountry(contact.getContactCountry());
955 this.setEmailAddress(contact.getContactEmailAddress());
956 this.setBirthday(contact.getContactBirthday());
957 this.setComment(contact.getContactComment());
959 // Get cellphone, phone and fax instance
960 DialableCellphoneNumber cellphone = contact.getContactCellphoneNumber();
961 DialableFaxNumber fax = contact.getContactFaxNumber();
962 DialableLandLineNumber phone = contact.getContactLandLineNumber();
965 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
966 this.setPhoneCountry(phone.getPhoneCountry());
967 this.setPhoneAreaCode(phone.getPhoneAreaCode());
968 this.setPhoneNumber(phone.getPhoneNumber());
971 if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) {
972 this.setCellphoneCarrier(cellphone.getCellphoneProvider());
973 this.setCellphoneNumber(cellphone.getPhoneNumber());
976 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
977 this.setFaxCountry(fax.getPhoneCountry());
978 this.setFaxAreaCode(fax.getPhoneAreaCode());
979 this.setFaxNumber(fax.getPhoneNumber());
984 * Removes given contact from all lists
986 * @param contact Contact instance to remove
988 private void removeContact (final Contact contact) {
989 // Is the instance valid?
990 if (null == contact) {
992 throw new NullPointerException("contact is null"); //NOI18N
993 } else if (contact.getContactId() == null) {
995 throw new NullPointerException("contact.contactId is null"); //NOI18N
996 } else if (contact.getContactId() < 1) {
997 // Not valid id number
998 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1001 // Remove from general list
1002 if (!this.contactList.remove(contact)) {
1003 // Did not remove contact
1004 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
1007 // Remove from other lists
1008 this.emailAddressList.remove(contact.getContactEmailAddress());