2 * Copyright (C) 2016 - 2024 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.UserContact;
39 import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
40 import org.mxchange.jcontacts.model.utils.ContactUtils;
41 import org.mxchange.jcountry.model.data.Country;
42 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
43 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
44 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
45 import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
46 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
47 import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
48 import org.mxchange.jusercore.model.user.User;
49 import org.mxchange.juserlogincore.events.confirmation.ObservableUserConfirmedAccountEvent;
50 import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent;
51 import org.mxchange.juserlogincore.events.registration.ObservableUserRegisteredEvent;
52 import org.mxchange.juserlogincore.exceptions.UserPasswordMismatchException;
53 import org.mxchange.pizzaapplication.beans.BasePizzaBean;
54 import org.mxchange.pizzaapplication.beans.user.PizzaUserWebRequestController;
55 import org.mxchange.pizzaapplication.beans.user.login.PizzaUserLoginWebSessionController;
58 * A general contact bean (controller)
60 * @author Roland Häder<roland@mxchange.org>
62 @Named ("contactController")
64 public class PizzaContactWebRequestBean extends BasePizzaBean implements PizzaContactWebRequestController {
69 private static final long serialVersionUID = 542_145_352_001L;
72 * Academic academicTitle
74 private String academicTitle;
79 private Date birthday;
89 private String comment;
92 * EJB for general contact purposes
94 @EJB (lookup = "java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote")
95 private ContactSessionBeanRemote contactBean;
101 @NamedCache (cacheName = "contactsCache")
102 private Cache<Long, Contact> contactsCache;
107 private Country country;
112 private String emailAddress;
118 @NamedCache (cacheName = "emailAddressCache")
119 private Cache<Long, String> emailAddressCache;
122 * Email address repeated
124 private String emailAddressRepeat;
129 private String familyName;
132 * Fax number's area code
134 private Integer faxAreaCode;
137 * Country instance for fax number
139 private Country faxCountry;
144 private Long faxNumber;
149 private String firstName;
154 private Short houseNumber;
157 * House number extension
159 private String houseNumberExtension;
162 * Whether a fax entry has been unlinked
164 private boolean isFaxUnlinked;
167 * Whether a land-line number has been unlinked
169 private boolean isLandLineUnlinked;
172 * Whether a mobile entry has been unlinked
174 private boolean isMobileUnlinked;
177 * Phone number area code
179 private Integer landLineAreaCode;
182 * Country instance for phone number
184 private Country landLineCountry;
189 private Long landLineNumber;
194 private Long mobileNumber;
197 * Mobile number's carrier
199 private MobileProvider mobileProvider;
202 * Personal academicTitle
204 private PersonalTitle personalTitle;
207 * A list of all selectable contacts
210 @NamedCache (cacheName = "selectableContactsCache")
211 private Cache<Long, Contact> selectableContactsCache;
216 private String street;
219 * Regular user controller
222 private PizzaUserWebRequestController userController;
225 * Login bean (controller)
228 private PizzaUserLoginWebSessionController userLoginController;
233 private Integer zipCode;
236 * Default constructor
238 public PizzaContactWebRequestBean () {
239 // Call super constructor
244 * Observes events being fired when an administrator has added a new
247 * @param event Event being fired
249 public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
250 // The event must be valid
253 throw new NullPointerException("event is null"); //NOI18N
254 } else if (event.getAddedContact() == null) {
256 throw new NullPointerException("event.addedContact is null"); //NOI18N
257 } else if (event.getAddedContact().getContactId() == null) {
259 throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
260 } else if (event.getAddedContact().getContactId() < 1) {
262 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
269 this.uniqueAddContact(event.getAddedContact());
271 // Add to selectable contacts
272 this.selectableContactsCache.put(event.getAddedContact().getContactId(), event.getAddedContact());
276 * Event observer for newly added users by administrator
278 * @param event Event being fired
280 public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
281 // event should not be null
284 throw new NullPointerException("event is null"); //NOI18N
285 } else if (event.getAddedUser() == null) {
287 throw new NullPointerException("event.addedUser is null"); //NOI18N
288 } else if (event.getAddedUser().getUserId() == null) {
290 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
291 } else if (event.getAddedUser().getUserId() < 1) {
293 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
301 * Observes events being fired when an administrator has linked a new user
302 * with existing contact data.
304 * @param event Event being fired
306 public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent event) {
307 // event should not be null
310 throw new NullPointerException("event is null"); //NOI18N
311 } else if (event.getLinkedUser() == null) {
313 throw new NullPointerException("event.linkedUser is null"); //NOI18N
314 } else if (event.getLinkedUser().getUserContact() == null) {
316 throw new NullPointerException("event.linkedUser.userContact is null"); //NOI18N
317 } else if (event.getLinkedUser().getUserContact().getContactId() == null) {
319 throw new NullPointerException("event.linkedUser.userContact.contactId is null"); //NOI18N
320 } else if (event.getLinkedUser().getUserContact().getContactId() < 1) {
322 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N
325 // Remove contact from list available contacts list
326 this.selectableContactsCache.remove(event.getLinkedUser().getUserContact().getContactId());
333 * Event observer for updated contact data by administrators
335 * @param event Updated contact data event
337 public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
338 // event should not be null
341 throw new NullPointerException("event is null"); //NOI18N
342 } else if (event.getUpdatedContact() == null) {
344 throw new NullPointerException("event.updatedContact is null"); //NOI18N
345 } else if (event.getUpdatedContact().getContactId() == null) {
347 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
348 } else if (event.getUpdatedContact().getContactId() < 1) {
350 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
353 // Add contact instance only once
354 this.uniqueAddContact(event.getUpdatedContact());
356 // Add email address to list
357 this.emailAddressCache.put(event.getUpdatedContact().getContactId(), event.getUpdatedContact().getContactEmailAddress());
361 * Event observer when user confirmed account.
363 * @param event Event being fired
365 public void afterUserConfirmedAccount (@Observes final ObservableUserConfirmedAccountEvent event) {
366 // event should not be null
369 throw new NullPointerException("event is null"); //NOI18N
370 } else if (event.getConfirmedUser() == null) {
372 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
373 } else if (event.getConfirmedUser().getUserId() == null) {
375 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
376 } else if (event.getConfirmedUser().getUserId() < 1) {
378 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
381 // Add contact instance only once
382 this.uniqueAddContact(event.getConfirmedUser().getUserContact());
386 * Event observer for logged-in user
388 * @param event Event instance
390 public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
391 // event should not be null
394 throw new NullPointerException("event is null"); //NOI18N
395 } else if (event.getLoggedInUser() == null) {
397 throw new NullPointerException("event.loggedInUser is null"); //NOI18N
398 } else if (event.getLoggedInUser().getUserId() == null) {
400 throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
401 } else if (event.getLoggedInUser().getUserId() < 1) {
403 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
406 // Copy all data to this bean
407 this.copyContact(event.getLoggedInUser().getUserContact());
411 * Event observer for new user registrations
413 * @param event User registration event
415 public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
416 // event should not be null
419 throw new NullPointerException("event is null"); //NOI18N
420 } else if (event.getRegisteredUser() == null) {
422 throw new NullPointerException("event.registeredUser is null"); //NOI18N
423 } else if (event.getRegisteredUser().getUserId() == null) {
425 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
426 } else if (event.getRegisteredUser().getUserId() < 1) {
428 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
432 final Contact registeredContact = event.getRegisteredUser().getUserContact();
434 // Copy all data from registered->user
435 this.copyContact(registeredContact);
437 // Add contact instance only once
438 this.uniqueAddContact(registeredContact);
440 // Add user name and email address
441 this.addUserNameEmailAddress(registeredContact);
448 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
449 public List<Contact> allContacts () {
451 final List<Contact> list = new LinkedList<>();
454 final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactsCache.iterator();
457 while (iterator.hasNext()) {
459 final Cache.Entry<Long, Contact> next = iterator.next();
462 list.add(next.getValue());
470 public void clearEmailAddresses () {
472 this.setEmailAddress(null);
473 this.setEmailAddressRepeat(null);
477 public Contact createContactInstance () {
478 // Is all required data set?
479 if (!this.isRequiredPersonalDataSet()) {
480 // No, then abort here
481 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
484 // Create new contact
485 final Contact contact = new UserContact(
486 this.getPersonalTitle(),
488 this.getFamilyName(),
493 // Don't set null or wrong references
494 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
495 // Now the number must be given
496 if (fax.getPhoneAreaCode() == null) {
498 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
499 } else if (fax.getPhoneAreaCode() < 1) {
501 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
502 } else if (fax.getPhoneNumber() == null) {
504 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
505 } else if (fax.getPhoneNumber() < 1) {
507 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
511 contact.setContactFaxNumber(fax);
514 // Is the provider set?
515 if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
516 // Is the number set?
517 if (mobile.getPhoneNumber() == null) {
519 throw new NullPointerException("mobile.phoneNumber is null"); //NOI18N
520 } else if (mobile.getPhoneNumber() < 1) {
522 throw new IllegalArgumentException("mobile.phoneNumber is zero or below."); //NOI18N
526 contact.setContactMobileNumber(mobile);
534 public String doChangePersonalContactData () {
535 // This method shall only be called if the user is logged-in
536 if (!this.userLoginController.isUserLoggedIn()) {
538 throw new IllegalStateException("User is not logged-in"); //NOI18N
539 } else if (!this.isRequiredChangePersonalDataSet()) {
540 // Not all required fields are set
541 throw new FaceletException("Not all required fields are set."); //NOI18N
542 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
543 // Password not matching
544 this.showFacesException("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()), FacesMessage.SEVERITY_ERROR); //NOI18N
548 // Get contact instance
549 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
551 // It should be there, so run some tests on it
552 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
553 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
554 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
557 contact.setContactPersonalTitle(this.getPersonalTitle());
558 contact.setContactFirstName(this.getFirstName());
559 contact.setContactFamilyName(this.getFamilyName());
560 contact.setContactStreet(this.getStreet());
561 contact.setContactHouseNumber(this.getHouseNumber());
562 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
563 contact.setContactZipCode(this.getZipCode());
564 contact.setContactCity(this.getCity());
565 contact.setContactCountry(this.getCountry());
567 // Update contact's mobile number
568 this.isMobileUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
570 // Update contact's land-line number
571 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
573 // Update contact's fax number
574 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
576 // Send it to the EJB
577 this.contactBean.updateContactData(contact, this.isMobileUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
580 return "contact_data_saved"; //NOI18N
584 * Getter for academic title
586 * @return Academic title
588 public String getAcademicTitle () {
589 return this.academicTitle;
593 * Setter for academic title
595 * @param academicTitle Academic title
597 public void setAcademicTitle (final String academicTitle) {
598 this.academicTitle = academicTitle;
602 * Getter for birth day
606 @SuppressWarnings ("ReturnOfDateField")
607 public Date getBirthday () {
608 return this.birthday;
612 * Setter for birth day
614 * @param birthday Birth day
616 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
617 public void setBirthday (final Date birthday) {
618 this.birthday = birthday;
622 * Getter for city name
626 public String getCity () {
631 * Setter for city name
633 * @param city City name
635 public void setCity (final String city) {
640 * Getter for comments
644 public String getComment () {
651 * @param comment Comments
653 public void setComment (final String comment) {
654 this.comment = comment;
658 public String getControllerType () {
659 return "general"; //NOI18N
664 public void setControllerType (final String controllerType) {
665 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
669 * Getter for country instance
671 * @return Country instance
673 public Country getCountry () {
678 * Setter for country instance
680 * @param country Country instance
682 public void setCountry (final Country country) {
683 this.country = country;
687 public String getEmailAddress () {
688 return this.emailAddress;
692 * Setter for email address
694 * @param emailAddress Email address
696 public void setEmailAddress (final String emailAddress) {
697 this.emailAddress = emailAddress;
701 * Getter for email address, repeated
703 * @return the emailAddress, repeated
705 public String getEmailAddressRepeat () {
706 return this.emailAddressRepeat;
710 * Setter for email address repeated
712 * @param emailAddressRepeat the emailAddress to set
714 public void setEmailAddressRepeat (final String emailAddressRepeat) {
715 this.emailAddressRepeat = emailAddressRepeat;
721 * @return the familyName
723 public String getFamilyName () {
724 return this.familyName;
730 * @param familyName the familyName to set
732 public void setFamilyName (final String familyName) {
733 this.familyName = familyName;
737 * Getter for fax number's area code
739 * @return Fax number's area code
741 public Integer getFaxAreaCode () {
742 return this.faxAreaCode;
746 * Setter for fax number's area code
748 * @param faxAreaCode Fax number's area code
750 public void setFaxAreaCode (final Integer faxAreaCode) {
751 this.faxAreaCode = faxAreaCode;
755 * Getter for fax's country instance
757 * @return Fax' country instance
759 public Country getFaxCountry () {
760 return this.faxCountry;
764 * Setter for fax's country instance
766 * @param faxCountry Fax' country instance
768 public void setFaxCountry (final Country faxCountry) {
769 this.faxCountry = faxCountry;
773 * Getter for fax number
777 public Long getFaxNumber () {
778 return this.faxNumber;
782 * Setter for fax number
784 * @param faxNumber Fax number
786 public void setFaxNumber (final Long faxNumber) {
787 this.faxNumber = faxNumber;
793 * @return the first name
795 public String getFirstName () {
796 return this.firstName;
802 * @param firstName the first name to set
804 public void setFirstName (final String firstName) {
805 this.firstName = firstName;
811 * @return the houseNumber
813 public Short getHouseNumber () {
814 return this.houseNumber;
820 * @param houseNumber the houseNumber to set
822 public void setHouseNumber (final Short houseNumber) {
823 this.houseNumber = houseNumber;
827 * Getter for house number extension, example: 123a 'a' is then the
828 * extension and 123 is the house number.
830 * @return House number extension
832 public String getHouseNumberExtension () {
833 return this.houseNumberExtension;
837 * Setter for house number extension
839 * @param houseNumberExtension House number extension
841 public void setHouseNumberExtension (final String houseNumberExtension) {
842 this.houseNumberExtension = houseNumberExtension;
846 * Getter for land-line number's area code
848 * @return Land-line number's area code
850 public Integer getLandLineAreaCode () {
851 return this.landLineAreaCode;
855 * Setter for land-line number's area code
857 * @param landLineAreaCode Land-line number's area code
859 public void setLandLineAreaCode (final Integer landLineAreaCode) {
860 this.landLineAreaCode = landLineAreaCode;
864 * Getter for land-line number's country instance
866 * @return Land-line number's country instance
868 public Country getLandLineCountry () {
869 return this.landLineCountry;
873 * Setter for land-line number's country instance
875 * @param landLineCountry Land-line number's country instance
877 public void setLandLineCountry (final Country landLineCountry) {
878 this.landLineCountry = landLineCountry;
882 * Getter for land-line number
884 * @return Land-line number
886 public Long getLandLineNumber () {
887 return this.landLineNumber;
891 * Setter for land-line number
893 * @param landLineNumber Land-line number
895 public void setLandLineNumber (final Long landLineNumber) {
896 this.landLineNumber = landLineNumber;
900 * Getter for mobile number
902 * @return Mobile number
904 public Long getMobileNumber () {
905 return this.mobileNumber;
909 * Setter for mobile number
911 * @param mobileNumber Mobile number
913 public void setMobileNumber (final Long mobileNumber) {
914 this.mobileNumber = mobileNumber;
918 * Getter for mobile number's carrier
920 * @return Mobile number's carrier
922 public MobileProvider getMobileProvider () {
923 return this.mobileProvider;
927 * Setter for mobile number's provider
929 * @param mobileProvider Mobile number's provider
931 public void setMobileProvider (final MobileProvider mobileProvider) {
932 this.mobileProvider = mobileProvider;
936 * Getter for personal title
938 * @return Personal title
940 public PersonalTitle getPersonalTitle () {
941 return this.personalTitle;
945 * Setter for personal title
947 * @param personalTitle Personal title
949 public void setPersonalTitle (final PersonalTitle personalTitle) {
950 this.personalTitle = personalTitle;
958 public String getStreet () {
965 * @param street Street
967 public void setStreet (final String street) {
968 this.street = street;
972 * Getter for ZIP code
976 public Integer getZipCode () {
981 * Setter for ZIP code
983 * @param zipCode ZIP code
985 public void setZipCode (final Integer zipCode) {
986 this.zipCode = zipCode;
990 * Post-construction method
993 public void init () {
995 if (!this.contactsCache.iterator().hasNext()) {
997 final List<Contact> contacts = this.contactBean.allContacts();
1000 for (final Contact contact : contacts) {
1002 this.contactsCache.put(contact.getContactId(), contact);
1003 this.emailAddressCache.put(contact.getContactId(), contact.getContactEmailAddress());
1005 } else if (this.selectableContactsCache.iterator().hasNext()) {
1006 // Has already entries, avoid executing below code
1011 final List<User> allUsers = this.userController.allUsers();
1013 // Get iterator from contacts cache
1014 final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactsCache.iterator();
1016 // Loop through all contacts
1017 while (iterator.hasNext()) {
1019 final Cache.Entry<Long, Contact> next = iterator.next();
1021 // Default is not found
1022 boolean isFound = false;
1024 // User list is not empty, check each entry, if contact is found
1025 for (final User user : allUsers) {
1026 // Is the contact the same?
1027 if (Objects.equals(user.getUserContact(), next.getValue())) {
1034 // Is contact not found?
1036 // Add it as selectable
1037 this.selectableContactsCache.put(next.getKey(), next.getValue());
1043 public boolean isEmailAddressRegistered (final Contact contact) {
1045 if (null == contact) {
1047 throw new NullPointerException("contact is null"); //NOI18N
1048 } else if (contact.getContactEmailAddress() == null) {
1050 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
1051 } else if (contact.getContactEmailAddress().isEmpty()) {
1053 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
1057 return ((this.emailAddressCache instanceof List) && (this.emailAddressCache.containsKey(contact.getContactId())));
1061 public boolean isRequiredChangePersonalDataSet () {
1062 return ((this.getPersonalTitle() != null) &&
1063 (this.getFirstName() != null) &&
1064 (this.getFamilyName() != null) &&
1065 (this.getStreet() != null) &&
1066 (this.getHouseNumber() != null) &&
1067 (this.getZipCode() != null) &&
1068 (this.getCity() != null));
1072 public boolean isRequiredPersonalDataSet () {
1073 return ((this.getPersonalTitle() != null) &&
1074 (this.getFirstName() != null) &&
1075 (this.getFamilyName() != null) &&
1076 (this.getStreet() != null) &&
1077 (this.getHouseNumber() != null) &&
1078 (this.getZipCode() != null) &&
1079 (this.getCity() != null) &&
1080 (this.getEmailAddress() != null) &&
1081 (this.getEmailAddressRepeat() != null));
1085 public boolean isSameEmailAddressEntered () {
1086 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
1090 * Returns a list of all selectable contacts for user creation. Contacts
1091 * from already existing users are excluded in this list.
1093 * @return A list of all selectable contacts
1095 public List<Contact> selectableContacts () {
1097 final List<Contact> selectableContacts = new LinkedList<>();
1099 // Get iterator from cache
1100 final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactsCache.iterator();
1102 // Loop through all contacts
1103 while (iterator.hasNext()) {
1105 final Cache.Entry<Long, Contact> next = iterator.next();
1107 // Add entry's value to list
1108 selectableContacts.add(next.getValue());
1112 return selectableContacts;
1116 public void updateContactDataFromController (final Contact contact) {
1117 // Is the instance valid?
1118 if (null == contact) {
1120 throw new NullPointerException("contact is null"); //NOI18N
1121 } else if (contact.getContactId() == null) {
1123 throw new NullPointerException("contact.contactId is null"); //NOI18N
1124 } else if (contact.getContactId() < 1) {
1125 // Not valid id number
1126 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1130 this.copyContact(contact);
1134 * Adds email address to bean's internal list.
1136 * @param contact Contact instance
1138 private void addUserNameEmailAddress (final Contact contact) {
1139 // Make sure the entry is not added yet
1140 if (this.emailAddressCache.containsKey(contact.getContactId())) {
1142 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
1146 this.emailAddressCache.put(contact.getContactId(), contact.getContactEmailAddress());
1152 private void clear () {
1155 this.setPersonalTitle(null);
1156 this.setAcademicTitle(null);
1157 this.setFirstName(null);
1158 this.setFamilyName(null);
1159 this.setStreet(null);
1160 this.setHouseNumber(null);
1161 this.setHouseNumberExtension(null);
1162 this.setZipCode(null);
1164 this.setCountry(null);
1167 this.clearEmailAddresses();
1168 this.setLandLineAreaCode(null);
1169 this.setLandLineCountry(null);
1170 this.setLandLineNumber(null);
1171 this.setMobileProvider(null);
1172 this.setMobileNumber(null);
1173 this.setFaxAreaCode(null);
1174 this.setFaxCountry(null);
1175 this.setFaxNumber(null);
1178 this.setBirthday(null);
1179 this.setComment(null);
1183 * Copies given contact into the controller
1185 * @param contact Contact instance
1187 private void copyContact (final Contact contact) {
1188 // Is the instance valid?
1189 if (null == contact) {
1191 throw new NullPointerException("contact is null"); //NOI18N
1192 } else if (contact.getContactId() == null) {
1194 throw new NullPointerException("contact.contactId is null"); //NOI18N
1195 } else if (contact.getContactId() < 1) {
1196 // Not valid id number
1197 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1202 this.setPersonalTitle(contact.getContactPersonalTitle());
1203 this.setAcademicTitle(contact.getContactTitle());
1204 this.setFirstName(contact.getContactFirstName());
1205 this.setFamilyName(contact.getContactFamilyName());
1206 this.setStreet(contact.getContactStreet());
1207 this.setHouseNumber(contact.getContactHouseNumber());
1208 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
1209 this.setZipCode(contact.getContactZipCode());
1210 this.setCity(contact.getContactCity());
1211 this.setCountry(contact.getContactCountry());
1212 this.setEmailAddress(contact.getContactEmailAddress());
1213 this.setBirthday(contact.getContactBirthday());
1214 this.setComment(contact.getContactComment());
1216 // Get mobile, phone and fax instance
1217 DialableMobileNumber mobile = contact.getContactMobileNumber();
1218 DialableFaxNumber fax = contact.getContactFaxNumber();
1219 DialableLandLineNumber phone = contact.getContactLandLineNumber();
1222 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
1223 this.setLandLineCountry(phone.getPhoneCountry());
1224 this.setLandLineAreaCode(phone.getPhoneAreaCode());
1225 this.setLandLineNumber(phone.getPhoneNumber());
1228 if ((mobile instanceof DialableMobileNumber) && (mobile.getMobileProvider() instanceof MobileProvider)) {
1229 this.setMobileProvider(mobile.getMobileProvider());
1230 this.setMobileNumber(mobile.getPhoneNumber());
1233 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
1234 this.setFaxCountry(fax.getPhoneCountry());
1235 this.setFaxAreaCode(fax.getPhoneAreaCode());
1236 this.setFaxNumber(fax.getPhoneNumber());
1241 * Removes given contact from all lists
1243 * @param contact Contact instance to remove
1245 private void removeContact (final Contact contact) {
1246 // Is the instance valid?
1247 if (null == contact) {
1249 throw new NullPointerException("contact is null"); //NOI18N
1250 } else if (contact.getContactId() == null) {
1252 throw new NullPointerException("contact.contactId is null"); //NOI18N
1253 } else if (contact.getContactId() < 1) {
1254 // Not valid id number
1255 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1258 // Remove from general list
1259 if (!this.contactsCache.remove(contact.getContactId())) {
1260 // Did not remove contact
1261 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
1264 // Remove from other lists
1265 this.emailAddressCache.remove(contact.getContactId());
1269 * Adds unique instance to contact list. First any existing instance is
1270 * being removed, then the new instance is added.
1272 * @param contact Contact instance to add uniquely
1274 private void uniqueAddContact (final Contact contact) {
1275 // Is the instance valid?
1276 if (null == contact) {
1278 throw new NullPointerException("contact is null"); //NOI18N
1279 } else if (contact.getContactId() == null) {
1281 throw new NullPointerException("contact.contactId is null"); //NOI18N
1282 } else if (contact.getContactId() < 1) {
1283 // Not valid id number
1284 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1287 // Get iterator from list
1288 final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactsCache.iterator();
1290 // "Walk" through all entries
1291 while (iterator.hasNext()) {
1293 final Cache.Entry<Long, Contact> next = iterator.next();
1295 // Is id number the same?
1296 if (Objects.equals(contact.getContactId(), next.getKey())) {
1297 // Found entry, so remove it and abort
1298 this.removeContact(next.getValue());
1303 // Add contact to list
1304 this.contactsCache.put(contact.getContactId(), contact);