2 * Copyright (C) 2016 - 2020 Free Software Foundation
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 fish.payara.cdi.jsr107.impl.NamedCache;
20 import java.text.MessageFormat;
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.cache.Cache;
29 import javax.enterprise.context.RequestScoped;
30 import javax.enterprise.event.Observes;
31 import javax.faces.view.facelets.FaceletException;
32 import javax.inject.Inject;
33 import javax.inject.Named;
34 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
35 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
36 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
37 import org.mxchange.jcontacts.model.contact.Contact;
38 import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
39 import org.mxchange.jcontacts.model.contact.Contacts;
40 import org.mxchange.jcontacts.model.contact.UserContact;
41 import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
42 import org.mxchange.jcountry.model.data.Country;
43 import org.mxchange.jjobs.beans.BaseJobsBean;
44 import org.mxchange.jjobs.beans.user.JobsUserWebRequestController;
45 import org.mxchange.jjobs.beans.user.login.JobsUserLoginWebSessionController;
46 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
47 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
48 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
49 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
50 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
51 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
52 import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
53 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
54 import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
55 import org.mxchange.jusercore.model.user.User;
56 import org.mxchange.juserlogincore.events.confirmation.ObservableUserConfirmedAccountEvent;
57 import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent;
58 import org.mxchange.juserlogincore.events.registration.ObservableUserRegisteredEvent;
59 import org.mxchange.juserlogincore.exceptions.UserPasswordMismatchException;
62 * A general contact controller (bean)
64 * @author Roland Häder<roland@mxchange.org>
66 @Named ("contactController")
68 public class JobsContactWebRequestBean extends BaseJobsBean implements JobsContactWebRequestController {
73 private static final long serialVersionUID = 542_145_347_916L;
76 * Academic academicTitle
78 private String academicTitle;
83 private Date birthday;
93 private String comment;
96 * EJB for general contact purposes
98 @EJB (lookup = "java:global/jjobs-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote")
99 private ContactSessionBeanRemote contactBean;
105 @NamedCache (cacheName = "contactCache")
106 private Cache<Long, Contact> contactCache;
111 private Country country;
116 private String emailAddress;
122 @NamedCache (cacheName = "emailAddressCache")
123 private Cache<Long, String> emailAddressCache;
126 * Email address repeated
128 private String emailAddressRepeat;
133 private String familyName;
136 * Fax number's area code
138 private Integer faxAreaCode;
141 * Country instance for fax number
143 private Country faxCountry;
148 private Long faxNumber;
153 private String firstName;
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 * Phone number area code
183 private Integer landLineAreaCode;
186 * Country instance for phone number
188 private Country landLineCountry;
193 private Long landLineNumber;
198 private Long mobileNumber;
201 * Mobile number's carrier
203 private MobileProvider mobileProvider;
206 * Personal academicTitle
208 private PersonalTitle personalTitle;
211 * A list of all selectable contacts
214 @NamedCache (cacheName = "selectableContactsCache")
215 private Cache<Long, Contact> selectableContactsCache;
220 private String street;
223 * Regular user controller
226 private JobsUserWebRequestController userController;
229 * Login bean (controller)
232 private JobsUserLoginWebSessionController userLoginController;
237 private Integer zipCode;
240 * Default constructor
242 public JobsContactWebRequestBean () {
243 // Call super constructor
248 * Observes events being fired when an administrator has added a new
251 * @param event Event being fired
253 public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
254 // The event must be valid
257 throw new NullPointerException("event is null"); //NOI18N
258 } else if (event.getAddedContact() == null) {
260 throw new NullPointerException("event.addedContact is null"); //NOI18N
261 } else if (event.getAddedContact().getContactId() == null) {
263 throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
264 } else if (event.getAddedContact().getContactId() < 1) {
266 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
273 this.uniqueAddContact(event.getAddedContact());
275 // Add to selectable contacts
276 this.selectableContactsCache.put(event.getAddedContact().getContactId(), event.getAddedContact());
280 * Event observer for newly added users by administrator
282 * @param event Event being fired
284 public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
285 // event should not be null
288 throw new NullPointerException("event is null"); //NOI18N
289 } else if (event.getAddedUser() == null) {
291 throw new NullPointerException("event.addedUser is null"); //NOI18N
292 } else if (event.getAddedUser().getUserId() == null) {
294 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
295 } else if (event.getAddedUser().getUserId() < 1) {
297 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
305 * Observes events being fired when an administrator has linked a new user
306 * with existing contact data.
308 * @param event Event being fired
310 public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent event) {
311 // event should not be null
314 throw new NullPointerException("event is null"); //NOI18N
315 } else if (event.getLinkedUser() == null) {
317 throw new NullPointerException("event.linkedUser is null"); //NOI18N
318 } else if (event.getLinkedUser().getUserContact() == null) {
320 throw new NullPointerException("event.linkedUser.userContact is null"); //NOI18N
321 } else if (event.getLinkedUser().getUserContact().getContactId() == null) {
323 throw new NullPointerException("event.linkedUser.userContact.contactId is null"); //NOI18N
324 } else if (event.getLinkedUser().getUserContact().getContactId() < 1) {
326 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N
329 // Remove contact from list available contacts list
330 this.selectableContactsCache.remove(event.getLinkedUser().getUserContact().getContactId());
337 * Event observer for updated contact data by administrators
339 * @param event Updated contact data event
341 public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
342 // event should not be null
345 throw new NullPointerException("event is null"); //NOI18N
346 } else if (event.getUpdatedContact() == null) {
348 throw new NullPointerException("event.updatedContact is null"); //NOI18N
349 } else if (event.getUpdatedContact().getContactId() == null) {
351 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
352 } else if (event.getUpdatedContact().getContactId() < 1) {
354 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
357 // Add contact instance only once
358 this.uniqueAddContact(event.getUpdatedContact());
360 // Add email address to list
361 this.emailAddressCache.put(event.getUpdatedContact().getContactId(), event.getUpdatedContact().getContactEmailAddress());
365 * Event observer when user confirmed account.
367 * @param event Event being fired
369 public void afterUserConfirmedAccount (@Observes final ObservableUserConfirmedAccountEvent event) {
370 // event should not be null
373 throw new NullPointerException("event is null"); //NOI18N
374 } else if (event.getConfirmedUser() == null) {
376 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
377 } else if (event.getConfirmedUser().getUserId() == null) {
379 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
380 } else if (event.getConfirmedUser().getUserId() < 1) {
382 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
385 // Add contact instance only once
386 this.uniqueAddContact(event.getConfirmedUser().getUserContact());
390 * Event observer for logged-in user
392 * @param event Event instance
394 public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
395 // event should not be null
398 throw new NullPointerException("event is null"); //NOI18N
399 } else if (event.getLoggedInUser() == null) {
401 throw new NullPointerException("event.loggedInUser is null"); //NOI18N
402 } else if (event.getLoggedInUser().getUserId() == null) {
404 throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
405 } else if (event.getLoggedInUser().getUserId() < 1) {
407 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
410 // Copy all data to this bean
411 this.copyContact(event.getLoggedInUser().getUserContact());
415 * Event observer for new user registrations
417 * @param event User registration event
419 public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
420 // event should not be null
423 throw new NullPointerException("event is null"); //NOI18N
424 } else if (event.getRegisteredUser() == null) {
426 throw new NullPointerException("event.registeredUser is null"); //NOI18N
427 } else if (event.getRegisteredUser().getUserId() == null) {
429 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
430 } else if (event.getRegisteredUser().getUserId() < 1) {
432 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
436 final Contact registeredContact = event.getRegisteredUser().getUserContact();
438 // Copy all data from registered->user
439 this.copyContact(registeredContact);
441 // Add contact instance only once
442 this.uniqueAddContact(registeredContact);
444 // Add user name and email address
445 this.addUserNameEmailAddress(registeredContact);
452 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
453 public List<Contact> allContacts () {
455 final List<Contact> list = new LinkedList<>();
458 final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactCache.iterator();
461 while (iterator.hasNext()) {
463 final Cache.Entry<Long, Contact> next = iterator.next();
466 list.add(next.getValue());
474 public void clearEmailAddresses () {
476 this.setEmailAddress(null);
477 this.setEmailAddressRepeat(null);
481 public Contact createContactInstance () {
482 // Is all required data set?
483 if (!this.isRequiredPersonalDataSet()) {
484 // No, then abort here
485 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
488 // Required personal data must be set
489 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
491 // Generate phone number
492 final DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
493 final DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
494 final DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
496 // Create new contact
497 Contact contact = new UserContact(this.getPersonalTitle(), this.getFirstName(), this.getFamilyName());
498 contact.setContactStreet(this.getStreet());
499 contact.setContactHouseNumber(this.getHouseNumber());
500 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
501 contact.setContactZipCode(this.getZipCode());
502 contact.setContactCity(this.getCity());
503 contact.setContactCountry(this.getCountry());
504 contact.setContactEmailAddress(this.getEmailAddress());
505 contact.setContactBirthday(this.getBirthday());
506 contact.setContactComment(this.getComment());
508 // Don't set null or wrong references
509 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
510 // Now the number must be given
511 if (landLine.getPhoneAreaCode() == null) {
513 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
514 } else if (landLine.getPhoneAreaCode() < 1) {
516 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
517 } else if (landLine.getPhoneNumber() == null) {
519 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
520 } else if (landLine.getPhoneNumber() < 1) {
522 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
526 contact.setContactLandLineNumber(landLine);
529 // Don't set null or wrong references
530 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
531 // Now the number must be given
532 if (fax.getPhoneAreaCode() == null) {
534 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
535 } else if (fax.getPhoneAreaCode() < 1) {
537 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
538 } else if (fax.getPhoneNumber() == null) {
540 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
541 } else if (fax.getPhoneNumber() < 1) {
543 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
547 contact.setContactFaxNumber(fax);
550 // Is the provider set?
551 if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
552 // Is the number set?
553 if (mobile.getPhoneNumber() == null) {
555 throw new NullPointerException("mobile.phoneNumber is null"); //NOI18N
556 } else if (mobile.getPhoneNumber() < 1) {
558 throw new IllegalArgumentException("mobile.phoneNumber is zero or below."); //NOI18N
562 contact.setContactMobileNumber(mobile);
570 public String doChangePersonalContactData () {
571 // This method shall only be called if the user is logged-in
572 if (!this.userLoginController.isUserLoggedIn()) {
574 throw new IllegalStateException("User is not logged-in"); //NOI18N
575 } else if (!this.isRequiredChangePersonalDataSet()) {
576 // Not all required fields are set
577 throw new FaceletException("Not all required fields are set."); //NOI18N
578 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
579 // Password not matching
580 this.showFacesMessage("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
584 // Get contact instance
585 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
587 // It should be there, so run some tests on it
588 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
589 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
590 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
593 contact.setContactPersonalTitle(this.getPersonalTitle());
594 contact.setContactFirstName(this.getFirstName());
595 contact.setContactFamilyName(this.getFamilyName());
596 contact.setContactStreet(this.getStreet());
597 contact.setContactHouseNumber(this.getHouseNumber());
598 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
599 contact.setContactZipCode(this.getZipCode());
600 contact.setContactCity(this.getCity());
601 contact.setContactCountry(this.getCountry());
603 // Update contact's mobile number
604 this.isMobileUnlinked = Contacts.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
606 // Update contact's land-line number
607 this.isLandLineUnlinked = Contacts.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
609 // Update contact's fax number
610 this.isFaxUnlinked = Contacts.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
612 // Send it to the EJB
613 this.contactBean.updateContactData(contact, this.isMobileUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
616 return "contact_data_saved"; //NOI18N
620 public Contact findContactById (final Long contactId) throws ContactNotFoundException {
621 // Validate parameter
622 if (null == contactId) {
624 throw new NullPointerException("contactId is null"); //NOI18N
625 } else if (contactId < 1) {
627 throw new IllegalArgumentException("contactId=" + contactId + " is invalid"); //NOI18N
628 } else if (!this.contactCache.containsKey(contactId)) {
630 throw new ContactNotFoundException(contactId);
634 final Contact contact = this.contactCache.get(contactId);
641 * Getter for academic title
643 * @return Academic title
645 public String getAcademicTitle () {
646 return this.academicTitle;
650 * Setter for academic title
652 * @param academicTitle Academic title
654 public void setAcademicTitle (final String academicTitle) {
655 this.academicTitle = academicTitle;
659 * Getter for birth day
663 @SuppressWarnings ("ReturnOfDateField")
664 public Date getBirthday () {
665 return this.birthday;
669 * Setter for birth day
671 * @param birthday Birth day
673 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
674 public void setBirthday (final Date birthday) {
675 this.birthday = birthday;
679 * Getter for city name
683 public String getCity () {
688 * Setter for city name
690 * @param city City name
692 public void setCity (final String city) {
697 * Getter for comments
701 public String getComment () {
708 * @param comment Comments
710 public void setComment (final String comment) {
711 this.comment = comment;
715 public String getControllerType () {
716 return "general"; //NOI18N
721 public void setControllerType (final String controllerType) {
722 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
726 * Getter for country instance
728 * @return Country instance
730 public Country getCountry () {
735 * Setter for country instance
737 * @param country Country instance
739 public void setCountry (final Country country) {
740 this.country = country;
744 public String getEmailAddress () {
745 return this.emailAddress;
749 * Setter for email address
751 * @param emailAddress Email address
753 public void setEmailAddress (final String emailAddress) {
754 this.emailAddress = emailAddress;
758 * Getter for email address, repeated
760 * @return the emailAddress, repeated
762 public String getEmailAddressRepeat () {
763 return this.emailAddressRepeat;
767 * Setter for email address repeated
769 * @param emailAddressRepeat the emailAddress to set
771 public void setEmailAddressRepeat (final String emailAddressRepeat) {
772 this.emailAddressRepeat = emailAddressRepeat;
778 * @return the familyName
780 public String getFamilyName () {
781 return this.familyName;
787 * @param familyName the familyName to set
789 public void setFamilyName (final String familyName) {
790 this.familyName = familyName;
794 * Getter for fax number's area code
796 * @return Fax number's area code
798 public Integer getFaxAreaCode () {
799 return this.faxAreaCode;
803 * Setter for fax number's area code
805 * @param faxAreaCode Fax number's area code
807 public void setFaxAreaCode (final Integer faxAreaCode) {
808 this.faxAreaCode = faxAreaCode;
812 * Getter for fax's country instance
814 * @return Fax' country instance
816 public Country getFaxCountry () {
817 return this.faxCountry;
821 * Setter for fax's country instance
823 * @param faxCountry Fax' country instance
825 public void setFaxCountry (final Country faxCountry) {
826 this.faxCountry = faxCountry;
830 * Getter for fax number
834 public Long getFaxNumber () {
835 return this.faxNumber;
839 * Setter for fax number
841 * @param faxNumber Fax number
843 public void setFaxNumber (final Long faxNumber) {
844 this.faxNumber = faxNumber;
850 * @return the first name
852 public String getFirstName () {
853 return this.firstName;
859 * @param firstName the first name to set
861 public void setFirstName (final String firstName) {
862 this.firstName = firstName;
868 * @return the houseNumber
870 public Short getHouseNumber () {
871 return this.houseNumber;
877 * @param houseNumber the houseNumber to set
879 public void setHouseNumber (final Short houseNumber) {
880 this.houseNumber = houseNumber;
884 * Getter for house number extension, example: 123a 'a' is then the
885 * extension and 123 is the house number.
887 * @return House number extension
889 public String getHouseNumberExtension () {
890 return this.houseNumberExtension;
894 * Setter for house number extension
896 * @param houseNumberExtension House number extension
898 public void setHouseNumberExtension (final String houseNumberExtension) {
899 this.houseNumberExtension = houseNumberExtension;
903 * Getter for land-line number's area code
905 * @return Land-line number's area code
907 public Integer getLandLineAreaCode () {
908 return this.landLineAreaCode;
912 * Setter for land-line number's area code
914 * @param landLineAreaCode Land-line number's area code
916 public void setLandLineAreaCode (final Integer landLineAreaCode) {
917 this.landLineAreaCode = landLineAreaCode;
921 * Getter for land-line number's country instance
923 * @return Land-line number's country instance
925 public Country getLandLineCountry () {
926 return this.landLineCountry;
930 * Setter for land-line number's country instance
932 * @param landLineCountry Land-line number's country instance
934 public void setLandLineCountry (final Country landLineCountry) {
935 this.landLineCountry = landLineCountry;
939 * Getter for land-line number
941 * @return Land-line number
943 public Long getLandLineNumber () {
944 return this.landLineNumber;
948 * Setter for land-line number
950 * @param landLineNumber Land-line number
952 public void setLandLineNumber (final Long landLineNumber) {
953 this.landLineNumber = landLineNumber;
957 * Getter for mobile number
959 * @return Mobile number
961 public Long getMobileNumber () {
962 return this.mobileNumber;
966 * Setter for mobile number
968 * @param mobileNumber Mobile number
970 public void setMobileNumber (final Long mobileNumber) {
971 this.mobileNumber = mobileNumber;
975 * Getter for mobile number's carrier
977 * @return Mobile number's carrier
979 public MobileProvider getMobileProvider () {
980 return this.mobileProvider;
984 * Setter for mobile number's provider
986 * @param mobileProvider Mobile number's provider
988 public void setMobileProvider (final MobileProvider mobileProvider) {
989 this.mobileProvider = mobileProvider;
993 * Getter for personal title
995 * @return Personal title
997 public PersonalTitle getPersonalTitle () {
998 return this.personalTitle;
1002 * Setter for personal title
1004 * @param personalTitle Personal title
1006 public void setPersonalTitle (final PersonalTitle personalTitle) {
1007 this.personalTitle = personalTitle;
1015 public String getStreet () {
1022 * @param street Street
1024 public void setStreet (final String street) {
1025 this.street = street;
1029 * Getter for ZIP code
1033 public Integer getZipCode () {
1034 return this.zipCode;
1038 * Setter for ZIP code
1040 * @param zipCode ZIP code
1042 public void setZipCode (final Integer zipCode) {
1043 this.zipCode = zipCode;
1047 * Post-construction method
1050 public void init () {
1052 if (!this.contactCache.iterator().hasNext()) {
1054 final List<Contact> contacts = this.contactBean.allContacts();
1057 for (final Contact contact : contacts) {
1059 this.contactCache.put(contact.getContactId(), contact);
1061 // Is email address given?
1062 if (contact.getContactEmailAddress() != null) {
1064 this.emailAddressCache.put(contact.getContactId(), contact.getContactEmailAddress());
1067 } else if (this.selectableContactsCache.iterator().hasNext()) {
1068 // Has already entries, avoid executing below code
1073 final List<User> allUsers = this.userController.allUsers();
1075 // Get iterator from contacts cache
1076 final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactCache.iterator();
1078 // Loop through all contacts
1079 while (iterator.hasNext()) {
1081 final Cache.Entry<Long, Contact> next = iterator.next();
1083 // Default is not found
1084 boolean isFound = false;
1086 // User list is not empty, check each entry, if contact is found
1087 for (final User user : allUsers) {
1088 // Is the contact the same?
1089 if (Objects.equals(user.getUserContact(), next.getValue())) {
1096 // Is contact not found?
1098 // Add it as selectable
1099 this.selectableContactsCache.put(next.getKey(), next.getValue());
1105 public boolean isEmailAddressRegistered (final Contact contact) {
1107 if (null == contact) {
1109 throw new NullPointerException("contact is null"); //NOI18N
1110 } else if (contact.getContactEmailAddress() == null) {
1112 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
1113 } else if (contact.getContactEmailAddress().isEmpty()) {
1115 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
1119 return ((this.emailAddressCache instanceof List) && (this.emailAddressCache.containsKey(contact.getContactId())));
1123 public boolean isEmailAddressRegistered (final String emailAddress) {
1124 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
1128 public boolean isRequiredChangePersonalDataSet () {
1129 return ((this.getPersonalTitle() != null) &&
1130 (this.getFirstName() != null) &&
1131 (this.getFamilyName() != null) &&
1132 (this.getStreet() != null) &&
1133 (this.getHouseNumber() != null) &&
1134 (this.getZipCode() != null) &&
1135 (this.getCity() != null));
1139 public boolean isRequiredPersonalDataSet () {
1140 return ((this.getPersonalTitle() != null) &&
1141 (this.getFirstName() != null) &&
1142 (this.getFamilyName() != null) &&
1143 (this.getStreet() != null) &&
1144 (this.getHouseNumber() != null) &&
1145 (this.getZipCode() != null) &&
1146 (this.getCity() != null) &&
1147 (this.getEmailAddress() != null) &&
1148 (this.getEmailAddressRepeat() != null));
1152 public boolean isSameEmailAddressEntered () {
1153 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
1157 * Returns a list of all selectable contacts for user creation. Contacts
1158 * from already existing users are excluded in this list.
1160 * @return A list of all selectable contacts
1162 public List<Contact> selectableContacts () {
1164 final List<Contact> selectableContacts = new LinkedList<>();
1166 // Get iterator from cache
1167 final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactCache.iterator();
1169 // Loop through all contacts
1170 while (iterator.hasNext()) {
1172 final Cache.Entry<Long, Contact> next = iterator.next();
1174 // Add entry's value to list
1175 selectableContacts.add(next.getValue());
1179 return selectableContacts;
1183 public void updateContactDataFromController (final Contact contact) {
1184 // Is the instance valid?
1185 if (null == contact) {
1187 throw new NullPointerException("contact is null"); //NOI18N
1188 } else if (contact.getContactId() == null) {
1190 throw new NullPointerException("contact.contactId is null"); //NOI18N
1191 } else if (contact.getContactId() < 1) {
1192 // Not valid id number
1193 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1197 this.copyContact(contact);
1201 * Adds email address to bean's internal list.
1203 * @param contact Contact instance
1205 private void addUserNameEmailAddress (final Contact contact) {
1206 // Make sure the entry is not added yet
1207 if (this.emailAddressCache.containsKey(contact.getContactId())) {
1209 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
1213 this.emailAddressCache.put(contact.getContactId(), contact.getContactEmailAddress());
1219 private void clear () {
1222 this.setPersonalTitle(null);
1223 this.setAcademicTitle(null);
1224 this.setFirstName(null);
1225 this.setFamilyName(null);
1226 this.setStreet(null);
1227 this.setHouseNumber(null);
1228 this.setHouseNumberExtension(null);
1229 this.setZipCode(null);
1231 this.setCountry(null);
1234 this.clearEmailAddresses();
1235 this.setLandLineAreaCode(null);
1236 this.setLandLineCountry(null);
1237 this.setLandLineNumber(null);
1238 this.setMobileProvider(null);
1239 this.setMobileNumber(null);
1240 this.setFaxAreaCode(null);
1241 this.setFaxCountry(null);
1242 this.setFaxNumber(null);
1245 this.setBirthday(null);
1246 this.setComment(null);
1250 * Copies given contact into the controller
1252 * @param contact Contact instance
1254 private void copyContact (final Contact contact) {
1257 this.setPersonalTitle(contact.getContactPersonalTitle());
1258 this.setAcademicTitle(contact.getContactTitle());
1259 this.setFirstName(contact.getContactFirstName());
1260 this.setFamilyName(contact.getContactFamilyName());
1261 this.setStreet(contact.getContactStreet());
1262 this.setHouseNumber(contact.getContactHouseNumber());
1263 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
1264 this.setZipCode(contact.getContactZipCode());
1265 this.setCity(contact.getContactCity());
1266 this.setCountry(contact.getContactCountry());
1267 this.setEmailAddress(contact.getContactEmailAddress());
1268 this.setBirthday(contact.getContactBirthday());
1269 this.setComment(contact.getContactComment());
1271 // Get mobile, phone and fax instance
1272 DialableMobileNumber mobile = contact.getContactMobileNumber();
1273 DialableFaxNumber fax = contact.getContactFaxNumber();
1274 DialableLandLineNumber phone = contact.getContactLandLineNumber();
1277 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
1278 this.setLandLineCountry(phone.getPhoneCountry());
1279 this.setLandLineAreaCode(phone.getPhoneAreaCode());
1280 this.setLandLineNumber(phone.getPhoneNumber());
1283 if ((mobile instanceof DialableMobileNumber) && (mobile.getMobileProvider() instanceof MobileProvider)) {
1284 this.setMobileProvider(mobile.getMobileProvider());
1285 this.setMobileNumber(mobile.getPhoneNumber());
1288 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
1289 this.setFaxCountry(fax.getPhoneCountry());
1290 this.setFaxAreaCode(fax.getPhoneAreaCode());
1291 this.setFaxNumber(fax.getPhoneNumber());
1296 * Removes given contact from all lists
1298 * @param contact Contact instance to remove
1300 private void removeContact (final Contact contact) {
1301 // Remove from general list
1302 if (!this.contactCache.remove(contact.getContactId())) {
1303 // Did not remove contact
1304 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
1307 // Remove from other lists
1308 this.emailAddressCache.remove(contact.getContactId());
1312 * Adds unique instance to contact list. First any existing instance is
1313 * being removed, then the new instance is added.
1315 * @param contact Contact instance to add uniquely
1317 private void uniqueAddContact (final Contact contact) {
1318 // Get iterator from list
1319 final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactCache.iterator();
1321 // "Walk" through all entries
1322 while (iterator.hasNext()) {
1324 final Cache.Entry<Long, Contact> next = iterator.next();
1326 // Is id number the same?
1327 if (Objects.equals(contact.getContactId(), next.getKey())) {
1328 // Found entry, so remove it and abort
1329 this.removeContact(next.getValue());
1334 // Add contact to list
1335 this.contactCache.put(contact.getContactId(), contact);