2 * Copyright (C) 2016 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.addressbook.beans.contact;
19 import java.text.MessageFormat;
20 import java.util.Collections;
21 import java.util.Date;
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.Objects;
25 import javax.annotation.PostConstruct;
26 import javax.enterprise.context.SessionScoped;
27 import javax.enterprise.event.Observes;
28 import javax.faces.view.facelets.FaceletException;
29 import javax.inject.Inject;
30 import javax.inject.Named;
31 import javax.naming.Context;
32 import javax.naming.InitialContext;
33 import javax.naming.NamingException;
34 import org.mxchange.addressbook.beans.login.AddressbookUserLoginWebSessionController;
35 import org.mxchange.jcontacts.contact.Contact;
36 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
37 import org.mxchange.jcontacts.contact.UserContact;
38 import org.mxchange.jcontacts.contact.gender.Gender;
39 import org.mxchange.jcontacts.contact.utils.ContactUtils;
40 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
41 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
42 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
43 import org.mxchange.jcountry.data.Country;
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 AddressbookContactWebSessionBean implements AddressbookContactWebSessionController {
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 AddressbookUserLoginWebSessionController loginController;
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 AddressbookContactWebSessionBean () {
212 // Get initial context
213 Context context = new InitialContext();
216 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/addressbook-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.user is null"); //NOI18N
286 } else if (event.getUpdatedContact().getContactId() == null) {
288 throw new NullPointerException("event.user.userId is null"); //NOI18N
289 } else if (event.getUpdatedContact().getContactId() < 1) {
291 throw new IllegalArgumentException(MessageFormat.format("userId of user={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 (final @Observes 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
346 // Copy all data from registered->user
347 this.copyContact(registeredContact);
349 // Add user name and email address
350 this.addUserNameEmailAddress(registeredContact);
356 //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterRegistration: EXIT!"); //NOI18N
360 public void afterUserLogin (final @Observes UserLoggedInEvent event) {
362 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
364 // event should not be null
367 throw new NullPointerException("event is null"); //NOI18N
368 } else if (event.getLoggedInUser() == null) {
370 throw new NullPointerException("event.user is null"); //NOI18N
371 } else if (event.getLoggedInUser().getUserId() == null) {
373 throw new NullPointerException("event.user.userId is null"); //NOI18N
374 } else if (event.getLoggedInUser().getUserId() < 1) {
376 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
379 // Copy all data to this bean
380 this.copyContact(event.getLoggedInUser().getUserContact());
383 //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N
387 public List<Contact> allContacts () {
389 /* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size()));
391 // Return un-modified list
392 return Collections.unmodifiableList(this.contactList);
396 public Contact createContactInstance () {
398 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName()));
400 // Is all required data set?
401 if (!this.isRequiredPersonalDataSet()) {
402 // No, then abort here
403 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
406 // Required personal data must be set
407 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
409 // Create new contact instance
410 Contact localContact = new UserContact();
412 // Generate phone number
413 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
414 DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
415 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
417 // Create new contact
418 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
419 contact.setContactStreet(this.getStreet());
420 contact.setContactHouseNumber(this.getHouseNumber());
421 contact.setContactZipCode(this.getZipCode());
422 contact.setContactCity(this.getCity());
423 contact.setContactCountry(this.getCountry());
424 contact.setContactEmailAddress(this.getEmailAddress());
425 contact.setContactBirthday(this.getBirthday());
426 contact.setContactComment(this.getComment());
429 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
430 // Don't set null or wrong references
431 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
432 // Now the number must be given
433 if (phone.getPhoneAreaCode() == null) {
435 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
436 } else if (phone.getPhoneAreaCode() < 1) {
438 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
439 } else if (phone.getPhoneNumber() == null) {
441 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
442 } else if (phone.getPhoneNumber() < 1) {
444 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
448 contact.setContactLandLineNumber(phone);
451 // Don't set null or wrong references
452 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
453 // Now the number must be given
454 if (fax.getPhoneAreaCode() == null) {
456 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
457 } else if (fax.getPhoneAreaCode() < 1) {
459 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
460 } else if (fax.getPhoneNumber() == null) {
462 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
463 } else if (fax.getPhoneNumber() < 1) {
465 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
469 contact.setContactFaxNumber(fax);
472 // Is the provider set?
473 if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
474 // Is the number set?
475 if (cellphone.getPhoneNumber() == null) {
477 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
478 } else if (cellphone.getPhoneNumber() < 1) {
480 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
483 // Set cellphone number
484 contact.setContactCellphoneNumber(cellphone);
488 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
495 public String doChangePersonalContactData () {
496 // This method shall only be called if the user is logged-in
497 if (!this.loginController.isUserLoggedIn()) {
499 throw new IllegalStateException("User is not logged-in"); //NOI18N
500 } else if (!this.isRequiredChangePersonalDataSet()) {
501 // Not all required fields are set
502 throw new FaceletException("Not all required fields are set."); //NOI18N
503 } else if (!this.loginController.ifCurrentPasswordMatches()) {
504 // Password not matching
505 throw new FaceletException(new UserPasswordMismatchException(this.loginController.getLoggedInUser()));
508 // Get contact instance
509 Contact contact = this.loginController.getLoggedInUser().getUserContact();
511 // It should be there, so run some tests on it
512 assert (contact instanceof Contact) : "Instance loginController.loggedInUser.userContact is null"; //NOI18N
513 assert (contact.getContactId() instanceof Long) : "Instance loginController.userContact.contactId is null"; //NOI18N
514 assert (contact.getContactId() > 0) : MessageFormat.format("Instance loginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
517 contact.setContactGender(this.getGender());
518 contact.setContactFirstName(this.getFirstName());
519 contact.setContactFamilyName(this.getFamilyName());
520 contact.setContactStreet(this.getStreet());
521 contact.setContactHouseNumber(this.getHouseNumber());
522 contact.setContactZipCode(this.getZipCode());
523 contact.setContactCity(this.getCity());
524 contact.setContactCountry(this.getCountry());
526 // Update contact's cellphone number
527 this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
529 // Update contact's land-line number
530 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
532 // Update contact's fax number
533 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
535 // Send it to the EJB
536 this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
539 return "contact_data_saved"; //NOI18N
543 @SuppressWarnings ("ReturnOfDateField")
544 public Date getBirthday () {
545 return this.birthday;
549 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
550 public void setBirthday (final Date birthday) {
551 this.birthday = birthday;
555 public MobileProvider getCellphoneCarrier () {
556 return this.cellphoneCarrier;
560 public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
561 this.cellphoneCarrier = cellphoneCarrier;
565 public Long getCellphoneNumber () {
566 return this.cellphoneNumber;
570 public void setCellphoneNumber (Long cellphoneNumber) {
571 this.cellphoneNumber = cellphoneNumber;
575 public String getCity () {
580 public void setCity (final String city) {
585 public String getComment () {
590 public void setComment (final String comment) {
591 this.comment = comment;
595 public Country getCountry () {
600 public void setCountry (final Country country) {
601 this.country = country;
605 public String getEmailAddress () {
606 return this.emailAddress;
610 public void setEmailAddress (final String emailAddress) {
611 this.emailAddress = emailAddress;
615 public String getEmailAddressRepeat () {
616 return this.emailAddressRepeat;
620 public void setEmailAddressRepeat (final String emailAddressRepeat) {
621 this.emailAddressRepeat = emailAddressRepeat;
625 public String getFamilyName () {
626 return this.familyName;
630 public void setFamilyName (final String familyName) {
631 this.familyName = familyName;
635 public Integer getFaxAreaCode () {
636 return this.faxAreaCode;
640 public void setFaxAreaCode (final Integer faxAreaCode) {
641 this.faxAreaCode = faxAreaCode;
645 public Country getFaxCountry () {
646 return this.faxCountry;
650 public void setFaxCountry (final Country faxCountry) {
651 this.faxCountry = faxCountry;
655 public Long getFaxNumber () {
656 return this.faxNumber;
660 public void setFaxNumber (final Long faxNumber) {
661 this.faxNumber = faxNumber;
665 public String getFirstName () {
666 return this.firstName;
670 public void setFirstName (final String firstName) {
671 this.firstName = firstName;
675 public Gender getGender () {
680 public void setGender (final Gender gender) {
681 this.gender = gender;
685 public Short getHouseNumber () {
686 return this.houseNumber;
690 public void setHouseNumber (final Short houseNumber) {
691 this.houseNumber = houseNumber;
695 public Integer getPhoneAreaCode () {
696 return this.phoneAreaCode;
700 public void setPhoneAreaCode (final Integer phoneAreaCode) {
701 this.phoneAreaCode = phoneAreaCode;
705 public Country getPhoneCountry () {
706 return this.phoneCountry;
710 public void setPhoneCountry (final Country phoneCountry) {
711 this.phoneCountry = phoneCountry;
715 public Long getPhoneNumber () {
716 return this.phoneNumber;
720 public void setPhoneNumber (final Long phoneNumber) {
721 this.phoneNumber = phoneNumber;
725 public String getStreet () {
730 public void setStreet (final String street) {
731 this.street = street;
735 public Integer getZipCode () {
740 public void setZipCode (final Integer zipCode) {
741 this.zipCode = zipCode;
745 public boolean hasContacts () {
746 return (!this.contactList.isEmpty());
750 * Post-initialization of this class
753 public void init () {
754 // Get full email address list for reducing EJB calls
755 this.emailAddressList = this.contactBean.getEmailAddressList();
757 // Get full contact list
758 this.contactList = this.contactBean.getAllContacts();
762 public boolean isEmailAddressRegistered (final Contact contact) {
764 if (null == contact) {
766 throw new NullPointerException("contact is null"); //NOI18N
767 } else if (contact.getContactEmailAddress() == null) {
769 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
770 } else if (contact.getContactEmailAddress().isEmpty()) {
772 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
776 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
780 public boolean isRequiredChangePersonalDataSet () {
781 return ((this.getGender() != null) &&
782 (this.getFirstName() != null) &&
783 (this.getFamilyName() != null) &&
784 (this.getStreet() != null) &&
785 (this.getHouseNumber() != null) &&
786 (this.getZipCode() != null) &&
787 (this.getCity() != null));
791 public boolean isRequiredPersonalDataSet () {
792 return ((this.getGender() != null) &&
793 (this.getFirstName() != null) &&
794 (this.getFamilyName() != null) &&
795 (this.getStreet() != null) &&
796 (this.getHouseNumber() != null) &&
797 (this.getZipCode() != null) &&
798 (this.getCity() != null) &&
799 (this.getEmailAddress() != null) &&
800 (this.getEmailAddressRepeat() != null));
804 public boolean isSameEmailAddressEntered () {
805 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
809 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
811 Contact localContact = null;
816 // Try to lookup it in visible user list
817 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
819 Contact next = iterator.next();
821 // Is the user id found?
822 if (Objects.equals(next.getContactId(), contactId)) {
823 // Copy to other variable
830 if (null == localContact) {
831 // Not visible for the current user
832 throw new ContactNotFoundException(contactId);
835 // Copy all data to this bean
836 this.copyContact(localContact);
843 public void updateContactDataFromController (final Contact contact) {
844 // Is the instance valid?
845 if (null == contact) {
847 throw new NullPointerException("contact is null"); //NOI18N
848 } else if (contact.getContactId() == null) {
850 throw new NullPointerException("contact.contactId is null"); //NOI18N
851 } else if (contact.getContactId() < 1) {
852 // Not valid id number
853 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
857 this.copyContact(contact);
861 * Adds email address to bean's internal list.
863 * @param contact Contact instance
865 private void addUserNameEmailAddress (final Contact contact) {
866 // Make sure the entry is not added yet
867 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
869 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
873 this.emailAddressList.add(contact.getContactEmailAddress());
879 private void clear () {
882 this.setGender(Gender.UNKNOWN);
883 this.setFirstName(null);
884 this.setFamilyName(null);
885 this.setStreet(null);
886 this.setHouseNumber(null);
887 this.setZipCode(null);
889 this.setCountry(null);
892 this.setEmailAddress(null);
893 this.setEmailAddressRepeat(null);
894 this.setPhoneAreaCode(null);
895 this.setCellphoneCarrier(null);
896 this.setFaxAreaCode(null);
899 this.setBirthday(null);
900 this.setComment(null);
904 * Copies given contact into the controller
906 * @param contact Contact instance
908 private void copyContact (final Contact contact) {
909 // Is the instance valid?
910 if (null == contact) {
912 throw new NullPointerException("contact is null"); //NOI18N
913 } else if (contact.getContactId() == null) {
915 throw new NullPointerException("contact.contactId is null"); //NOI18N
916 } else if (contact.getContactId() < 1) {
917 // Not valid id number
918 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
923 this.setGender(contact.getContactGender());
924 this.setFirstName(contact.getContactFirstName());
925 this.setFamilyName(contact.getContactFamilyName());
926 this.setStreet(contact.getContactStreet());
927 this.setHouseNumber(contact.getContactHouseNumber());
928 this.setZipCode(contact.getContactZipCode());
929 this.setCity(contact.getContactCity());
930 this.setCountry(contact.getContactCountry());
931 this.setEmailAddress(contact.getContactEmailAddress());
932 this.setBirthday(contact.getContactBirthday());
933 this.setComment(contact.getContactComment());
935 // Get cellphone, phone and fax instance
936 DialableCellphoneNumber cellphone = contact.getContactCellphoneNumber();
937 DialableFaxNumber fax = contact.getContactFaxNumber();
938 DialableLandLineNumber phone = contact.getContactLandLineNumber();
941 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
942 this.setPhoneCountry(phone.getPhoneCountry());
943 this.setPhoneAreaCode(phone.getPhoneAreaCode());
944 this.setPhoneNumber(phone.getPhoneNumber());
947 if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) {
948 this.setCellphoneCarrier(cellphone.getCellphoneProvider());
949 this.setCellphoneNumber(cellphone.getPhoneNumber());
952 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
953 this.setFaxCountry(fax.getPhoneCountry());
954 this.setFaxAreaCode(fax.getPhoneAreaCode());
955 this.setFaxNumber(fax.getPhoneNumber());
960 * Removes given contact from all lists
962 * @param contact Contact instance to remove
964 private void removeContact (final Contact contact) {
965 // Is the instance valid?
966 if (null == contact) {
968 throw new NullPointerException("contact is null"); //NOI18N
969 } else if (contact.getContactId() == null) {
971 throw new NullPointerException("contact.contactId is null"); //NOI18N
972 } else if (contact.getContactId() < 1) {
973 // Not valid id number
974 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
977 // Remove from general list
978 if (!this.contactList.remove(contact)) {
979 // Did not remove contact
980 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
983 // Remove from other lists
984 this.emailAddressList.remove(contact.getContactEmailAddress());