2 * Copyright (C) 2016 Roland Häder
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.LinkedList;
24 import java.util.List;
25 import java.util.Objects;
26 import javax.annotation.PostConstruct;
27 import javax.enterprise.context.SessionScoped;
28 import javax.enterprise.event.Observes;
29 import javax.faces.view.facelets.FaceletException;
30 import javax.inject.Inject;
31 import javax.inject.Named;
32 import javax.naming.Context;
33 import javax.naming.InitialContext;
34 import javax.naming.NamingException;
35 import org.mxchange.jcontacts.contact.Contact;
36 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
37 import org.mxchange.jcontacts.contact.UserContact;
38 import org.mxchange.jcontacts.contact.gender.Gender;
39 import org.mxchange.jcontacts.contact.utils.ContactUtils;
40 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
41 import org.mxchange.jcontacts.events.contact.deleted.ObservableAdminDeletedContactEvent;
42 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
43 import org.mxchange.jcontacts.events.fax.unlinked.ObservableAdminUnlinkedFaxNumberEvent;
44 import org.mxchange.jcontacts.events.landline.unlinked.ObservableAdminUnlinkedLandLineNumberEvent;
45 import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent;
46 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
47 import org.mxchange.jcountry.data.Country;
48 import org.mxchange.jjobs.beans.BaseJobsController;
49 import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
50 import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
51 import org.mxchange.jphone.events.mobile.remove.AdminRemoveMobileNumberFromListEvent;
52 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
53 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
54 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
55 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
56 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
57 import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
58 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
59 import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent;
60 import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
61 import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent;
62 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
63 import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
64 import org.mxchange.jusercore.model.user.User;
67 * A general contact controller (bean)
69 * @author Roland Häder<roland@mxchange.org>
71 @Named ("contactController")
73 public class JobsContactWebSessionBean extends BaseJobsController implements JobsContactWebSessionController {
78 private static final long serialVersionUID = 542_145_347_916L;
83 private Date birthday;
93 private String comment;
98 private final ContactSessionBeanRemote contactBean;
103 private final List<Contact> contacts;
108 private Country country;
113 private String emailAddress;
116 * Email address repeated
118 private String emailAddressRepeat;
123 private final List<String> emailAddresses;
128 private String familyName;
131 * Fax number's area code
133 private Integer faxAreaCode;
136 * Country instance for fax number
138 private Country faxCountry;
143 private Long faxNumber;
148 private String firstName;
153 private Gender gender;
158 private Short houseNumber;
161 * House number extension
163 private String houseNumberExtension;
166 * Whether a fax entry has been unlinked
168 private boolean isFaxUnlinked;
171 * Whether a land-line number has been unlinked
173 private boolean isLandLineUnlinked;
176 * Whether a mobile entry has been unlinked
178 private boolean isMobileUnlinked;
181 * Land-line number area code
183 private Integer landLineAreaCode;
186 * Country instance for land-line number
188 private Country landLineCountry;
193 private Long landLineNumber;
198 private Long mobileNumber;
203 private MobileProvider mobileProvider;
206 * A list of all selectable contacts
208 private List<Contact> selectableContacts;
213 private String street;
218 private String title;
221 * Regular user controller
224 private JobsUserWebSessionController userController;
227 * Login controller (bean)
230 private JobsUserLoginWebSessionController userLoginController;
235 private Integer zipCode;
238 * Default constructor
240 public JobsContactWebSessionBean () {
243 // Get initial context
244 Context context = new InitialContext();
247 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jjobs-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
248 } catch (final NamingException e) {
250 throw new FaceletException(e);
254 this.contacts = new LinkedList<>();
255 this.emailAddresses = new LinkedList<>();
259 public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
260 // The event must be valid
263 throw new NullPointerException("event is null"); //NOI18N
264 } else if (event.getAddedContact() == null) {
266 throw new NullPointerException("event.addedContact is null"); //NOI18N
267 } else if (event.getAddedContact().getContactId() == null) {
269 throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
270 } else if (event.getAddedContact().getContactId() < 1) {
272 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
279 this.uniqueAddContact(event.getAddedContact());
281 // Add to selectable contacts
282 this.selectableContacts.add(event.getAddedContact());
286 public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
287 // event should not be null
290 throw new NullPointerException("event is null"); //NOI18N
291 } else if (event.getAddedUser() == null) {
293 throw new NullPointerException("event.addedUser is null"); //NOI18N
294 } else if (event.getAddedUser().getUserId() == null) {
296 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
297 } else if (event.getAddedUser().getUserId() < 1) {
299 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
307 public void afterAdminDeletedContactEvent (@Observes final ObservableAdminDeletedContactEvent event) {
308 // event should not be null
311 throw new NullPointerException("event is null"); //NOI18N
312 } else if (event.getDeletedContact() == null) {
314 throw new NullPointerException("event.deletedContact is null"); //NOI18N
315 } else if (event.getDeletedContact().getContactId() == null) {
317 throw new NullPointerException("event.deletedContact.contactId is null"); //NOI18N
318 } else if (event.getDeletedContact().getContactId() < 1) {
320 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getDeletedContact(), event.getDeletedContact().getContactId())); //NOI18N
323 // Remove from both lists
324 this.contacts.remove(event.getDeletedContact());
325 this.selectableContacts.remove(event.getDeletedContact());
332 public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent event) {
333 // event should not be null
336 throw new NullPointerException("event is null"); //NOI18N
337 } else if (event.getLinkedUser() == null) {
339 throw new NullPointerException("event.linkedUser is null"); //NOI18N
340 } else if (event.getLinkedUser().getUserContact() == null) {
342 throw new NullPointerException("event.linkedUser.userContact is null"); //NOI18N
343 } else if (event.getLinkedUser().getUserContact().getContactId() == null) {
345 throw new NullPointerException("event.linkedUser.userContact.contactId is null"); //NOI18N
346 } else if (event.getLinkedUser().getUserContact().getContactId() < 1) {
348 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N
351 // Remove contact from list available contacts list
352 this.selectableContacts.remove(event.getLinkedUser().getUserContact());
359 public void afterAdminUnlinkedFaxContactDataEvent (@Observes final ObservableAdminUnlinkedFaxNumberEvent event) {
360 // event should not be null
363 throw new NullPointerException("event is null"); //NOI18N
364 } else if (event.getUnlinkedFaxNumber() == null) {
366 throw new NullPointerException("event.unlinkedFaxNumber is null"); //NOI18N
367 } else if (event.getUnlinkedFaxNumber().getPhoneId() == null) {
369 throw new NullPointerException("event.unlinkedFaxNumber.contactId is null"); //NOI18N
370 } else if (event.getUnlinkedFaxNumber().getPhoneId() < 1) {
372 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedFaxNumber(), event.getUnlinkedFaxNumber().getPhoneId())); //NOI18N
375 // Remove it from list
376 this.removeFromContacts(event.getUnlinkedFaxNumber());
383 public void afterAdminUnlinkedLandLineContactDataEvent (@Observes final ObservableAdminUnlinkedLandLineNumberEvent event) {
384 // event should not be null
387 throw new NullPointerException("event is null"); //NOI18N
388 } else if (event.getUnlinkedLandLineNumber() == null) {
390 throw new NullPointerException("event.unlinkedLandLineNumber is null"); //NOI18N
391 } else if (event.getUnlinkedLandLineNumber().getPhoneId() == null) {
393 throw new NullPointerException("event.unlinkedLandLineNumber.contactId is null"); //NOI18N
394 } else if (event.getUnlinkedLandLineNumber().getPhoneId() < 1) {
396 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedLandLineNumber(), event.getUnlinkedLandLineNumber().getPhoneId())); //NOI18N
399 // Remove it from list
400 this.removeFromContacts(event.getUnlinkedLandLineNumber());
407 public void afterAdminUnlinkedMobileContactDataEvent (@Observes final ObservableAdminUnlinkedMobileNumberEvent event) {
408 // event should not be null
411 throw new NullPointerException("event is null"); //NOI18N
412 } else if (event.getUnlinkedMobileNumber() == null) {
414 throw new NullPointerException("event.unlinkedMobileNumber is null"); //NOI18N
415 } else if (event.getUnlinkedMobileNumber().getPhoneId() == null) {
417 throw new NullPointerException("event.unlinkedMobileNumber.contactId is null"); //NOI18N
418 } else if (event.getUnlinkedMobileNumber().getPhoneId() < 1) {
420 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedMobileNumber(), event.getUnlinkedMobileNumber().getPhoneId())); //NOI18N
423 // Remove it from list
424 this.removeFromContacts(event.getUnlinkedMobileNumber());
431 public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
432 // event should not be null
435 throw new NullPointerException("event is null"); //NOI18N
436 } else if (event.getUpdatedContact() == null) {
438 throw new NullPointerException("event.updatedContact is null"); //NOI18N
439 } else if (event.getUpdatedContact().getContactId() == null) {
441 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
442 } else if (event.getUpdatedContact().getContactId() < 1) {
444 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
447 // Add contact instance only once
448 this.uniqueAddContact(event.getUpdatedContact());
450 // Add email address to list
451 this.emailAddresses.add(event.getUpdatedContact().getContactEmailAddress());
455 public void afterUserConfirmedAccountEventEvent (@Observes final ObservableUserConfirmedAccountEvent event) {
456 // event should not be null
459 throw new NullPointerException("event is null"); //NOI18N
460 } else if (event.getConfirmedUser() == null) {
462 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
463 } else if (event.getConfirmedUser().getUserId() == null) {
465 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
466 } else if (event.getConfirmedUser().getUserId() < 1) {
468 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
471 // Add contact instance only once
472 this.uniqueAddContact(event.getConfirmedUser().getUserContact());
476 public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
477 // event should not be null
480 throw new NullPointerException("event is null"); //NOI18N
481 } else if (event.getLoggedInUser() == null) {
483 throw new NullPointerException("event.loggedInUser is null"); //NOI18N
484 } else if (event.getLoggedInUser().getUserId() == null) {
486 throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
487 } else if (event.getLoggedInUser().getUserId() < 1) {
489 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
492 // Copy all data to this bean
493 this.copyContact(event.getLoggedInUser().getUserContact());
497 public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
498 // event should not be null
501 throw new NullPointerException("event is null"); //NOI18N
502 } else if (event.getRegisteredUser() == null) {
504 throw new NullPointerException("event.registeredUser is null"); //NOI18N
505 } else if (event.getRegisteredUser().getUserId() == null) {
507 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
508 } else if (event.getRegisteredUser().getUserId() < 1) {
510 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
514 Contact registeredContact = event.getRegisteredUser().getUserContact();
516 // Copy all data from registered->user
517 this.copyContact(registeredContact);
519 // Add user name and email address
520 this.addUserNameEmailAddress(registeredContact);
527 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
528 public List<Contact> allContacts () {
530 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size()));
532 // Return un-modified list
533 return this.contacts;
537 public Contact createContactInstance () {
539 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName()));
541 // Is all required data set?
542 if (!this.isRequiredPersonalDataSet()) {
543 // No, then abort here
544 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
547 // Generate phone number
548 DialableLandLineNumber phone = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
549 DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
550 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
552 // Create new contact
553 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
554 contact.setContactStreet(this.getStreet());
555 contact.setContactHouseNumber(this.getHouseNumber());
556 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
557 contact.setContactZipCode(this.getZipCode());
558 contact.setContactCity(this.getCity());
559 contact.setContactCountry(this.getCountry());
560 contact.setContactEmailAddress(this.getEmailAddress());
561 contact.setContactBirthday(this.getBirthday());
562 contact.setContactComment(this.getComment());
565 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
566 // Don't set null or wrong references
567 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
568 // Now the number must be given
569 if (phone.getPhoneAreaCode() == null) {
571 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
572 } else if (phone.getPhoneAreaCode() < 1) {
574 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
575 } else if (phone.getPhoneNumber() == null) {
577 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
578 } else if (phone.getPhoneNumber() < 1) {
580 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
584 contact.setContactLandLineNumber(phone);
587 // Don't set null or wrong references
588 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
589 // Now the number must be given
590 if (fax.getPhoneAreaCode() == null) {
592 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
593 } else if (fax.getPhoneAreaCode() < 1) {
595 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
596 } else if (fax.getPhoneNumber() == null) {
598 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
599 } else if (fax.getPhoneNumber() < 1) {
601 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
605 contact.setContactFaxNumber(fax);
608 // Is the provider set?
609 if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
610 // Is the number set?
611 if (mobile.getPhoneNumber() == null) {
613 throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N
614 } else if (mobile.getPhoneNumber() < 1) {
616 throw new IllegalArgumentException("mobileNumber.phoneNumber is zero or below."); //NOI18N
620 contact.setContactMobileNumber(mobile);
624 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
630 public String doChangePersonalContactData () {
631 // This method shall only be called if the user is logged-in
632 if (!this.userLoginController.isUserLoggedIn()) {
634 throw new IllegalStateException("User is not logged-in"); //NOI18N
635 } else if (!this.isRequiredChangePersonalDataSet()) {
636 // Not all required fields are set
637 throw new FaceletException("Not all required fields are set."); //NOI18N
638 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
639 // Password not matching
640 this.showFacesMessage("form_login_change_personal:currentPassword", "ERROR_USER_CURRENT_PASSWORD_MISMATCHING"); //NOI18N
644 // Get contact instance
645 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
647 // It should be there, so run some tests on it
648 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
649 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
650 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
653 contact.setContactGender(this.getGender());
654 contact.setContactFirstName(this.getFirstName());
655 contact.setContactFamilyName(this.getFamilyName());
656 contact.setContactStreet(this.getStreet());
657 contact.setContactHouseNumber(this.getHouseNumber());
658 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
659 contact.setContactZipCode(this.getZipCode());
660 contact.setContactCity(this.getCity());
661 contact.setContactCountry(this.getCountry());
663 // Update contact's mobile number
664 this.isMobileUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
666 // Update contact's land-line number
667 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
669 // Update contact's fax number
670 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
672 // Send it to the EJB
673 this.contactBean.updateContactData(contact, this.isMobileUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
676 return "user_contact_data_saved"; //NOI18N
680 @SuppressWarnings ("ReturnOfDateField")
681 public Date getBirthday () {
682 return this.birthday;
686 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
687 public void setBirthday (final Date birthday) {
688 this.birthday = birthday;
692 public String getCity () {
697 public void setCity (final String city) {
702 public String getComment () {
707 public void setComment (final String comment) {
708 this.comment = comment;
712 public String getControllerType () {
713 return "general"; //NOI18N
718 public void setControllerType (final String controllerType) {
719 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
723 public Country getCountry () {
728 public void setCountry (final Country country) {
729 this.country = country;
733 public String getEmailAddress () {
734 return this.emailAddress;
738 public void setEmailAddress (final String emailAddress) {
739 this.emailAddress = emailAddress;
743 public String getEmailAddressRepeat () {
744 return this.emailAddressRepeat;
748 public void setEmailAddressRepeat (final String emailAddressRepeat) {
749 this.emailAddressRepeat = emailAddressRepeat;
753 public String getFamilyName () {
754 return this.familyName;
758 public void setFamilyName (final String familyName) {
759 this.familyName = familyName;
763 public Integer getFaxAreaCode () {
764 return this.faxAreaCode;
768 public void setFaxAreaCode (final Integer faxAreaCode) {
769 this.faxAreaCode = faxAreaCode;
773 public Country getFaxCountry () {
774 return this.faxCountry;
778 public void setFaxCountry (final Country faxCountry) {
779 this.faxCountry = faxCountry;
783 public Long getFaxNumber () {
784 return this.faxNumber;
788 public void setFaxNumber (final Long faxNumber) {
789 this.faxNumber = faxNumber;
793 public String getFirstName () {
794 return this.firstName;
798 public void setFirstName (final String firstName) {
799 this.firstName = firstName;
803 public Gender getGender () {
808 public void setGender (final Gender gender) {
809 this.gender = gender;
813 public Short getHouseNumber () {
814 return this.houseNumber;
818 public void setHouseNumber (final Short houseNumber) {
819 this.houseNumber = houseNumber;
823 public String getHouseNumberExtension () {
824 return this.houseNumberExtension;
828 public void setHouseNumberExtension (final String houseNumberExtension) {
829 this.houseNumberExtension = houseNumberExtension;
833 public Integer getLandLineAreaCode () {
834 return this.landLineAreaCode;
838 public void setLandLineAreaCode (final Integer landLineAreaCode) {
839 this.landLineAreaCode = landLineAreaCode;
843 public Country getLandLineCountry () {
844 return this.landLineCountry;
848 public void setLandLineCountry (final Country landLineCountry) {
849 this.landLineCountry = landLineCountry;
853 public Long getLandLineNumber () {
854 return this.landLineNumber;
858 public void setLandLineNumber (final Long landLineNumber) {
859 this.landLineNumber = landLineNumber;
863 public Long getMobileNumber () {
864 return this.mobileNumber;
868 public void setMobileNumber (Long mobileNumber) {
869 this.mobileNumber = mobileNumber;
873 public MobileProvider getMobileProvider () {
874 return this.mobileProvider;
878 public void setMobileProvider (final MobileProvider mobileProvider) {
879 this.mobileProvider = mobileProvider;
883 public String getStreet () {
888 public void setStreet (final String street) {
889 this.street = street;
893 public String getTitle () {
898 public void setTitle (final String title) {
903 public Integer getZipCode () {
908 public void setZipCode (final Integer zipCode) {
909 this.zipCode = zipCode;
913 * Post-initialization of this class
916 public void init () {
917 // Get full email address list for reducing EJB calls
918 this.emailAddresses.addAll(this.contactBean.getEmailAddressList());
921 List<Contact> allContacts = this.contactBean.getAllContacts();
923 // Get full contact list
924 this.contacts.addAll(allContacts);
927 List<User> allUsers = this.userController.allUsers();
930 Iterator<Contact> iterator = allContacts.iterator();
933 while (iterator.hasNext()) {
935 Contact next = iterator.next();
938 Iterator<User> userIterator = allUsers.iterator();
940 // Loop through all users
941 while (userIterator.hasNext()) {
943 User nextUser = userIterator.next();
946 if (Objects.equals(next, nextUser.getUserContact())) {
955 this.selectableContacts = allContacts;
959 public boolean isEmailAddressRegistered (final Contact contact) {
961 if (null == contact) {
963 throw new NullPointerException("contact is null"); //NOI18N
964 } else if (contact.getContactEmailAddress() == null) {
966 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
967 } else if (contact.getContactEmailAddress().isEmpty()) {
969 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
973 return ((this.emailAddresses instanceof List) && (this.emailAddresses.contains(contact.getContactEmailAddress())));
977 public boolean isRequiredChangePersonalDataSet () {
978 return ((this.getGender() != null) &&
979 (this.getFirstName() != null) &&
980 (this.getFamilyName() != null) &&
981 (this.getStreet() != null) &&
982 (this.getHouseNumber() != null) &&
983 (this.getZipCode() != null) &&
984 (this.getCity() != null));
988 public boolean isRequiredPersonalDataSet () {
989 return ((this.getGender() != null) &&
990 (this.getFirstName() != null) &&
991 (this.getFamilyName() != null) &&
992 (this.getStreet() != null) &&
993 (this.getHouseNumber() != null) &&
994 (this.getZipCode() != null) &&
995 (this.getCity() != null) &&
996 (this.getEmailAddress() != null) &&
997 (this.getEmailAddressRepeat() != null));
1001 public boolean isSameEmailAddressEntered () {
1002 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
1006 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
1008 Contact localContact = null;
1013 // Try to lookup it in visible user list
1014 for (final Iterator<Contact> iterator = this.contacts.iterator(); iterator.hasNext();) {
1016 Contact next = iterator.next();
1018 // Is the user id found?
1019 if (Objects.equals(next.getContactId(), contactId)) {
1020 // Copy to other variable
1021 localContact = next;
1026 // Is it still null?
1027 if (null == localContact) {
1028 // Not visible for the current user
1029 throw new ContactNotFoundException(contactId);
1032 // Copy all data to this bean
1033 this.copyContact(localContact);
1036 return localContact;
1040 public void removeMobileNumberFromListEvent (@Observes final AdminRemoveMobileNumberFromListEvent event) {
1041 // event should not be null
1042 if (null == event) {
1044 throw new NullPointerException("event is null"); //NOI18N
1045 } else if (event.getMobileNumberList() == null) {
1047 throw new NullPointerException("event.mobileList is null"); //NOI18N
1048 } else if (event.getMobileNumberList().isEmpty()) {
1049 // List is empty, no need to check
1053 // Check all entries
1054 for (final Contact contact : this.contacts) {
1055 // Is the mobile instance set and in list?
1056 if ((contact.getContactMobileNumber() instanceof DialableMobileNumber) && (event.getMobileNumberList().contains(contact.getContactMobileNumber()))) {
1057 // Found it, so remvoe it from list
1058 event.getMobileNumberList().remove(contact.getContactMobileNumber());
1064 public List<Contact> selectableContacts () {
1065 return Collections.unmodifiableList(this.selectableContacts);
1069 public void updateContactDataFromController (final Contact contact) {
1070 // Is the instance valid?
1071 if (null == contact) {
1073 throw new NullPointerException("contact is null"); //NOI18N
1074 } else if (contact.getContactId() == null) {
1076 throw new NullPointerException("contact.contactId is null"); //NOI18N
1077 } else if (contact.getContactId() < 1) {
1078 // Not valid id number
1079 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1083 this.copyContact(contact);
1087 * Adds email address to bean's internal list.
1089 * @param contact Contact instance
1091 private void addUserNameEmailAddress (final Contact contact) {
1092 // Make sure the entry is not added yet
1093 if (this.emailAddresses.contains(contact.getContactEmailAddress())) {
1095 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
1099 this.emailAddresses.add(contact.getContactEmailAddress());
1105 private void clear () {
1108 this.setGender(null);
1109 this.setTitle(null);
1110 this.setFirstName(null);
1111 this.setFamilyName(null);
1112 this.setStreet(null);
1113 this.setHouseNumber(null);
1114 this.setHouseNumberExtension(null);
1115 this.setZipCode(null);
1117 this.setCountry(null);
1120 this.setEmailAddress(null);
1121 this.setEmailAddressRepeat(null);
1122 this.setLandLineAreaCode(null);
1123 this.setLandLineCountry(null);
1124 this.setLandLineNumber(null);
1125 this.setMobileProvider(null);
1126 this.setMobileNumber(null);
1127 this.setFaxAreaCode(null);
1128 this.setFaxCountry(null);
1129 this.setFaxNumber(null);
1132 this.setBirthday(null);
1133 this.setComment(null);
1137 * Copies given contact into the controller
1139 * @param contact Contact instance
1141 private void copyContact (final Contact contact) {
1142 // Is the instance valid?
1143 if (null == contact) {
1145 throw new NullPointerException("contact is null"); //NOI18N
1146 } else if (contact.getContactId() == null) {
1148 throw new NullPointerException("contact.contactId is null"); //NOI18N
1149 } else if (contact.getContactId() < 1) {
1150 // Not valid id number
1151 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1156 this.setGender(contact.getContactGender());
1157 this.setTitle(contact.getContactTitle());
1158 this.setFirstName(contact.getContactFirstName());
1159 this.setFamilyName(contact.getContactFamilyName());
1160 this.setStreet(contact.getContactStreet());
1161 this.setHouseNumber(contact.getContactHouseNumber());
1162 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
1163 this.setZipCode(contact.getContactZipCode());
1164 this.setCity(contact.getContactCity());
1165 this.setCountry(contact.getContactCountry());
1166 this.setEmailAddress(contact.getContactEmailAddress());
1167 this.setBirthday(contact.getContactBirthday());
1168 this.setComment(contact.getContactComment());
1170 // Get mobile, phone and fax instance
1171 DialableMobileNumber mobile = contact.getContactMobileNumber();
1172 DialableFaxNumber fax = contact.getContactFaxNumber();
1173 DialableLandLineNumber phone = contact.getContactLandLineNumber();
1176 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
1177 this.setLandLineCountry(phone.getPhoneCountry());
1178 this.setLandLineAreaCode(phone.getPhoneAreaCode());
1179 this.setLandLineNumber(phone.getPhoneNumber());
1182 if ((mobile instanceof DialableMobileNumber) && (mobile.getMobileProvider() instanceof MobileProvider)) {
1183 this.setMobileProvider(mobile.getMobileProvider());
1184 this.setMobileNumber(mobile.getPhoneNumber());
1187 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
1188 this.setFaxCountry(fax.getPhoneCountry());
1189 this.setFaxAreaCode(fax.getPhoneAreaCode());
1190 this.setFaxNumber(fax.getPhoneNumber());
1195 * Removes given contact from all lists
1197 * @param contact Contact instance to remove
1199 private void removeContact (final Contact contact) {
1200 // Is the instance valid?
1201 if (null == contact) {
1203 throw new NullPointerException("contact is null"); //NOI18N
1204 } else if (contact.getContactId() == null) {
1206 throw new NullPointerException("contact.contactId is null"); //NOI18N
1207 } else if (contact.getContactId() < 1) {
1208 // Not valid id number
1209 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1212 // Remove from general list
1213 if (!this.contacts.remove(contact)) {
1214 // Did not remove contact
1215 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
1218 // Remove from other lists
1219 this.emailAddresses.remove(contact.getContactEmailAddress());
1223 * Removes given fax number from all contacts
1225 * @param faxNumber Fax number to remove
1227 private void removeFromContacts (final DialableFaxNumber faxNumber) {
1229 System.out.println(MessageFormat.format("{0}.removeFromContacts: faxNumber={1} - CALLED!", this.getClass().getSimpleName(), faxNumber)); //NOI18N
1232 if (null == faxNumber) {
1234 throw new NullPointerException("faxNumber is null"); //NOI18N
1235 } else if (faxNumber.getPhoneId() == null) {
1237 throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
1238 } else if (faxNumber.getPhoneId() < 1) {
1240 throw new NullPointerException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N
1243 // Loop through all contacts
1244 for (final Contact contact : this.contacts) {
1246 System.out.println(MessageFormat.format("{0}.removeFromContacts: contact={1},contact.contactFaxNumber={2}", this.getClass().getSimpleName(), contact, contact.getContactFaxNumber())); //NOI18N
1248 // Is the number set?
1249 if (Objects.equals(contact.getContactFaxNumber(), faxNumber)) {
1251 System.out.println(MessageFormat.format("{0}.removeFromContacts: Unsetting faxNumber={1} ...", this.getClass().getSimpleName(), faxNumber)); //NOI18N
1254 contact.setContactFaxNumber(null);
1260 * Removes given land-line number from all contacts
1262 * @param landLineNumber Land-line number to remove
1264 private void removeFromContacts (final DialableLandLineNumber landLineNumber) {
1266 System.out.println(MessageFormat.format("{0}.removeFromContacts: landLineNumber={1} - CALLED!", this.getClass().getSimpleName(), landLineNumber)); //NOI18N
1269 if (null == landLineNumber) {
1271 throw new NullPointerException("landLineNumber is null"); //NOI18N
1272 } else if (landLineNumber.getPhoneId() == null) {
1274 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
1275 } else if (landLineNumber.getPhoneId() < 1) {
1277 throw new NullPointerException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N
1280 // Loop through all contacts
1281 for (final Contact contact : this.contacts) {
1283 System.out.println(MessageFormat.format("{0}.removeFromContacts: contact={1},contact.contactLandLineNumber={2}", this.getClass().getSimpleName(), contact, contact.getContactLandLineNumber())); //NOI18N
1285 // Is the number set?
1286 if (Objects.equals(contact.getContactLandLineNumber(), landLineNumber)) {
1288 System.out.println(MessageFormat.format("{0}.removeFromContacts: Unsetting landLineNumber={1} ...", this.getClass().getSimpleName(), landLineNumber)); //NOI18N
1291 contact.setContactLandLineNumber(null);
1297 * Removes given mobile number from all contacts
1299 * @param mobileNumber Mobile number to remove
1301 private void removeFromContacts (final DialableMobileNumber mobileNumber) {
1303 System.out.println(MessageFormat.format("{0}.removeFromContacts: mobileNumber={1} - CALLED!", this.getClass().getSimpleName(), mobileNumber)); //NOI18N
1306 if (null == mobileNumber) {
1308 throw new NullPointerException("mobileNumber is null"); //NOI18N
1309 } else if (mobileNumber.getPhoneId() == null) {
1311 throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N
1312 } else if (mobileNumber.getPhoneId() < 1) {
1314 throw new NullPointerException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N
1317 // Loop through all contacts
1318 for (final Contact contact : this.contacts) {
1320 System.out.println(MessageFormat.format("{0}.removeFromContacts: contact={1},contact.contactMobileNumber={2}", this.getClass().getSimpleName(), contact, contact.getContactMobileNumber())); //NOI18N
1322 // Is the number set?
1323 if (Objects.equals(contact.getContactMobileNumber(), mobileNumber)) {
1325 System.out.println(MessageFormat.format("{0}.removeFromContacts: Unsetting mobileNumber={1} ...", this.getClass().getSimpleName(), mobileNumber)); //NOI18N
1328 contact.setContactMobileNumber(null);
1334 * Adds unique instance to contact list. First any existing instance is
1335 * being removed, then the new instance is added.
1337 * @param contact Contact instance to add uniquely
1339 private void uniqueAddContact (final Contact contact) {
1340 // Is the instance valid?
1341 if (null == contact) {
1343 throw new NullPointerException("contact is null"); //NOI18N
1344 } else if (contact.getContactId() == null) {
1346 throw new NullPointerException("contact.contactId is null"); //NOI18N
1347 } else if (contact.getContactId() < 1) {
1348 // Not valid id number
1349 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1352 // Get iterator from list
1353 Iterator<Contact> iterator = this.contacts.iterator();
1355 // "Walk" through all entries
1356 while (iterator.hasNext()) {
1358 Contact next = iterator.next();
1360 // Is id number the same?
1361 if (Objects.equals(contact.getContactId(), next.getContactId())) {
1362 // Found entry, so remove it and abort
1363 this.removeContact(next);
1368 // Add contact to list
1369 this.contacts.add(contact);