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) {
233 // The event must be valid
236 throw new NullPointerException("event is null"); //NOI18N
237 } else if (event.getAddedContact() == null) {
239 throw new NullPointerException("event.addedContact is null"); //NOI18N
240 } else if (event.getAddedContact().getContactId() == null) {
242 throw new NullPointerException("event.addedContact.customerId is null"); //NOI18N
243 } else if (event.getAddedContact().getContactId() < 1) {
245 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.customerId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
252 this.contactList.add(event.getAddedContact());
256 public void afterAdminAddedCustomer (@Observes final AdminAddedCustomerEvent event) {
257 // The event must be valid
260 throw new NullPointerException("event is null"); //NOI18N
261 } else if (event.getAddedCustomer() == null) {
263 throw new NullPointerException("event.addedCustomer is null"); //NOI18N
264 } else if (event.getAddedCustomer().getCustomerId() == null) {
266 throw new NullPointerException("event.addedCustomer.customerId is null"); //NOI18N
267 } else if (event.getAddedCustomer().getCustomerId() < 1) {
269 throw new IllegalArgumentException(MessageFormat.format("event.addedCustomer.customerId={0} is not valid", event.getAddedCustomer().getCustomerId())); //NOI18N //NOI18N
276 this.contactList.add(event.getAddedCustomer().getCustomerContact());
280 public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
282 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminAddedUserEvent: event={0} - CALLED!", event)); //NOI18N
284 // event should not be null
287 throw new NullPointerException("event is null"); //NOI18N
288 } else if (event.getAddedUser() == null) {
290 throw new NullPointerException("event.addedUser is null"); //NOI18N
291 } else if (event.getAddedUser().getUserId() == null) {
293 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
294 } else if (event.getAddedUser().getUserId() < 1) {
296 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
303 //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminAddedUserEvent: EXIT!"); //NOI18N
307 public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
309 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
311 // event should not be null
314 throw new NullPointerException("event is null"); //NOI18N
315 } else if (event.getUpdatedContact() == null) {
317 throw new NullPointerException("event.updatedContact is null"); //NOI18N
318 } else if (event.getUpdatedContact().getContactId() == null) {
320 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
321 } else if (event.getUpdatedContact().getContactId() < 1) {
323 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
326 // Get iterator from list
327 Iterator<Contact> iterator = this.contactList.iterator();
329 // "Walk" through all entries
330 while (iterator.hasNext()) {
332 Contact next = iterator.next();
334 // Is id number the same?
335 if (Objects.equals(event.getUpdatedContact().getContactId(), next.getContactId())) {
336 // Found entry, so remove it and abort
337 this.contactList.remove(next);
339 // Remove also email from list
340 this.emailAddressList.remove(next.getContactEmailAddress());
345 // Add contact to list
346 this.contactList.add(event.getUpdatedContact());
348 // Add email address to list
349 this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
353 public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
355 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
357 // event should not be null
360 throw new NullPointerException("event is null"); //NOI18N
361 } else if (event.getRegisteredUser() == null) {
363 throw new NullPointerException("event.registeredUser is null"); //NOI18N
364 } else if (event.getRegisteredUser().getUserId() == null) {
366 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
367 } else if (event.getRegisteredUser().getUserId() < 1) {
369 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
373 Contact registeredContact = event.getRegisteredUser().getUserContact();
376 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: registeredContact={0}", registeredContact)); //NOI18N
378 // Copy all data from registered->user
379 this.copyContact(registeredContact);
381 // Add user name and email address
382 this.addUserNameEmailAddress(registeredContact);
388 //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterRegistration: EXIT!"); //NOI18N
392 public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) {
394 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
396 // event should not be null
399 throw new NullPointerException("event is null"); //NOI18N
400 } else if (event.getConfirmedUser() == null) {
402 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
403 } else if (event.getConfirmedUser().getUserId() == null) {
405 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
406 } else if (event.getConfirmedUser().getUserId() < 1) {
408 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
411 // "Cache" contact instance
412 Contact contact = event.getConfirmedUser().getUserContact();
414 // Get iterator from list
415 Iterator<Contact> iterator = this.contactList.iterator();
417 // "Walk" through all entries
418 while (iterator.hasNext()) {
420 Contact next = iterator.next();
422 // Is id number the same?
423 if (Objects.equals(contact.getContactId(), next.getContactId())) {
424 // Found entry, so remove it and abort
425 this.contactList.remove(next);
430 // Add contact to list
431 this.contactList.add(contact);
435 public void afterUserLogin (@Observes final UserLoggedInEvent event) {
437 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
439 // event should not be null
442 throw new NullPointerException("event is null"); //NOI18N
443 } else if (event.getLoggedInUser() == null) {
445 throw new NullPointerException("event.loggedInUser is null"); //NOI18N
446 } else if (event.getLoggedInUser().getUserId() == null) {
448 throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
449 } else if (event.getLoggedInUser().getUserId() < 1) {
451 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
454 // Copy all data to this bean
455 this.copyContact(event.getLoggedInUser().getUserContact());
458 //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N
462 public List<Contact> allContacts () {
464 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size()));
466 // Return un-modified list
467 return Collections.unmodifiableList(this.contactList);
471 public Contact createContactInstance () {
473 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName()));
475 // Is all required data set?
476 if (!this.isRequiredPersonalDataSet()) {
477 // No, then abort here
478 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
481 // Generate phone number
482 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
483 DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
484 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
486 // Create new contact
487 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
488 contact.setContactStreet(this.getStreet());
489 contact.setContactHouseNumber(this.getHouseNumber());
490 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
491 contact.setContactZipCode(this.getZipCode());
492 contact.setContactCity(this.getCity());
493 contact.setContactCountry(this.getCountry());
494 contact.setContactEmailAddress(this.getEmailAddress());
495 contact.setContactBirthday(this.getBirthday());
496 contact.setContactComment(this.getComment());
499 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
500 // Don't set null or wrong references
501 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
502 // Now the number must be given
503 if (phone.getPhoneAreaCode() == null) {
505 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
506 } else if (phone.getPhoneAreaCode() < 1) {
508 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
509 } else if (phone.getPhoneNumber() == null) {
511 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
512 } else if (phone.getPhoneNumber() < 1) {
514 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
518 contact.setContactLandLineNumber(phone);
521 // Don't set null or wrong references
522 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
523 // Now the number must be given
524 if (fax.getPhoneAreaCode() == null) {
526 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
527 } else if (fax.getPhoneAreaCode() < 1) {
529 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
530 } else if (fax.getPhoneNumber() == null) {
532 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
533 } else if (fax.getPhoneNumber() < 1) {
535 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
539 contact.setContactFaxNumber(fax);
542 // Is the provider set?
543 if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
544 // Is the number set?
545 if (cellphone.getPhoneNumber() == null) {
547 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
548 } else if (cellphone.getPhoneNumber() < 1) {
550 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
553 // Set cellphone number
554 contact.setContactCellphoneNumber(cellphone);
558 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
564 public String doChangePersonalContactData () {
565 // This method shall only be called if the user is logged-in
566 if (!this.userLoginController.isUserLoggedIn()) {
568 throw new IllegalStateException("User is not logged-in"); //NOI18N
569 } else if (!this.isRequiredChangePersonalDataSet()) {
570 // Not all required fields are set
571 throw new FaceletException("Not all required fields are set."); //NOI18N
572 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
573 // Password not matching
574 this.showFacesMessage("login_change_personal_form:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
578 // Get contact instance
579 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
581 // It should be there, so run some tests on it
582 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
583 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
584 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
587 contact.setContactGender(this.getGender());
588 contact.setContactFirstName(this.getFirstName());
589 contact.setContactFamilyName(this.getFamilyName());
590 contact.setContactStreet(this.getStreet());
591 contact.setContactHouseNumber(this.getHouseNumber());
592 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
593 contact.setContactZipCode(this.getZipCode());
594 contact.setContactCity(this.getCity());
595 contact.setContactCountry(this.getCountry());
597 // Update contact's cellphone number
598 this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
600 // Update contact's land-line number
601 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
603 // Update contact's fax number
604 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
606 // Send it to the EJB
607 this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
610 return "contact_data_saved"; //NOI18N
614 @SuppressWarnings ("ReturnOfDateField")
615 public Date getBirthday () {
616 return this.birthday;
620 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
621 public void setBirthday (final Date birthday) {
622 this.birthday = birthday;
626 public MobileProvider getCellphoneCarrier () {
627 return this.cellphoneCarrier;
631 public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
632 this.cellphoneCarrier = cellphoneCarrier;
636 public Long getCellphoneNumber () {
637 return this.cellphoneNumber;
641 public void setCellphoneNumber (Long cellphoneNumber) {
642 this.cellphoneNumber = cellphoneNumber;
646 public String getCity () {
651 public void setCity (final String city) {
656 public String getComment () {
661 public void setComment (final String comment) {
662 this.comment = comment;
666 public Country getCountry () {
671 public void setCountry (final Country country) {
672 this.country = country;
676 public String getEmailAddress () {
677 return this.emailAddress;
681 public void setEmailAddress (final String emailAddress) {
682 this.emailAddress = emailAddress;
686 public String getEmailAddressRepeat () {
687 return this.emailAddressRepeat;
691 public void setEmailAddressRepeat (final String emailAddressRepeat) {
692 this.emailAddressRepeat = emailAddressRepeat;
696 public String getFamilyName () {
697 return this.familyName;
701 public void setFamilyName (final String familyName) {
702 this.familyName = familyName;
706 public Integer getFaxAreaCode () {
707 return this.faxAreaCode;
711 public void setFaxAreaCode (final Integer faxAreaCode) {
712 this.faxAreaCode = faxAreaCode;
716 public Country getFaxCountry () {
717 return this.faxCountry;
721 public void setFaxCountry (final Country faxCountry) {
722 this.faxCountry = faxCountry;
726 public Long getFaxNumber () {
727 return this.faxNumber;
731 public void setFaxNumber (final Long faxNumber) {
732 this.faxNumber = faxNumber;
736 public String getFirstName () {
737 return this.firstName;
741 public void setFirstName (final String firstName) {
742 this.firstName = firstName;
746 public Gender getGender () {
751 public void setGender (final Gender gender) {
752 this.gender = gender;
756 public Short getHouseNumber () {
757 return this.houseNumber;
761 public void setHouseNumber (final Short houseNumber) {
762 this.houseNumber = houseNumber;
766 public String getHouseNumberExtension () {
767 return this.houseNumberExtension;
771 public void setHouseNumberExtension (final String houseNumberExtension) {
772 this.houseNumberExtension = houseNumberExtension;
776 public Integer getPhoneAreaCode () {
777 return this.phoneAreaCode;
781 public void setPhoneAreaCode (final Integer phoneAreaCode) {
782 this.phoneAreaCode = phoneAreaCode;
786 public Country getPhoneCountry () {
787 return this.phoneCountry;
791 public void setPhoneCountry (final Country phoneCountry) {
792 this.phoneCountry = phoneCountry;
796 public Long getPhoneNumber () {
797 return this.phoneNumber;
801 public void setPhoneNumber (final Long phoneNumber) {
802 this.phoneNumber = phoneNumber;
806 public String getStreet () {
811 public void setStreet (final String street) {
812 this.street = street;
816 public Integer getZipCode () {
821 public void setZipCode (final Integer zipCode) {
822 this.zipCode = zipCode;
826 public boolean hasContacts () {
827 return (!this.contactList.isEmpty());
831 * Post-initialization of this class
834 public void init () {
835 // Get full email address list for reducing EJB calls
836 this.emailAddressList = this.contactBean.getEmailAddressList();
838 // Get full contact list
839 this.contactList = this.contactBean.getAllContacts();
843 public boolean isEmailAddressRegistered (final Contact contact) {
845 if (null == contact) {
847 throw new NullPointerException("contact is null"); //NOI18N
848 } else if (contact.getContactEmailAddress() == null) {
850 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
851 } else if (contact.getContactEmailAddress().isEmpty()) {
853 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
857 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
861 public boolean isRequiredChangePersonalDataSet () {
862 return ((this.getGender() != null) &&
863 (this.getFirstName() != null) &&
864 (this.getFamilyName() != null) &&
865 (this.getStreet() != null) &&
866 (this.getHouseNumber() != null) &&
867 (this.getZipCode() != null) &&
868 (this.getCity() != null));
872 public boolean isRequiredPersonalDataSet () {
873 return ((this.getGender() != null) &&
874 (this.getFirstName() != null) &&
875 (this.getFamilyName() != null) &&
876 (this.getStreet() != null) &&
877 (this.getHouseNumber() != null) &&
878 (this.getZipCode() != null) &&
879 (this.getCity() != null) &&
880 (this.getEmailAddress() != null) &&
881 (this.getEmailAddressRepeat() != null));
885 public boolean isSameEmailAddressEntered () {
886 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
890 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
892 Contact localContact = null;
897 // Try to lookup it in visible user list
898 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
900 Contact next = iterator.next();
902 // Is the user id found?
903 if (Objects.equals(next.getContactId(), contactId)) {
904 // Copy to other variable
911 if (null == localContact) {
912 // Not visible for the current user
913 throw new ContactNotFoundException(contactId);
916 // Copy all data to this bean
917 this.copyContact(localContact);
924 public void updateContactDataFromController (final Contact contact) {
925 // Is the instance valid?
926 if (null == contact) {
928 throw new NullPointerException("contact is null"); //NOI18N
929 } else if (contact.getContactId() == null) {
931 throw new NullPointerException("contact.contactId is null"); //NOI18N
932 } else if (contact.getContactId() < 1) {
933 // Not valid id number
934 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
938 this.copyContact(contact);
942 * Adds email address to bean's internal list.
944 * @param contact Contact instance
946 private void addUserNameEmailAddress (final Contact contact) {
947 // Make sure the entry is not added yet
948 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
950 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
954 this.emailAddressList.add(contact.getContactEmailAddress());
960 private void clear () {
963 this.setFirstName(null);
964 this.setFamilyName(null);
965 this.setStreet(null);
966 this.setHouseNumber(null);
967 this.setHouseNumberExtension(null);
968 this.setZipCode(null);
970 this.setCountry(null);
973 this.setEmailAddress(null);
974 this.setEmailAddressRepeat(null);
975 this.setPhoneCountry(null);
976 this.setPhoneAreaCode(null);
977 this.setPhoneCountry(null);
978 this.setPhoneNumber(null);
979 this.setCellphoneCarrier(null);
980 this.setCellphoneNumber(null);
981 this.setFaxAreaCode(null);
982 this.setFaxCountry(null);
983 this.setFaxNumber(null);
986 this.setBirthday(null);
987 this.setComment(null);
991 * Copies given contact into the controller
993 * @param contact Contact instance
995 private void copyContact (final Contact contact) {
996 // Is the instance valid?
997 if (null == contact) {
999 throw new NullPointerException("contact is null"); //NOI18N
1000 } else if (contact.getContactId() == null) {
1002 throw new NullPointerException("contact.contactId is null"); //NOI18N
1003 } else if (contact.getContactId() < 1) {
1004 // Not valid id number
1005 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1010 this.setGender(contact.getContactGender());
1011 this.setFirstName(contact.getContactFirstName());
1012 this.setFamilyName(contact.getContactFamilyName());
1013 this.setStreet(contact.getContactStreet());
1014 this.setHouseNumber(contact.getContactHouseNumber());
1015 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
1016 this.setZipCode(contact.getContactZipCode());
1017 this.setCity(contact.getContactCity());
1018 this.setCountry(contact.getContactCountry());
1019 this.setEmailAddress(contact.getContactEmailAddress());
1020 this.setBirthday(contact.getContactBirthday());
1021 this.setComment(contact.getContactComment());
1023 // Get cellphone, phone and fax instance
1024 DialableCellphoneNumber cellphone = contact.getContactCellphoneNumber();
1025 DialableFaxNumber fax = contact.getContactFaxNumber();
1026 DialableLandLineNumber phone = contact.getContactLandLineNumber();
1029 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
1030 this.setPhoneCountry(phone.getPhoneCountry());
1031 this.setPhoneAreaCode(phone.getPhoneAreaCode());
1032 this.setPhoneNumber(phone.getPhoneNumber());
1035 if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) {
1036 this.setCellphoneCarrier(cellphone.getCellphoneProvider());
1037 this.setCellphoneNumber(cellphone.getPhoneNumber());
1040 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
1041 this.setFaxCountry(fax.getPhoneCountry());
1042 this.setFaxAreaCode(fax.getPhoneAreaCode());
1043 this.setFaxNumber(fax.getPhoneNumber());
1048 * Removes given contact from all lists
1050 * @param contact Contact instance to remove
1052 private void removeContact (final Contact contact) {
1053 // Is the instance valid?
1054 if (null == contact) {
1056 throw new NullPointerException("contact is null"); //NOI18N
1057 } else if (contact.getContactId() == null) {
1059 throw new NullPointerException("contact.contactId is null"); //NOI18N
1060 } else if (contact.getContactId() < 1) {
1061 // Not valid id number
1062 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1065 // Remove from general list
1066 if (!this.contactList.remove(contact)) {
1067 // Did not remove contact
1068 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
1071 // Remove from other lists
1072 this.emailAddressList.remove(contact.getContactEmailAddress());