2 * Copyright (C) 2016 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.pizzaapplication.beans.contact;
19 import java.text.MessageFormat;
20 import java.util.Collections;
21 import java.util.Date;
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.Objects;
25 import javax.annotation.PostConstruct;
26 import javax.enterprise.context.SessionScoped;
27 import javax.enterprise.event.Observes;
28 import javax.faces.view.facelets.FaceletException;
29 import javax.inject.Inject;
30 import javax.inject.Named;
31 import javax.naming.Context;
32 import javax.naming.InitialContext;
33 import javax.naming.NamingException;
34 import org.mxchange.jcontacts.contact.Contact;
35 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
36 import org.mxchange.jcontacts.contact.UserContact;
37 import org.mxchange.jcontacts.contact.gender.Gender;
38 import org.mxchange.jcontacts.contact.utils.ContactUtils;
39 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
40 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
41 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
42 import org.mxchange.jcountry.data.Country;
43 import org.mxchange.jcustomercore.events.customer.added.AdminAddedCustomerEvent;
44 import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
45 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
46 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
47 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
48 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
49 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
50 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
51 import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
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;
56 import org.mxchange.pizzaapplication.beans.BasePizzaController;
57 import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController;
60 * A general contact bean (controller)
62 * @author Roland Haeder<roland@mxchange.org>
64 @Named ("contactController")
66 public class PizzaContactWebSessionBean extends BasePizzaController implements PizzaContactWebSessionController {
71 private static final long serialVersionUID = 542_145_347_916L;
76 private Date birthday;
79 * Cellphone number's carrier
81 private MobileProvider cellphoneCarrier;
86 private Long cellphoneNumber;
96 private String comment;
101 private final ContactSessionBeanRemote contactBean;
106 private List<Contact> contactList;
111 private Country country;
116 private String emailAddress;
121 private List<String> emailAddressList;
124 * Email address repeated
126 private String emailAddressRepeat;
131 private String familyName;
134 * Fax number's area code
136 private Integer faxAreaCode;
139 * Country instance for fax number
141 private Country faxCountry;
146 private Long faxNumber;
151 private String firstName;
156 private Gender gender;
161 private Short houseNumber;
164 * Whether a cellphone entry has been unlinked
166 private boolean isCellphoneUnlinked;
169 * Whether a fax entry has been unlinked
171 private boolean isFaxUnlinked;
174 * Whether a land-line number has been unlinked
176 private boolean isLandLineUnlinked;
179 * Phone number area code
181 private Integer phoneAreaCode;
184 * Country instance for phone number
186 private Country phoneCountry;
191 private Long phoneNumber;
196 private String street;
199 * Login bean (controller)
202 private PizzaUserLoginWebSessionController userLoginController;
207 private Integer zipCode;
210 * Default constructor
212 public PizzaContactWebSessionBean () {
215 // Get initial context
216 Context context = new InitialContext();
219 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
220 } catch (final NamingException e) {
222 throw new FaceletException(e);
227 public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) {
228 // The event must be valid
231 throw new NullPointerException("event is null"); //NOI18N
232 } else if (event.getAddedContact() == null) {
234 throw new NullPointerException("event.addedContact is null"); //NOI18N
235 } else if (event.getAddedContact().getContactId() == null) {
237 throw new NullPointerException("event.addedContact.customerId is null"); //NOI18N
238 } else if (event.getAddedContact().getContactId() < 1) {
240 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.customerId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
247 this.contactList.add(event.getAddedContact());
251 public void afterAdminAddedCustomer (@Observes final AdminAddedCustomerEvent event) {
252 // The event must be valid
255 throw new NullPointerException("event is null"); //NOI18N
256 } else if (event.getAddedCustomer() == null) {
258 throw new NullPointerException("event.addedCustomer is null"); //NOI18N
259 } else if (event.getAddedCustomer().getCustomerId() == null) {
261 throw new NullPointerException("event.addedCustomer.customerId is null"); //NOI18N
262 } else if (event.getAddedCustomer().getCustomerId() < 1) {
264 throw new IllegalArgumentException(MessageFormat.format("event.addedCustomer.customerId={0} is not valid", event.getAddedCustomer().getCustomerId())); //NOI18N //NOI18N
271 this.contactList.add(event.getAddedCustomer().getCustomerContact());
275 public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
277 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminAddedUserEvent: event={0} - CALLED!", event)); //NOI18N
279 // event should not be null
282 throw new NullPointerException("event is null"); //NOI18N
283 } else if (event.getAddedUser() == null) {
285 throw new NullPointerException("event.addedUser is null"); //NOI18N
286 } else if (event.getAddedUser().getUserId() == null) {
288 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
289 } else if (event.getAddedUser().getUserId() < 1) {
291 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
298 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminAddedUserEvent: EXIT!"); //NOI18N
302 public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
304 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
306 // event should not be null
309 throw new NullPointerException("event is null"); //NOI18N
310 } else if (event.getUpdatedContact() == null) {
312 throw new NullPointerException("event.updatedContact is null"); //NOI18N
313 } else if (event.getUpdatedContact().getContactId() == null) {
315 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
316 } else if (event.getUpdatedContact().getContactId() < 1) {
318 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
321 // Get iterator from list
322 Iterator<Contact> iterator = this.contactList.iterator();
324 // "Walk" through all entries
325 while (iterator.hasNext()) {
327 Contact next = iterator.next();
329 // Is id number the same?
330 if (Objects.equals(event.getUpdatedContact().getContactId(), next.getContactId())) {
331 // Found entry, so remove it and abort
332 this.contactList.remove(next);
334 // Remove also email from list
335 this.emailAddressList.remove(next.getContactEmailAddress());
340 // Add contact to list
341 this.contactList.add(event.getUpdatedContact());
343 // Add email address to list
344 this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
348 public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
350 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
352 // event should not be null
355 throw new NullPointerException("event is null"); //NOI18N
356 } else if (event.getRegisteredUser() == null) {
358 throw new NullPointerException("event.registeredUser is null"); //NOI18N
359 } else if (event.getRegisteredUser().getUserId() == null) {
361 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
362 } else if (event.getRegisteredUser().getUserId() < 1) {
364 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
368 Contact registeredContact = event.getRegisteredUser().getUserContact();
371 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: registeredContact={0}", registeredContact)); //NOI18N
373 // Copy all data from registered->user
374 this.copyContact(registeredContact);
376 // Add user name and email address
377 this.addUserNameEmailAddress(registeredContact);
383 //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterRegistration: EXIT!"); //NOI18N
387 public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) {
389 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
391 // event should not be null
394 throw new NullPointerException("event is null"); //NOI18N
395 } else if (event.getConfirmedUser() == null) {
397 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
398 } else if (event.getConfirmedUser().getUserId() == null) {
400 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
401 } else if (event.getConfirmedUser().getUserId() < 1) {
403 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
406 // "Cache" contact instance
407 Contact contact = event.getConfirmedUser().getUserContact();
409 // Get iterator from list
410 Iterator<Contact> iterator = this.contactList.iterator();
412 // "Walk" through all entries
413 while (iterator.hasNext()) {
415 Contact next = iterator.next();
417 // Is id number the same?
418 if (Objects.equals(contact.getContactId(), next.getContactId())) {
419 // Found entry, so remove it and abort
420 this.contactList.remove(next);
425 // Add contact to list
426 this.contactList.add(contact);
430 public void afterUserLogin (@Observes final UserLoggedInEvent event) {
432 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
434 // event should not be null
437 throw new NullPointerException("event is null"); //NOI18N
438 } else if (event.getLoggedInUser() == null) {
440 throw new NullPointerException("event.loggedInUser is null"); //NOI18N
441 } else if (event.getLoggedInUser().getUserId() == null) {
443 throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
444 } else if (event.getLoggedInUser().getUserId() < 1) {
446 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
449 // Copy all data to this bean
450 this.copyContact(event.getLoggedInUser().getUserContact());
453 //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N
457 public List<Contact> allContacts () {
459 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size()));
461 // Return un-modified list
462 return Collections.unmodifiableList(this.contactList);
466 public Contact createContactInstance () {
468 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName()));
470 // Is all required data set?
471 if (!this.isRequiredPersonalDataSet()) {
472 // No, then abort here
473 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
476 // Generate phone number
477 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
478 DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
479 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
481 // Create new contact
482 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
483 contact.setContactStreet(this.getStreet());
484 contact.setContactHouseNumber(this.getHouseNumber());
485 contact.setContactZipCode(this.getZipCode());
486 contact.setContactCity(this.getCity());
487 contact.setContactCountry(this.getCountry());
488 contact.setContactEmailAddress(this.getEmailAddress());
489 contact.setContactBirthday(this.getBirthday());
490 contact.setContactComment(this.getComment());
493 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
494 // Don't set null or wrong references
495 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
496 // Now the number must be given
497 if (phone.getPhoneAreaCode() == null) {
499 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
500 } else if (phone.getPhoneAreaCode() < 1) {
502 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
503 } else if (phone.getPhoneNumber() == null) {
505 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
506 } else if (phone.getPhoneNumber() < 1) {
508 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
512 contact.setContactLandLineNumber(phone);
515 // Don't set null or wrong references
516 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
517 // Now the number must be given
518 if (fax.getPhoneAreaCode() == null) {
520 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
521 } else if (fax.getPhoneAreaCode() < 1) {
523 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
524 } else if (fax.getPhoneNumber() == null) {
526 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
527 } else if (fax.getPhoneNumber() < 1) {
529 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
533 contact.setContactFaxNumber(fax);
536 // Is the provider set?
537 if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
538 // Is the number set?
539 if (cellphone.getPhoneNumber() == null) {
541 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
542 } else if (cellphone.getPhoneNumber() < 1) {
544 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
547 // Set cellphone number
548 contact.setContactCellphoneNumber(cellphone);
552 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
558 public String doChangePersonalContactData () {
559 // This method shall only be called if the user is logged-in
560 if (!this.userLoginController.isUserLoggedIn()) {
562 throw new IllegalStateException("User is not logged-in"); //NOI18N
563 } else if (!this.isRequiredChangePersonalDataSet()) {
564 // Not all required fields are set
565 throw new FaceletException("Not all required fields are set."); //NOI18N
566 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
567 // Password not matching
568 throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()));
571 // Get contact instance
572 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
574 // It should be there, so run some tests on it
575 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
576 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
577 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
580 contact.setContactGender(this.getGender());
581 contact.setContactFirstName(this.getFirstName());
582 contact.setContactFamilyName(this.getFamilyName());
583 contact.setContactStreet(this.getStreet());
584 contact.setContactHouseNumber(this.getHouseNumber());
585 contact.setContactZipCode(this.getZipCode());
586 contact.setContactCity(this.getCity());
587 contact.setContactCountry(this.getCountry());
589 // Update contact's cellphone number
590 this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
592 // Update contact's land-line number
593 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
595 // Update contact's fax number
596 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
598 // Send it to the EJB
599 this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
602 return "contact_data_saved"; //NOI18N
606 @SuppressWarnings ("ReturnOfDateField")
607 public Date getBirthday () {
608 return this.birthday;
612 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
613 public void setBirthday (final Date birthday) {
614 this.birthday = birthday;
618 public MobileProvider getCellphoneCarrier () {
619 return this.cellphoneCarrier;
623 public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
624 this.cellphoneCarrier = cellphoneCarrier;
628 public Long getCellphoneNumber () {
629 return this.cellphoneNumber;
633 public void setCellphoneNumber (Long cellphoneNumber) {
634 this.cellphoneNumber = cellphoneNumber;
638 public String getCity () {
643 public void setCity (final String city) {
648 public String getComment () {
653 public void setComment (final String comment) {
654 this.comment = comment;
658 public Country getCountry () {
663 public void setCountry (final Country country) {
664 this.country = country;
668 public String getEmailAddress () {
669 return this.emailAddress;
673 public void setEmailAddress (final String emailAddress) {
674 this.emailAddress = emailAddress;
678 public String getEmailAddressRepeat () {
679 return this.emailAddressRepeat;
683 public void setEmailAddressRepeat (final String emailAddressRepeat) {
684 this.emailAddressRepeat = emailAddressRepeat;
688 public String getFamilyName () {
689 return this.familyName;
693 public void setFamilyName (final String familyName) {
694 this.familyName = familyName;
698 public Integer getFaxAreaCode () {
699 return this.faxAreaCode;
703 public void setFaxAreaCode (final Integer faxAreaCode) {
704 this.faxAreaCode = faxAreaCode;
708 public Country getFaxCountry () {
709 return this.faxCountry;
713 public void setFaxCountry (final Country faxCountry) {
714 this.faxCountry = faxCountry;
718 public Long getFaxNumber () {
719 return this.faxNumber;
723 public void setFaxNumber (final Long faxNumber) {
724 this.faxNumber = faxNumber;
728 public String getFirstName () {
729 return this.firstName;
733 public void setFirstName (final String firstName) {
734 this.firstName = firstName;
738 public Gender getGender () {
743 public void setGender (final Gender gender) {
744 this.gender = gender;
748 public Short getHouseNumber () {
749 return this.houseNumber;
753 public void setHouseNumber (final Short houseNumber) {
754 this.houseNumber = houseNumber;
758 public Integer getPhoneAreaCode () {
759 return this.phoneAreaCode;
763 public void setPhoneAreaCode (final Integer phoneAreaCode) {
764 this.phoneAreaCode = phoneAreaCode;
768 public Country getPhoneCountry () {
769 return this.phoneCountry;
773 public void setPhoneCountry (final Country phoneCountry) {
774 this.phoneCountry = phoneCountry;
778 public Long getPhoneNumber () {
779 return this.phoneNumber;
783 public void setPhoneNumber (final Long phoneNumber) {
784 this.phoneNumber = phoneNumber;
788 public String getStreet () {
793 public void setStreet (final String street) {
794 this.street = street;
798 public Integer getZipCode () {
803 public void setZipCode (final Integer zipCode) {
804 this.zipCode = zipCode;
808 public boolean hasContacts () {
809 return (!this.contactList.isEmpty());
813 * Post-initialization of this class
816 public void init () {
817 // Get full email address list for reducing EJB calls
818 this.emailAddressList = this.contactBean.getEmailAddressList();
820 // Get full contact list
821 this.contactList = this.contactBean.getAllContacts();
825 public boolean isEmailAddressRegistered (final Contact contact) {
827 if (null == contact) {
829 throw new NullPointerException("contact is null"); //NOI18N
830 } else if (contact.getContactEmailAddress() == null) {
832 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
833 } else if (contact.getContactEmailAddress().isEmpty()) {
835 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
839 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
843 public boolean isRequiredChangePersonalDataSet () {
844 return ((this.getGender() != null) &&
845 (this.getFirstName() != null) &&
846 (this.getFamilyName() != null) &&
847 (this.getStreet() != null) &&
848 (this.getHouseNumber() != null) &&
849 (this.getZipCode() != null) &&
850 (this.getCity() != null));
854 public boolean isRequiredPersonalDataSet () {
855 return ((this.getGender() != null) &&
856 (this.getFirstName() != null) &&
857 (this.getFamilyName() != null) &&
858 (this.getStreet() != null) &&
859 (this.getHouseNumber() != null) &&
860 (this.getZipCode() != null) &&
861 (this.getCity() != null) &&
862 (this.getEmailAddress() != null) &&
863 (this.getEmailAddressRepeat() != null));
867 public boolean isSameEmailAddressEntered () {
868 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
872 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
874 Contact localContact = null;
879 // Try to lookup it in visible user list
880 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
882 Contact next = iterator.next();
884 // Is the user id found?
885 if (Objects.equals(next.getContactId(), contactId)) {
886 // Copy to other variable
893 if (null == localContact) {
894 // Not visible for the current user
895 throw new ContactNotFoundException(contactId);
898 // Copy all data to this bean
899 this.copyContact(localContact);
906 public void updateContactDataFromController (final Contact contact) {
907 // Is the instance valid?
908 if (null == contact) {
910 throw new NullPointerException("contact is null"); //NOI18N
911 } else if (contact.getContactId() == null) {
913 throw new NullPointerException("contact.contactId is null"); //NOI18N
914 } else if (contact.getContactId() < 1) {
915 // Not valid id number
916 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
920 this.copyContact(contact);
924 * Adds email address to bean's internal list.
926 * @param contact Contact instance
928 private void addUserNameEmailAddress (final Contact contact) {
929 // Make sure the entry is not added yet
930 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
932 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
936 this.emailAddressList.add(contact.getContactEmailAddress());
942 private void clear () {
945 this.setGender(Gender.UNKNOWN);
946 this.setFirstName(null);
947 this.setFamilyName(null);
948 this.setStreet(null);
949 this.setHouseNumber(null);
950 this.setZipCode(null);
952 this.setCountry(null);
955 this.setEmailAddress(null);
956 this.setEmailAddressRepeat(null);
957 this.setPhoneCountry(null);
958 this.setPhoneAreaCode(null);
959 this.setPhoneCountry(null);
960 this.setPhoneNumber(null);
961 this.setCellphoneCarrier(null);
962 this.setCellphoneNumber(null);
963 this.setFaxAreaCode(null);
964 this.setFaxCountry(null);
965 this.setFaxNumber(null);
968 this.setBirthday(null);
969 this.setComment(null);
973 * Copies given contact into the controller
975 * @param contact Contact instance
977 private void copyContact (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
992 this.setGender(contact.getContactGender());
993 this.setFirstName(contact.getContactFirstName());
994 this.setFamilyName(contact.getContactFamilyName());
995 this.setStreet(contact.getContactStreet());
996 this.setHouseNumber(contact.getContactHouseNumber());
997 this.setZipCode(contact.getContactZipCode());
998 this.setCity(contact.getContactCity());
999 this.setCountry(contact.getContactCountry());
1000 this.setEmailAddress(contact.getContactEmailAddress());
1001 this.setBirthday(contact.getContactBirthday());
1002 this.setComment(contact.getContactComment());
1004 // Get cellphone, phone and fax instance
1005 DialableCellphoneNumber cellphone = contact.getContactCellphoneNumber();
1006 DialableFaxNumber fax = contact.getContactFaxNumber();
1007 DialableLandLineNumber phone = contact.getContactLandLineNumber();
1010 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
1011 this.setPhoneCountry(phone.getPhoneCountry());
1012 this.setPhoneAreaCode(phone.getPhoneAreaCode());
1013 this.setPhoneNumber(phone.getPhoneNumber());
1016 if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) {
1017 this.setCellphoneCarrier(cellphone.getCellphoneProvider());
1018 this.setCellphoneNumber(cellphone.getPhoneNumber());
1021 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
1022 this.setFaxCountry(fax.getPhoneCountry());
1023 this.setFaxAreaCode(fax.getPhoneAreaCode());
1024 this.setFaxNumber(fax.getPhoneNumber());
1029 * Removes given contact from all lists
1031 * @param contact Contact instance to remove
1033 private void removeContact (final Contact contact) {
1034 // Is the instance valid?
1035 if (null == contact) {
1037 throw new NullPointerException("contact is null"); //NOI18N
1038 } else if (contact.getContactId() == null) {
1040 throw new NullPointerException("contact.contactId is null"); //NOI18N
1041 } else if (contact.getContactId() < 1) {
1042 // Not valid id number
1043 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1046 // Remove from general list
1047 if (!this.contactList.remove(contact)) {
1048 // Did not remove contact
1049 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
1052 // Remove from other lists
1053 this.emailAddressList.remove(contact.getContactEmailAddress());