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.pizzaapplication.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.model.contact.Contact;
37 import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
38 import org.mxchange.jcontacts.model.contact.ContactUtils;
39 import org.mxchange.jcontacts.model.contact.UserContact;
40 import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
41 import org.mxchange.jcountry.model.data.Country;
42 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
43 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
44 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
45 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
46 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
47 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
48 import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
49 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
50 import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
51 import org.mxchange.jusercore.model.user.User;
52 import org.mxchange.juserlogincore.events.confirmation.ObservableUserConfirmedAccountEvent;
53 import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent;
54 import org.mxchange.juserlogincore.events.registration.ObservableUserRegisteredEvent;
55 import org.mxchange.juserlogincore.exceptions.UserPasswordMismatchException;
56 import org.mxchange.pizzaapplication.beans.BasePizzaBean;
57 import org.mxchange.pizzaapplication.beans.user.PizzaUserWebRequestController;
58 import org.mxchange.pizzaapplication.beans.user.login.PizzaUserLoginWebSessionController;
61 * A general contact bean (controller)
63 * @author Roland Häder<roland@mxchange.org>
65 @Named ("contactController")
67 public class PizzaContactWebRequestBean extends BasePizzaBean implements PizzaContactWebRequestController {
72 private static final long serialVersionUID = 542_145_347_916L;
75 * Academic academicTitle
77 private String academicTitle;
82 private Date birthday;
92 private String comment;
95 * EJB for general contact purposes
97 @EJB (lookup = "java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote")
98 private ContactSessionBeanRemote contactBean;
104 @NamedCache (cacheName = "contactsCache")
105 private Cache<Long, Contact> contactsCache;
110 private Country country;
115 private String emailAddress;
121 @NamedCache (cacheName = "emailAddressCache")
122 private Cache<Long, String> emailAddressCache;
125 * Email address repeated
127 private String emailAddressRepeat;
132 private String familyName;
135 * Fax number's area code
137 private Integer faxAreaCode;
140 * Country instance for fax number
142 private Country faxCountry;
147 private Long faxNumber;
152 private String firstName;
157 private Short houseNumber;
160 * House number extension
162 private String houseNumberExtension;
165 * Whether a fax entry has been unlinked
167 private boolean isFaxUnlinked;
170 * Whether a land-line number has been unlinked
172 private boolean isLandLineUnlinked;
175 * Whether a mobile entry has been unlinked
177 private boolean isMobileUnlinked;
180 * Phone number area code
182 private Integer landLineAreaCode;
185 * Country instance for phone number
187 private Country landLineCountry;
192 private Long landLineNumber;
197 private Long mobileNumber;
200 * Mobile number's carrier
202 private MobileProvider mobileProvider;
205 * Personal academicTitle
207 private PersonalTitle personalTitle;
210 * A list of all selectable contacts
213 @NamedCache (cacheName = "selectableContactsCache")
214 private Cache<Long, Contact> selectableContactsCache;
219 private String street;
222 * Regular user controller
225 private PizzaUserWebRequestController userController;
228 * Login bean (controller)
231 private PizzaUserLoginWebSessionController userLoginController;
236 private Integer zipCode;
239 * Default constructor
241 public PizzaContactWebRequestBean () {
242 // Call super constructor
247 * Observes events being fired when an administrator has added a new
250 * @param event Event being fired
252 public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
253 // The event must be valid
256 throw new NullPointerException("event is null"); //NOI18N
257 } else if (event.getAddedContact() == null) {
259 throw new NullPointerException("event.addedContact is null"); //NOI18N
260 } else if (event.getAddedContact().getContactId() == null) {
262 throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
263 } else if (event.getAddedContact().getContactId() < 1) {
265 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
272 this.uniqueAddContact(event.getAddedContact());
274 // Add to selectable contacts
275 this.selectableContactsCache.put(event.getAddedContact().getContactId(), event.getAddedContact());
279 * Event observer for newly added users by administrator
281 * @param event Event being fired
283 public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
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
304 * Observes events being fired when an administrator has linked a new user
305 * with existing contact data.
307 * @param event Event being fired
309 public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent event) {
310 // event should not be null
313 throw new NullPointerException("event is null"); //NOI18N
314 } else if (event.getLinkedUser() == null) {
316 throw new NullPointerException("event.linkedUser is null"); //NOI18N
317 } else if (event.getLinkedUser().getUserContact() == null) {
319 throw new NullPointerException("event.linkedUser.userContact is null"); //NOI18N
320 } else if (event.getLinkedUser().getUserContact().getContactId() == null) {
322 throw new NullPointerException("event.linkedUser.userContact.contactId is null"); //NOI18N
323 } else if (event.getLinkedUser().getUserContact().getContactId() < 1) {
325 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N
328 // Remove contact from list available contacts list
329 this.selectableContactsCache.remove(event.getLinkedUser().getUserContact().getContactId());
336 * Event observer for updated contact data by administrators
338 * @param event Updated contact data event
340 public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
341 // event should not be null
344 throw new NullPointerException("event is null"); //NOI18N
345 } else if (event.getUpdatedContact() == null) {
347 throw new NullPointerException("event.updatedContact is null"); //NOI18N
348 } else if (event.getUpdatedContact().getContactId() == null) {
350 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
351 } else if (event.getUpdatedContact().getContactId() < 1) {
353 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
356 // Add contact instance only once
357 this.uniqueAddContact(event.getUpdatedContact());
359 // Add email address to list
360 this.emailAddressCache.put(event.getUpdatedContact().getContactId(), event.getUpdatedContact().getContactEmailAddress());
364 * Event observer when user confirmed account.
366 * @param event Event being fired
368 public void afterUserConfirmedAccount (@Observes final ObservableUserConfirmedAccountEvent event) {
369 // event should not be null
372 throw new NullPointerException("event is null"); //NOI18N
373 } else if (event.getConfirmedUser() == null) {
375 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
376 } else if (event.getConfirmedUser().getUserId() == null) {
378 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
379 } else if (event.getConfirmedUser().getUserId() < 1) {
381 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
384 // Add contact instance only once
385 this.uniqueAddContact(event.getConfirmedUser().getUserContact());
389 * Event observer for logged-in user
391 * @param event Event instance
393 public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
394 // event should not be null
397 throw new NullPointerException("event is null"); //NOI18N
398 } else if (event.getLoggedInUser() == null) {
400 throw new NullPointerException("event.loggedInUser is null"); //NOI18N
401 } else if (event.getLoggedInUser().getUserId() == null) {
403 throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
404 } else if (event.getLoggedInUser().getUserId() < 1) {
406 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
409 // Copy all data to this bean
410 this.copyContact(event.getLoggedInUser().getUserContact());
414 * Event observer for new user registrations
416 * @param event User registration event
418 public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
419 // event should not be null
422 throw new NullPointerException("event is null"); //NOI18N
423 } else if (event.getRegisteredUser() == null) {
425 throw new NullPointerException("event.registeredUser is null"); //NOI18N
426 } else if (event.getRegisteredUser().getUserId() == null) {
428 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
429 } else if (event.getRegisteredUser().getUserId() < 1) {
431 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
435 final Contact registeredContact = event.getRegisteredUser().getUserContact();
437 // Copy all data from registered->user
438 this.copyContact(registeredContact);
440 // Add contact instance only once
441 this.uniqueAddContact(registeredContact);
443 // Add user name and email address
444 this.addUserNameEmailAddress(registeredContact);
451 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
452 public List<Contact> allContacts () {
454 final List<Contact> list = new LinkedList<>();
457 final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactsCache.iterator();
460 while (iterator.hasNext()) {
462 final Cache.Entry<Long, Contact> next = iterator.next();
465 list.add(next.getValue());
473 public void clearEmailAddresses () {
475 this.setEmailAddress(null);
476 this.setEmailAddressRepeat(null);
480 public Contact createContactInstance () {
481 // Is all required data set?
482 if (!this.isRequiredPersonalDataSet()) {
483 // No, then abort here
484 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
487 // Required personal data must be set
488 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
490 // Generate phone number
491 DialableLandLineNumber phone = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
492 DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
493 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
495 // Create new contact
496 Contact contact = new UserContact(this.getPersonalTitle(), this.getFirstName(), this.getFamilyName());
497 contact.setContactStreet(this.getStreet());
498 contact.setContactHouseNumber(this.getHouseNumber());
499 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
500 contact.setContactZipCode(this.getZipCode());
501 contact.setContactCity(this.getCity());
502 contact.setContactCountry(this.getCountry());
503 contact.setContactEmailAddress(this.getEmailAddress());
504 contact.setContactBirthday(this.getBirthday());
505 contact.setContactComment(this.getComment());
507 // Don't set null or wrong references
508 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
509 // Now the number must be given
510 if (phone.getPhoneAreaCode() == null) {
512 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
513 } else if (phone.getPhoneAreaCode() < 1) {
515 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
516 } else if (phone.getPhoneNumber() == null) {
518 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
519 } else if (phone.getPhoneNumber() < 1) {
521 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
525 contact.setContactLandLineNumber(phone);
528 // Don't set null or wrong references
529 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
530 // Now the number must be given
531 if (fax.getPhoneAreaCode() == null) {
533 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
534 } else if (fax.getPhoneAreaCode() < 1) {
536 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
537 } else if (fax.getPhoneNumber() == null) {
539 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
540 } else if (fax.getPhoneNumber() < 1) {
542 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
546 contact.setContactFaxNumber(fax);
549 // Is the provider set?
550 if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
551 // Is the number set?
552 if (mobile.getPhoneNumber() == null) {
554 throw new NullPointerException("mobile.phoneNumber is null"); //NOI18N
555 } else if (mobile.getPhoneNumber() < 1) {
557 throw new IllegalArgumentException("mobile.phoneNumber is zero or below."); //NOI18N
561 contact.setContactMobileNumber(mobile);
569 public String doChangePersonalContactData () {
570 // This method shall only be called if the user is logged-in
571 if (!this.userLoginController.isUserLoggedIn()) {
573 throw new IllegalStateException("User is not logged-in"); //NOI18N
574 } else if (!this.isRequiredChangePersonalDataSet()) {
575 // Not all required fields are set
576 throw new FaceletException("Not all required fields are set."); //NOI18N
577 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
578 // Password not matching
579 this.showFacesMessage("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
583 // Get contact instance
584 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
586 // It should be there, so run some tests on it
587 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
588 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
589 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
592 contact.setContactPersonalTitle(this.getPersonalTitle());
593 contact.setContactFirstName(this.getFirstName());
594 contact.setContactFamilyName(this.getFamilyName());
595 contact.setContactStreet(this.getStreet());
596 contact.setContactHouseNumber(this.getHouseNumber());
597 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
598 contact.setContactZipCode(this.getZipCode());
599 contact.setContactCity(this.getCity());
600 contact.setContactCountry(this.getCountry());
602 // Update contact's mobile number
603 this.isMobileUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
605 // Update contact's land-line number
606 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
608 // Update contact's fax number
609 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
611 // Send it to the EJB
612 this.contactBean.updateContactData(contact, this.isMobileUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
615 return "contact_data_saved"; //NOI18N
619 * Getter for academic title
621 * @return Academic title
623 public String getAcademicTitle () {
624 return this.academicTitle;
628 * Setter for academic title
630 * @param academicTitle Academic title
632 public void setAcademicTitle (final String academicTitle) {
633 this.academicTitle = academicTitle;
637 * Getter for birth day
641 @SuppressWarnings ("ReturnOfDateField")
642 public Date getBirthday () {
643 return this.birthday;
647 * Setter for birth day
649 * @param birthday Birth day
651 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
652 public void setBirthday (final Date birthday) {
653 this.birthday = birthday;
657 * Getter for city name
661 public String getCity () {
666 * Setter for city name
668 * @param city City name
670 public void setCity (final String city) {
675 * Getter for comments
679 public String getComment () {
686 * @param comment Comments
688 public void setComment (final String comment) {
689 this.comment = comment;
693 public String getControllerType () {
694 return "general"; //NOI18N
699 public void setControllerType (final String controllerType) {
700 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
704 * Getter for country instance
706 * @return Country instance
708 public Country getCountry () {
713 * Setter for country instance
715 * @param country Country instance
717 public void setCountry (final Country country) {
718 this.country = country;
722 public String getEmailAddress () {
723 return this.emailAddress;
727 * Setter for email address
729 * @param emailAddress Email address
731 public void setEmailAddress (final String emailAddress) {
732 this.emailAddress = emailAddress;
736 * Getter for email address, repeated
738 * @return the emailAddress, repeated
740 public String getEmailAddressRepeat () {
741 return this.emailAddressRepeat;
745 * Setter for email address repeated
747 * @param emailAddressRepeat the emailAddress to set
749 public void setEmailAddressRepeat (final String emailAddressRepeat) {
750 this.emailAddressRepeat = emailAddressRepeat;
756 * @return the familyName
758 public String getFamilyName () {
759 return this.familyName;
765 * @param familyName the familyName to set
767 public void setFamilyName (final String familyName) {
768 this.familyName = familyName;
772 * Getter for fax number's area code
774 * @return Fax number's area code
776 public Integer getFaxAreaCode () {
777 return this.faxAreaCode;
781 * Setter for fax number's area code
783 * @param faxAreaCode Fax number's area code
785 public void setFaxAreaCode (final Integer faxAreaCode) {
786 this.faxAreaCode = faxAreaCode;
790 * Getter for fax's country instance
792 * @return Fax' country instance
794 public Country getFaxCountry () {
795 return this.faxCountry;
799 * Setter for fax's country instance
801 * @param faxCountry Fax' country instance
803 public void setFaxCountry (final Country faxCountry) {
804 this.faxCountry = faxCountry;
808 * Getter for fax number
812 public Long getFaxNumber () {
813 return this.faxNumber;
817 * Setter for fax number
819 * @param faxNumber Fax number
821 public void setFaxNumber (final Long faxNumber) {
822 this.faxNumber = faxNumber;
828 * @return the first name
830 public String getFirstName () {
831 return this.firstName;
837 * @param firstName the first name to set
839 public void setFirstName (final String firstName) {
840 this.firstName = firstName;
846 * @return the houseNumber
848 public Short getHouseNumber () {
849 return this.houseNumber;
855 * @param houseNumber the houseNumber to set
857 public void setHouseNumber (final Short houseNumber) {
858 this.houseNumber = houseNumber;
862 * Getter for house number extension, example: 123a 'a' is then the
863 * extension and 123 is the house number.
865 * @return House number extension
867 public String getHouseNumberExtension () {
868 return this.houseNumberExtension;
872 * Setter for house number extension
874 * @param houseNumberExtension House number extension
876 public void setHouseNumberExtension (final String houseNumberExtension) {
877 this.houseNumberExtension = houseNumberExtension;
881 * Getter for land-line number's area code
883 * @return Land-line number's area code
885 public Integer getLandLineAreaCode () {
886 return this.landLineAreaCode;
890 * Setter for land-line number's area code
892 * @param landLineAreaCode Land-line number's area code
894 public void setLandLineAreaCode (final Integer landLineAreaCode) {
895 this.landLineAreaCode = landLineAreaCode;
899 * Getter for land-line number's country instance
901 * @return Land-line number's country instance
903 public Country getLandLineCountry () {
904 return this.landLineCountry;
908 * Setter for land-line number's country instance
910 * @param landLineCountry Land-line number's country instance
912 public void setLandLineCountry (final Country landLineCountry) {
913 this.landLineCountry = landLineCountry;
917 * Getter for land-line number
919 * @return Land-line number
921 public Long getLandLineNumber () {
922 return this.landLineNumber;
926 * Setter for land-line number
928 * @param landLineNumber Land-line number
930 public void setLandLineNumber (final Long landLineNumber) {
931 this.landLineNumber = landLineNumber;
935 * Getter for mobile number
937 * @return Mobile number
939 public Long getMobileNumber () {
940 return this.mobileNumber;
944 * Setter for mobile number
946 * @param mobileNumber Mobile number
948 public void setMobileNumber (final Long mobileNumber) {
949 this.mobileNumber = mobileNumber;
953 * Getter for mobile number's carrier
955 * @return Mobile number's carrier
957 public MobileProvider getMobileProvider () {
958 return this.mobileProvider;
962 * Setter for mobile number's provider
964 * @param mobileProvider Mobile number's provider
966 public void setMobileProvider (final MobileProvider mobileProvider) {
967 this.mobileProvider = mobileProvider;
971 * Getter for personal title
973 * @return Personal title
975 public PersonalTitle getPersonalTitle () {
976 return this.personalTitle;
980 * Setter for personal title
982 * @param personalTitle Personal title
984 public void setPersonalTitle (final PersonalTitle personalTitle) {
985 this.personalTitle = personalTitle;
993 public String getStreet () {
1000 * @param street Street
1002 public void setStreet (final String street) {
1003 this.street = street;
1007 * Getter for ZIP code
1011 public Integer getZipCode () {
1012 return this.zipCode;
1016 * Setter for ZIP code
1018 * @param zipCode ZIP code
1020 public void setZipCode (final Integer zipCode) {
1021 this.zipCode = zipCode;
1025 * Post-construction method
1028 public void init () {
1030 if (!this.contactsCache.iterator().hasNext()) {
1032 final List<Contact> contacts = this.contactBean.allContacts();
1035 for (final Contact contact : contacts) {
1037 this.contactsCache.put(contact.getContactId(), contact);
1038 this.emailAddressCache.put(contact.getContactId(), contact.getContactEmailAddress());
1040 } else if (this.selectableContactsCache.iterator().hasNext()) {
1041 // Has already entries, avoid executing below code
1046 final List<User> allUsers = this.userController.allUsers();
1048 // Get iterator from contacts cache
1049 final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactsCache.iterator();
1051 // Loop through all contacts
1052 while (iterator.hasNext()) {
1054 final Cache.Entry<Long, Contact> next = iterator.next();
1056 // Default is not found
1057 boolean isFound = false;
1059 // User list is not empty, check each entry, if contact is found
1060 for (final User user : allUsers) {
1061 // Is the contact the same?
1062 if (Objects.equals(user.getUserContact(), next.getValue())) {
1069 // Is contact not found?
1071 // Add it as selectable
1072 this.selectableContactsCache.put(next.getKey(), next.getValue());
1078 public boolean isEmailAddressRegistered (final Contact contact) {
1080 if (null == contact) {
1082 throw new NullPointerException("contact is null"); //NOI18N
1083 } else if (contact.getContactEmailAddress() == null) {
1085 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
1086 } else if (contact.getContactEmailAddress().isEmpty()) {
1088 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
1092 return ((this.emailAddressCache instanceof List) && (this.emailAddressCache.containsKey(contact.getContactId())));
1096 public boolean isRequiredChangePersonalDataSet () {
1097 return ((this.getPersonalTitle() != null) &&
1098 (this.getFirstName() != null) &&
1099 (this.getFamilyName() != null) &&
1100 (this.getStreet() != null) &&
1101 (this.getHouseNumber() != null) &&
1102 (this.getZipCode() != null) &&
1103 (this.getCity() != null));
1107 public boolean isRequiredPersonalDataSet () {
1108 return ((this.getPersonalTitle() != null) &&
1109 (this.getFirstName() != null) &&
1110 (this.getFamilyName() != null) &&
1111 (this.getStreet() != null) &&
1112 (this.getHouseNumber() != null) &&
1113 (this.getZipCode() != null) &&
1114 (this.getCity() != null) &&
1115 (this.getEmailAddress() != null) &&
1116 (this.getEmailAddressRepeat() != null));
1120 public boolean isSameEmailAddressEntered () {
1121 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
1125 * Returns a list of all selectable contacts for user creation. Contacts
1126 * from already existing users are excluded in this list.
1128 * @return A list of all selectable contacts
1130 public List<Contact> selectableContacts () {
1132 final List<Contact> selectableContacts = new LinkedList<>();
1134 // Get iterator from cache
1135 final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactsCache.iterator();
1137 // Loop through all contacts
1138 while (iterator.hasNext()) {
1140 final Cache.Entry<Long, Contact> next = iterator.next();
1142 // Add entry's value to list
1143 selectableContacts.add(next.getValue());
1147 return selectableContacts;
1151 public void updateContactDataFromController (final Contact contact) {
1152 // Is the instance valid?
1153 if (null == contact) {
1155 throw new NullPointerException("contact is null"); //NOI18N
1156 } else if (contact.getContactId() == null) {
1158 throw new NullPointerException("contact.contactId is null"); //NOI18N
1159 } else if (contact.getContactId() < 1) {
1160 // Not valid id number
1161 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1165 this.copyContact(contact);
1169 * Adds email address to bean's internal list.
1171 * @param contact Contact instance
1173 private void addUserNameEmailAddress (final Contact contact) {
1174 // Make sure the entry is not added yet
1175 if (this.emailAddressCache.containsKey(contact.getContactId())) {
1177 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
1181 this.emailAddressCache.put(contact.getContactId(), contact.getContactEmailAddress());
1187 private void clear () {
1190 this.setPersonalTitle(null);
1191 this.setAcademicTitle(null);
1192 this.setFirstName(null);
1193 this.setFamilyName(null);
1194 this.setStreet(null);
1195 this.setHouseNumber(null);
1196 this.setHouseNumberExtension(null);
1197 this.setZipCode(null);
1199 this.setCountry(null);
1202 this.clearEmailAddresses();
1203 this.setLandLineAreaCode(null);
1204 this.setLandLineCountry(null);
1205 this.setLandLineNumber(null);
1206 this.setMobileProvider(null);
1207 this.setMobileNumber(null);
1208 this.setFaxAreaCode(null);
1209 this.setFaxCountry(null);
1210 this.setFaxNumber(null);
1213 this.setBirthday(null);
1214 this.setComment(null);
1218 * Copies given contact into the controller
1220 * @param contact Contact instance
1222 private void copyContact (final Contact contact) {
1223 // Is the instance valid?
1224 if (null == contact) {
1226 throw new NullPointerException("contact is null"); //NOI18N
1227 } else if (contact.getContactId() == null) {
1229 throw new NullPointerException("contact.contactId is null"); //NOI18N
1230 } else if (contact.getContactId() < 1) {
1231 // Not valid id number
1232 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1237 this.setPersonalTitle(contact.getContactPersonalTitle());
1238 this.setAcademicTitle(contact.getContactTitle());
1239 this.setFirstName(contact.getContactFirstName());
1240 this.setFamilyName(contact.getContactFamilyName());
1241 this.setStreet(contact.getContactStreet());
1242 this.setHouseNumber(contact.getContactHouseNumber());
1243 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
1244 this.setZipCode(contact.getContactZipCode());
1245 this.setCity(contact.getContactCity());
1246 this.setCountry(contact.getContactCountry());
1247 this.setEmailAddress(contact.getContactEmailAddress());
1248 this.setBirthday(contact.getContactBirthday());
1249 this.setComment(contact.getContactComment());
1251 // Get mobile, phone and fax instance
1252 DialableMobileNumber mobile = contact.getContactMobileNumber();
1253 DialableFaxNumber fax = contact.getContactFaxNumber();
1254 DialableLandLineNumber phone = contact.getContactLandLineNumber();
1257 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
1258 this.setLandLineCountry(phone.getPhoneCountry());
1259 this.setLandLineAreaCode(phone.getPhoneAreaCode());
1260 this.setLandLineNumber(phone.getPhoneNumber());
1263 if ((mobile instanceof DialableMobileNumber) && (mobile.getMobileProvider() instanceof MobileProvider)) {
1264 this.setMobileProvider(mobile.getMobileProvider());
1265 this.setMobileNumber(mobile.getPhoneNumber());
1268 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
1269 this.setFaxCountry(fax.getPhoneCountry());
1270 this.setFaxAreaCode(fax.getPhoneAreaCode());
1271 this.setFaxNumber(fax.getPhoneNumber());
1276 * Removes given contact from all lists
1278 * @param contact Contact instance to remove
1280 private void removeContact (final Contact contact) {
1281 // Is the instance valid?
1282 if (null == contact) {
1284 throw new NullPointerException("contact is null"); //NOI18N
1285 } else if (contact.getContactId() == null) {
1287 throw new NullPointerException("contact.contactId is null"); //NOI18N
1288 } else if (contact.getContactId() < 1) {
1289 // Not valid id number
1290 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1293 // Remove from general list
1294 if (!this.contactsCache.remove(contact.getContactId())) {
1295 // Did not remove contact
1296 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
1299 // Remove from other lists
1300 this.emailAddressCache.remove(contact.getContactId());
1304 * Adds unique instance to contact list. First any existing instance is
1305 * being removed, then the new instance is added.
1307 * @param contact Contact instance to add uniquely
1309 private void uniqueAddContact (final Contact contact) {
1310 // Is the instance valid?
1311 if (null == contact) {
1313 throw new NullPointerException("contact is null"); //NOI18N
1314 } else if (contact.getContactId() == null) {
1316 throw new NullPointerException("contact.contactId is null"); //NOI18N
1317 } else if (contact.getContactId() < 1) {
1318 // Not valid id number
1319 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1322 // Get iterator from list
1323 final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactsCache.iterator();
1325 // "Walk" through all entries
1326 while (iterator.hasNext()) {
1328 final Cache.Entry<Long, Contact> next = iterator.next();
1330 // Is id number the same?
1331 if (Objects.equals(contact.getContactId(), next.getKey())) {
1332 // Found entry, so remove it and abort
1333 this.removeContact(next.getValue());
1338 // Add contact to list
1339 this.contactsCache.put(contact.getContactId(), contact);