]> git.mxchange.org Git - jfinancials-war.git/blobdiff - src/java/org/mxchange/jfinancials/beans/contact/FinancialsContactWebRequestBean.java
Updated copyright year
[jfinancials-war.git] / src / java / org / mxchange / jfinancials / beans / contact / FinancialsContactWebRequestBean.java
index 1162fded5b94c70e56254ce3cfb3a5beb9ad8420..29316ec548ef7a859163a976abc54389c4268bf3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2022 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
  */
 package org.mxchange.jfinancials.beans.contact;
 
-import fish.payara.cdi.jsr107.impl.NamedCache;
 import java.text.MessageFormat;
 import java.util.Date;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
 import java.util.Objects;
-import javax.annotation.PostConstruct;
-import javax.cache.Cache;
 import javax.ejb.EJB;
 import javax.enterprise.context.RequestScoped;
+import javax.enterprise.event.Event;
 import javax.enterprise.event.Observes;
-import javax.faces.view.facelets.FaceletException;
+import javax.enterprise.inject.Any;
+import javax.faces.FacesException;
+import javax.faces.application.FacesMessage;
 import javax.inject.Inject;
 import javax.inject.Named;
-import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
-import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.ObservableUpdatedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.UpdatedContactEvent;
+import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
 import org.mxchange.jcontacts.model.contact.Contact;
 import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
-import org.mxchange.jcontacts.model.contact.ContactUtils;
+import org.mxchange.jcontacts.model.contact.Contacts;
 import org.mxchange.jcontacts.model.contact.UserContact;
 import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
 import org.mxchange.jcountry.model.data.Country;
-import org.mxchange.jfinancials.beans.BaseFinancialsController;
-import org.mxchange.jfinancials.beans.user.FinancialsUserWebRequestController;
+import org.mxchange.jfinancials.beans.BaseFinancialsBean;
+import org.mxchange.jfinancials.beans.contact.list.FinancialsContactListWebViewController;
 import org.mxchange.jfinancials.beans.user.login.FinancialsUserLoginWebSessionController;
 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
@@ -51,10 +49,8 @@ import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
 import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
 import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.juserlogincore.events.confirmation.ObservableUserConfirmedAccountEvent;
+import org.mxchange.jusercore.events.user.update.pre.ObservablePreUserPersonalDataUpdatedEvent;
 import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent;
-import org.mxchange.juserlogincore.events.registration.ObservableUserRegisteredEvent;
 import org.mxchange.juserlogincore.exceptions.UserPasswordMismatchException;
 
 /**
@@ -64,7 +60,7 @@ import org.mxchange.juserlogincore.exceptions.UserPasswordMismatchException;
  */
 @Named ("contactController")
 @RequestScoped
-public class FinancialsContactWebRequestBean extends BaseFinancialsController implements FinancialsContactWebRequestController {
+public class FinancialsContactWebRequestBean extends BaseFinancialsBean implements FinancialsContactWebRequestController {
 
        /**
         * Serial number
@@ -98,11 +94,16 @@ public class FinancialsContactWebRequestBean extends BaseFinancialsController im
        private ContactSessionBeanRemote contactBean;
 
        /**
-        * Contact list
+        * An instance of a contact-list backing bean
         */
+       private FinancialsContactListWebViewController contactListController;
+
+       /**
+        * Event being fired when a user has updated his contact data
+        */
+       @Any
        @Inject
-       @NamedCache (cacheName = "contactsCache")
-       private Cache<Long, Contact> contactsCache;
+       private Event<ObservableUpdatedContactEvent> contactUpdatedEvent;
 
        /**
         * Country instance
@@ -114,13 +115,6 @@ public class FinancialsContactWebRequestBean extends BaseFinancialsController im
         */
        private String emailAddress;
 
-       /**
-        * Email address list
-        */
-       @Inject
-       @NamedCache (cacheName = "emailAddressCache")
-       private Cache<Long, String> emailAddressCache;
-
        /**
         * Email address repeated
         */
@@ -161,21 +155,6 @@ public class FinancialsContactWebRequestBean extends BaseFinancialsController im
         */
        private String houseNumberExtension;
 
-       /**
-        * Whether a fax entry has been unlinked
-        */
-       private boolean isFaxUnlinked;
-
-       /**
-        * Whether a land-line number has been unlinked
-        */
-       private boolean isLandLineUnlinked;
-
-       /**
-        * Whether a mobile entry has been unlinked
-        */
-       private boolean isMobileUnlinked;
-
        /**
         * Phone number area code
         */
@@ -206,24 +185,11 @@ public class FinancialsContactWebRequestBean extends BaseFinancialsController im
         */
        private PersonalTitle personalTitle;
 
-       /**
-        * A list of all selectable contacts
-        */
-       @Inject
-       @NamedCache (cacheName = "selectableContactsCache")
-       private Cache<Long, Contact> selectableContactsCache;
-
        /**
         * Street
         */
        private String street;
 
-       /**
-        * Regular user controller
-        */
-       @Inject
-       private FinancialsUserWebRequestController userController;
-
        /**
         * Login bean (controller)
         */
@@ -243,45 +209,13 @@ public class FinancialsContactWebRequestBean extends BaseFinancialsController im
                super();
        }
 
-       /**
-        * Observes events being fired when an administrator has added a new
-        * contact.
-        * <p>
-        * @param event Event being fired
-        */
-       public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
-               // The event must be valid
-               if (null == event) {
-                       // Throw NPE
-                       throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getAddedContact() == null) {
-                       // Throw again ...
-                       throw new NullPointerException("event.addedContact is null"); //NOI18N
-               } else if (event.getAddedContact().getContactId() == null) {
-                       // ... and again
-                       throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
-               } else if (event.getAddedContact().getContactId() < 1) {
-                       // Not valid
-                       throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
-               }
-
-               // Clear this bean
-               this.clear();
-
-               // Call other method
-               this.uniqueAddContact(event.getAddedContact());
-
-               // Add to selectable contacts
-               this.selectableContactsCache.put(event.getAddedContact().getContactId(), event.getAddedContact());
-       }
-
        /**
         * Event observer for newly added users by administrator
         * <p>
         * @param event Event being fired
         */
        public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
-               // event should not be null
+               // Event and contained entity instance should not be null
                if (null == event) {
                        // Throw NPE
                        throw new NullPointerException("event is null"); //NOI18N
@@ -307,7 +241,7 @@ public class FinancialsContactWebRequestBean extends BaseFinancialsController im
         * @param event Event being fired
         */
        public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent event) {
-               // event should not be null
+               // Event and contained entity instance should not be null
                if (null == event) {
                        // Throw NPE
                        throw new NullPointerException("event is null"); //NOI18N
@@ -325,73 +259,17 @@ public class FinancialsContactWebRequestBean extends BaseFinancialsController im
                        throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N
                }
 
-               // Remove contact from list available contacts list
-               this.selectableContactsCache.remove(event.getLinkedUser().getUserContact().getContactId());
-
                // Clear all data
                this.clear();
        }
 
-       /**
-        * Event observer for updated contact data by administrators
-        * <p>
-        * @param event Updated contact data event
-        */
-       public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
-               // event should not be null
-               if (null == event) {
-                       // Throw NPE
-                       throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getUpdatedContact() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.updatedContact is null"); //NOI18N
-               } else if (event.getUpdatedContact().getContactId() == null) {
-                       // userId is null
-                       throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
-               } else if (event.getUpdatedContact().getContactId() < 1) {
-                       // Not avalid id
-                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
-               }
-
-               // Add contact instance only once
-               this.uniqueAddContact(event.getUpdatedContact());
-
-               // Add email address to list
-               this.emailAddressCache.put(event.getUpdatedContact().getContactId(), event.getUpdatedContact().getContactEmailAddress());
-       }
-
-       /**
-        * Event observer when user confirmed account.
-        * <p>
-        * @param event Event being fired
-        */
-       public void afterUserConfirmedAccount (@Observes final ObservableUserConfirmedAccountEvent event) {
-               // event should not be null
-               if (null == event) {
-                       // Throw NPE
-                       throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getConfirmedUser() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.confirmedUser is null"); //NOI18N
-               } else if (event.getConfirmedUser().getUserId() == null) {
-                       // userId is null
-                       throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
-               } else if (event.getConfirmedUser().getUserId() < 1) {
-                       // Not avalid id
-                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
-               }
-
-               // Add contact instance only once
-               this.uniqueAddContact(event.getConfirmedUser().getUserContact());
-       }
-
        /**
         * Event observer for logged-in user
         * <p>
         * @param event Event instance
         */
        public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
-               // event should not be null
+               // Event and contained entity instance should not be null
                if (null == event) {
                        // Throw NPE
                        throw new NullPointerException("event is null"); //NOI18N
@@ -407,66 +285,27 @@ public class FinancialsContactWebRequestBean extends BaseFinancialsController im
                }
 
                // Copy all data to this bean
-               this.copyContact(event.getLoggedInUser().getUserContact());
+               this.copyFromContact(event.getLoggedInUser().getUserContact());
        }
 
        /**
-        * Event observer for new user registrations
+        * Observes events being fired before an updated of personal data done by a
+        * user has started.
         * <p>
-        * @param event User registration event
+        * @param event Event being observed
         */
-       public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
-               // event should not be null
+       public void beforeUserUpdatedPersonalDataEvent (@Observes final ObservablePreUserPersonalDataUpdatedEvent event) {
+               // Is the instance valid?
                if (null == event) {
                        // Throw NPE
                        throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getRegisteredUser() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.registeredUser is null"); //NOI18N
-               } else if (event.getRegisteredUser().getUserId() == null) {
-                       // userId is null
-                       throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
-               } else if (event.getRegisteredUser().getUserId() < 1) {
-                       // Not avalid id
-                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
-               }
-
-               // Get user instance
-               final Contact registeredContact = event.getRegisteredUser().getUserContact();
-
-               // Copy all data from registered->user
-               this.copyContact(registeredContact);
-
-               // Add contact instance only once
-               this.uniqueAddContact(registeredContact);
-
-               // Add user name and email address
-               this.addUserNameEmailAddress(registeredContact);
-
-               // Clear all data
-               this.clear();
-       }
-
-       @Override
-       @SuppressWarnings ("ReturnOfCollectionOrArrayField")
-       public List<Contact> allContacts () {
-               // Init list
-               final List<Contact> list = new LinkedList<>();
-
-               // Get iterator
-               final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactsCache.iterator();
-
-               // Loop over all
-               while (iterator.hasNext()) {
-                       // Get next entry
-                       final Cache.Entry<Long, Contact> next = iterator.next();
-
-                       // Add value to list
-                       list.add(next.getValue());
+               } else if (event.getUpdatedUser() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("event.updatedUser is null"); //NOI18N
                }
 
-               // Return it
-               return list;
+               // Set all
+               this.copyToContact(event.getUpdatedUser().getUserContact());
        }
 
        @Override
@@ -481,87 +320,20 @@ public class FinancialsContactWebRequestBean extends BaseFinancialsController im
                // Is all required data set?
                if (!this.isRequiredPersonalDataSet()) {
                        // No, then abort here
-                       throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
+                       throw new FacesException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
                }
 
                // Required personal data must be set
                assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
 
-               // Generate phone number
-               DialableLandLineNumber phone = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
-               DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
-               DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
-
                // Create new contact
-               Contact contact = new UserContact(this.getPersonalTitle(), this.getFirstName(), this.getFamilyName());
-               contact.setContactStreet(this.getStreet());
-               contact.setContactHouseNumber(this.getHouseNumber());
-               contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
-               contact.setContactZipCode(this.getZipCode());
-               contact.setContactCity(this.getCity());
-               contact.setContactCountry(this.getCountry());
-               contact.setContactEmailAddress(this.getEmailAddress());
-               contact.setContactBirthday(this.getBirthday());
-               contact.setContactComment(this.getComment());
-
-               // Don't set null or wrong references
-               if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
-                       // Now the number must be given
-                       if (phone.getPhoneAreaCode() == null) {
-                               // Is null
-                               throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
-                       } else if (phone.getPhoneAreaCode() < 1) {
-                               // Abort here
-                               throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
-                       } else if (phone.getPhoneNumber() == null) {
-                               // Is null
-                               throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
-                       } else if (phone.getPhoneNumber() < 1) {
-                               // Abort here
-                               throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
-                       }
-
-                       // Set phone number
-                       contact.setContactLandLineNumber(phone);
-               }
+               final Contact contact = new UserContact(
+                                         this.getPersonalTitle(),
+                                         this.getFirstName(),
+                                         this.getFamilyName()
+                         );
 
-               // Don't set null or wrong references
-               if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
-                       // Now the number must be given
-                       if (fax.getPhoneAreaCode() == null) {
-                               // Is null
-                               throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
-                       } else if (fax.getPhoneAreaCode() < 1) {
-                               // Abort here
-                               throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
-                       } else if (fax.getPhoneNumber() == null) {
-                               // Is null
-                               throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
-                       } else if (fax.getPhoneNumber() < 1) {
-                               // Abort here
-                               throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
-                       }
-
-                       // Set fax number
-                       contact.setContactFaxNumber(fax);
-               }
-
-               // Is the provider set?
-               if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
-                       // Is the number set?
-                       if (mobile.getPhoneNumber() == null) {
-                               // Is null
-                               throw new NullPointerException("mobile.phoneNumber is null"); //NOI18N
-                       } else if (mobile.getPhoneNumber() < 1) {
-                               // Abort here
-                               throw new IllegalArgumentException("mobile.phoneNumber is zero or below."); //NOI18N
-                       }
-
-                       // Set mobile number
-                       contact.setContactMobileNumber(mobile);
-               }
-
-               // Return it
+               // Return instance
                return contact;
        }
 
@@ -573,15 +345,15 @@ public class FinancialsContactWebRequestBean extends BaseFinancialsController im
                        throw new IllegalStateException("User is not logged-in"); //NOI18N
                } else if (!this.isRequiredChangePersonalDataSet()) {
                        // Not all required fields are set
-                       throw new FaceletException("Not all required fields are set."); //NOI18N
+                       throw new FacesException("Not all required fields are set."); //NOI18N
                } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
                        // Password not matching
-                       this.showFacesMessage("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
+                       this.showFacesMessage("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()), FacesMessage.SEVERITY_ERROR); //NOI18N
                        return ""; //NOI18N
                }
 
                // Get contact instance
-               Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
+               final Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
 
                // It should be there, so run some tests on it
                assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
@@ -600,16 +372,27 @@ public class FinancialsContactWebRequestBean extends BaseFinancialsController im
                contact.setContactCountry(this.getCountry());
 
                // Update contact's mobile number
-               this.isMobileUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
+               final boolean isMobileUnlinked = Contacts.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
 
                // Update contact's land-line number
-               this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
+               final boolean isLandLineUnlinked = Contacts.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
 
                // Update contact's fax number
-               this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
+               final boolean isFaxUnlinked = Contacts.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
 
-               // Send it to the EJB
-               this.contactBean.updateContactData(contact, this.isMobileUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
+               // Init updated contact instance
+               final Contact updatedContact;
+
+               try {
+                       // Send it to the EJB
+                       updatedContact = this.contactBean.updateContactData(contact, isMobileUnlinked, isLandLineUnlinked, isFaxUnlinked);
+               } catch (final ContactNotFoundException ex) {
+                       // Throw as cause
+                       throw new FacesException(ex);
+               }
+
+               // Fire event
+               this.contactUpdatedEvent.fire(new UpdatedContactEvent(updatedContact));
 
                // All fine
                return "contact_data_saved"; //NOI18N
@@ -689,17 +472,6 @@ public class FinancialsContactWebRequestBean extends BaseFinancialsController im
                this.comment = comment;
        }
 
-       @Override
-       public String getControllerType () {
-               return "general"; //NOI18N
-       }
-
-       @Override
-       @Deprecated
-       public void setControllerType (final String controllerType) {
-               throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
-       }
-
        /**
         * Getter for country instance
         * <p>
@@ -1021,59 +793,6 @@ public class FinancialsContactWebRequestBean extends BaseFinancialsController im
                this.zipCode = zipCode;
        }
 
-       /**
-        * Post-construction method
-        */
-       @PostConstruct
-       public void init () {
-               // Is cache there?
-               if (!this.contactsCache.iterator().hasNext()) {
-                       // Get whole list
-                       final List<Contact> contacts = this.contactBean.allContacts();
-
-                       // Add all
-                       for (final Contact contact : contacts) {
-                               // Add it to cache
-                               this.contactsCache.put(contact.getContactId(), contact);
-                               this.emailAddressCache.put(contact.getContactId(), contact.getContactEmailAddress());
-                       }
-               } else if (this.selectableContactsCache.iterator().hasNext()) {
-                       // Has already entries, avoid executing below code
-                       return;
-               }
-
-               // Get all users
-               final List<User> allUsers = this.userController.allUsers();
-
-               // Get iterator from contacts cache
-               final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactsCache.iterator();
-
-               // Loop through all contacts
-               while (iterator.hasNext()) {
-                       // Get next element
-                       final Cache.Entry<Long, Contact> next = iterator.next();
-
-                       // Default is not found
-                       boolean isFound = false;
-
-                       // User list is not empty, check each entry, if contact is found
-                       for (final User user : allUsers) {
-                               // Is the contact the same?
-                               if (Objects.equals(user.getUserContact(), next.getValue())) {
-                                       // Found one
-                                       isFound = true;
-                                       break;
-                               }
-                       }
-
-                       // Is contact not found?
-                       if (!isFound) {
-                               // Add it as selectable
-                               this.selectableContactsCache.put(next.getKey(), next.getValue());
-                       }
-               }
-       }
-
        @Override
        public boolean isEmailAddressRegistered (final Contact contact) {
                // Cherck parameter
@@ -1088,8 +807,28 @@ public class FinancialsContactWebRequestBean extends BaseFinancialsController im
                        throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
                }
 
+               // Default is not registered
+               boolean isRegistered = false;
+
                // Determine it
-               return ((this.emailAddressCache instanceof List) && (this.emailAddressCache.containsKey(contact.getContactId())));
+               for (final Contact currentContact : this.contactListController.getAllContacts()) {
+                       // Is same contact found?
+                       if (currentContact.getContactEmailAddress().equals(contact.getContactEmailAddress())) {
+                               // Found same email address
+                               isRegistered = true;
+
+                               // Skipp further iterations
+                               break;
+                       }
+               }
+
+               // Return status
+               return isRegistered;
+       }
+
+       @Override
+       public boolean isEmailAddressRegistered (final String emailAddress) {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
 
        @Override
@@ -1121,66 +860,6 @@ public class FinancialsContactWebRequestBean extends BaseFinancialsController im
                return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
        }
 
-       /**
-        * Returns a list of all selectable contacts for user creation. Contacts
-        * from already existing users are excluded in this list.
-        * <p>
-        * @return A list of all selectable contacts
-        */
-       public List<Contact> selectableContacts () {
-               // Init list
-               final List<Contact> selectableContacts = new LinkedList<>();
-
-               // Get iterator from cache
-               final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactsCache.iterator();
-
-               // Loop through all contacts
-               while (iterator.hasNext()) {
-                       // Get next element
-                       final Cache.Entry<Long, Contact> next = iterator.next();
-
-                       // Add entry's value to list
-                       selectableContacts.add(next.getValue());
-               }
-
-               // Return list
-               return selectableContacts;
-       }
-
-       @Override
-       public void updateContactDataFromController (final Contact contact) {
-               // Is the instance valid?
-               if (null == contact) {
-                       // Throw NPE
-                       throw new NullPointerException("contact is null"); //NOI18N
-               } else if (contact.getContactId() == null) {
-                       // Throw NPE
-                       throw new NullPointerException("contact.contactId is null"); //NOI18N
-               } else if (contact.getContactId() < 1) {
-                       // Not valid id number
-                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
-               }
-
-               // Set all
-               this.copyContact(contact);
-       }
-
-       /**
-        * Adds email address to bean's internal list.
-        * <p>
-        * @param contact Contact instance
-        */
-       private void addUserNameEmailAddress (final Contact contact) {
-               // Make sure the entry is not added yet
-               if (this.emailAddressCache.containsKey(contact.getContactId())) {
-                       // Already added
-                       throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
-               }
-
-               // Add email addres
-               this.emailAddressCache.put(contact.getContactId(), contact.getContactEmailAddress());
-       }
-
        /**
         * Clears this bean
         */
@@ -1215,23 +894,11 @@ public class FinancialsContactWebRequestBean extends BaseFinancialsController im
        }
 
        /**
-        * Copies given contact into the controller
+        * Copies given contact data into the controller
         * <p>
         * @param contact Contact instance
         */
-       private void copyContact (final Contact contact) {
-               // Is the instance valid?
-               if (null == contact) {
-                       // Throw NPE
-                       throw new NullPointerException("contact is null"); //NOI18N
-               } else if (contact.getContactId() == null) {
-                       // Throw NPE
-                       throw new NullPointerException("contact.contactId is null"); //NOI18N
-               } else if (contact.getContactId() < 1) {
-                       // Not valid id number
-                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
-               }
-
+       private void copyFromContact (final Contact contact) {
                // Copy all fields:
                // - base data
                this.setPersonalTitle(contact.getContactPersonalTitle());
@@ -1249,94 +916,112 @@ public class FinancialsContactWebRequestBean extends BaseFinancialsController im
                this.setComment(contact.getContactComment());
 
                // Get mobile, phone and fax instance
-               DialableMobileNumber mobile = contact.getContactMobileNumber();
-               DialableFaxNumber fax = contact.getContactFaxNumber();
-               DialableLandLineNumber phone = contact.getContactLandLineNumber();
-
-               // - contact data
-               if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
-                       this.setLandLineCountry(phone.getPhoneCountry());
-                       this.setLandLineAreaCode(phone.getPhoneAreaCode());
-                       this.setLandLineNumber(phone.getPhoneNumber());
-               }
-
-               if ((mobile instanceof DialableMobileNumber) && (mobile.getMobileProvider() instanceof MobileProvider)) {
-                       this.setMobileProvider(mobile.getMobileProvider());
-                       this.setMobileNumber(mobile.getPhoneNumber());
-               }
+               final DialableFaxNumber fax = contact.getContactFaxNumber();
+               final DialableLandLineNumber landLine = contact.getContactLandLineNumber();
+               final DialableMobileNumber mobile = contact.getContactMobileNumber();
 
+               // Is a fax number set?
                if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
+                       // Copy elements
                        this.setFaxCountry(fax.getPhoneCountry());
                        this.setFaxAreaCode(fax.getPhoneAreaCode());
                        this.setFaxNumber(fax.getPhoneNumber());
                }
-       }
 
-       /**
-        * Removes given contact from all lists
-        * <p>
-        * @param contact Contact instance to remove
-        */
-       private void removeContact (final Contact contact) {
-               // Is the instance valid?
-               if (null == contact) {
-                       // Throw NPE
-                       throw new NullPointerException("contact is null"); //NOI18N
-               } else if (contact.getContactId() == null) {
-                       // Throw NPE
-                       throw new NullPointerException("contact.contactId is null"); //NOI18N
-               } else if (contact.getContactId() < 1) {
-                       // Not valid id number
-                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
+               // Is a land-line number set?
+               if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneAreaCode() > 0)) {
+                       // Copy elements
+                       this.setLandLineCountry(landLine.getPhoneCountry());
+                       this.setLandLineAreaCode(landLine.getPhoneAreaCode());
+                       this.setLandLineNumber(landLine.getPhoneNumber());
                }
 
-               // Remove from general list
-               if (!this.contactsCache.remove(contact.getContactId())) {
-                       // Did not remove contact
-                       throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
+               // Is a mobile number set?
+               if ((mobile instanceof DialableMobileNumber) && (mobile.getMobileProvider() instanceof MobileProvider)) {
+                       // Copy elements
+                       this.setMobileProvider(mobile.getMobileProvider());
+                       this.setMobileNumber(mobile.getMobileNumber());
                }
-
-               // Remove from other lists
-               this.emailAddressCache.remove(contact.getContactId());
        }
 
        /**
-        * Adds unique instance to contact list. First any existing instance is
-        * being removed, then the new instance is added.
+        * Copies all fields from this backing bean into given instance.
         * <p>
-        * @param contact Contact instance to add uniquely
+        * @param contact An instance of a Contact class
         */
-       private void uniqueAddContact (final Contact contact) {
-               // Is the instance valid?
-               if (null == contact) {
-                       // Throw NPE
-                       throw new NullPointerException("contact is null"); //NOI18N
-               } else if (contact.getContactId() == null) {
-                       // Throw NPE
-                       throw new NullPointerException("contact.contactId is null"); //NOI18N
-               } else if (contact.getContactId() < 1) {
-                       // Not valid id number
-                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
-               }
+       private void copyToContact (final Contact contact) {
+               // Set other elements
+               contact.setContactStreet(this.getStreet());
+               contact.setContactHouseNumber(this.getHouseNumber());
+               contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
+               contact.setContactZipCode(this.getZipCode());
+               contact.setContactCity(this.getCity());
+               contact.setContactCountry(this.getCountry());
+               contact.setContactEmailAddress(this.getEmailAddress());
+               contact.setContactBirthday(this.getBirthday());
+               contact.setContactComment(this.getComment());
 
-               // Get iterator from list
-               final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactsCache.iterator();
+               // Generate phone number
+               final DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
+               final DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
+               final DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
+
+               // Don't set null or wrong references
+               if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
+                       // Now the number must be given
+                       if (landLine.getPhoneAreaCode() == null) {
+                               // Is null
+                               throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
+                       } else if (landLine.getPhoneAreaCode() < 1) {
+                               // Abort here
+                               throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
+                       } else if (landLine.getPhoneNumber() == null) {
+                               // Is null
+                               throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
+                       } else if (landLine.getPhoneNumber() < 1) {
+                               // Abort here
+                               throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
+                       }
 
-               // "Walk" through all entries
-               while (iterator.hasNext()) {
-                       // Get next element
-                       final Cache.Entry<Long, Contact> next = iterator.next();
+                       // Set phone number
+                       contact.setContactLandLineNumber(landLine);
+               }
 
-                       // Is id number the same?
-                       if (Objects.equals(contact.getContactId(), next.getKey())) {
-                               // Found entry, so remove it and abort
-                               this.removeContact(next.getValue());
-                               break;
+               // Don't set null or wrong references
+               if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
+                       // Now the number must be given
+                       if (fax.getPhoneAreaCode() == null) {
+                               // Is null
+                               throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
+                       } else if (fax.getPhoneAreaCode() < 1) {
+                               // Abort here
+                               throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
+                       } else if (fax.getPhoneNumber() == null) {
+                               // Is null
+                               throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
+                       } else if (fax.getPhoneNumber() < 1) {
+                               // Abort here
+                               throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
                        }
+
+                       // Set fax number
+                       contact.setContactFaxNumber(fax);
                }
 
-               // Add contact to list
-               this.contactsCache.put(contact.getContactId(), contact);
+               // Is the provider set?
+               if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
+                       // Is the number set?
+                       if (mobile.getMobileNumber() == null) {
+                               // Is null
+                               throw new NullPointerException("mobile.phoneNumber is null"); //NOI18N
+                       } else if (mobile.getMobileNumber() < 1) {
+                               // Abort here
+                               throw new IllegalArgumentException("mobile.phoneNumber is zero or below."); //NOI18N
+                       }
+
+                       // Set mobile number
+                       contact.setContactMobileNumber(mobile);
+               }
        }
 
 }