2 * Copyright (C) 2016 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jjobs.beans.contact;
19 import java.text.MessageFormat;
20 import java.util.Collections;
21 import java.util.Date;
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.Objects;
25 import javax.annotation.PostConstruct;
26 import javax.enterprise.context.SessionScoped;
27 import javax.enterprise.event.Observes;
28 import javax.faces.view.facelets.FaceletException;
29 import javax.inject.Inject;
30 import javax.inject.Named;
31 import javax.naming.Context;
32 import javax.naming.InitialContext;
33 import javax.naming.NamingException;
34 import org.mxchange.jcontacts.contact.Contact;
35 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
36 import org.mxchange.jcontacts.contact.UserContact;
37 import org.mxchange.jcontacts.contact.gender.Gender;
38 import org.mxchange.jcontacts.contact.utils.ContactUtils;
39 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
40 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
41 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
42 import org.mxchange.jcountry.data.Country;
43 import org.mxchange.jjobs.beans.BaseJobsController;
44 import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
45 import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
46 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
47 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
48 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
49 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
50 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
51 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
52 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
53 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
54 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
55 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
58 * A general contact bean (controller)
60 * @author Roland Haeder<roland@mxchange.org>
62 @Named ("contactController")
64 public class JobsContactWebSessionBean extends BaseJobsController implements JobsContactWebSessionController {
69 private static final long serialVersionUID = 542_145_347_916L;
74 private Date birthday;
77 * Cellphone number's carrier
79 private MobileProvider cellphoneCarrier;
84 private Long cellphoneNumber;
94 private String comment;
99 private final ContactSessionBeanRemote contactBean;
104 private List<Contact> contactList;
109 private Country country;
114 private String emailAddress;
119 private List<String> emailAddressList;
122 * Email address repeated
124 private String emailAddressRepeat;
129 private String familyName;
132 * Fax number's area code
134 private Integer faxAreaCode;
137 * Country instance for fax number
139 private Country faxCountry;
144 private Long faxNumber;
149 private String firstName;
154 private Gender gender;
159 private Short houseNumber;
162 * Whether a cellphone entry has been unlinked
164 private boolean isCellphoneUnlinked;
167 * Whether a fax entry has been unlinked
169 private boolean isFaxUnlinked;
172 * Whether a land-line number has been unlinked
174 private boolean isLandLineUnlinked;
177 * Phone number area code
179 private Integer phoneAreaCode;
182 * Country instance for phone number
184 private Country phoneCountry;
189 private Long phoneNumber;
194 private String street;
197 * Login bean (controller)
200 private JobsUserLoginWebSessionController userLoginController;
205 private Integer zipCode;
208 * Default constructor
210 public JobsContactWebSessionBean () {
213 // Get initial context
214 Context context = new InitialContext();
217 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
218 } catch (final NamingException e) {
220 throw new FaceletException(e);
225 public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) {
226 // The event must be valid
229 throw new NullPointerException("event is null"); //NOI18N
230 } else if (event.getAddedContact() == null) {
232 throw new NullPointerException("event.addedContact is null"); //NOI18N
233 } else if (event.getAddedContact().getContactId() == null) {
235 throw new NullPointerException("event.addedContact.customerId is null"); //NOI18N
236 } else if (event.getAddedContact().getContactId() < 1) {
238 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.customerId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
245 this.contactList.add(event.getAddedContact());
249 public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
251 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminAddedUserEvent: event={0} - CALLED!", event)); //NOI18N
253 // event should not be null
256 throw new NullPointerException("event is null"); //NOI18N
257 } else if (event.getAddedUser() == null) {
259 throw new NullPointerException("event.addedUser is null"); //NOI18N
260 } else if (event.getAddedUser().getUserId() == null) {
262 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
263 } else if (event.getAddedUser().getUserId() < 1) {
265 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
272 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminAddedUserEvent: EXIT!"); //NOI18N
276 public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
278 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
280 // event should not be null
283 throw new NullPointerException("event is null"); //NOI18N
284 } else if (event.getUpdatedContact() == null) {
286 throw new NullPointerException("event.updatedUser is null"); //NOI18N
287 } else if (event.getUpdatedContact().getContactId() == null) {
289 throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
290 } else if (event.getUpdatedContact().getContactId() < 1) {
292 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
295 // Get iterator from list
296 Iterator<Contact> iterator = this.contactList.iterator();
298 // "Walk" through all entries
299 while (iterator.hasNext()) {
301 Contact next = iterator.next();
303 // Is id number the same?
304 if (Objects.equals(event.getUpdatedContact().getContactId(), next.getContactId())) {
305 // Found entry, so remove it and abort
306 this.contactList.remove(next);
308 // Remove also email from list
309 this.emailAddressList.remove(next.getContactEmailAddress());
314 // Add contact to list
315 this.contactList.add(event.getUpdatedContact());
317 // Add email address to list
318 this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
322 public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
324 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
326 // event should not be null
329 throw new NullPointerException("event is null"); //NOI18N
330 } else if (event.getRegisteredUser() == null) {
332 throw new NullPointerException("event.user is null"); //NOI18N
333 } else if (event.getRegisteredUser().getUserId() == null) {
335 throw new NullPointerException("event.user.userId is null"); //NOI18N
336 } else if (event.getRegisteredUser().getUserId() < 1) {
338 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
342 Contact registeredContact = event.getRegisteredUser().getUserContact();
345 //* 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 (@Observes final 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 // Generate phone number
407 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
408 DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
409 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
411 // Create new contact
412 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
413 contact.setContactStreet(this.getStreet());
414 contact.setContactHouseNumber(this.getHouseNumber());
415 contact.setContactZipCode(this.getZipCode());
416 contact.setContactCity(this.getCity());
417 contact.setContactCountry(this.getCountry());
418 contact.setContactEmailAddress(this.getEmailAddress());
419 contact.setContactBirthday(this.getBirthday());
420 contact.setContactComment(this.getComment());
423 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
425 // Don't set null or wrong references
426 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
427 // Now the number must be given
428 if (phone.getPhoneAreaCode() == null) {
430 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
431 } else if (phone.getPhoneAreaCode() < 1) {
433 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
434 } else if (phone.getPhoneNumber() == null) {
436 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
437 } else if (phone.getPhoneNumber() < 1) {
439 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
443 contact.setContactLandLineNumber(phone);
446 // Don't set null or wrong references
447 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
448 // Now the number must be given
449 if (fax.getPhoneAreaCode() == null) {
451 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
452 } else if (fax.getPhoneAreaCode() < 1) {
454 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
455 } else if (fax.getPhoneNumber() == null) {
457 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
458 } else if (fax.getPhoneNumber() < 1) {
460 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
464 contact.setContactFaxNumber(fax);
467 // Is the provider set?
468 if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
469 // Is the number set?
470 if (cellphone.getPhoneNumber() == null) {
472 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
473 } else if (cellphone.getPhoneNumber() < 1) {
475 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
478 // Set cellphone number
479 contact.setContactCellphoneNumber(cellphone);
483 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
490 public String doChangePersonalContactData () {
491 // This method shall only be called if the user is logged-in
492 if (!this.userLoginController.isUserLoggedIn()) {
494 throw new IllegalStateException("User is not logged-in"); //NOI18N
495 } else if (!this.isRequiredChangePersonalDataSet()) {
496 // Not all required fields are set
497 throw new FaceletException("Not all required fields are set."); //NOI18N
498 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
499 // Password not matching
500 throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()));
503 // Get contact instance
504 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
506 // It should be there, so run some tests on it
507 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
508 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
509 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
512 contact.setContactGender(this.getGender());
513 contact.setContactFirstName(this.getFirstName());
514 contact.setContactFamilyName(this.getFamilyName());
515 contact.setContactStreet(this.getStreet());
516 contact.setContactHouseNumber(this.getHouseNumber());
517 contact.setContactZipCode(this.getZipCode());
518 contact.setContactCity(this.getCity());
519 contact.setContactCountry(this.getCountry());
521 // Update contact's cellphone number
522 this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
524 // Update contact's land-line number
525 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
527 // Update contact's fax number
528 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
530 // Send it to the EJB
531 this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
534 return "contact_data_saved"; //NOI18N
538 @SuppressWarnings ("ReturnOfDateField")
539 public Date getBirthday () {
540 return this.birthday;
544 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
545 public void setBirthday (final Date birthday) {
546 this.birthday = birthday;
550 public MobileProvider getCellphoneCarrier () {
551 return this.cellphoneCarrier;
555 public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
556 this.cellphoneCarrier = cellphoneCarrier;
560 public Long getCellphoneNumber () {
561 return this.cellphoneNumber;
565 public void setCellphoneNumber (Long cellphoneNumber) {
566 this.cellphoneNumber = cellphoneNumber;
570 public String getCity () {
575 public void setCity (final String city) {
580 public String getComment () {
585 public void setComment (final String comment) {
586 this.comment = comment;
590 public Country getCountry () {
595 public void setCountry (final Country country) {
596 this.country = country;
600 public String getEmailAddress () {
601 return this.emailAddress;
605 public void setEmailAddress (final String emailAddress) {
606 this.emailAddress = emailAddress;
610 public String getEmailAddressRepeat () {
611 return this.emailAddressRepeat;
615 public void setEmailAddressRepeat (final String emailAddressRepeat) {
616 this.emailAddressRepeat = emailAddressRepeat;
620 public String getFamilyName () {
621 return this.familyName;
625 public void setFamilyName (final String familyName) {
626 this.familyName = familyName;
630 public Integer getFaxAreaCode () {
631 return this.faxAreaCode;
635 public void setFaxAreaCode (final Integer faxAreaCode) {
636 this.faxAreaCode = faxAreaCode;
640 public Country getFaxCountry () {
641 return this.faxCountry;
645 public void setFaxCountry (final Country faxCountry) {
646 this.faxCountry = faxCountry;
650 public Long getFaxNumber () {
651 return this.faxNumber;
655 public void setFaxNumber (final Long faxNumber) {
656 this.faxNumber = faxNumber;
660 public String getFirstName () {
661 return this.firstName;
665 public void setFirstName (final String firstName) {
666 this.firstName = firstName;
670 public Gender getGender () {
675 public void setGender (final Gender gender) {
676 this.gender = gender;
680 public Short getHouseNumber () {
681 return this.houseNumber;
685 public void setHouseNumber (final Short houseNumber) {
686 this.houseNumber = houseNumber;
690 public Integer getPhoneAreaCode () {
691 return this.phoneAreaCode;
695 public void setPhoneAreaCode (final Integer phoneAreaCode) {
696 this.phoneAreaCode = phoneAreaCode;
700 public Country getPhoneCountry () {
701 return this.phoneCountry;
705 public void setPhoneCountry (final Country phoneCountry) {
706 this.phoneCountry = phoneCountry;
710 public Long getPhoneNumber () {
711 return this.phoneNumber;
715 public void setPhoneNumber (final Long phoneNumber) {
716 this.phoneNumber = phoneNumber;
720 public String getStreet () {
725 public void setStreet (final String street) {
726 this.street = street;
730 public Integer getZipCode () {
735 public void setZipCode (final Integer zipCode) {
736 this.zipCode = zipCode;
740 public boolean hasContacts () {
741 return (!this.contactList.isEmpty());
745 * Post-initialization of this class
748 public void init () {
749 // Get full email address list for reducing EJB calls
750 this.emailAddressList = this.contactBean.getEmailAddressList();
752 // Get full contact list
753 this.contactList = this.contactBean.getAllContacts();
757 public boolean isEmailAddressRegistered (final Contact contact) {
759 if (null == contact) {
761 throw new NullPointerException("contact is null"); //NOI18N
762 } else if (contact.getContactEmailAddress() == null) {
764 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
765 } else if (contact.getContactEmailAddress().isEmpty()) {
767 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
771 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
775 public boolean isRequiredChangePersonalDataSet () {
776 return ((this.getGender() != null) &&
777 (this.getFirstName() != null) &&
778 (this.getFamilyName() != null) &&
779 (this.getStreet() != null) &&
780 (this.getHouseNumber() != null) &&
781 (this.getZipCode() != null) &&
782 (this.getCity() != null));
786 public boolean isRequiredPersonalDataSet () {
787 return ((this.getGender() != null) &&
788 (this.getFirstName() != null) &&
789 (this.getFamilyName() != null) &&
790 (this.getStreet() != null) &&
791 (this.getHouseNumber() != null) &&
792 (this.getZipCode() != null) &&
793 (this.getCity() != null) &&
794 (this.getEmailAddress() != null) &&
795 (this.getEmailAddressRepeat() != null));
799 public boolean isSameEmailAddressEntered () {
800 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
804 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
806 Contact localContact = null;
811 // Try to lookup it in visible user list
812 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
814 Contact next = iterator.next();
816 // Is the user id found?
817 if (Objects.equals(next.getContactId(), contactId)) {
818 // Copy to other variable
825 if (null == localContact) {
826 // Not visible for the current user
827 throw new ContactNotFoundException(contactId);
830 // Copy all data to this bean
831 this.copyContact(localContact);
838 public void updateContactDataFromController (final Contact contact) {
839 // Is the instance valid?
840 if (null == contact) {
842 throw new NullPointerException("contact is null"); //NOI18N
843 } else if (contact.getContactId() == null) {
845 throw new NullPointerException("contact.contactId is null"); //NOI18N
846 } else if (contact.getContactId() < 1) {
847 // Not valid id number
848 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
852 this.copyContact(contact);
856 * Adds email address to bean's internal list.
858 * @param contact Contact instance
860 private void addUserNameEmailAddress (final Contact contact) {
861 // Make sure the entry is not added yet
862 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
864 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
868 this.emailAddressList.add(contact.getContactEmailAddress());
874 private void clear () {
877 this.setGender(Gender.UNKNOWN);
878 this.setFirstName(null);
879 this.setFamilyName(null);
880 this.setStreet(null);
881 this.setHouseNumber(null);
882 this.setZipCode(null);
884 this.setCountry(null);
887 this.setEmailAddress(null);
888 this.setEmailAddressRepeat(null);
889 this.setPhoneAreaCode(null);
890 this.setPhoneCountry(null);
891 this.setPhoneNumber(null);
892 this.setCellphoneCarrier(null);
893 this.setCellphoneNumber(null);
894 this.setFaxAreaCode(null);
895 this.setFaxCountry(null);
896 this.setFaxNumber(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());