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.Date;
21 import java.util.Iterator;
22 import java.util.List;
23 import java.util.Objects;
24 import javax.annotation.PostConstruct;
25 import javax.enterprise.context.SessionScoped;
26 import javax.enterprise.event.Observes;
27 import javax.faces.view.facelets.FaceletException;
28 import javax.inject.Inject;
29 import javax.inject.Named;
30 import javax.naming.Context;
31 import javax.naming.InitialContext;
32 import javax.naming.NamingException;
33 import org.mxchange.jcontacts.contact.Contact;
34 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
35 import org.mxchange.jcontacts.contact.UserContact;
36 import org.mxchange.jcontacts.contact.gender.Gender;
37 import org.mxchange.jcontacts.contact.utils.ContactUtils;
38 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
39 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
40 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
41 import org.mxchange.jcountry.data.Country;
42 import org.mxchange.jcustomercore.events.customer.added.AdminAddedCustomerEvent;
43 import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
44 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
45 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
46 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
47 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
48 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
49 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
50 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
51 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
52 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
53 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
54 import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController;
57 * A general contact bean (controller)
59 * @author Roland Haeder<roland@mxchange.org>
61 @Named ("contactController")
63 public class PizzaContactWebSessionBean implements PizzaContactWebSessionController {
68 private static final long serialVersionUID = 542_145_347_916L;
73 private Date birthday;
76 * Cellphone number's carrier
78 private MobileProvider cellphoneCarrier;
83 private Long cellphoneNumber;
93 private String comment;
98 private final ContactSessionBeanRemote contactBean;
103 private List<Contact> contactList;
108 private Country country;
113 private String emailAddress;
118 private List<String> emailAddressList;
121 * Email address repeated
123 private String emailAddressRepeat;
128 private String familyName;
131 * Fax number's area code
133 private Integer faxAreaCode;
136 * Country instance for fax number
138 private Country faxCountry;
143 private Long faxNumber;
148 private String firstName;
153 private Gender gender;
158 private Short houseNumber;
161 * Whether a cellphone entry has been unlinked
163 private boolean isCellphoneUnlinked;
166 * Whether a fax entry has been unlinked
168 private boolean isFaxUnlinked;
171 * Whether a land-line number has been unlinked
173 private boolean isLandLineUnlinked;
176 * Login bean (controller)
179 private PizzaUserLoginWebSessionController userLoginController;
182 * Phone number area code
184 private Integer phoneAreaCode;
187 * Country instance for phone number
189 private Country phoneCountry;
194 private Long phoneNumber;
199 private String street;
204 private Integer zipCode;
207 * Default constructor
209 public PizzaContactWebSessionBean () {
212 // Get initial context
213 Context context = new InitialContext();
216 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/PizzaService-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
217 } catch (final NamingException e) {
219 throw new FaceletException(e);
224 public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) {
225 // The event must be valid
228 throw new NullPointerException("event is null"); //NOI18N
229 } else if (event.getAddedContact() == null) {
231 throw new NullPointerException("event.addedContact is null"); //NOI18N
232 } else if (event.getAddedContact().getContactId() == null) {
234 throw new NullPointerException("event.addedContact.customerId is null"); //NOI18N
235 } else if (event.getAddedContact().getContactId() < 1) {
237 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.customerId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
244 this.contactList.add(event.getAddedContact());
248 public void afterAdminAddedCustomer (@Observes final AdminAddedCustomerEvent event) {
249 // The event must be valid
252 throw new NullPointerException("event is null"); //NOI18N
253 } else if (event.getAddedCustomer() == null) {
255 throw new NullPointerException("event.addedCustomer is null"); //NOI18N
256 } else if (event.getAddedCustomer().getCustomerId() == null) {
258 throw new NullPointerException("event.addedCustomer.customerId is null"); //NOI18N
259 } else if (event.getAddedCustomer().getCustomerId() < 1) {
261 throw new IllegalArgumentException(MessageFormat.format("event.addedCustomer.customerId={0} is not valid", event.getAddedCustomer().getCustomerId())); //NOI18N //NOI18N
268 this.contactList.add(event.getAddedCustomer().getCustomerContact());
272 public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
274 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminAddedUserEvent: event={0} - CALLED!", event)); //NOI18N
276 // event should not be null
279 throw new NullPointerException("event is null"); //NOI18N
280 } else if (event.getAddedUser() == null) {
282 throw new NullPointerException("event.addedUser is null"); //NOI18N
283 } else if (event.getAddedUser().getUserId() == null) {
285 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
286 } else if (event.getAddedUser().getUserId() < 1) {
288 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
295 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminAddedUserEvent: EXIT!"); //NOI18N
299 public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
301 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
303 // event should not be null
306 throw new NullPointerException("event is null"); //NOI18N
307 } else if (event.getUpdatedContact() == null) {
309 throw new NullPointerException("event.updatedUser is null"); //NOI18N
310 } else if (event.getUpdatedContact().getContactId() == null) {
312 throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
313 } else if (event.getUpdatedContact().getContactId() < 1) {
315 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
318 // Get iterator from list
319 Iterator<Contact> iterator = this.contactList.iterator();
321 // "Walk" through all entries
322 while (iterator.hasNext()) {
324 Contact next = iterator.next();
326 // Is id number the same?
327 if (Objects.equals(event.getUpdatedContact().getContactId(), next.getContactId())) {
328 // Found entry, so remove it and abort
329 this.contactList.remove(next);
331 // Remove also email from list
332 this.emailAddressList.remove(next.getContactEmailAddress());
337 // Add contact to list
338 this.contactList.add(event.getUpdatedContact());
340 // Add email address to list
341 this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
345 public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
347 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
349 // event should not be null
352 throw new NullPointerException("event is null"); //NOI18N
353 } else if (event.getRegisteredUser() == null) {
355 throw new NullPointerException("event.user is null"); //NOI18N
356 } else if (event.getRegisteredUser().getUserId() == null) {
358 throw new NullPointerException("event.user.userId is null"); //NOI18N
359 } else if (event.getRegisteredUser().getUserId() < 1) {
361 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
365 Contact registeredContact = event.getRegisteredUser().getUserContact();
368 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: registeredContact={0}", registeredContact)); //NOI18N
369 // Copy all data from registered->user
370 this.copyContact(registeredContact);
372 // Add user name and email address
373 this.addUserNameEmailAddress(registeredContact);
379 //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterRegistration: EXIT!"); //NOI18N
383 public void afterUserLogin (@Observes final UserLoggedInEvent event) {
385 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
387 // event should not be null
390 throw new NullPointerException("event is null"); //NOI18N
391 } else if (event.getLoggedInUser() == null) {
393 throw new NullPointerException("event.user is null"); //NOI18N
394 } else if (event.getLoggedInUser().getUserId() == null) {
396 throw new NullPointerException("event.user.userId is null"); //NOI18N
397 } else if (event.getLoggedInUser().getUserId() < 1) {
399 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
402 // Copy all data to this bean
403 this.copyContact(event.getLoggedInUser().getUserContact());
406 //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N
410 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
411 public List<Contact> allContacts () {
413 /* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size()));
415 // Return un-modified list
416 return this.contactList;
420 public Contact createContactInstance () {
422 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName()));
424 // Is all required data set?
425 if (!this.isRequiredPersonalDataSet()) {
426 // No, then abort here
427 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
430 // Required personal data must be set
431 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
433 // Generate phone number
434 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
435 DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
436 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
438 // Create new contact
439 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
440 contact.setContactStreet(this.getStreet());
441 contact.setContactHouseNumber(this.getHouseNumber());
442 contact.setContactZipCode(this.getZipCode());
443 contact.setContactCity(this.getCity());
444 contact.setContactCountry(this.getCountry());
445 contact.setContactEmailAddress(this.getEmailAddress());
446 contact.setContactBirthday(this.getBirthday());
447 contact.setContactComment(this.getComment());
450 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
451 // Don't set null or wrong references
452 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
453 // Now the number must be given
454 if (phone.getPhoneAreaCode() == null) {
456 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
457 } else if (phone.getPhoneAreaCode() < 1) {
459 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
460 } else if (phone.getPhoneNumber() == null) {
462 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
463 } else if (phone.getPhoneNumber() < 1) {
465 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
469 contact.setContactLandLineNumber(phone);
472 // Don't set null or wrong references
473 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
474 // Now the number must be given
475 if (fax.getPhoneAreaCode() == null) {
477 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
478 } else if (fax.getPhoneAreaCode() < 1) {
480 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
481 } else if (fax.getPhoneNumber() == null) {
483 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
484 } else if (fax.getPhoneNumber() < 1) {
486 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
490 contact.setContactFaxNumber(fax);
493 // Is the provider set?
494 if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
495 // Is the number set?
496 if (cellphone.getPhoneNumber() == null) {
498 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
499 } else if (cellphone.getPhoneNumber() < 1) {
501 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
504 // Set cellphone number
505 contact.setContactCellphoneNumber(cellphone);
509 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
516 public String doChangePersonalContactData () {
517 // This method shall only be called if the user is logged-in
518 if (!this.userLoginController.isUserLoggedIn()) {
520 throw new IllegalStateException("User is not logged-in"); //NOI18N
521 } else if (!this.isRequiredChangePersonalDataSet()) {
522 // Not all required fields are set
523 throw new FaceletException("Not all required fields are set."); //NOI18N
524 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
525 // Password not matching
526 throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()));
529 // Get contact instance
530 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
532 // It should be there, so run some tests on it
533 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
534 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
535 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
538 contact.setContactGender(this.getGender());
539 contact.setContactFirstName(this.getFirstName());
540 contact.setContactFamilyName(this.getFamilyName());
541 contact.setContactStreet(this.getStreet());
542 contact.setContactHouseNumber(this.getHouseNumber());
543 contact.setContactZipCode(this.getZipCode());
544 contact.setContactCity(this.getCity());
545 contact.setContactCountry(this.getCountry());
547 // Update contact's cellphone number
548 this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
550 // Update contact's land-line number
551 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
553 // Update contact's fax number
554 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
556 // Send it to the EJB
557 this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
560 return "contact_data_saved"; //NOI18N
564 @SuppressWarnings ("ReturnOfDateField")
565 public Date getBirthday () {
566 return this.birthday;
570 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
571 public void setBirthday (final Date birthday) {
572 this.birthday = birthday;
576 public MobileProvider getCellphoneCarrier () {
577 return this.cellphoneCarrier;
581 public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
582 this.cellphoneCarrier = cellphoneCarrier;
586 public Long getCellphoneNumber () {
587 return this.cellphoneNumber;
591 public void setCellphoneNumber (Long cellphoneNumber) {
592 this.cellphoneNumber = cellphoneNumber;
596 public String getCity () {
601 public void setCity (final String city) {
606 public String getComment () {
611 public void setComment (final String comment) {
612 this.comment = comment;
616 public Country getCountry () {
621 public void setCountry (final Country country) {
622 this.country = country;
626 public String getEmailAddress () {
627 return this.emailAddress;
631 public void setEmailAddress (final String emailAddress) {
632 this.emailAddress = emailAddress;
636 public String getEmailAddressRepeat () {
637 return this.emailAddressRepeat;
641 public void setEmailAddressRepeat (final String emailAddressRepeat) {
642 this.emailAddressRepeat = emailAddressRepeat;
646 public String getFamilyName () {
647 return this.familyName;
651 public void setFamilyName (final String familyName) {
652 this.familyName = familyName;
656 public Integer getFaxAreaCode () {
657 return this.faxAreaCode;
661 public void setFaxAreaCode (final Integer faxAreaCode) {
662 this.faxAreaCode = faxAreaCode;
666 public Country getFaxCountry () {
667 return this.faxCountry;
671 public void setFaxCountry (final Country faxCountry) {
672 this.faxCountry = faxCountry;
676 public Long getFaxNumber () {
677 return this.faxNumber;
681 public void setFaxNumber (final Long faxNumber) {
682 this.faxNumber = faxNumber;
686 public String getFirstName () {
687 return this.firstName;
691 public void setFirstName (final String firstName) {
692 this.firstName = firstName;
696 public Gender getGender () {
701 public void setGender (final Gender gender) {
702 this.gender = gender;
706 public Short getHouseNumber () {
707 return this.houseNumber;
711 public void setHouseNumber (final Short houseNumber) {
712 this.houseNumber = houseNumber;
716 public Integer getPhoneAreaCode () {
717 return this.phoneAreaCode;
721 public void setPhoneAreaCode (final Integer phoneAreaCode) {
722 this.phoneAreaCode = phoneAreaCode;
726 public Country getPhoneCountry () {
727 return this.phoneCountry;
731 public void setPhoneCountry (final Country phoneCountry) {
732 this.phoneCountry = phoneCountry;
736 public Long getPhoneNumber () {
737 return this.phoneNumber;
741 public void setPhoneNumber (final Long phoneNumber) {
742 this.phoneNumber = phoneNumber;
746 public String getStreet () {
751 public void setStreet (final String street) {
752 this.street = street;
756 public Integer getZipCode () {
761 public void setZipCode (final Integer zipCode) {
762 this.zipCode = zipCode;
766 public boolean hasContacts () {
767 return (!this.allContacts().isEmpty());
771 * Post-initialization of this class
774 public void init () {
775 // Get full email address list for reducing EJB calls
776 this.emailAddressList = this.contactBean.getEmailAddressList();
778 // Get full contact list
779 this.contactList = this.contactBean.getAllContacts();
783 public boolean isEmailAddressRegistered (final Contact contact) {
784 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
788 public boolean isRequiredChangePersonalDataSet () {
789 return ((this.getGender() != null) &&
790 (this.getFirstName() != null) &&
791 (this.getFamilyName() != null) &&
792 (this.getStreet() != null) &&
793 (this.getHouseNumber() != null) &&
794 (this.getZipCode() != null) &&
795 (this.getCity() != null));
799 public boolean isRequiredPersonalDataSet () {
800 return ((this.getGender() != null) &&
801 (this.getFirstName() != null) &&
802 (this.getFamilyName() != null) &&
803 (this.getStreet() != null) &&
804 (this.getHouseNumber() != null) &&
805 (this.getZipCode() != null) &&
806 (this.getCity() != null) &&
807 (this.getEmailAddress() != null) &&
808 (this.getEmailAddressRepeat() != null));
812 public boolean isSameEmailAddressEntered () {
813 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
817 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
819 Contact localContact = null;
824 // Try to lookup it in visible user list
825 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
827 Contact next = iterator.next();
829 // Is the user id found?
830 if (Objects.equals(next.getContactId(), contactId)) {
831 // Copy to other variable
838 if (null == localContact) {
839 // Not visible for the current user
840 throw new ContactNotFoundException(contactId);
843 // Copy all data to this bean
844 this.copyContact(localContact);
851 public void updateContactDataFromController (final Contact contact) {
852 // Is the instance valid?
853 if (null == contact) {
855 throw new NullPointerException("contact is null"); //NOI18N
856 } else if (contact.getContactId() == null) {
858 throw new NullPointerException("contact.contactId is null"); //NOI18N
859 } else if (contact.getContactId() < 1) {
860 // Not valid id number
861 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
865 this.copyContact(contact);
869 * Adds email address to bean's internal list.
871 * @param contact Contact instance
873 private void addUserNameEmailAddress (final Contact contact) {
874 // Make sure the entry is not added yet
875 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
877 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
881 this.emailAddressList.add(contact.getContactEmailAddress());
887 private void clear () {
890 this.setGender(Gender.UNKNOWN);
891 this.setFirstName(null);
892 this.setFamilyName(null);
893 this.setStreet(null);
894 this.setHouseNumber(null);
895 this.setZipCode(null);
897 this.setCountry(null);
900 this.setEmailAddress(null);
901 this.setEmailAddressRepeat(null);
902 this.setPhoneCountry(null);
903 this.setPhoneAreaCode(null);
904 this.setPhoneNumber(null);
905 this.setCellphoneCarrier(null);
906 this.setCellphoneNumber(null);
907 this.setFaxCountry(null);
908 this.setFaxAreaCode(null);
909 this.setFaxNumber(null);
912 this.setBirthday(null);
913 this.setComment(null);
917 * Copies given contact into the controller
919 * @param contact Contact instance
921 private void copyContact (final Contact contact) {
922 // Is the instance valid?
923 if (null == contact) {
925 throw new NullPointerException("contact is null"); //NOI18N
926 } else if (contact.getContactId() == null) {
928 throw new NullPointerException("contact.contactId is null"); //NOI18N
929 } else if (contact.getContactId() < 1) {
930 // Not valid id number
931 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
936 this.setGender(contact.getContactGender());
937 this.setFirstName(contact.getContactFirstName());
938 this.setFamilyName(contact.getContactFamilyName());
939 this.setStreet(contact.getContactStreet());
940 this.setHouseNumber(contact.getContactHouseNumber());
941 this.setZipCode(contact.getContactZipCode());
942 this.setCity(contact.getContactCity());
943 this.setCountry(contact.getContactCountry());
944 this.setEmailAddress(contact.getContactEmailAddress());
945 this.setBirthday(contact.getContactBirthday());
946 this.setComment(contact.getContactComment());
948 // Get cellphone, phone and fax instance
949 DialableCellphoneNumber cellphone = contact.getContactCellphoneNumber();
950 DialableFaxNumber fax = contact.getContactFaxNumber();
951 DialableLandLineNumber phone = contact.getContactLandLineNumber();
954 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
955 this.setPhoneCountry(phone.getPhoneCountry());
956 this.setPhoneAreaCode(phone.getPhoneAreaCode());
957 this.setPhoneNumber(phone.getPhoneNumber());
960 if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) {
961 this.setCellphoneCarrier(cellphone.getCellphoneProvider());
962 this.setCellphoneNumber(cellphone.getPhoneNumber());
965 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
966 this.setFaxCountry(fax.getPhoneCountry());
967 this.setFaxAreaCode(fax.getPhoneAreaCode());
968 this.setFaxNumber(fax.getPhoneNumber());
973 * Removes given contact from all lists
975 * @param contact Contact instance to remove
977 private void removeContact (final Contact contact) {
978 // Is the instance valid?
979 if (null == contact) {
981 throw new NullPointerException("contact is null"); //NOI18N
982 } else if (contact.getContactId() == null) {
984 throw new NullPointerException("contact.contactId is null"); //NOI18N
985 } else if (contact.getContactId() < 1) {
986 // Not valid id number
987 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
990 // Remove from general list
991 if (!this.contactList.remove(contact)) {
992 // Did not remove contact
993 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
996 // Remove from other lists
997 this.emailAddressList.remove(contact.getContactEmailAddress());