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 Contact createContactInstance () {
464 // Is all required data set?
465 if (!this.isRequiredPersonalDataSet()) {
466 // No, then abort here
467 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
470 // Required personal data must be set
471 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
473 // Generate phone number
474 DialableLandLineNumber phone = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
475 DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
476 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
478 // Create new contact
479 Contact contact = new UserContact(this.getPersonalTitle(), this.getFirstName(), this.getFamilyName());
480 contact.setContactStreet(this.getStreet());
481 contact.setContactHouseNumber(this.getHouseNumber());
482 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
483 contact.setContactZipCode(this.getZipCode());
484 contact.setContactCity(this.getCity());
485 contact.setContactCountry(this.getCountry());
486 contact.setContactEmailAddress(this.getEmailAddress());
487 contact.setContactBirthday(this.getBirthday());
488 contact.setContactComment(this.getComment());
490 // Don't set null or wrong references
491 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
492 // Now the number must be given
493 if (phone.getPhoneAreaCode() == null) {
495 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
496 } else if (phone.getPhoneAreaCode() < 1) {
498 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
499 } else if (phone.getPhoneNumber() == null) {
501 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
502 } else if (phone.getPhoneNumber() < 1) {
504 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
508 contact.setContactLandLineNumber(phone);
511 // Don't set null or wrong references
512 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
513 // Now the number must be given
514 if (fax.getPhoneAreaCode() == null) {
516 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
517 } else if (fax.getPhoneAreaCode() < 1) {
519 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
520 } else if (fax.getPhoneNumber() == null) {
522 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
523 } else if (fax.getPhoneNumber() < 1) {
525 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
529 contact.setContactFaxNumber(fax);
532 // Is the provider set?
533 if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
534 // Is the number set?
535 if (mobile.getPhoneNumber() == null) {
537 throw new NullPointerException("mobile.phoneNumber is null"); //NOI18N
538 } else if (mobile.getPhoneNumber() < 1) {
540 throw new IllegalArgumentException("mobile.phoneNumber is zero or below."); //NOI18N
544 contact.setContactMobileNumber(mobile);
552 public String doChangePersonalContactData () {
553 // This method shall only be called if the user is logged-in
554 if (!this.userLoginController.isUserLoggedIn()) {
556 throw new IllegalStateException("User is not logged-in"); //NOI18N
557 } else if (!this.isRequiredChangePersonalDataSet()) {
558 // Not all required fields are set
559 throw new FaceletException("Not all required fields are set."); //NOI18N
560 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
561 // Password not matching
562 this.showFacesMessage("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
566 // Get contact instance
567 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
569 // It should be there, so run some tests on it
570 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
571 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
572 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
575 contact.setContactPersonalTitle(this.getPersonalTitle());
576 contact.setContactFirstName(this.getFirstName());
577 contact.setContactFamilyName(this.getFamilyName());
578 contact.setContactStreet(this.getStreet());
579 contact.setContactHouseNumber(this.getHouseNumber());
580 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
581 contact.setContactZipCode(this.getZipCode());
582 contact.setContactCity(this.getCity());
583 contact.setContactCountry(this.getCountry());
585 // Update contact's mobile number
586 this.isMobileUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
588 // Update contact's land-line number
589 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
591 // Update contact's fax number
592 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
594 // Send it to the EJB
595 this.contactBean.updateContactData(contact, this.isMobileUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
598 return "contact_data_saved"; //NOI18N
602 public String getAcademicTitle () {
603 return this.academicTitle;
607 public void setAcademicTitle (final String academicTitle) {
608 this.academicTitle = academicTitle;
612 @SuppressWarnings ("ReturnOfDateField")
613 public Date getBirthday () {
614 return this.birthday;
618 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
619 public void setBirthday (final Date birthday) {
620 this.birthday = birthday;
624 public String getCity () {
629 public void setCity (final String city) {
634 public String getComment () {
639 public void setComment (final String comment) {
640 this.comment = comment;
644 public String getControllerType () {
645 return "general"; //NOI18N
650 public void setControllerType (final String controllerType) {
651 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
655 public Country getCountry () {
660 public void setCountry (final Country country) {
661 this.country = country;
665 public String getEmailAddress () {
666 return this.emailAddress;
670 public void setEmailAddress (final String emailAddress) {
671 this.emailAddress = emailAddress;
675 public String getEmailAddressRepeat () {
676 return this.emailAddressRepeat;
680 public void setEmailAddressRepeat (final String emailAddressRepeat) {
681 this.emailAddressRepeat = emailAddressRepeat;
685 public String getFamilyName () {
686 return this.familyName;
690 public void setFamilyName (final String familyName) {
691 this.familyName = familyName;
695 public Integer getFaxAreaCode () {
696 return this.faxAreaCode;
700 public void setFaxAreaCode (final Integer faxAreaCode) {
701 this.faxAreaCode = faxAreaCode;
705 public Country getFaxCountry () {
706 return this.faxCountry;
710 public void setFaxCountry (final Country faxCountry) {
711 this.faxCountry = faxCountry;
715 public Long getFaxNumber () {
716 return this.faxNumber;
720 public void setFaxNumber (final Long faxNumber) {
721 this.faxNumber = faxNumber;
725 public String getFirstName () {
726 return this.firstName;
730 public void setFirstName (final String firstName) {
731 this.firstName = firstName;
735 public Short getHouseNumber () {
736 return this.houseNumber;
740 public void setHouseNumber (final Short houseNumber) {
741 this.houseNumber = houseNumber;
745 public String getHouseNumberExtension () {
746 return this.houseNumberExtension;
750 public void setHouseNumberExtension (final String houseNumberExtension) {
751 this.houseNumberExtension = houseNumberExtension;
755 public Integer getLandLineAreaCode () {
756 return this.landLineAreaCode;
760 public void setLandLineAreaCode (final Integer landLineAreaCode) {
761 this.landLineAreaCode = landLineAreaCode;
765 public Country getLandLineCountry () {
766 return this.landLineCountry;
770 public void setLandLineCountry (final Country landLineCountry) {
771 this.landLineCountry = landLineCountry;
775 public Long getLandLineNumber () {
776 return this.landLineNumber;
780 public void setLandLineNumber (final Long landLineNumber) {
781 this.landLineNumber = landLineNumber;
785 public Long getMobileNumber () {
786 return this.mobileNumber;
790 public void setMobileNumber (final Long mobileNumber) {
791 this.mobileNumber = mobileNumber;
795 public MobileProvider getMobileProvider () {
796 return this.mobileProvider;
800 public void setMobileProvider (final MobileProvider mobileProvider) {
801 this.mobileProvider = mobileProvider;
805 public PersonalTitle getPersonalTitle () {
806 return this.personalTitle;
810 public void setPersonalTitle (final PersonalTitle personalTitle) {
811 this.personalTitle = personalTitle;
815 public String getStreet () {
820 public void setStreet (final String street) {
821 this.street = street;
825 public Integer getZipCode () {
830 public void setZipCode (final Integer zipCode) {
831 this.zipCode = zipCode;
835 * Post-construction method
838 public void init () {
841 // Get initial context
842 Context context = new InitialContext();
845 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jjobs-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
846 } catch (final NamingException e) {
848 throw new FaceletException(e);
851 // Get full email address list for reducing EJB calls
852 this.emailAddressList.addAll(this.contactBean.getEmailAddressList());
855 List<Contact> allContacts = this.contactBean.getAllContacts();
857 // Get full contact list
858 this.contactList.addAll(allContacts);
861 List<User> allUsers = this.userController.allUsers();
864 Iterator<Contact> iterator = allContacts.iterator();
867 while (iterator.hasNext()) {
869 Contact next = iterator.next();
872 Iterator<User> userIterator = allUsers.iterator();
874 // Loop through all users
875 while (userIterator.hasNext()) {
877 User nextUser = userIterator.next();
880 if (Objects.equals(next, nextUser.getUserContact())) {
889 this.selectableContacts = allContacts;
893 public boolean isEmailAddressRegistered (final Contact contact) {
895 if (null == contact) {
897 throw new NullPointerException("contact is null"); //NOI18N
898 } else if (contact.getContactEmailAddress() == null) {
900 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
901 } else if (contact.getContactEmailAddress().isEmpty()) {
903 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
907 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
911 public boolean isRequiredChangePersonalDataSet () {
912 return ((this.getPersonalTitle() != null) &&
913 (this.getFirstName() != null) &&
914 (this.getFamilyName() != null) &&
915 (this.getStreet() != null) &&
916 (this.getHouseNumber() != null) &&
917 (this.getZipCode() != null) &&
918 (this.getCity() != null));
922 public boolean isRequiredPersonalDataSet () {
923 return ((this.getPersonalTitle() != null) &&
924 (this.getFirstName() != null) &&
925 (this.getFamilyName() != null) &&
926 (this.getStreet() != null) &&
927 (this.getHouseNumber() != null) &&
928 (this.getZipCode() != null) &&
929 (this.getCity() != null) &&
930 (this.getEmailAddress() != null) &&
931 (this.getEmailAddressRepeat() != null));
935 public boolean isSameEmailAddressEntered () {
936 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
940 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
942 Contact localContact = null;
947 // Try to lookup it in visible user list
948 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
950 Contact next = iterator.next();
952 // Is the user id found?
953 if (Objects.equals(next.getContactId(), contactId)) {
954 // Copy to other variable
961 if (null == localContact) {
962 // Not visible for the current user
963 throw new ContactNotFoundException(contactId);
966 // Copy all data to this bean
967 this.copyContact(localContact);
974 public List<Contact> selectableContacts () {
975 return Collections.unmodifiableList(this.selectableContacts);
979 public void updateContactDataFromController (final Contact contact) {
980 // Is the instance valid?
981 if (null == contact) {
983 throw new NullPointerException("contact is null"); //NOI18N
984 } else if (contact.getContactId() == null) {
986 throw new NullPointerException("contact.contactId is null"); //NOI18N
987 } else if (contact.getContactId() < 1) {
988 // Not valid id number
989 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
993 this.copyContact(contact);
997 * Adds email address to bean's internal list.
999 * @param contact Contact instance
1001 private void addUserNameEmailAddress (final Contact contact) {
1002 // Make sure the entry is not added yet
1003 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
1005 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
1009 this.emailAddressList.add(contact.getContactEmailAddress());
1015 private void clear () {
1018 this.setPersonalTitle(null);
1019 this.setAcademicTitle(null);
1020 this.setFirstName(null);
1021 this.setFamilyName(null);
1022 this.setStreet(null);
1023 this.setHouseNumber(null);
1024 this.setHouseNumberExtension(null);
1025 this.setZipCode(null);
1027 this.setCountry(null);
1030 this.setEmailAddress(null);
1031 this.setEmailAddressRepeat(null);
1032 this.setLandLineAreaCode(null);
1033 this.setLandLineCountry(null);
1034 this.setLandLineNumber(null);
1035 this.setMobileProvider(null);
1036 this.setMobileNumber(null);
1037 this.setFaxAreaCode(null);
1038 this.setFaxCountry(null);
1039 this.setFaxNumber(null);
1042 this.setBirthday(null);
1043 this.setComment(null);
1047 * Copies given contact into the controller
1049 * @param contact Contact instance
1051 private void copyContact (final Contact contact) {
1052 // Is the instance valid?
1053 if (null == contact) {
1055 throw new NullPointerException("contact is null"); //NOI18N
1056 } else if (contact.getContactId() == null) {
1058 throw new NullPointerException("contact.contactId is null"); //NOI18N
1059 } else if (contact.getContactId() < 1) {
1060 // Not valid id number
1061 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1066 this.setPersonalTitle(contact.getContactPersonalTitle());
1067 this.setAcademicTitle(contact.getContactTitle());
1068 this.setFirstName(contact.getContactFirstName());
1069 this.setFamilyName(contact.getContactFamilyName());
1070 this.setStreet(contact.getContactStreet());
1071 this.setHouseNumber(contact.getContactHouseNumber());
1072 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
1073 this.setZipCode(contact.getContactZipCode());
1074 this.setCity(contact.getContactCity());
1075 this.setCountry(contact.getContactCountry());
1076 this.setEmailAddress(contact.getContactEmailAddress());
1077 this.setBirthday(contact.getContactBirthday());
1078 this.setComment(contact.getContactComment());
1080 // Get mobile, phone and fax instance
1081 DialableMobileNumber mobile = contact.getContactMobileNumber();
1082 DialableFaxNumber fax = contact.getContactFaxNumber();
1083 DialableLandLineNumber phone = contact.getContactLandLineNumber();
1086 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
1087 this.setLandLineCountry(phone.getPhoneCountry());
1088 this.setLandLineAreaCode(phone.getPhoneAreaCode());
1089 this.setLandLineNumber(phone.getPhoneNumber());
1092 if ((mobile instanceof DialableMobileNumber) && (mobile.getMobileProvider() instanceof MobileProvider)) {
1093 this.setMobileProvider(mobile.getMobileProvider());
1094 this.setMobileNumber(mobile.getPhoneNumber());
1097 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
1098 this.setFaxCountry(fax.getPhoneCountry());
1099 this.setFaxAreaCode(fax.getPhoneAreaCode());
1100 this.setFaxNumber(fax.getPhoneNumber());
1105 * Removes given contact from all lists
1107 * @param contact Contact instance to remove
1109 private void removeContact (final Contact contact) {
1110 // Is the instance valid?
1111 if (null == contact) {
1113 throw new NullPointerException("contact is null"); //NOI18N
1114 } else if (contact.getContactId() == null) {
1116 throw new NullPointerException("contact.contactId is null"); //NOI18N
1117 } else if (contact.getContactId() < 1) {
1118 // Not valid id number
1119 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1122 // Remove from general list
1123 if (!this.contactList.remove(contact)) {
1124 // Did not remove contact
1125 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
1128 // Remove from other lists
1129 this.emailAddressList.remove(contact.getContactEmailAddress());
1133 * Adds unique instance to contact list. First any existing instance is
1134 * being removed, then the new instance is added.
1136 * @param contact Contact instance to add uniquely
1138 private void uniqueAddContact (final Contact contact) {
1139 // Is the instance valid?
1140 if (null == contact) {
1142 throw new NullPointerException("contact is null"); //NOI18N
1143 } else if (contact.getContactId() == null) {
1145 throw new NullPointerException("contact.contactId is null"); //NOI18N
1146 } else if (contact.getContactId() < 1) {
1147 // Not valid id number
1148 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1151 // Get iterator from list
1152 Iterator<Contact> iterator = this.contactList.iterator();
1154 // "Walk" through all entries
1155 while (iterator.hasNext()) {
1157 Contact next = iterator.next();
1159 // Is id number the same?
1160 if (Objects.equals(contact.getContactId(), next.getContactId())) {
1161 // Found entry, so remove it and abort
1162 this.removeContact(next);
1167 // Add contact to list
1168 this.contactList.add(contact);