2 * Copyright (C) 2016, 2017 Roland Häder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jjobs.beans.contact;
19 import java.text.MessageFormat;
20 import java.util.Collections;
21 import java.util.Date;
22 import java.util.Iterator;
23 import java.util.LinkedList;
24 import java.util.List;
25 import java.util.Objects;
26 import javax.annotation.PostConstruct;
27 import javax.enterprise.context.SessionScoped;
28 import javax.enterprise.event.Observes;
29 import javax.faces.view.facelets.FaceletException;
30 import javax.inject.Inject;
31 import javax.inject.Named;
32 import javax.naming.Context;
33 import javax.naming.InitialContext;
34 import javax.naming.NamingException;
35 import org.mxchange.jcontacts.contact.Contact;
36 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
37 import org.mxchange.jcontacts.contact.ContactUtils;
38 import org.mxchange.jcontacts.contact.UserContact;
39 import org.mxchange.jcontacts.contact.title.PersonalTitle;
40 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
41 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
42 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
43 import org.mxchange.jcountry.data.Country;
44 import org.mxchange.jjobs.beans.BaseJobsController;
45 import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
46 import org.mxchange.jjobs.beans.user.login.JobsUserLoginWebSessionController;
47 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
48 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
49 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
50 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
51 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
52 import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
53 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
54 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
55 import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
56 import org.mxchange.jusercore.model.user.User;
57 import org.mxchange.juserlogincore.events.confirmation.ObservableUserConfirmedAccountEvent;
58 import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent;
59 import org.mxchange.juserlogincore.events.registration.ObservableUserRegisteredEvent;
60 import org.mxchange.juserlogincore.exceptions.UserPasswordMismatchException;
63 * A general contact controller (bean)
65 * @author Roland Häder<roland@mxchange.org>
67 @Named ("contactController")
69 public class JobsContactWebSessionBean extends BaseJobsController implements JobsContactWebSessionController {
74 private static final long serialVersionUID = 542_145_347_916L;
77 * Academic academicTitle
79 private String academicTitle;
84 private Date birthday;
94 private String comment;
99 private ContactSessionBeanRemote contactBean;
104 private final List<Contact> contactList;
109 private Country country;
114 private String emailAddress;
119 private final List<String> emailAddressList;
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
209 private List<Contact> selectableContacts;
214 private String street;
217 * Regular user controller
220 private JobsUserWebSessionController userController;
223 * Login bean (controller)
226 private JobsUserLoginWebSessionController userLoginController;
231 private Integer zipCode;
234 * Default constructor
236 public JobsContactWebSessionBean () {
237 // Call super constructor
241 this.contactList = new LinkedList<>();
242 this.emailAddressList = new LinkedList<>();
246 * Observes events being fired when an administrator has added a new
249 * @param event Event being fired
251 public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
252 // The event must be valid
255 throw new NullPointerException("event is null"); //NOI18N
256 } else if (event.getAddedContact() == null) {
258 throw new NullPointerException("event.addedContact is null"); //NOI18N
259 } else if (event.getAddedContact().getContactId() == null) {
261 throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
262 } else if (event.getAddedContact().getContactId() < 1) {
264 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
271 this.uniqueAddContact(event.getAddedContact());
273 // Add to selectable contacts
274 this.selectableContacts.add(event.getAddedContact());
278 * Event observer for newly added users by administrator
280 * @param event Event being fired
282 public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
284 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("contactController.afterAdminAddedUserEvent(): event={0} - CALLED!", event)); //NOI18N
286 // event should not be null
289 throw new NullPointerException("event is null"); //NOI18N
290 } else if (event.getAddedUser() == null) {
292 throw new NullPointerException("event.addedUser is null"); //NOI18N
293 } else if (event.getAddedUser().getUserId() == null) {
295 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
296 } else if (event.getAddedUser().getUserId() < 1) {
298 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
306 * Observes events being fired when an administrator has linked a new user
307 * with existing contact data.
309 * @param event Event being fired
311 public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent event) {
312 // event should not be null
315 throw new NullPointerException("event is null"); //NOI18N
316 } else if (event.getLinkedUser() == null) {
318 throw new NullPointerException("event.linkedUser is null"); //NOI18N
319 } else if (event.getLinkedUser().getUserContact() == null) {
321 throw new NullPointerException("event.linkedUser.userContact is null"); //NOI18N
322 } else if (event.getLinkedUser().getUserContact().getContactId() == null) {
324 throw new NullPointerException("event.linkedUser.userContact.contactId is null"); //NOI18N
325 } else if (event.getLinkedUser().getUserContact().getContactId() < 1) {
327 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N
330 // Remove contact from list available contacts list
331 this.selectableContacts.remove(event.getLinkedUser().getUserContact());
338 * Event observer for updated contact data by administrators
340 * @param event Updated contact data event
342 public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
343 // event should not be null
346 throw new NullPointerException("event is null"); //NOI18N
347 } else if (event.getUpdatedContact() == null) {
349 throw new NullPointerException("event.updatedContact is null"); //NOI18N
350 } else if (event.getUpdatedContact().getContactId() == null) {
352 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
353 } else if (event.getUpdatedContact().getContactId() < 1) {
355 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
358 // Add contact instance only once
359 this.uniqueAddContact(event.getUpdatedContact());
361 // Add email address to list
362 this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
365 //* NOISY-DEBUG: */ System.out.println("contactController.afterAdminUpdatedContactDataEvent(): EXIT!"); //NOI18N
369 * Event observer when user confirmed account.
371 * @param event Event being fired
373 public void afterUserConfirmedAccount (@Observes final ObservableUserConfirmedAccountEvent event) {
374 // event should not be null
377 throw new NullPointerException("event is null"); //NOI18N
378 } else if (event.getConfirmedUser() == null) {
380 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
381 } else if (event.getConfirmedUser().getUserId() == null) {
383 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
384 } else if (event.getConfirmedUser().getUserId() < 1) {
386 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
389 // Add contact instance only once
390 this.uniqueAddContact(event.getConfirmedUser().getUserContact());
394 * Event observer for logged-in user
396 * @param event Event instance
398 public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
399 // event should not be null
402 throw new NullPointerException("event is null"); //NOI18N
403 } else if (event.getLoggedInUser() == null) {
405 throw new NullPointerException("event.loggedInUser is null"); //NOI18N
406 } else if (event.getLoggedInUser().getUserId() == null) {
408 throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
409 } else if (event.getLoggedInUser().getUserId() < 1) {
411 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
414 // Copy all data to this bean
415 this.copyContact(event.getLoggedInUser().getUserContact());
419 * Event observer for new user registrations
421 * @param event User registration event
423 public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
424 // event should not be null
427 throw new NullPointerException("event is null"); //NOI18N
428 } else if (event.getRegisteredUser() == null) {
430 throw new NullPointerException("event.registeredUser is null"); //NOI18N
431 } else if (event.getRegisteredUser().getUserId() == null) {
433 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
434 } else if (event.getRegisteredUser().getUserId() < 1) {
436 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
440 Contact registeredContact = event.getRegisteredUser().getUserContact();
442 // Copy all data from registered->user
443 this.copyContact(registeredContact);
445 // Add contact instance only once
446 this.uniqueAddContact(registeredContact);
448 // Add user name and email address
449 this.addUserNameEmailAddress(registeredContact);
456 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
457 public List<Contact> allContacts () {
458 // Return un-modified list
459 return this.contactList;
463 public void clearEmailAddresses () {
465 this.setEmailAddress(null);
466 this.setEmailAddressRepeat(null);
470 public Contact createContactInstance () {
471 // Is all required data set?
472 if (!this.isRequiredPersonalDataSet()) {
473 // No, then abort here
474 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
477 // Required personal data must be set
478 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
480 // Generate phone number
481 DialableLandLineNumber phone = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
482 DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
483 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
485 // Create new contact
486 Contact contact = new UserContact(this.getPersonalTitle(), this.getFirstName(), this.getFamilyName());
487 contact.setContactStreet(this.getStreet());
488 contact.setContactHouseNumber(this.getHouseNumber());
489 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
490 contact.setContactZipCode(this.getZipCode());
491 contact.setContactCity(this.getCity());
492 contact.setContactCountry(this.getCountry());
493 contact.setContactEmailAddress(this.getEmailAddress());
494 contact.setContactBirthday(this.getBirthday());
495 contact.setContactComment(this.getComment());
497 // Don't set null or wrong references
498 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
499 // Now the number must be given
500 if (phone.getPhoneAreaCode() == null) {
502 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
503 } else if (phone.getPhoneAreaCode() < 1) {
505 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
506 } else if (phone.getPhoneNumber() == null) {
508 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
509 } else if (phone.getPhoneNumber() < 1) {
511 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
515 contact.setContactLandLineNumber(phone);
518 // Don't set null or wrong references
519 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
520 // Now the number must be given
521 if (fax.getPhoneAreaCode() == null) {
523 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
524 } else if (fax.getPhoneAreaCode() < 1) {
526 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
527 } else if (fax.getPhoneNumber() == null) {
529 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
530 } else if (fax.getPhoneNumber() < 1) {
532 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
536 contact.setContactFaxNumber(fax);
539 // Is the provider set?
540 if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
541 // Is the number set?
542 if (mobile.getPhoneNumber() == null) {
544 throw new NullPointerException("mobile.phoneNumber is null"); //NOI18N
545 } else if (mobile.getPhoneNumber() < 1) {
547 throw new IllegalArgumentException("mobile.phoneNumber is zero or below."); //NOI18N
551 contact.setContactMobileNumber(mobile);
559 public String doChangePersonalContactData () {
560 // This method shall only be called if the user is logged-in
561 if (!this.userLoginController.isUserLoggedIn()) {
563 throw new IllegalStateException("User is not logged-in"); //NOI18N
564 } else if (!this.isRequiredChangePersonalDataSet()) {
565 // Not all required fields are set
566 throw new FaceletException("Not all required fields are set."); //NOI18N
567 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
568 // Password not matching
569 this.showFacesMessage("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
573 // Get contact instance
574 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
576 // It should be there, so run some tests on it
577 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
578 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
579 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
582 contact.setContactPersonalTitle(this.getPersonalTitle());
583 contact.setContactFirstName(this.getFirstName());
584 contact.setContactFamilyName(this.getFamilyName());
585 contact.setContactStreet(this.getStreet());
586 contact.setContactHouseNumber(this.getHouseNumber());
587 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
588 contact.setContactZipCode(this.getZipCode());
589 contact.setContactCity(this.getCity());
590 contact.setContactCountry(this.getCountry());
592 // Update contact's mobile number
593 this.isMobileUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
595 // Update contact's land-line number
596 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
598 // Update contact's fax number
599 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
601 // Send it to the EJB
602 this.contactBean.updateContactData(contact, this.isMobileUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
605 return "contact_data_saved"; //NOI18N
609 * Getter for academic title
611 * @return Academic title
613 public String getAcademicTitle () {
614 return this.academicTitle;
618 * Setter for academic title
620 * @param academicTitle Academic title
622 public void setAcademicTitle (final String academicTitle) {
623 this.academicTitle = academicTitle;
627 * Getter for birth day
631 @SuppressWarnings ("ReturnOfDateField")
632 public Date getBirthday () {
633 return this.birthday;
637 * Setter for birth day
639 * @param birthday Birth day
641 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
642 public void setBirthday (final Date birthday) {
643 this.birthday = birthday;
647 * Getter for city name
651 public String getCity () {
656 * Setter for city name
658 * @param city City name
660 public void setCity (final String city) {
665 * Getter for comments
669 public String getComment () {
676 * @param comment Comments
678 public void setComment (final String comment) {
679 this.comment = comment;
683 public String getControllerType () {
684 return "general"; //NOI18N
689 public void setControllerType (final String controllerType) {
690 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
694 * Getter for country instance
696 * @return Country instance
698 public Country getCountry () {
703 * Setter for country instance
705 * @param country Country instance
707 public void setCountry (final Country country) {
708 this.country = country;
712 public String getEmailAddress () {
713 return this.emailAddress;
717 * Setter for email address
719 * @param emailAddress Email address
721 public void setEmailAddress (final String emailAddress) {
722 this.emailAddress = emailAddress;
726 * Getter for email address, repeated
728 * @return the emailAddress, repeated
730 public String getEmailAddressRepeat () {
731 return this.emailAddressRepeat;
735 * Setter for email address repeated
737 * @param emailAddressRepeat the emailAddress to set
739 public void setEmailAddressRepeat (final String emailAddressRepeat) {
740 this.emailAddressRepeat = emailAddressRepeat;
746 * @return the familyName
748 public String getFamilyName () {
749 return this.familyName;
755 * @param familyName the familyName to set
757 public void setFamilyName (final String familyName) {
758 this.familyName = familyName;
762 * Getter for fax number's area code
764 * @return Fax number's area code
766 public Integer getFaxAreaCode () {
767 return this.faxAreaCode;
771 * Setter for fax number's area code
773 * @param faxAreaCode Fax number's area code
775 public void setFaxAreaCode (final Integer faxAreaCode) {
776 this.faxAreaCode = faxAreaCode;
780 * Getter for fax's country instance
782 * @return Fax' country instance
784 public Country getFaxCountry () {
785 return this.faxCountry;
789 * Setter for fax's country instance
791 * @param faxCountry Fax' country instance
793 public void setFaxCountry (final Country faxCountry) {
794 this.faxCountry = faxCountry;
798 * Getter for fax number
802 public Long getFaxNumber () {
803 return this.faxNumber;
807 * Setter for fax number
809 * @param faxNumber Fax number
811 public void setFaxNumber (final Long faxNumber) {
812 this.faxNumber = faxNumber;
818 * @return the first name
820 public String getFirstName () {
821 return this.firstName;
827 * @param firstName the first name to set
829 public void setFirstName (final String firstName) {
830 this.firstName = firstName;
836 * @return the houseNumber
838 public Short getHouseNumber () {
839 return this.houseNumber;
845 * @param houseNumber the houseNumber to set
847 public void setHouseNumber (final Short houseNumber) {
848 this.houseNumber = houseNumber;
852 * Getter for house number extension, example: 123a 'a' is then the
853 * extension and 123 is the house number.
855 * @return House number extension
857 public String getHouseNumberExtension () {
858 return this.houseNumberExtension;
862 * Setter for house number extension
864 * @param houseNumberExtension House number extension
866 public void setHouseNumberExtension (final String houseNumberExtension) {
867 this.houseNumberExtension = houseNumberExtension;
871 * Getter for land-line number's area code
873 * @return Land-line number's area code
875 public Integer getLandLineAreaCode () {
876 return this.landLineAreaCode;
880 * Setter for land-line number's area code
882 * @param landLineAreaCode Land-line number's area code
884 public void setLandLineAreaCode (final Integer landLineAreaCode) {
885 this.landLineAreaCode = landLineAreaCode;
889 * Getter for land-line number's country instance
891 * @return Land-line number's country instance
893 public Country getLandLineCountry () {
894 return this.landLineCountry;
898 * Setter for land-line number's country instance
900 * @param landLineCountry Land-line number's country instance
902 public void setLandLineCountry (final Country landLineCountry) {
903 this.landLineCountry = landLineCountry;
907 * Getter for land-line number
909 * @return Land-line number
911 public Long getLandLineNumber () {
912 return this.landLineNumber;
916 * Setter for land-line number
918 * @param landLineNumber Land-line number
920 public void setLandLineNumber (final Long landLineNumber) {
921 this.landLineNumber = landLineNumber;
925 * Getter for mobile number
927 * @return Mobile number
929 public Long getMobileNumber () {
930 return this.mobileNumber;
934 * Setter for mobile number
936 * @param mobileNumber Mobile number
938 public void setMobileNumber (final Long mobileNumber) {
939 this.mobileNumber = mobileNumber;
943 * Getter for mobile number's carrier
945 * @return Mobile number's carrier
947 public MobileProvider getMobileProvider () {
948 return this.mobileProvider;
952 * Setter for mobile number's provider
954 * @param mobileProvider Mobile number's provider
956 public void setMobileProvider (final MobileProvider mobileProvider) {
957 this.mobileProvider = mobileProvider;
961 * Getter for personal title
963 * @return Personal title
965 public PersonalTitle getPersonalTitle () {
966 return this.personalTitle;
970 * Setter for personal title
972 * @param personalTitle Personal title
974 public void setPersonalTitle (final PersonalTitle personalTitle) {
975 this.personalTitle = personalTitle;
983 public String getStreet () {
990 * @param street Street
992 public void setStreet (final String street) {
993 this.street = street;
997 * Getter for ZIP code
1001 public Integer getZipCode () {
1002 return this.zipCode;
1006 * Setter for ZIP code
1008 * @param zipCode ZIP code
1010 public void setZipCode (final Integer zipCode) {
1011 this.zipCode = zipCode;
1015 * Post-construction method
1018 public void init () {
1021 // Get initial context
1022 Context context = new InitialContext();
1025 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jjobs-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
1026 } catch (final NamingException e) {
1028 throw new FaceletException(e);
1031 // Get full email address list for reducing EJB calls
1032 this.emailAddressList.addAll(this.contactBean.getEmailAddressList());
1035 List<Contact> allContacts = this.contactBean.getAllContacts();
1037 // Get full contact list
1038 this.contactList.addAll(allContacts);
1041 List<User> allUsers = this.userController.allUsers();
1044 Iterator<Contact> iterator = allContacts.iterator();
1047 while (iterator.hasNext()) {
1049 Contact next = iterator.next();
1052 Iterator<User> userIterator = allUsers.iterator();
1054 // Loop through all users
1055 while (userIterator.hasNext()) {
1056 // Get user instance
1057 User nextUser = userIterator.next();
1060 if (Objects.equals(next, nextUser.getUserContact())) {
1069 this.selectableContacts = allContacts;
1073 public boolean isEmailAddressRegistered (final Contact contact) {
1075 if (null == contact) {
1077 throw new NullPointerException("contact is null"); //NOI18N
1078 } else if (contact.getContactEmailAddress() == null) {
1080 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
1081 } else if (contact.getContactEmailAddress().isEmpty()) {
1083 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
1087 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
1091 public boolean isRequiredChangePersonalDataSet () {
1092 return ((this.getPersonalTitle() != null) &&
1093 (this.getFirstName() != null) &&
1094 (this.getFamilyName() != null) &&
1095 (this.getStreet() != null) &&
1096 (this.getHouseNumber() != null) &&
1097 (this.getZipCode() != null) &&
1098 (this.getCity() != null));
1102 public boolean isRequiredPersonalDataSet () {
1103 return ((this.getPersonalTitle() != null) &&
1104 (this.getFirstName() != null) &&
1105 (this.getFamilyName() != null) &&
1106 (this.getStreet() != null) &&
1107 (this.getHouseNumber() != null) &&
1108 (this.getZipCode() != null) &&
1109 (this.getCity() != null) &&
1110 (this.getEmailAddress() != null) &&
1111 (this.getEmailAddressRepeat() != null));
1115 public boolean isSameEmailAddressEntered () {
1116 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
1120 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
1122 Contact localContact = null;
1127 // Try to lookup it in visible user list
1128 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
1130 Contact next = iterator.next();
1132 // Is the user id found?
1133 if (Objects.equals(next.getContactId(), contactId)) {
1134 // Copy to other variable
1135 localContact = next;
1140 // Is it still null?
1141 if (null == localContact) {
1142 // Not visible for the current user
1143 throw new ContactNotFoundException(contactId);
1146 // Copy all data to this bean
1147 this.copyContact(localContact);
1150 return localContact;
1154 public List<Contact> selectableContacts () {
1155 return Collections.unmodifiableList(this.selectableContacts);
1159 public void updateContactDataFromController (final Contact contact) {
1160 // Is the instance valid?
1161 if (null == contact) {
1163 throw new NullPointerException("contact is null"); //NOI18N
1164 } else if (contact.getContactId() == null) {
1166 throw new NullPointerException("contact.contactId is null"); //NOI18N
1167 } else if (contact.getContactId() < 1) {
1168 // Not valid id number
1169 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1173 this.copyContact(contact);
1177 * Adds email address to bean's internal list.
1179 * @param contact Contact instance
1181 private void addUserNameEmailAddress (final Contact contact) {
1182 // Make sure the entry is not added yet
1183 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
1185 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
1189 this.emailAddressList.add(contact.getContactEmailAddress());
1195 private void clear () {
1198 this.setPersonalTitle(null);
1199 this.setAcademicTitle(null);
1200 this.setFirstName(null);
1201 this.setFamilyName(null);
1202 this.setStreet(null);
1203 this.setHouseNumber(null);
1204 this.setHouseNumberExtension(null);
1205 this.setZipCode(null);
1207 this.setCountry(null);
1210 this.clearEmailAddresses();
1211 this.setLandLineAreaCode(null);
1212 this.setLandLineCountry(null);
1213 this.setLandLineNumber(null);
1214 this.setMobileProvider(null);
1215 this.setMobileNumber(null);
1216 this.setFaxAreaCode(null);
1217 this.setFaxCountry(null);
1218 this.setFaxNumber(null);
1221 this.setBirthday(null);
1222 this.setComment(null);
1226 * Copies given contact into the controller
1228 * @param contact Contact instance
1230 private void copyContact (final Contact contact) {
1231 // Is the instance valid?
1232 if (null == contact) {
1234 throw new NullPointerException("contact is null"); //NOI18N
1235 } else if (contact.getContactId() == null) {
1237 throw new NullPointerException("contact.contactId is null"); //NOI18N
1238 } else if (contact.getContactId() < 1) {
1239 // Not valid id number
1240 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1245 this.setPersonalTitle(contact.getContactPersonalTitle());
1246 this.setAcademicTitle(contact.getContactTitle());
1247 this.setFirstName(contact.getContactFirstName());
1248 this.setFamilyName(contact.getContactFamilyName());
1249 this.setStreet(contact.getContactStreet());
1250 this.setHouseNumber(contact.getContactHouseNumber());
1251 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
1252 this.setZipCode(contact.getContactZipCode());
1253 this.setCity(contact.getContactCity());
1254 this.setCountry(contact.getContactCountry());
1255 this.setEmailAddress(contact.getContactEmailAddress());
1256 this.setBirthday(contact.getContactBirthday());
1257 this.setComment(contact.getContactComment());
1259 // Get mobile, phone and fax instance
1260 DialableMobileNumber mobile = contact.getContactMobileNumber();
1261 DialableFaxNumber fax = contact.getContactFaxNumber();
1262 DialableLandLineNumber phone = contact.getContactLandLineNumber();
1265 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
1266 this.setLandLineCountry(phone.getPhoneCountry());
1267 this.setLandLineAreaCode(phone.getPhoneAreaCode());
1268 this.setLandLineNumber(phone.getPhoneNumber());
1271 if ((mobile instanceof DialableMobileNumber) && (mobile.getMobileProvider() instanceof MobileProvider)) {
1272 this.setMobileProvider(mobile.getMobileProvider());
1273 this.setMobileNumber(mobile.getPhoneNumber());
1276 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
1277 this.setFaxCountry(fax.getPhoneCountry());
1278 this.setFaxAreaCode(fax.getPhoneAreaCode());
1279 this.setFaxNumber(fax.getPhoneNumber());
1284 * Removes given contact from all lists
1286 * @param contact Contact instance to remove
1288 private void removeContact (final Contact contact) {
1289 // Is the instance valid?
1290 if (null == contact) {
1292 throw new NullPointerException("contact is null"); //NOI18N
1293 } else if (contact.getContactId() == null) {
1295 throw new NullPointerException("contact.contactId is null"); //NOI18N
1296 } else if (contact.getContactId() < 1) {
1297 // Not valid id number
1298 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1301 // Remove from general list
1302 if (!this.contactList.remove(contact)) {
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.emailAddressList.remove(contact.getContactEmailAddress());
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 // Is the instance valid?
1319 if (null == contact) {
1321 throw new NullPointerException("contact is null"); //NOI18N
1322 } else if (contact.getContactId() == null) {
1324 throw new NullPointerException("contact.contactId is null"); //NOI18N
1325 } else if (contact.getContactId() < 1) {
1326 // Not valid id number
1327 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1330 // Get iterator from list
1331 Iterator<Contact> iterator = this.contactList.iterator();
1333 // "Walk" through all entries
1334 while (iterator.hasNext()) {
1336 Contact next = iterator.next();
1338 // Is id number the same?
1339 if (Objects.equals(contact.getContactId(), next.getContactId())) {
1340 // Found entry, so remove it and abort
1341 this.removeContact(next);
1346 // Add contact to list
1347 this.contactList.add(contact);