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.login.JobsUserLoginWebSessionController;
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;
57 * A general contact bean (controller)
59 * @author Roland Haeder<roland@mxchange.org>
61 @Named ("contactController")
63 public class JobsContactWebSessionBean implements JobsContactWebSessionController {
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 * Phone number area code
178 private Integer phoneAreaCode;
181 * Country instance for phone number
183 private Country phoneCountry;
188 private Long phoneNumber;
193 private String street;
196 * Login bean (controller)
199 private JobsUserLoginWebSessionController userLoginController;
204 private Integer zipCode;
207 * Default constructor
209 public JobsContactWebSessionBean () {
212 // Get initial context
213 Context context = new InitialContext();
216 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jratecalc-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 afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
250 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminAddedUserEvent: event={0} - CALLED!", event)); //NOI18N
252 // event should not be null
255 throw new NullPointerException("event is null"); //NOI18N
256 } else if (event.getAddedUser() == null) {
258 throw new NullPointerException("event.addedUser is null"); //NOI18N
259 } else if (event.getAddedUser().getUserId() == null) {
261 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
262 } else if (event.getAddedUser().getUserId() < 1) {
264 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
271 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminAddedUserEvent: EXIT!"); //NOI18N
275 public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
277 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
279 // event should not be null
282 throw new NullPointerException("event is null"); //NOI18N
283 } else if (event.getUpdatedContact() == null) {
285 throw new NullPointerException("event.updatedUser is null"); //NOI18N
286 } else if (event.getUpdatedContact().getContactId() == null) {
288 throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
289 } else if (event.getUpdatedContact().getContactId() < 1) {
291 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
294 // Get iterator from list
295 Iterator<Contact> iterator = this.contactList.iterator();
297 // "Walk" through all entries
298 while (iterator.hasNext()) {
300 Contact next = iterator.next();
302 // Is id number the same?
303 if (Objects.equals(event.getUpdatedContact().getContactId(), next.getContactId())) {
304 // Found entry, so remove it and abort
305 this.contactList.remove(next);
307 // Remove also email from list
308 this.emailAddressList.remove(next.getContactEmailAddress());
313 // Add contact to list
314 this.contactList.add(event.getUpdatedContact());
316 // Add email address to list
317 this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
321 public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
323 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
325 // event should not be null
328 throw new NullPointerException("event is null"); //NOI18N
329 } else if (event.getRegisteredUser() == null) {
331 throw new NullPointerException("event.user is null"); //NOI18N
332 } else if (event.getRegisteredUser().getUserId() == null) {
334 throw new NullPointerException("event.user.userId is null"); //NOI18N
335 } else if (event.getRegisteredUser().getUserId() < 1) {
337 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
341 Contact registeredContact = event.getRegisteredUser().getUserContact();
344 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: registeredContact={0}", registeredContact)); //NOI18N
345 // Copy all data from registered->user
346 this.copyContact(registeredContact);
348 // Add user name and email address
349 this.addUserNameEmailAddress(registeredContact);
355 //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterRegistration: EXIT!"); //NOI18N
359 public void afterUserLogin (@Observes final UserLoggedInEvent event) {
361 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
363 // event should not be null
366 throw new NullPointerException("event is null"); //NOI18N
367 } else if (event.getLoggedInUser() == null) {
369 throw new NullPointerException("event.user is null"); //NOI18N
370 } else if (event.getLoggedInUser().getUserId() == null) {
372 throw new NullPointerException("event.user.userId is null"); //NOI18N
373 } else if (event.getLoggedInUser().getUserId() < 1) {
375 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
378 // Copy all data to this bean
379 this.copyContact(event.getLoggedInUser().getUserContact());
382 //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N
386 public List<Contact> allContacts () {
388 /* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size()));
390 // Return un-modified list
391 return Collections.unmodifiableList(this.contactList);
395 public Contact createContactInstance () {
397 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName()));
399 // Is all required data set?
400 if (!this.isRequiredPersonalDataSet()) {
401 // No, then abort here
402 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
405 // Required personal data must be set
406 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
408 // Create new contact instance
409 Contact localContact = new UserContact();
411 // Generate phone number
412 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
413 DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
414 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
416 // Create new contact
417 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
418 contact.setContactStreet(this.getStreet());
419 contact.setContactHouseNumber(this.getHouseNumber());
420 contact.setContactZipCode(this.getZipCode());
421 contact.setContactCity(this.getCity());
422 contact.setContactCountry(this.getCountry());
423 contact.setContactEmailAddress(this.getEmailAddress());
424 contact.setContactBirthday(this.getBirthday());
425 contact.setContactComment(this.getComment());
428 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
429 // Don't set null or wrong references
430 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
431 // Now the number must be given
432 if (phone.getPhoneAreaCode() == null) {
434 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
435 } else if (phone.getPhoneAreaCode() < 1) {
437 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
438 } else if (phone.getPhoneNumber() == null) {
440 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
441 } else if (phone.getPhoneNumber() < 1) {
443 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
447 contact.setContactLandLineNumber(phone);
450 // Don't set null or wrong references
451 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
452 // Now the number must be given
453 if (fax.getPhoneAreaCode() == null) {
455 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
456 } else if (fax.getPhoneAreaCode() < 1) {
458 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
459 } else if (fax.getPhoneNumber() == null) {
461 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
462 } else if (fax.getPhoneNumber() < 1) {
464 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
468 contact.setContactFaxNumber(fax);
471 // Is the provider set?
472 if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
473 // Is the number set?
474 if (cellphone.getPhoneNumber() == null) {
476 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
477 } else if (cellphone.getPhoneNumber() < 1) {
479 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
482 // Set cellphone number
483 contact.setContactCellphoneNumber(cellphone);
487 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
494 public String doChangePersonalContactData () {
495 // This method shall only be called if the user is logged-in
496 if (!this.userLoginController.isUserLoggedIn()) {
498 throw new IllegalStateException("User is not logged-in"); //NOI18N
499 } else if (!this.isRequiredChangePersonalDataSet()) {
500 // Not all required fields are set
501 throw new FaceletException("Not all required fields are set."); //NOI18N
502 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
503 // Password not matching
504 throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()));
507 // Get contact instance
508 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
510 // It should be there, so run some tests on it
511 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
512 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
513 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
516 contact.setContactGender(this.getGender());
517 contact.setContactFirstName(this.getFirstName());
518 contact.setContactFamilyName(this.getFamilyName());
519 contact.setContactStreet(this.getStreet());
520 contact.setContactHouseNumber(this.getHouseNumber());
521 contact.setContactZipCode(this.getZipCode());
522 contact.setContactCity(this.getCity());
523 contact.setContactCountry(this.getCountry());
525 // Update contact's cellphone number
526 this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
528 // Update contact's land-line number
529 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
531 // Update contact's fax number
532 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
534 // Send it to the EJB
535 this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
538 return "contact_data_saved"; //NOI18N
542 @SuppressWarnings ("ReturnOfDateField")
543 public Date getBirthday () {
544 return this.birthday;
548 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
549 public void setBirthday (final Date birthday) {
550 this.birthday = birthday;
554 public MobileProvider getCellphoneCarrier () {
555 return this.cellphoneCarrier;
559 public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
560 this.cellphoneCarrier = cellphoneCarrier;
564 public Long getCellphoneNumber () {
565 return this.cellphoneNumber;
569 public void setCellphoneNumber (Long cellphoneNumber) {
570 this.cellphoneNumber = cellphoneNumber;
574 public String getCity () {
579 public void setCity (final String city) {
584 public String getComment () {
589 public void setComment (final String comment) {
590 this.comment = comment;
594 public Country getCountry () {
599 public void setCountry (final Country country) {
600 this.country = country;
604 public String getEmailAddress () {
605 return this.emailAddress;
609 public void setEmailAddress (final String emailAddress) {
610 this.emailAddress = emailAddress;
614 public String getEmailAddressRepeat () {
615 return this.emailAddressRepeat;
619 public void setEmailAddressRepeat (final String emailAddressRepeat) {
620 this.emailAddressRepeat = emailAddressRepeat;
624 public String getFamilyName () {
625 return this.familyName;
629 public void setFamilyName (final String familyName) {
630 this.familyName = familyName;
634 public Integer getFaxAreaCode () {
635 return this.faxAreaCode;
639 public void setFaxAreaCode (final Integer faxAreaCode) {
640 this.faxAreaCode = faxAreaCode;
644 public Country getFaxCountry () {
645 return this.faxCountry;
649 public void setFaxCountry (final Country faxCountry) {
650 this.faxCountry = faxCountry;
654 public Long getFaxNumber () {
655 return this.faxNumber;
659 public void setFaxNumber (final Long faxNumber) {
660 this.faxNumber = faxNumber;
664 public String getFirstName () {
665 return this.firstName;
669 public void setFirstName (final String firstName) {
670 this.firstName = firstName;
674 public Gender getGender () {
679 public void setGender (final Gender gender) {
680 this.gender = gender;
684 public Short getHouseNumber () {
685 return this.houseNumber;
689 public void setHouseNumber (final Short houseNumber) {
690 this.houseNumber = houseNumber;
694 public Integer getPhoneAreaCode () {
695 return this.phoneAreaCode;
699 public void setPhoneAreaCode (final Integer phoneAreaCode) {
700 this.phoneAreaCode = phoneAreaCode;
704 public Country getPhoneCountry () {
705 return this.phoneCountry;
709 public void setPhoneCountry (final Country phoneCountry) {
710 this.phoneCountry = phoneCountry;
714 public Long getPhoneNumber () {
715 return this.phoneNumber;
719 public void setPhoneNumber (final Long phoneNumber) {
720 this.phoneNumber = phoneNumber;
724 public String getStreet () {
729 public void setStreet (final String street) {
730 this.street = street;
734 public Integer getZipCode () {
739 public void setZipCode (final Integer zipCode) {
740 this.zipCode = zipCode;
744 public boolean hasContacts () {
745 return (!this.contactList.isEmpty());
749 * Post-initialization of this class
752 public void init () {
753 // Get full email address list for reducing EJB calls
754 this.emailAddressList = this.contactBean.getEmailAddressList();
756 // Get full contact list
757 this.contactList = this.contactBean.getAllContacts();
761 public boolean isEmailAddressRegistered (final Contact contact) {
763 if (null == contact) {
765 throw new NullPointerException("contact is null"); //NOI18N
766 } else if (contact.getContactEmailAddress() == null) {
768 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
769 } else if (contact.getContactEmailAddress().isEmpty()) {
771 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
775 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
779 public boolean isRequiredChangePersonalDataSet () {
780 return ((this.getGender() != null) &&
781 (this.getFirstName() != null) &&
782 (this.getFamilyName() != null) &&
783 (this.getStreet() != null) &&
784 (this.getHouseNumber() != null) &&
785 (this.getZipCode() != null) &&
786 (this.getCity() != null));
790 public boolean isRequiredPersonalDataSet () {
791 return ((this.getGender() != null) &&
792 (this.getFirstName() != null) &&
793 (this.getFamilyName() != null) &&
794 (this.getStreet() != null) &&
795 (this.getHouseNumber() != null) &&
796 (this.getZipCode() != null) &&
797 (this.getCity() != null) &&
798 (this.getEmailAddress() != null) &&
799 (this.getEmailAddressRepeat() != null));
803 public boolean isSameEmailAddressEntered () {
804 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
808 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
810 Contact localContact = null;
815 // Try to lookup it in visible user list
816 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
818 Contact next = iterator.next();
820 // Is the user id found?
821 if (Objects.equals(next.getContactId(), contactId)) {
822 // Copy to other variable
829 if (null == localContact) {
830 // Not visible for the current user
831 throw new ContactNotFoundException(contactId);
834 // Copy all data to this bean
835 this.copyContact(localContact);
842 public void updateContactDataFromController (final Contact contact) {
843 // Is the instance valid?
844 if (null == contact) {
846 throw new NullPointerException("contact is null"); //NOI18N
847 } else if (contact.getContactId() == null) {
849 throw new NullPointerException("contact.contactId is null"); //NOI18N
850 } else if (contact.getContactId() < 1) {
851 // Not valid id number
852 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
856 this.copyContact(contact);
860 * Adds email address to bean's internal list.
862 * @param contact Contact instance
864 private void addUserNameEmailAddress (final Contact contact) {
865 // Make sure the entry is not added yet
866 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
868 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
872 this.emailAddressList.add(contact.getContactEmailAddress());
878 private void clear () {
881 this.setGender(Gender.UNKNOWN);
882 this.setFirstName(null);
883 this.setFamilyName(null);
884 this.setStreet(null);
885 this.setHouseNumber(null);
886 this.setZipCode(null);
888 this.setCountry(null);
891 this.setEmailAddress(null);
892 this.setEmailAddressRepeat(null);
893 this.setPhoneAreaCode(null);
894 this.setCellphoneCarrier(null);
895 this.setFaxAreaCode(null);
898 this.setBirthday(null);
899 this.setComment(null);
903 * Copies given contact into the controller
905 * @param contact Contact instance
907 private void copyContact (final Contact contact) {
908 // Is the instance valid?
909 if (null == contact) {
911 throw new NullPointerException("contact is null"); //NOI18N
912 } else if (contact.getContactId() == null) {
914 throw new NullPointerException("contact.contactId is null"); //NOI18N
915 } else if (contact.getContactId() < 1) {
916 // Not valid id number
917 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
922 this.setGender(contact.getContactGender());
923 this.setFirstName(contact.getContactFirstName());
924 this.setFamilyName(contact.getContactFamilyName());
925 this.setStreet(contact.getContactStreet());
926 this.setHouseNumber(contact.getContactHouseNumber());
927 this.setZipCode(contact.getContactZipCode());
928 this.setCity(contact.getContactCity());
929 this.setCountry(contact.getContactCountry());
930 this.setEmailAddress(contact.getContactEmailAddress());
931 this.setBirthday(contact.getContactBirthday());
932 this.setComment(contact.getContactComment());
934 // Get cellphone, phone and fax instance
935 DialableCellphoneNumber cellphone = contact.getContactCellphoneNumber();
936 DialableFaxNumber fax = contact.getContactFaxNumber();
937 DialableLandLineNumber phone = contact.getContactLandLineNumber();
940 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
941 this.setPhoneCountry(phone.getPhoneCountry());
942 this.setPhoneAreaCode(phone.getPhoneAreaCode());
943 this.setPhoneNumber(phone.getPhoneNumber());
946 if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) {
947 this.setCellphoneCarrier(cellphone.getCellphoneProvider());
948 this.setCellphoneNumber(cellphone.getPhoneNumber());
951 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
952 this.setFaxCountry(fax.getPhoneCountry());
953 this.setFaxAreaCode(fax.getPhoneAreaCode());
954 this.setFaxNumber(fax.getPhoneNumber());
959 * Removes given contact from all lists
961 * @param contact Contact instance to remove
963 private void removeContact (final Contact contact) {
964 // Is the instance valid?
965 if (null == contact) {
967 throw new NullPointerException("contact is null"); //NOI18N
968 } else if (contact.getContactId() == null) {
970 throw new NullPointerException("contact.contactId is null"); //NOI18N
971 } else if (contact.getContactId() < 1) {
972 // Not valid id number
973 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
976 // Remove from general list
977 if (!this.contactList.remove(contact)) {
978 // Did not remove contact
979 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
982 // Remove from other lists
983 this.emailAddressList.remove(contact.getContactEmailAddress());