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 * House number extension
166 private String houseNumberExtension;
169 * Whether a cellphone entry has been unlinked
171 private boolean isCellphoneUnlinked;
174 * Whether a fax entry has been unlinked
176 private boolean isFaxUnlinked;
179 * Whether a land-line number has been unlinked
181 private boolean isLandLineUnlinked;
184 * Phone number area code
186 private Integer phoneAreaCode;
189 * Country instance for phone number
191 private Country phoneCountry;
196 private Long phoneNumber;
201 private String street;
204 * Login bean (controller)
207 private PizzaUserLoginWebSessionController userLoginController;
212 private Integer zipCode;
215 * Default constructor
217 public PizzaContactWebSessionBean () {
220 // Get initial context
221 Context context = new InitialContext();
224 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
225 } catch (final NamingException e) {
227 throw new FaceletException(e);
232 public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) {
234 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("contactController.afterAdminAddedContact(): event={0} - CALLED!", event)); //NOI18N
236 // The event must be valid
239 throw new NullPointerException("event is null"); //NOI18N
240 } else if (event.getAddedContact() == null) {
242 throw new NullPointerException("event.addedContact is null"); //NOI18N
243 } else if (event.getAddedContact().getContactId() == null) {
245 throw new NullPointerException("event.addedContact.customerId is null"); //NOI18N
246 } else if (event.getAddedContact().getContactId() < 1) {
248 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.customerId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
255 this.contactList.add(event.getAddedContact());
259 public void afterAdminAddedCustomer (@Observes final AdminAddedCustomerEvent event) {
260 // The event must be valid
263 this.selectableContacts.add(event.getAddedContact());
266 //* NOISY-DEBUG: */ System.out.println("contactController.afterAdminAddedContact(): EXIT!"); //NOI18N
270 public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
272 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("contactController.afterAdminAddedUserEvent(): event={0} - CALLED!", event)); //NOI18N
274 // event should not be null
277 throw new NullPointerException("event is null"); //NOI18N
278 } else if (event.getAddedCustomer() == null) {
280 throw new NullPointerException("event.addedCustomer is null"); //NOI18N
281 } else if (event.getAddedCustomer().getCustomerId() == null) {
283 throw new NullPointerException("event.addedCustomer.customerId is null"); //NOI18N
284 } else if (event.getAddedCustomer().getCustomerId() < 1) {
286 throw new IllegalArgumentException(MessageFormat.format("event.addedCustomer.customerId={0} is not valid", event.getAddedCustomer().getCustomerId())); //NOI18N //NOI18N
293 this.contactList.add(event.getAddedCustomer().getCustomerContact());
296 //* NOISY-DEBUG: */ System.out.println("contactController.afterAdminAddedUserEvent(): EXIT!"); //NOI18N
300 public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
302 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminAddedUserEvent: event={0} - CALLED!", event)); //NOI18N
304 // event should not be null
307 throw new NullPointerException("event is null"); //NOI18N
308 } else if (event.getAddedUser() == null) {
310 throw new NullPointerException("event.addedUser is null"); //NOI18N
311 } else if (event.getAddedUser().getUserId() == null) {
313 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
314 } else if (event.getAddedUser().getUserId() < 1) {
316 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
323 //* NOISY-DEBUG: */ System.out.println("contactController.afterAdminAddedUserEvent(): EXIT!"); //NOI18N
327 public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
329 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("contactController.afterAdminUpdatedContactDataEvent(): event={0} - CALLED!", event)); //NOI18N
331 // event should not be null
334 throw new NullPointerException("event is null"); //NOI18N
335 } else if (event.getUpdatedContact() == null) {
337 throw new NullPointerException("event.updatedContact is null"); //NOI18N
338 } else if (event.getUpdatedContact().getContactId() == null) {
340 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
341 } else if (event.getUpdatedContact().getContactId() < 1) {
343 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
346 // Get iterator from list
347 Iterator<Contact> iterator = this.contactList.iterator();
349 // "Walk" through all entries
350 while (iterator.hasNext()) {
352 Contact next = iterator.next();
354 // Is id number the same?
355 if (Objects.equals(event.getUpdatedContact().getContactId(), next.getContactId())) {
356 // Found entry, so remove it and abort
357 this.contactList.remove(next);
359 // Remove also email from list
360 this.emailAddressList.remove(next.getContactEmailAddress());
365 // Add contact to list
366 this.contactList.add(event.getUpdatedContact());
368 // Add email address to list
369 this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
372 //* NOISY-DEBUG: */ System.out.println("contactController.afterAdminUpdatedContactDataEvent(): EXIT!"); //NOI18N
376 public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
378 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
380 // event should not be null
383 throw new NullPointerException("event is null"); //NOI18N
384 } else if (event.getRegisteredUser() == null) {
386 throw new NullPointerException("event.registeredUser is null"); //NOI18N
387 } else if (event.getRegisteredUser().getUserId() == null) {
389 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
390 } else if (event.getRegisteredUser().getUserId() < 1) {
392 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
396 Contact registeredContact = event.getRegisteredUser().getUserContact();
399 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: registeredContact={0}", registeredContact)); //NOI18N
400 // Copy all data from registered->user
401 this.copyContact(registeredContact);
403 // Add user name and email address
404 this.addUserNameEmailAddress(registeredContact);
410 //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterRegistration: EXIT!"); //NOI18N
414 public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) {
416 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
418 // event should not be null
421 throw new NullPointerException("event is null"); //NOI18N
422 } else if (event.getConfirmedUser() == null) {
424 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
425 } else if (event.getConfirmedUser().getUserId() == null) {
427 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
428 } else if (event.getConfirmedUser().getUserId() < 1) {
430 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
433 // "Cache" contact instance
434 Contact contact = event.getConfirmedUser().getUserContact();
436 // Get iterator from list
437 Iterator<Contact> iterator = this.contactList.iterator();
439 // "Walk" through all entries
440 while (iterator.hasNext()) {
442 Contact next = iterator.next();
444 // Is id number the same?
445 if (Objects.equals(contact.getContactId(), next.getContactId())) {
446 // Found entry, so remove it and abort
447 this.contactList.remove(next);
452 // Add contact to list
453 this.contactList.add(contact);
456 //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterAdminUpdatedContactDataEvent: EXIT!"); //NOI18N
460 public void afterUserLogin (@Observes final UserLoggedInEvent event) {
462 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
464 // event should not be null
467 throw new NullPointerException("event is null"); //NOI18N
468 } else if (event.getLoggedInUser() == null) {
470 throw new NullPointerException("event.loggedInUser is null"); //NOI18N
471 } else if (event.getLoggedInUser().getUserId() == null) {
473 throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
474 } else if (event.getLoggedInUser().getUserId() < 1) {
476 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
479 // Copy all data to this bean
480 this.copyContact(event.getLoggedInUser().getUserContact());
483 //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N
487 public List<Contact> allContacts () {
489 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size()));
491 // Return un-modified list
492 return Collections.unmodifiableList(this.contactList);
496 public Contact createContactInstance () {
498 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName()));
500 // Is all required data set?
501 if (!this.isRequiredPersonalDataSet()) {
502 // No, then abort here
503 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
506 // Generate phone number
507 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
508 DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
509 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
511 // Create new contact
512 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
513 contact.setContactStreet(this.getStreet());
514 contact.setContactHouseNumber(this.getHouseNumber());
515 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
516 contact.setContactZipCode(this.getZipCode());
517 contact.setContactCity(this.getCity());
518 contact.setContactCountry(this.getCountry());
519 contact.setContactEmailAddress(this.getEmailAddress());
520 contact.setContactBirthday(this.getBirthday());
521 contact.setContactComment(this.getComment());
524 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
525 // Don't set null or wrong references
526 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
527 // Now the number must be given
528 if (phone.getPhoneAreaCode() == null) {
530 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
531 } else if (phone.getPhoneAreaCode() < 1) {
533 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
534 } else if (phone.getPhoneNumber() == null) {
536 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
537 } else if (phone.getPhoneNumber() < 1) {
539 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
543 contact.setContactLandLineNumber(phone);
546 // Don't set null or wrong references
547 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
548 // Now the number must be given
549 if (fax.getPhoneAreaCode() == null) {
551 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
552 } else if (fax.getPhoneAreaCode() < 1) {
554 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
555 } else if (fax.getPhoneNumber() == null) {
557 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
558 } else if (fax.getPhoneNumber() < 1) {
560 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
564 contact.setContactFaxNumber(fax);
567 // Is the provider set?
568 if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
569 // Is the number set?
570 if (cellphone.getPhoneNumber() == null) {
572 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
573 } else if (cellphone.getPhoneNumber() < 1) {
575 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
578 // Set cellphone number
579 contact.setContactCellphoneNumber(cellphone);
583 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
589 public String doChangePersonalContactData () {
590 // This method shall only be called if the user is logged-in
591 if (!this.userLoginController.isUserLoggedIn()) {
593 throw new IllegalStateException("User is not logged-in"); //NOI18N
594 } else if (!this.isRequiredChangePersonalDataSet()) {
595 // Not all required fields are set
596 throw new FaceletException("Not all required fields are set."); //NOI18N
597 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
598 // Password not matching
599 this.showFacesMessage("login_change_personal_form:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
603 // Get contact instance
604 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
606 // It should be there, so run some tests on it
607 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
608 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
609 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
612 contact.setContactGender(this.getGender());
613 contact.setContactFirstName(this.getFirstName());
614 contact.setContactFamilyName(this.getFamilyName());
615 contact.setContactStreet(this.getStreet());
616 contact.setContactHouseNumber(this.getHouseNumber());
617 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
618 contact.setContactZipCode(this.getZipCode());
619 contact.setContactCity(this.getCity());
620 contact.setContactCountry(this.getCountry());
622 // Update contact's cellphone number
623 this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
625 // Update contact's land-line number
626 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
628 // Update contact's fax number
629 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
631 // Send it to the EJB
632 this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
635 return "contact_data_saved"; //NOI18N
639 @SuppressWarnings ("ReturnOfDateField")
640 public Date getBirthday () {
641 return this.birthday;
645 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
646 public void setBirthday (final Date birthday) {
647 this.birthday = birthday;
651 public MobileProvider getCellphoneCarrier () {
652 return this.cellphoneCarrier;
656 public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
657 this.cellphoneCarrier = cellphoneCarrier;
661 public Long getCellphoneNumber () {
662 return this.cellphoneNumber;
666 public void setCellphoneNumber (Long cellphoneNumber) {
667 this.cellphoneNumber = cellphoneNumber;
671 public String getCity () {
676 public void setCity (final String city) {
681 public String getComment () {
686 public void setComment (final String comment) {
687 this.comment = comment;
691 public String getControllerType () {
692 return "general"; //NOI18N
697 public void setControllerType (final String controllerType) {
698 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
702 public Country getCountry () {
707 public void setCountry (final Country country) {
708 this.country = country;
712 public String getEmailAddress () {
713 return this.emailAddress;
717 public void setEmailAddress (final String emailAddress) {
718 this.emailAddress = emailAddress;
722 public String getEmailAddressRepeat () {
723 return this.emailAddressRepeat;
727 public void setEmailAddressRepeat (final String emailAddressRepeat) {
728 this.emailAddressRepeat = emailAddressRepeat;
732 public String getFamilyName () {
733 return this.familyName;
737 public void setFamilyName (final String familyName) {
738 this.familyName = familyName;
742 public Integer getFaxAreaCode () {
743 return this.faxAreaCode;
747 public void setFaxAreaCode (final Integer faxAreaCode) {
748 this.faxAreaCode = faxAreaCode;
752 public Country getFaxCountry () {
753 return this.faxCountry;
757 public void setFaxCountry (final Country faxCountry) {
758 this.faxCountry = faxCountry;
762 public Long getFaxNumber () {
763 return this.faxNumber;
767 public void setFaxNumber (final Long faxNumber) {
768 this.faxNumber = faxNumber;
772 public String getFirstName () {
773 return this.firstName;
777 public void setFirstName (final String firstName) {
778 this.firstName = firstName;
782 public Gender getGender () {
787 public void setGender (final Gender gender) {
788 this.gender = gender;
792 public Short getHouseNumber () {
793 return this.houseNumber;
797 public void setHouseNumber (final Short houseNumber) {
798 this.houseNumber = houseNumber;
802 public String getHouseNumberExtension () {
803 return this.houseNumberExtension;
807 public void setHouseNumberExtension (final String houseNumberExtension) {
808 this.houseNumberExtension = houseNumberExtension;
812 public Integer getPhoneAreaCode () {
813 return this.phoneAreaCode;
817 public void setPhoneAreaCode (final Integer phoneAreaCode) {
818 this.phoneAreaCode = phoneAreaCode;
822 public Country getPhoneCountry () {
823 return this.phoneCountry;
827 public void setPhoneCountry (final Country phoneCountry) {
828 this.phoneCountry = phoneCountry;
832 public Long getPhoneNumber () {
833 return this.phoneNumber;
837 public void setPhoneNumber (final Long phoneNumber) {
838 this.phoneNumber = phoneNumber;
842 public String getStreet () {
847 public void setStreet (final String street) {
848 this.street = street;
852 public Integer getZipCode () {
857 public void setZipCode (final Integer zipCode) {
858 this.zipCode = zipCode;
862 public boolean hasContacts () {
863 return (!this.contactList.isEmpty());
867 * Post-initialization of this class
870 public void init () {
871 // Get full email address list for reducing EJB calls
872 this.emailAddressList = this.contactBean.getEmailAddressList();
874 // Get full contact list
875 this.contactList = this.contactBean.getAllContacts();
879 public boolean isEmailAddressRegistered (final Contact contact) {
881 if (null == contact) {
883 throw new NullPointerException("contact is null"); //NOI18N
884 } else if (contact.getContactEmailAddress() == null) {
886 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
887 } else if (contact.getContactEmailAddress().isEmpty()) {
889 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
893 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
897 public boolean isRequiredChangePersonalDataSet () {
898 return ((this.getGender() != null) &&
899 (this.getFirstName() != null) &&
900 (this.getFamilyName() != null) &&
901 (this.getStreet() != null) &&
902 (this.getHouseNumber() != null) &&
903 (this.getZipCode() != null) &&
904 (this.getCity() != null));
908 public boolean isRequiredPersonalDataSet () {
909 return ((this.getGender() != null) &&
910 (this.getFirstName() != null) &&
911 (this.getFamilyName() != null) &&
912 (this.getStreet() != null) &&
913 (this.getHouseNumber() != null) &&
914 (this.getZipCode() != null) &&
915 (this.getCity() != null) &&
916 (this.getEmailAddress() != null) &&
917 (this.getEmailAddressRepeat() != null));
921 public boolean isSameEmailAddressEntered () {
922 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
926 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
928 Contact localContact = null;
933 // Try to lookup it in visible user list
934 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
936 Contact next = iterator.next();
938 // Is the user id found?
939 if (Objects.equals(next.getContactId(), contactId)) {
940 // Copy to other variable
947 if (null == localContact) {
948 // Not visible for the current user
949 throw new ContactNotFoundException(contactId);
952 // Copy all data to this bean
953 this.copyContact(localContact);
960 public void updateContactDataFromController (final Contact contact) {
961 // Is the instance valid?
962 if (null == contact) {
964 throw new NullPointerException("contact is null"); //NOI18N
965 } else if (contact.getContactId() == null) {
967 throw new NullPointerException("contact.contactId is null"); //NOI18N
968 } else if (contact.getContactId() < 1) {
969 // Not valid id number
970 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
974 this.copyContact(contact);
978 * Adds email address to bean's internal list.
980 * @param contact Contact instance
982 private void addUserNameEmailAddress (final Contact contact) {
983 // Make sure the entry is not added yet
984 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
986 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
990 this.emailAddressList.add(contact.getContactEmailAddress());
996 private void clear () {
999 this.setFirstName(null);
1000 this.setFamilyName(null);
1001 this.setStreet(null);
1002 this.setHouseNumber(null);
1003 this.setHouseNumberExtension(null);
1004 this.setZipCode(null);
1006 this.setCountry(null);
1009 this.setEmailAddress(null);
1010 this.setEmailAddressRepeat(null);
1011 this.setPhoneCountry(null);
1012 this.setPhoneAreaCode(null);
1013 this.setPhoneCountry(null);
1014 this.setPhoneNumber(null);
1015 this.setCellphoneCarrier(null);
1016 this.setCellphoneNumber(null);
1017 this.setFaxAreaCode(null);
1018 this.setFaxCountry(null);
1019 this.setFaxNumber(null);
1022 this.setBirthday(null);
1023 this.setComment(null);
1027 * Copies given contact into the controller
1029 * @param contact Contact instance
1031 private void copyContact (final Contact contact) {
1032 // Is the instance valid?
1033 if (null == contact) {
1035 throw new NullPointerException("contact is null"); //NOI18N
1036 } else if (contact.getContactId() == null) {
1038 throw new NullPointerException("contact.contactId is null"); //NOI18N
1039 } else if (contact.getContactId() < 1) {
1040 // Not valid id number
1041 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1046 this.setGender(contact.getContactGender());
1047 this.setFirstName(contact.getContactFirstName());
1048 this.setFamilyName(contact.getContactFamilyName());
1049 this.setStreet(contact.getContactStreet());
1050 this.setHouseNumber(contact.getContactHouseNumber());
1051 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
1052 this.setZipCode(contact.getContactZipCode());
1053 this.setCity(contact.getContactCity());
1054 this.setCountry(contact.getContactCountry());
1055 this.setEmailAddress(contact.getContactEmailAddress());
1056 this.setBirthday(contact.getContactBirthday());
1057 this.setComment(contact.getContactComment());
1059 // Get cellphone, phone and fax instance
1060 DialableCellphoneNumber cellphone = contact.getContactCellphoneNumber();
1061 DialableFaxNumber fax = contact.getContactFaxNumber();
1062 DialableLandLineNumber phone = contact.getContactLandLineNumber();
1065 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
1066 this.setPhoneCountry(phone.getPhoneCountry());
1067 this.setPhoneAreaCode(phone.getPhoneAreaCode());
1068 this.setPhoneNumber(phone.getPhoneNumber());
1071 if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) {
1072 this.setCellphoneCarrier(cellphone.getCellphoneProvider());
1073 this.setCellphoneNumber(cellphone.getPhoneNumber());
1076 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
1077 this.setFaxCountry(fax.getPhoneCountry());
1078 this.setFaxAreaCode(fax.getPhoneAreaCode());
1079 this.setFaxNumber(fax.getPhoneNumber());
1084 * Removes given contact from all lists
1086 * @param contact Contact instance to remove
1088 private void removeContact (final Contact contact) {
1089 // Is the instance valid?
1090 if (null == contact) {
1092 throw new NullPointerException("contact is null"); //NOI18N
1093 } else if (contact.getContactId() == null) {
1095 throw new NullPointerException("contact.contactId is null"); //NOI18N
1096 } else if (contact.getContactId() < 1) {
1097 // Not valid id number
1098 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1101 // Remove from general list
1102 if (!this.contactList.remove(contact)) {
1103 // Did not remove contact
1104 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
1107 // Remove from other lists
1108 this.emailAddressList.remove(contact.getContactEmailAddress());