2 * Copyright (C) 2016 Roland Haeder
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.HashMap;
23 import java.util.Iterator;
24 import java.util.LinkedList;
25 import java.util.List;
27 import java.util.Objects;
28 import javax.annotation.PostConstruct;
29 import javax.enterprise.context.SessionScoped;
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 javax.naming.Context;
35 import javax.naming.InitialContext;
36 import javax.naming.NamingException;
37 import org.mxchange.jcontacts.contact.Contact;
38 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
39 import org.mxchange.jcontacts.contact.UserContact;
40 import org.mxchange.jcontacts.contact.gender.Gender;
41 import org.mxchange.jcontacts.contact.utils.ContactUtils;
42 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
43 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
44 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
45 import org.mxchange.jcountry.data.Country;
46 import org.mxchange.jjobs.beans.BaseJobsController;
47 import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
48 import org.mxchange.jjobs.beans.phone.JobsAdminPhoneWebRequestController;
49 import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
50 import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
51 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
52 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
53 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
54 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
55 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
56 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
57 import org.mxchange.jphone.phonenumbers.phone.AdminPhoneSessionBeanRemote;
58 import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
59 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
60 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
61 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
62 import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
63 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
64 import org.mxchange.jusercore.model.user.User;
67 * A general contact bean (controller)
69 * @author Roland Haeder<roland@mxchange.org>
71 @Named ("contactController")
73 public class JobsContactWebSessionBean extends BaseJobsController implements JobsContactWebSessionController {
78 private static final long serialVersionUID = 542_145_347_916L;
81 * Remote EJB for phone number (administrative)
83 private AdminPhoneSessionBeanRemote adminPhoneBean;
86 * Administrative phone controller
89 private JobsAdminPhoneWebRequestController adminPhoneController;
94 private Date birthday;
97 * Cellphone number's carrier
99 private MobileProvider cellphoneCarrier;
104 private Long cellphoneNumber;
107 * All cell phone numbers
109 private final List<DialableCellphoneNumber> cellphoneNumbers;
119 private String comment;
122 * Remote contact bean
124 private final ContactSessionBeanRemote contactBean;
129 private final List<Contact> contactList;
132 * "Cache" for contact lists, mostly only one is assigned. So this cache
133 * shouldn't grow beyond control.
135 private final Map<Long, List<Contact>> contacts;
140 private Country country;
145 private String emailAddress;
150 private final List<String> emailAddressList;
153 * Email address repeated
155 private String emailAddressRepeat;
160 private String familyName;
163 * Fax number's area code
165 private Integer faxAreaCode;
168 * Country instance for fax number
170 private Country faxCountry;
175 private Long faxNumber;
180 private String firstName;
185 private Gender gender;
190 private Short houseNumber;
193 * House number extension
195 private String houseNumberExtension;
198 * Whether a cellphone entry has been unlinked
200 private boolean isCellphoneUnlinked;
203 * Whether a fax entry has been unlinked
205 private boolean isFaxUnlinked;
208 * Whether a land-line number has been unlinked
210 private boolean isLandLineUnlinked;
213 * Phone number area code
215 private Integer phoneAreaCode;
218 * Country instance for phone number
220 private Country phoneCountry;
225 private Long phoneNumber;
228 * A list of all selectable contacts
230 private List<Contact> selectableContacts;
235 private String street;
240 private String title;
243 * Regular user controller
246 private JobsUserWebSessionController userController;
249 * Login bean (controller)
252 private JobsUserLoginWebSessionController userLoginController;
257 private Integer zipCode;
260 * Default constructor
262 public JobsContactWebSessionBean () {
265 // Get initial context
266 Context context = new InitialContext();
269 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
271 // Try to lookup the beans
272 this.adminPhoneBean = (AdminPhoneSessionBeanRemote) context.lookup("java:global/jjobs-ejb/adminphone!org.mxchange.jphone.phonenumbers.phone.AdminPhoneSessionBeanRemote"); //NOI18N
273 } catch (final NamingException e) {
275 throw new FaceletException(e);
279 this.cellphoneNumbers = new LinkedList<>();
280 this.contacts = new HashMap<>(10);
281 this.contactList = new LinkedList<>();
282 this.emailAddressList = new LinkedList<>();
286 public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) {
287 // The event must be valid
290 throw new NullPointerException("event is null"); //NOI18N
291 } else if (event.getAddedContact() == null) {
293 throw new NullPointerException("event.addedContact is null"); //NOI18N
294 } else if (event.getAddedContact().getContactId() == null) {
296 throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
297 } else if (event.getAddedContact().getContactId() < 1) {
299 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
306 this.uniqueAddContact(event.getAddedContact());
308 // Add to selectable contacts
309 this.selectableContacts.add(event.getAddedContact());
313 public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
314 // event should not be null
317 throw new NullPointerException("event is null"); //NOI18N
318 } else if (event.getAddedUser() == null) {
320 throw new NullPointerException("event.addedUser is null"); //NOI18N
321 } else if (event.getAddedUser().getUserId() == null) {
323 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
324 } else if (event.getAddedUser().getUserId() < 1) {
326 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
334 public void afterAdminLinkedUser (@Observes final AdminLinkedUserEvent event) {
335 // event should not be null
338 throw new NullPointerException("event is null"); //NOI18N
339 } else if (event.getLinkedUser() == null) {
341 throw new NullPointerException("event.linkedUser is null"); //NOI18N
342 } else if (event.getLinkedUser().getUserContact() == null) {
344 throw new NullPointerException("event.linkedUser.userContact is null"); //NOI18N
345 } else if (event.getLinkedUser().getUserContact().getContactId() == null) {
347 throw new NullPointerException("event.linkedUser.userContact.contactId is null"); //NOI18N
348 } else if (event.getLinkedUser().getUserContact().getContactId() < 1) {
350 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N
353 // Remove contact from list available contacts list
354 this.selectableContacts.remove(event.getLinkedUser().getUserContact());
361 public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
362 // event should not be null
365 throw new NullPointerException("event is null"); //NOI18N
366 } else if (event.getUpdatedContact() == null) {
368 throw new NullPointerException("event.updatedContact is null"); //NOI18N
369 } else if (event.getUpdatedContact().getContactId() == null) {
371 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
372 } else if (event.getUpdatedContact().getContactId() < 1) {
374 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
377 // Add contact instance only once
378 this.uniqueAddContact(event.getUpdatedContact());
380 // Add email address to list
381 this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
385 public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
386 // event should not be null
389 throw new NullPointerException("event is null"); //NOI18N
390 } else if (event.getRegisteredUser() == null) {
392 throw new NullPointerException("event.registeredUser is null"); //NOI18N
393 } else if (event.getRegisteredUser().getUserId() == null) {
395 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
396 } else if (event.getRegisteredUser().getUserId() < 1) {
398 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
402 Contact registeredContact = event.getRegisteredUser().getUserContact();
404 // Copy all data from registered->user
405 this.copyContact(registeredContact);
407 // Add contact instance only once
408 this.uniqueAddContact(registeredContact);
410 // Add user name and email address
411 this.addUserNameEmailAddress(registeredContact);
418 public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) {
419 // event should not be null
422 throw new NullPointerException("event is null"); //NOI18N
423 } else if (event.getConfirmedUser() == null) {
425 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
426 } else if (event.getConfirmedUser().getUserId() == null) {
428 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
429 } else if (event.getConfirmedUser().getUserId() < 1) {
431 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
434 // Add contact instance only once
435 this.uniqueAddContact(event.getConfirmedUser().getUserContact());
439 public void afterUserLogin (@Observes final UserLoggedInEvent event) {
440 // event should not be null
443 throw new NullPointerException("event is null"); //NOI18N
444 } else if (event.getLoggedInUser() == null) {
446 throw new NullPointerException("event.loggedInUser is null"); //NOI18N
447 } else if (event.getLoggedInUser().getUserId() == null) {
449 throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
450 } else if (event.getLoggedInUser().getUserId() < 1) {
452 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
455 // Copy all data to this bean
456 this.copyContact(event.getLoggedInUser().getUserContact());
460 public List<Contact> allCellphoneContacts () {
462 Long phoneId = this.adminPhoneController.getCellPhone().getPhoneId();
465 if (this.contacts.containsKey(phoneId)) {
466 // Return cached version
467 return this.contacts.get(phoneId);
470 List<Contact> list = new LinkedList<>();
472 // "Walk" through all contacts
473 for (final Contact contact : this.contactList) {
474 // Is cellphone instance the same?
475 if (Objects.equals(contact.getContactCellphoneNumber(), this.adminPhoneController.getCellPhone())) {
481 // Store result in cache
482 this.contacts.put(phoneId, list);
484 // Return now-cached list
490 public List<Contact> allContacts () {
492 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size()));
494 // Return un-modified list
495 return Collections.unmodifiableList(this.contactList);
499 public Contact createContactInstance () {
501 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName()));
503 // Is all required data set?
504 if (!this.isRequiredPersonalDataSet()) {
505 // No, then abort here
506 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
509 // Generate phone number
510 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
511 DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
512 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
514 // Create new contact
515 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
516 contact.setContactStreet(this.getStreet());
517 contact.setContactHouseNumber(this.getHouseNumber());
518 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
519 contact.setContactZipCode(this.getZipCode());
520 contact.setContactCity(this.getCity());
521 contact.setContactCountry(this.getCountry());
522 contact.setContactEmailAddress(this.getEmailAddress());
523 contact.setContactBirthday(this.getBirthday());
524 contact.setContactComment(this.getComment());
527 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
529 // Don't set null or wrong references
530 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
531 // Now the number must be given
532 if (phone.getPhoneAreaCode() == null) {
534 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
535 } else if (phone.getPhoneAreaCode() < 1) {
537 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
538 } else if (phone.getPhoneNumber() == null) {
540 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
541 } else if (phone.getPhoneNumber() < 1) {
543 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
547 contact.setContactLandLineNumber(phone);
550 // Don't set null or wrong references
551 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
552 // Now the number must be given
553 if (fax.getPhoneAreaCode() == null) {
555 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
556 } else if (fax.getPhoneAreaCode() < 1) {
558 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
559 } else if (fax.getPhoneNumber() == null) {
561 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
562 } else if (fax.getPhoneNumber() < 1) {
564 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
568 contact.setContactFaxNumber(fax);
571 // Is the provider set?
572 if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
573 // Is the number set?
574 if (cellphone.getPhoneNumber() == null) {
576 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
577 } else if (cellphone.getPhoneNumber() < 1) {
579 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
582 // Set cellphone number
583 contact.setContactCellphoneNumber(cellphone);
587 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
594 public String doChangePersonalContactData () {
595 // This method shall only be called if the user is logged-in
596 if (!this.userLoginController.isUserLoggedIn()) {
598 throw new IllegalStateException("User is not logged-in"); //NOI18N
599 } else if (!this.isRequiredChangePersonalDataSet()) {
600 // Not all required fields are set
601 throw new FaceletException("Not all required fields are set."); //NOI18N
602 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
603 // Password not matching
604 this.showFacesMessage("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
608 // Get contact instance
609 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
611 // It should be there, so run some tests on it
612 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
613 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
614 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
617 contact.setContactGender(this.getGender());
618 contact.setContactFirstName(this.getFirstName());
619 contact.setContactFamilyName(this.getFamilyName());
620 contact.setContactStreet(this.getStreet());
621 contact.setContactHouseNumber(this.getHouseNumber());
622 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
623 contact.setContactZipCode(this.getZipCode());
624 contact.setContactCity(this.getCity());
625 contact.setContactCountry(this.getCountry());
627 // Update contact's cellphone number
628 this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
630 // Update contact's land-line number
631 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
633 // Update contact's fax number
634 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
636 // Send it to the EJB
637 this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
640 return "contact_data_saved"; //NOI18N
644 @SuppressWarnings ("ReturnOfDateField")
645 public Date getBirthday () {
646 return this.birthday;
650 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
651 public void setBirthday (final Date birthday) {
652 this.birthday = birthday;
656 public MobileProvider getCellphoneCarrier () {
657 return this.cellphoneCarrier;
661 public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
662 this.cellphoneCarrier = cellphoneCarrier;
666 public Long getCellphoneNumber () {
667 return this.cellphoneNumber;
671 public void setCellphoneNumber (Long cellphoneNumber) {
672 this.cellphoneNumber = cellphoneNumber;
676 public String getCity () {
681 public void setCity (final String city) {
686 public String getComment () {
691 public void setComment (final String comment) {
692 this.comment = comment;
696 public String getControllerType () {
697 return "general"; //NOI18N
702 public void setControllerType (final String controllerType) {
703 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
707 public Country getCountry () {
712 public void setCountry (final Country country) {
713 this.country = country;
717 public String getEmailAddress () {
718 return this.emailAddress;
722 public void setEmailAddress (final String emailAddress) {
723 this.emailAddress = emailAddress;
727 public String getEmailAddressRepeat () {
728 return this.emailAddressRepeat;
732 public void setEmailAddressRepeat (final String emailAddressRepeat) {
733 this.emailAddressRepeat = emailAddressRepeat;
737 public String getFamilyName () {
738 return this.familyName;
742 public void setFamilyName (final String familyName) {
743 this.familyName = familyName;
747 public Integer getFaxAreaCode () {
748 return this.faxAreaCode;
752 public void setFaxAreaCode (final Integer faxAreaCode) {
753 this.faxAreaCode = faxAreaCode;
757 public Country getFaxCountry () {
758 return this.faxCountry;
762 public void setFaxCountry (final Country faxCountry) {
763 this.faxCountry = faxCountry;
767 public Long getFaxNumber () {
768 return this.faxNumber;
772 public void setFaxNumber (final Long faxNumber) {
773 this.faxNumber = faxNumber;
777 public String getFirstName () {
778 return this.firstName;
782 public void setFirstName (final String firstName) {
783 this.firstName = firstName;
787 public Gender getGender () {
792 public void setGender (final Gender gender) {
793 this.gender = gender;
797 public Short getHouseNumber () {
798 return this.houseNumber;
802 public void setHouseNumber (final Short houseNumber) {
803 this.houseNumber = houseNumber;
807 public String getHouseNumberExtension () {
808 return this.houseNumberExtension;
812 public void setHouseNumberExtension (final String houseNumberExtension) {
813 this.houseNumberExtension = houseNumberExtension;
817 public Integer getPhoneAreaCode () {
818 return this.phoneAreaCode;
822 public void setPhoneAreaCode (final Integer phoneAreaCode) {
823 this.phoneAreaCode = phoneAreaCode;
827 public Country getPhoneCountry () {
828 return this.phoneCountry;
832 public void setPhoneCountry (final Country phoneCountry) {
833 this.phoneCountry = phoneCountry;
837 public Long getPhoneNumber () {
838 return this.phoneNumber;
842 public void setPhoneNumber (final Long phoneNumber) {
843 this.phoneNumber = phoneNumber;
847 public String getStreet () {
852 public void setStreet (final String street) {
853 this.street = street;
857 public String getTitle () {
862 public void setTitle (final String title) {
867 public Integer getZipCode () {
872 public void setZipCode (final Integer zipCode) {
873 this.zipCode = zipCode;
877 public boolean hasContacts () {
878 return (!this.contactList.isEmpty());
882 * Post-initialization of this class
885 public void init () {
886 // Get full email address list for reducing EJB calls
887 this.emailAddressList.addAll(this.contactBean.getEmailAddressList());
889 // Get full contact list
890 this.contactList.addAll(this.contactBean.getAllContacts());
893 List<User> allUsers = this.userController.allUsers();
896 List<Contact> allContacts = this.contactBean.getAllContacts();
899 Iterator<Contact> iterator = allContacts.iterator();
902 while (iterator.hasNext()) {
904 Contact next = iterator.next();
907 Iterator<User> userIterator = allUsers.iterator();
909 // Loop through all users
910 while (userIterator.hasNext()) {
912 User nextUser = userIterator.next();
915 if (Objects.equals(next, nextUser.getUserContact())) {
924 this.selectableContacts = allContacts;
927 this.cellphoneNumbers.addAll(this.adminPhoneBean.allCellphoneNumbers());
931 public boolean isEmailAddressRegistered (final Contact contact) {
933 if (null == contact) {
935 throw new NullPointerException("contact is null"); //NOI18N
936 } else if (contact.getContactEmailAddress() == null) {
938 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
939 } else if (contact.getContactEmailAddress().isEmpty()) {
941 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
945 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
949 public boolean isRequiredChangePersonalDataSet () {
950 return ((this.getGender() != null) &&
951 (this.getFirstName() != null) &&
952 (this.getFamilyName() != null) &&
953 (this.getStreet() != null) &&
954 (this.getHouseNumber() != null) &&
955 (this.getZipCode() != null) &&
956 (this.getCity() != null));
960 public boolean isRequiredPersonalDataSet () {
961 return ((this.getGender() != null) &&
962 (this.getFirstName() != null) &&
963 (this.getFamilyName() != null) &&
964 (this.getStreet() != null) &&
965 (this.getHouseNumber() != null) &&
966 (this.getZipCode() != null) &&
967 (this.getCity() != null) &&
968 (this.getEmailAddress() != null) &&
969 (this.getEmailAddressRepeat() != null));
973 public boolean isSameEmailAddressEntered () {
974 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
978 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
980 Contact localContact = null;
985 // Try to lookup it in visible user list
986 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
988 Contact next = iterator.next();
990 // Is the user id found?
991 if (Objects.equals(next.getContactId(), contactId)) {
992 // Copy to other variable
999 if (null == localContact) {
1000 // Not visible for the current user
1001 throw new ContactNotFoundException(contactId);
1004 // Copy all data to this bean
1005 this.copyContact(localContact);
1008 return localContact;
1012 public List<Contact> selectableContacts () {
1013 return Collections.unmodifiableList(this.selectableContacts);
1017 public void updateContactDataFromController (final Contact contact) {
1018 // Is the instance valid?
1019 if (null == contact) {
1021 throw new NullPointerException("contact is null"); //NOI18N
1022 } else if (contact.getContactId() == null) {
1024 throw new NullPointerException("contact.contactId is null"); //NOI18N
1025 } else if (contact.getContactId() < 1) {
1026 // Not valid id number
1027 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1031 this.copyContact(contact);
1035 * Adds email address to bean's internal list.
1037 * @param contact Contact instance
1039 private void addUserNameEmailAddress (final Contact contact) {
1040 // Make sure the entry is not added yet
1041 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
1043 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
1047 this.emailAddressList.add(contact.getContactEmailAddress());
1053 private void clear () {
1056 this.setGender(null);
1057 this.setTitle(null);
1058 this.setFirstName(null);
1059 this.setFamilyName(null);
1060 this.setStreet(null);
1061 this.setHouseNumber(null);
1062 this.setHouseNumberExtension(null);
1063 this.setZipCode(null);
1065 this.setCountry(null);
1068 this.setEmailAddress(null);
1069 this.setEmailAddressRepeat(null);
1070 this.setPhoneAreaCode(null);
1071 this.setPhoneCountry(null);
1072 this.setPhoneNumber(null);
1073 this.setCellphoneCarrier(null);
1074 this.setCellphoneNumber(null);
1075 this.setFaxAreaCode(null);
1076 this.setFaxCountry(null);
1077 this.setFaxNumber(null);
1080 this.setBirthday(null);
1081 this.setComment(null);
1085 * Copies given contact into the controller
1087 * @param contact Contact instance
1089 private void copyContact (final Contact contact) {
1090 // Is the instance valid?
1091 if (null == contact) {
1093 throw new NullPointerException("contact is null"); //NOI18N
1094 } else if (contact.getContactId() == null) {
1096 throw new NullPointerException("contact.contactId is null"); //NOI18N
1097 } else if (contact.getContactId() < 1) {
1098 // Not valid id number
1099 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1104 this.setGender(contact.getContactGender());
1105 this.setTitle(contact.getContactTitle());
1106 this.setFirstName(contact.getContactFirstName());
1107 this.setFamilyName(contact.getContactFamilyName());
1108 this.setStreet(contact.getContactStreet());
1109 this.setHouseNumber(contact.getContactHouseNumber());
1110 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
1111 this.setZipCode(contact.getContactZipCode());
1112 this.setCity(contact.getContactCity());
1113 this.setCountry(contact.getContactCountry());
1114 this.setEmailAddress(contact.getContactEmailAddress());
1115 this.setBirthday(contact.getContactBirthday());
1116 this.setComment(contact.getContactComment());
1118 // Get cellphone, phone and fax instance
1119 DialableCellphoneNumber cellphone = contact.getContactCellphoneNumber();
1120 DialableFaxNumber fax = contact.getContactFaxNumber();
1121 DialableLandLineNumber phone = contact.getContactLandLineNumber();
1124 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
1125 this.setPhoneCountry(phone.getPhoneCountry());
1126 this.setPhoneAreaCode(phone.getPhoneAreaCode());
1127 this.setPhoneNumber(phone.getPhoneNumber());
1130 if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) {
1131 this.setCellphoneCarrier(cellphone.getCellphoneProvider());
1132 this.setCellphoneNumber(cellphone.getPhoneNumber());
1135 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
1136 this.setFaxCountry(fax.getPhoneCountry());
1137 this.setFaxAreaCode(fax.getPhoneAreaCode());
1138 this.setFaxNumber(fax.getPhoneNumber());
1143 * Removes given contact from all lists
1145 * @param contact Contact instance to remove
1147 private void removeContact (final Contact contact) {
1148 // Is the instance valid?
1149 if (null == contact) {
1151 throw new NullPointerException("contact is null"); //NOI18N
1152 } else if (contact.getContactId() == null) {
1154 throw new NullPointerException("contact.contactId is null"); //NOI18N
1155 } else if (contact.getContactId() < 1) {
1156 // Not valid id number
1157 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1160 // Remove from general list
1161 if (!this.contactList.remove(contact)) {
1162 // Did not remove contact
1163 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
1166 // Remove from other lists
1167 this.emailAddressList.remove(contact.getContactEmailAddress());
1171 * Adds unique instance to contact list. First any existing instance is
1172 * being removed, then the new instance is added.
1174 * @param contact Contact instance to add uniquely
1176 private void uniqueAddContact (final Contact contact) {
1177 // Is the instance valid?
1178 if (null == contact) {
1180 throw new NullPointerException("contact is null"); //NOI18N
1181 } else if (contact.getContactId() == null) {
1183 throw new NullPointerException("contact.contactId is null"); //NOI18N
1184 } else if (contact.getContactId() < 1) {
1185 // Not valid id number
1186 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1189 // Get iterator from list
1190 Iterator<Contact> iterator = this.contactList.iterator();
1192 // "Walk" through all entries
1193 while (iterator.hasNext()) {
1195 Contact next = iterator.next();
1197 // Is id number the same?
1198 if (Objects.equals(contact.getContactId(), next.getContactId())) {
1199 // Found entry, so remove it and abort
1200 this.removeContact(next);
1205 // Add contact to list
1206 this.contactList.add(contact);