From 8e0df0cf281bf63f6683aea90c28427ef04d5af5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 2 Sep 2017 21:52:41 +0200 Subject: [PATCH] Please rename/cherry-pick: - having to much session-scoped beans was a bad design idea anyway - on each new session, "tons" of EJB (JNDI lookup + business method invocation) will occur which will overrun the EJB container soon or later - also having JNDI lookup in PostConstruct-annotated methods was bad, too because it "confuses" the web container - while it is building proxy objects arround every managed class (like also now converters, JSF 2.3.x only) especially backing beans, there should be no JNDI lookup hapening - but initializing some lists for performance reasons is the right thing to do - maybe later some other annotation will be used instead, but for now it is fine - so let's make this painless and rename all session-scoped backing beans and re-annotate them with RequestScoped for now as this is also reduces memory foot-print MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- ...ddressbookBusinessDataWebRequestBean.java} | 81 +++++++--- ...bookBusinessDataWebRequestController.java} | 2 +- ...ressbookCompanyEmployeeWebRequestBean.java | 53 ++++-- ...kCompanyEmployeeWebRequestController.java} | 2 +- ...AddressbookAdminContactWebRequestBean.java | 2 +- ... => AddressbookContactWebRequestBean.java} | 94 +++++++---- ...dressbookContactWebRequestController.java} | 2 +- ...ddressbookContactPhoneWebRequestBean.java} | 12 +- ...bookContactPhoneWebRequestController.java} | 2 +- ...AddressbookAdminCountryWebRequestBean.java | 8 +- ... => AddressbookCountryWebRequestBean.java} | 54 +++++-- ...dressbookCountryWebRequestController.java} | 2 +- .../AddressbookWebRequestHelperBean.java | 4 +- ...dressbookMobileProviderWebRequestBean.java | 50 +++++- .../AddressbookAdminPhoneWebRequestBean.java | 2 +- ...va => AddressbookPhoneWebRequestBean.java} | 125 ++++++++++++-- ...AddressbookPhoneWebRequestController.java} | 2 +- .../AddressbookUserProfileWebRequestBean.java | 12 +- .../AddressbookAdminUserWebRequestBean.java | 15 +- ...ava => AddressbookUserWebRequestBean.java} | 152 +++++++----------- ... AddressbookUserWebRequestController.java} | 17 +- ...ddressbookUserActivityWebRequestBean.java} | 35 ++-- ...bookUserActivityWebRequestController.java} | 2 +- ...essbookConfirmationLinkWebRequestBean.java | 7 +- ...AddressbookEmailChangeWebRequestBean.java} | 37 +++-- ...sbookEmailChangeWebRequestController.java} | 2 +- .../AddressbookUserLoginWebSessionBean.java | 4 +- ...ddressbookUserRegisterWebRequestBean.java} | 20 +-- ...bookUserRegisterWebRequestController.java} | 2 +- ... AddressbookResendLinkWebRequestBean.java} | 12 +- ...ssbookResendLinkWebRequestController.java} | 2 +- .../AddressbookBusinessContactConverter.java | 2 +- .../AddressbookCompanyEmployeeConverter.java | 2 +- ...dressbookCompanyHeadquartersConverter.java | 2 +- .../contact/AddressbookContactConverter.java | 2 +- .../country/AddressbookCountryConverter.java | 2 +- .../fax/AddressbookFaxNumberConverter.java | 2 +- .../AddressbookLandLineNumberConverter.java | 2 +- .../AddressbookMobileNumberConverter.java | 2 +- .../AddressbookMobileProviderConverter.java | 2 +- .../user/AddressbookUserConverter.java | 2 +- .../AddressbookCompanyNameValidator.java | 2 +- .../AddressbookEmailAddressValidator.java | 2 +- .../user/AddressbookUserIdValidator.java | 2 +- web/guest/user/user_list.xhtml | 34 ++-- 45 files changed, 549 insertions(+), 327 deletions(-) rename src/java/org/mxchange/addressbook/beans/business/basicdata/{AddressbookBusinessDataWebSessionBean.java => AddressbookBusinessDataWebRequestBean.java} (79%) rename src/java/org/mxchange/addressbook/beans/business/basicdata/{AddressbookBusinessDataWebSessionController.java => AddressbookBusinessDataWebRequestController.java} (93%) rename src/java/org/mxchange/addressbook/beans/business/employee/{AddressbookCompanyEmployeeWebSessionController.java => AddressbookCompanyEmployeeWebRequestController.java} (93%) rename src/java/org/mxchange/addressbook/beans/contact/{AddressbookContactWebSessionBean.java => AddressbookContactWebRequestBean.java} (93%) rename src/java/org/mxchange/addressbook/beans/contact/{AddressbookContactWebSessionController.java => AddressbookContactWebRequestController.java} (97%) rename src/java/org/mxchange/addressbook/beans/contact/phone/{AddressbookContactPhoneWebSessionBean.java => AddressbookContactPhoneWebRequestBean.java} (97%) rename src/java/org/mxchange/addressbook/beans/contact/phone/{AddressbookContactPhoneWebSessionController.java => AddressbookContactPhoneWebRequestController.java} (93%) rename src/java/org/mxchange/addressbook/beans/country/{AddressbookCountryWebApplicationBean.java => AddressbookCountryWebRequestBean.java} (68%) rename src/java/org/mxchange/addressbook/beans/country/{AddressbookCountryWebApplicationController.java => AddressbookCountryWebRequestController.java} (92%) rename src/java/org/mxchange/addressbook/beans/phone/{AddressbookPhoneWebApplicationBean.java => AddressbookPhoneWebRequestBean.java} (88%) rename src/java/org/mxchange/addressbook/beans/phone/{AddressbookPhoneWebApplicationController.java => AddressbookPhoneWebRequestController.java} (96%) rename src/java/org/mxchange/addressbook/beans/user/{AddressbookUserWebSessionBean.java => AddressbookUserWebRequestBean.java} (91%) rename src/java/org/mxchange/addressbook/beans/user/{AddressbookUserWebSessionController.java => AddressbookUserWebRequestController.java} (91%) rename src/java/org/mxchange/addressbook/beans/user/activity/{AddressbookUserActivityWebApplicationBean.java => AddressbookUserActivityWebRequestBean.java} (95%) rename src/java/org/mxchange/addressbook/beans/user/activity/{AddressbookUserActivityWebApplicationController.java => AddressbookUserActivityWebRequestController.java} (91%) rename src/java/org/mxchange/addressbook/beans/user/email_address/{AddressbookEmailChangeWebSessionBean.java => AddressbookEmailChangeWebRequestBean.java} (90%) rename src/java/org/mxchange/addressbook/beans/user/email_address/{AddressbookEmailChangeWebSessionController.java => AddressbookEmailChangeWebRequestController.java} (94%) rename src/java/org/mxchange/addressbook/beans/user/register/{AddressbookUserRegisterWebSessionBean.java => AddressbookUserRegisterWebRequestBean.java} (95%) rename src/java/org/mxchange/addressbook/beans/user/register/{AddressbookUserRegisterWebSessionController.java => AddressbookUserRegisterWebRequestController.java} (93%) rename src/java/org/mxchange/addressbook/beans/user/resendlink/{AddressbookResendLinkWebSessionBean.java => AddressbookResendLinkWebRequestBean.java} (94%) rename src/java/org/mxchange/addressbook/beans/user/resendlink/{AddressbookResendLinkWebSessionController.java => AddressbookResendLinkWebRequestController.java} (93%) diff --git a/src/java/org/mxchange/addressbook/beans/business/basicdata/AddressbookBusinessDataWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/business/basicdata/AddressbookBusinessDataWebRequestBean.java similarity index 79% rename from src/java/org/mxchange/addressbook/beans/business/basicdata/AddressbookBusinessDataWebSessionBean.java rename to src/java/org/mxchange/addressbook/beans/business/basicdata/AddressbookBusinessDataWebRequestBean.java index 4be303ac..47c6a218 100644 --- a/src/java/org/mxchange/addressbook/beans/business/basicdata/AddressbookBusinessDataWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/business/basicdata/AddressbookBusinessDataWebRequestBean.java @@ -17,11 +17,12 @@ package org.mxchange.addressbook.beans.business.basicdata; import java.text.MessageFormat; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import javax.annotation.PostConstruct; import javax.ejb.EJB; -import javax.enterprise.context.SessionScoped; +import javax.enterprise.context.RequestScoped; import javax.enterprise.event.Observes; import javax.inject.Inject; import javax.inject.Named; @@ -39,8 +40,8 @@ import org.mxchange.jcountry.model.data.Country; * @author Roland Häder */ @Named ("companyDataController") -@SessionScoped -public class AddressbookBusinessDataWebSessionBean extends BaseAddressbookController implements AddressbookBusinessDataWebSessionController { +@RequestScoped +public class AddressbookBusinessDataWebRequestBean extends BaseAddressbookController implements AddressbookBusinessDataWebRequestController { /** * Serial number @@ -56,7 +57,9 @@ public class AddressbookBusinessDataWebSessionBean extends BaseAddressbookContro /** * A list of all registered companies (globally) */ - private final List businessContacts; + @Inject + @Cached (cacheName = "basicDataCache") + private transient Cache basicDataCache; /** * EJB for general basic business data purposes @@ -75,7 +78,7 @@ public class AddressbookBusinessDataWebSessionBean extends BaseAddressbookContro private String companyEmailAddress; /** - * Company name + * Company cacheName */ private String companyName; @@ -118,12 +121,9 @@ public class AddressbookBusinessDataWebSessionBean extends BaseAddressbookContro /** * Constructor */ - public AddressbookBusinessDataWebSessionBean () { + public AddressbookBusinessDataWebRequestBean () { // Call super constructor super(); - - // Init list - this.businessContacts = new LinkedList<>(); } /** @@ -142,10 +142,10 @@ public class AddressbookBusinessDataWebSessionBean extends BaseAddressbookContro throw new NullPointerException("event.basicData is null"); } else if (event.getBasicData().getBasicDataId() == null) { // Throw NPE again - throw new NullPointerException("event.basicData.basicDataId is null"); + throw new NullPointerException("event.basicData.companyDataId is null"); } else if (event.getBasicData().getBasicDataId() < 1) { // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("event.basicData.basicDataId={0} is invalid", event.getBasicData().getBasicDataId())); + throw new IllegalArgumentException(MessageFormat.format("event.basicData.companyDataId={0} is invalid", event.getBasicData().getBasicDataId())); } else if (event.getBasicData().getCompanyName() == null) { // Throw NPE again throw new NullPointerException("event.basicData.companyName is null"); @@ -155,7 +155,7 @@ public class AddressbookBusinessDataWebSessionBean extends BaseAddressbookContro } // Add it to list - this.businessContacts.add(event.getBasicData()); + this.basicDataCache.put(event.getBasicData().getBasicDataId(), event.getBasicData()); } /** @@ -165,8 +165,23 @@ public class AddressbookBusinessDataWebSessionBean extends BaseAddressbookContro */ @SuppressWarnings ("ReturnOfCollectionOrArrayField") public List allCompanyBasicData () { + // Init list + List list = new LinkedList<>(); + + // Get iterator + Iterator> iterator = this.basicDataCache.iterator(); + + // Loop over all + while (iterator.hasNext()) { + // Get next entry + final Cache.Entry next = iterator.next(); + + // Add value to list + list.add(next.getValue()); + } + // Return it - return this.businessContacts; + return list; } /** @@ -206,18 +221,18 @@ public class AddressbookBusinessDataWebSessionBean extends BaseAddressbookContro } /** - * Getter for company name + * Getter for company cacheName *

- * @return Company name + * @return Company cacheName */ public String getCompanyName () { return this.companyName; } /** - * Setter for company name + * Setter for company cacheName *

- * @param companyName Company name + * @param companyName Company cacheName */ public void setCompanyName (final String companyName) { this.companyName = companyName; @@ -336,8 +351,36 @@ public class AddressbookBusinessDataWebSessionBean extends BaseAddressbookContro */ @PostConstruct public void initializeList () { - // Init user's contact list - this.businessContacts.addAll(this.adminBusinessDataBean.allCompanyBasicData()); + // Is cache there? + if (!this.basicDataCache.iterator().hasNext()) { + // Get whole list + List list = this.businessDataBean.allCompanyBasicData(); + + // Add all + for (final Iterator iterator = list.iterator(); iterator.hasNext();) { + // Get next element + final BusinessBasicData next = iterator.next(); + + // Add it to cache + this.basicDataCache.put(next.getBasicDataId(), next); + } + } + } + + /** + * Clears this bean + */ + private void clear () { + // Clear all data: + this.setCompanyComments(null); + this.setCompanyEmailAddress(null); + this.setCompanyName(null); + this.setFaxAreaCode(null); + this.setFaxCountry(null); + this.setFaxNumber(null); + this.setLandLineAreaCode(null); + this.setLandLineCountry(null); + this.setLandLineNumber(null); } } diff --git a/src/java/org/mxchange/addressbook/beans/business/basicdata/AddressbookBusinessDataWebSessionController.java b/src/java/org/mxchange/addressbook/beans/business/basicdata/AddressbookBusinessDataWebRequestController.java similarity index 93% rename from src/java/org/mxchange/addressbook/beans/business/basicdata/AddressbookBusinessDataWebSessionController.java rename to src/java/org/mxchange/addressbook/beans/business/basicdata/AddressbookBusinessDataWebRequestController.java index ca46bea6..44dd6a82 100644 --- a/src/java/org/mxchange/addressbook/beans/business/basicdata/AddressbookBusinessDataWebSessionController.java +++ b/src/java/org/mxchange/addressbook/beans/business/basicdata/AddressbookBusinessDataWebRequestController.java @@ -23,6 +23,6 @@ import java.io.Serializable; *

* @author Roland Häder */ -public interface AddressbookBusinessDataWebSessionController extends Serializable { +public interface AddressbookBusinessDataWebRequestController extends Serializable { } diff --git a/src/java/org/mxchange/addressbook/beans/business/employee/AddressbookCompanyEmployeeWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/business/employee/AddressbookCompanyEmployeeWebRequestBean.java index af67cbf0..c33698d2 100644 --- a/src/java/org/mxchange/addressbook/beans/business/employee/AddressbookCompanyEmployeeWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/business/employee/AddressbookCompanyEmployeeWebRequestBean.java @@ -16,15 +16,18 @@ */ package org.mxchange.addressbook.beans.business.employee; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import javax.annotation.PostConstruct; +import javax.cache.Cache; import javax.ejb.EJB; -import javax.enterprise.context.SessionScoped; +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; import javax.inject.Named; -import org.mxchange.addressbook.beans.BaseAddressbookController; import org.mxchange.jcontactsbusiness.model.employee.CompanyEmployeeSessionBeanRemote; import org.mxchange.jcontactsbusiness.model.employee.Employee; +import org.mxchange.addressbook.beans.BaseAddressbookController; /** * A request-scoped bean for general purposes for company employees. @@ -32,8 +35,8 @@ import org.mxchange.jcontactsbusiness.model.employee.Employee; * @author Roland Häder */ @Named ("companyEmployeeController") -@SessionScoped -public class AddressbookCompanyEmployeeWebRequestBean extends BaseAddressbookController implements AddressbookCompanyEmployeeWebSessionController { +@RequestScoped +public class AddressbookCompanyEmployeeWebRequestBean extends BaseAddressbookController implements AddressbookCompanyEmployeeWebRequestController { /** * Serial number @@ -49,7 +52,9 @@ public class AddressbookCompanyEmployeeWebRequestBean extends BaseAddressbookCon /** * List of all company employees */ - private final List companyEmployees; + @Inject + @Cached(cacheName = "companyEmployeeCache") + private transient Cache companyEmployeeCache; /** * Default constructor @@ -57,9 +62,6 @@ public class AddressbookCompanyEmployeeWebRequestBean extends BaseAddressbookCon public AddressbookCompanyEmployeeWebRequestBean () { // Call super constructor super(); - - // Init list instance - this.companyEmployees = new LinkedList<>(); } /** @@ -69,7 +71,23 @@ public class AddressbookCompanyEmployeeWebRequestBean extends BaseAddressbookCon */ @SuppressWarnings ("ReturnOfCollectionOrArrayField") public List allCompanyEmployees () { - return this.companyEmployees; + // Init list + List list = new LinkedList<>(); + + // Get iterator + Iterator> iterator = this.companyEmployeeCache.iterator(); + + // Loop over all + while (iterator.hasNext()) { + // Get next entry + final Cache.Entry next = iterator.next(); + + // Add value to list + list.add(next.getValue()); + } + + // Return it + return list; } /** @@ -77,11 +95,20 @@ public class AddressbookCompanyEmployeeWebRequestBean extends BaseAddressbookCon */ @PostConstruct public void init () { - // Get all entries from remote bean - List employees = this.companyEmployeeBean.allCompanyEmployees(); + // Is cache there? + if (!this.companyEmployeeCache.iterator().hasNext()) { + // Get whole list + List list = this.companyEmployeeBean.allCompanyEmployees(); + + // Add all + for (final Iterator iterator = list.iterator(); iterator.hasNext();) { + // Get next element + final Employee next = iterator.next(); - // Copy it to main list - this.companyEmployees.addAll(employees); + // Add it to cache + this.companyEmployeeCache.put(next.getEmployeeId(), next); + } + } } } diff --git a/src/java/org/mxchange/addressbook/beans/business/employee/AddressbookCompanyEmployeeWebSessionController.java b/src/java/org/mxchange/addressbook/beans/business/employee/AddressbookCompanyEmployeeWebRequestController.java similarity index 93% rename from src/java/org/mxchange/addressbook/beans/business/employee/AddressbookCompanyEmployeeWebSessionController.java rename to src/java/org/mxchange/addressbook/beans/business/employee/AddressbookCompanyEmployeeWebRequestController.java index 25606668..9d7708fb 100644 --- a/src/java/org/mxchange/addressbook/beans/business/employee/AddressbookCompanyEmployeeWebSessionController.java +++ b/src/java/org/mxchange/addressbook/beans/business/employee/AddressbookCompanyEmployeeWebRequestController.java @@ -23,6 +23,6 @@ import java.io.Serializable; *

* @author Roland Häder */ -public interface AddressbookCompanyEmployeeWebSessionController extends Serializable { +public interface AddressbookCompanyEmployeeWebRequestController extends Serializable { } diff --git a/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java index 24b6c4ab..ebd57ab7 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java @@ -107,7 +107,7 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookContro * General contact controller */ @Inject - private AddressbookContactWebSessionController contactController; + private AddressbookContactWebRequestController contactController; /** * Country instance diff --git a/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebRequestBean.java similarity index 93% rename from src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java rename to src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebRequestBean.java index 234057b8..59598088 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebRequestBean.java @@ -25,13 +25,13 @@ import java.util.List; import java.util.Objects; import javax.annotation.PostConstruct; import javax.ejb.EJB; -import javax.enterprise.context.SessionScoped; +import javax.enterprise.context.RequestScoped; import javax.enterprise.event.Observes; import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; import javax.inject.Named; import org.mxchange.addressbook.beans.BaseAddressbookController; -import org.mxchange.addressbook.beans.user.AddressbookUserWebSessionController; +import org.mxchange.addressbook.beans.user.AddressbookUserWebRequestController; import org.mxchange.addressbook.beans.user.login.AddressbookUserLoginWebSessionController; import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent; import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent; @@ -62,8 +62,8 @@ import org.mxchange.juserlogincore.exceptions.UserPasswordMismatchException; * @author Roland Häder */ @Named ("contactController") -@SessionScoped -public class AddressbookContactWebSessionBean extends BaseAddressbookController implements AddressbookContactWebSessionController { +@RequestScoped +public class AddressbookContactWebRequestBean extends BaseAddressbookController implements AddressbookContactWebRequestController { /** * Serial number @@ -99,7 +99,9 @@ public class AddressbookContactWebSessionBean extends BaseAddressbookController /** * Contact list */ - private final List contactList; + @Inject + @Cached (cacheName = "contactsCache") + private transient Cache contactsCache; /** * Country instance @@ -114,7 +116,9 @@ public class AddressbookContactWebSessionBean extends BaseAddressbookController /** * Email address list */ - private final List emailAddressList; + @Inject + @Cached (cacheName = "emailAddressCache") + private transient Cache emailAddressCache; /** * Email address repeated @@ -215,7 +219,7 @@ public class AddressbookContactWebSessionBean extends BaseAddressbookController * Regular user controller */ @Inject - private AddressbookUserWebSessionController userController; + private AddressbookUserWebRequestController userController; /** * Login bean (controller) @@ -231,13 +235,9 @@ public class AddressbookContactWebSessionBean extends BaseAddressbookController /** * Default constructor */ - public AddressbookContactWebSessionBean () { + public AddressbookContactWebRequestBean () { // Call super constructor super(); - - // Init lists/maps - this.contactList = new LinkedList<>(); - this.emailAddressList = new LinkedList<>(); } /** @@ -354,7 +354,7 @@ public class AddressbookContactWebSessionBean extends BaseAddressbookController this.uniqueAddContact(event.getUpdatedContact()); // Add email address to list - this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress()); + this.emailAddressCache.put(event.getUpdatedContact().getContactId(), event.getUpdatedContact().getContactEmailAddress()); } /** @@ -447,8 +447,23 @@ public class AddressbookContactWebSessionBean extends BaseAddressbookController @Override @SuppressWarnings ("ReturnOfCollectionOrArrayField") public List allContacts () { - // Return un-modified list - return this.contactList; + // Init list + List list = new LinkedList<>(); + + // Get iterator + Iterator> iterator = this.contactsCache.iterator(); + + // Loop over all + while (iterator.hasNext()) { + // Get next entry + final Cache.Entry next = iterator.next(); + + // Add value to list + list.add(next.getValue()); + } + + // Return it + return list; } @Override @@ -1008,20 +1023,31 @@ public class AddressbookContactWebSessionBean extends BaseAddressbookController */ @PostConstruct public void init () { - // Get full email address list for reducing EJB calls - this.emailAddressList.addAll(this.contactBean.getEmailAddressList()); - // Get all contacts - List allContacts = this.contactBean.getAllContacts(); - - // Get full contact list - this.contactList.addAll(allContacts); + final List selectable = new LinkedList<>(); + + // Is cache there? + if (!this.contactsCache.iterator().hasNext()) { + // Get whole list + List list = this.contactBean.allContacts(); + + // Add all + for (final Iterator iterator = list.iterator(); iterator.hasNext();) { + // Get next element + final Contact next = iterator.next(); + + // Add it to cache + this.contactsCache.put(next.getContactId(), next); + this.emailAddressCache.put(next.getContactId(), next.getContactEmailAddress()); + selectable.add(next); + } + } // Get all users List allUsers = this.userController.allUsers(); // Get iterator - Iterator iterator = allContacts.iterator(); + Iterator iterator = selectable.iterator(); // Loop through it while (iterator.hasNext()) { @@ -1046,7 +1072,7 @@ public class AddressbookContactWebSessionBean extends BaseAddressbookController } // Set contact list - this.selectableContacts = allContacts; + this.selectableContacts = selectable; } @Override @@ -1064,7 +1090,7 @@ public class AddressbookContactWebSessionBean extends BaseAddressbookController } // Determine it - return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress()))); + return ((this.emailAddressCache instanceof List) && (this.emailAddressCache.containsKey(contact.getContactId()))); } @Override @@ -1131,13 +1157,13 @@ public class AddressbookContactWebSessionBean extends BaseAddressbookController */ private void addUserNameEmailAddress (final Contact contact) { // Make sure the entry is not added yet - if (this.emailAddressList.contains(contact.getContactEmailAddress())) { + 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.emailAddressList.add(contact.getContactEmailAddress()); + this.emailAddressCache.put(contact.getContactId(), contact.getContactEmailAddress()); } /** @@ -1250,13 +1276,13 @@ public class AddressbookContactWebSessionBean extends BaseAddressbookController } // Remove from general list - if (!this.contactList.remove(contact)) { + if (!this.contactsCache.remove(contact.getContactId())) { // Did not remove contact throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N } // Remove from other lists - this.emailAddressList.remove(contact.getContactEmailAddress()); + this.emailAddressCache.remove(contact.getContactId()); } /** @@ -1279,23 +1305,23 @@ public class AddressbookContactWebSessionBean extends BaseAddressbookController } // Get iterator from list - Iterator iterator = this.contactList.iterator(); + Iterator> iterator = this.contactsCache.iterator(); // "Walk" through all entries while (iterator.hasNext()) { // Get next element - Contact next = iterator.next(); + Cache.Entry next = iterator.next(); // Is id number the same? - if (Objects.equals(contact.getContactId(), next.getContactId())) { + if (Objects.equals(contact.getContactId(), next.getKey())) { // Found entry, so remove it and abort - this.removeContact(next); + this.removeContact(next.getValue()); break; } } // Add contact to list - this.contactList.add(contact); + this.contactsCache.put(contact.getContactId(), contact); } } diff --git a/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionController.java b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebRequestController.java similarity index 97% rename from src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionController.java rename to src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebRequestController.java index c41847e0..69f54a5c 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionController.java +++ b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebRequestController.java @@ -25,7 +25,7 @@ import org.mxchange.jcontacts.model.contact.Contact; *

* @author Roland Häder */ -public interface AddressbookContactWebSessionController extends Serializable { +public interface AddressbookContactWebRequestController extends Serializable { /** * Minimum password length diff --git a/src/java/org/mxchange/addressbook/beans/contact/phone/AddressbookContactPhoneWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/contact/phone/AddressbookContactPhoneWebRequestBean.java similarity index 97% rename from src/java/org/mxchange/addressbook/beans/contact/phone/AddressbookContactPhoneWebSessionBean.java rename to src/java/org/mxchange/addressbook/beans/contact/phone/AddressbookContactPhoneWebRequestBean.java index c9a46394..1b933fd2 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/phone/AddressbookContactPhoneWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/contact/phone/AddressbookContactPhoneWebRequestBean.java @@ -22,12 +22,12 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Objects; -import javax.enterprise.context.SessionScoped; +import javax.enterprise.context.RequestScoped; import javax.enterprise.event.Observes; import javax.inject.Inject; import javax.inject.Named; import org.mxchange.addressbook.beans.BaseAddressbookController; -import org.mxchange.addressbook.beans.contact.AddressbookContactWebSessionController; +import org.mxchange.addressbook.beans.contact.AddressbookContactWebRequestController; import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent; import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent; import org.mxchange.jcontacts.events.fax.unlinked.ObservableAdminUnlinkedFaxNumberEvent; @@ -49,8 +49,8 @@ import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; * @author Roland Häder */ @Named ("contactPhoneController") -@SessionScoped -public class AddressbookContactPhoneWebSessionBean extends BaseAddressbookController implements AddressbookContactPhoneWebSessionController { +@RequestScoped +public class AddressbookContactPhoneWebRequestBean extends BaseAddressbookController implements AddressbookContactPhoneWebRequestController { /** * Serial number @@ -61,7 +61,7 @@ public class AddressbookContactPhoneWebSessionBean extends BaseAddressbookContro * General contact controller */ @Inject - private AddressbookContactWebSessionController contactController; + private AddressbookContactWebRequestController contactController; /** * "Cache" for contact's mobile, land-line and fax numbers. Currently one @@ -88,7 +88,7 @@ public class AddressbookContactPhoneWebSessionBean extends BaseAddressbookContro /** * Default constructor */ - public AddressbookContactPhoneWebSessionBean () { + public AddressbookContactPhoneWebRequestBean () { // Call super constructor super(); diff --git a/src/java/org/mxchange/addressbook/beans/contact/phone/AddressbookContactPhoneWebSessionController.java b/src/java/org/mxchange/addressbook/beans/contact/phone/AddressbookContactPhoneWebRequestController.java similarity index 93% rename from src/java/org/mxchange/addressbook/beans/contact/phone/AddressbookContactPhoneWebSessionController.java rename to src/java/org/mxchange/addressbook/beans/contact/phone/AddressbookContactPhoneWebRequestController.java index 586156c0..09915e73 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/phone/AddressbookContactPhoneWebSessionController.java +++ b/src/java/org/mxchange/addressbook/beans/contact/phone/AddressbookContactPhoneWebRequestController.java @@ -23,6 +23,6 @@ import java.io.Serializable; *

* @author Roland Häder */ -public interface AddressbookContactPhoneWebSessionController extends Serializable { +public interface AddressbookContactPhoneWebRequestController extends Serializable { } diff --git a/src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebRequestBean.java index 496b64b1..6564ffd8 100644 --- a/src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebRequestBean.java @@ -27,12 +27,12 @@ import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; import javax.inject.Named; import org.mxchange.addressbook.beans.BaseAddressbookController; -import org.mxchange.jcountry.model.data.Country; -import org.mxchange.jcountry.model.data.CountryData; -import org.mxchange.jcountry.model.data.CountrySingletonBeanRemote; import org.mxchange.jcountry.events.AdminAddedCountryEvent; import org.mxchange.jcountry.events.ObservableAdminAddedCountryEvent; import org.mxchange.jcountry.exceptions.CountryAlreadyAddedException; +import org.mxchange.jcountry.model.data.Country; +import org.mxchange.jcountry.model.data.CountryData; +import org.mxchange.jcountry.model.data.CountrySingletonBeanRemote; /** * An administrative country bean @@ -75,7 +75,7 @@ public class AddressbookAdminCountryWebRequestBean extends BaseAddressbookContro * Regular country controller */ @Inject - private AddressbookCountryWebApplicationController countryController; + private AddressbookCountryWebRequestController countryController; /** * Local dial prefix diff --git a/src/java/org/mxchange/addressbook/beans/country/AddressbookCountryWebApplicationBean.java b/src/java/org/mxchange/addressbook/beans/country/AddressbookCountryWebRequestBean.java similarity index 68% rename from src/java/org/mxchange/addressbook/beans/country/AddressbookCountryWebApplicationBean.java rename to src/java/org/mxchange/addressbook/beans/country/AddressbookCountryWebRequestBean.java index 42377c4b..62b35dd4 100644 --- a/src/java/org/mxchange/addressbook/beans/country/AddressbookCountryWebApplicationBean.java +++ b/src/java/org/mxchange/addressbook/beans/country/AddressbookCountryWebRequestBean.java @@ -17,16 +17,19 @@ package org.mxchange.addressbook.beans.country; import java.text.MessageFormat; +import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import javax.annotation.PostConstruct; import javax.ejb.EJB; -import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.context.RequestScoped; import javax.enterprise.event.Observes; +import javax.inject.Inject; import javax.inject.Named; import org.mxchange.addressbook.beans.BaseAddressbookController; +import org.mxchange.jcountry.events.ObservableAdminAddedCountryEvent; import org.mxchange.jcountry.model.data.Country; import org.mxchange.jcountry.model.data.CountrySingletonBeanRemote; -import org.mxchange.jcountry.events.ObservableAdminAddedCountryEvent; /** * A country bean @@ -34,8 +37,8 @@ import org.mxchange.jcountry.events.ObservableAdminAddedCountryEvent; * @author Roland Häder */ @Named ("countryController") -@ApplicationScoped -public class AddressbookCountryWebApplicationBean extends BaseAddressbookController implements AddressbookCountryWebApplicationController { +@RequestScoped +public class AddressbookCountryWebRequestBean extends BaseAddressbookController implements AddressbookCountryWebRequestController { /** * Serial number @@ -51,12 +54,14 @@ public class AddressbookCountryWebApplicationBean extends BaseAddressbookControl /** * List of all countries */ - private List countryList; + @Inject + @Cached (cacheName = "countryCache") + private transient Cache countryCache; /** * Default constructor */ - public AddressbookCountryWebApplicationBean () { + public AddressbookCountryWebRequestBean () { // Call super constructor super(); } @@ -84,14 +89,29 @@ public class AddressbookCountryWebApplicationBean extends BaseAddressbookControl } // Add the event - this.countryList.add(event.getAddedCountry()); + this.countryCache.put(event.getAddedCountry().getCountryId(), event.getAddedCountry()); } @Override @SuppressWarnings ("ReturnOfCollectionOrArrayField") public List allCountries () { - // Return "cached" version - return this.countryList; + // Init list + List list = new LinkedList<>(); + + // Get iterator + Iterator> iterator = this.countryCache.iterator(); + + // Loop over all + while (iterator.hasNext()) { + // Get next entry + final Cache.Entry next = iterator.next(); + + // Add value to list + list.add(next.getValue()); + } + + // Return it + return list; } /** @@ -99,8 +119,20 @@ public class AddressbookCountryWebApplicationBean extends BaseAddressbookControl */ @PostConstruct public void init () { - // "Cache" country list as this will not change so often. - this.countryList = this.countryBean.allCountries(); + // Is cache there? + if (!this.countryCache.iterator().hasNext()) { + // Get whole list + List list = this.countryBean.allCountries(); + + // Add all + for (final Iterator iterator = list.iterator(); iterator.hasNext();) { + // Get next element + final Country next = iterator.next(); + + // Add it to cache + this.countryCache.put(next.getCountryId(), next); + } + } } } diff --git a/src/java/org/mxchange/addressbook/beans/country/AddressbookCountryWebApplicationController.java b/src/java/org/mxchange/addressbook/beans/country/AddressbookCountryWebRequestController.java similarity index 92% rename from src/java/org/mxchange/addressbook/beans/country/AddressbookCountryWebApplicationController.java rename to src/java/org/mxchange/addressbook/beans/country/AddressbookCountryWebRequestController.java index a30298cb..89fb0b6b 100644 --- a/src/java/org/mxchange/addressbook/beans/country/AddressbookCountryWebApplicationController.java +++ b/src/java/org/mxchange/addressbook/beans/country/AddressbookCountryWebRequestController.java @@ -25,7 +25,7 @@ import org.mxchange.jcountry.model.data.Country; *

* @author Roland Häder */ -public interface AddressbookCountryWebApplicationController extends Serializable { +public interface AddressbookCountryWebRequestController extends Serializable { /** * A list of all countries diff --git a/src/java/org/mxchange/addressbook/beans/helper/AddressbookWebRequestHelperBean.java b/src/java/org/mxchange/addressbook/beans/helper/AddressbookWebRequestHelperBean.java index bdba46c2..72572c8c 100644 --- a/src/java/org/mxchange/addressbook/beans/helper/AddressbookWebRequestHelperBean.java +++ b/src/java/org/mxchange/addressbook/beans/helper/AddressbookWebRequestHelperBean.java @@ -25,7 +25,7 @@ import javax.inject.Named; import org.mxchange.addressbook.beans.contact.AddressbookAdminContactWebRequestController; import org.mxchange.addressbook.beans.phone.AddressbookAdminPhoneWebRequestController; import org.mxchange.addressbook.beans.user.AddressbookAdminUserWebRequestController; -import org.mxchange.addressbook.beans.user.AddressbookUserWebSessionController; +import org.mxchange.addressbook.beans.user.AddressbookUserWebRequestController; import org.mxchange.jcontacts.events.contact.created.CreatedContactEvent; import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent; import org.mxchange.jcontacts.model.contact.Contact; @@ -136,7 +136,7 @@ public class AddressbookWebRequestHelperBean implements AddressbookWebRequestHel * Regular user controller */ @Inject - private AddressbookUserWebSessionController userController; + private AddressbookUserWebRequestController userController; /** * Event for when a user instance was created diff --git a/src/java/org/mxchange/addressbook/beans/mobileprovider/AddressbookMobileProviderWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/mobileprovider/AddressbookMobileProviderWebRequestBean.java index 7b34a89d..bf017338 100644 --- a/src/java/org/mxchange/addressbook/beans/mobileprovider/AddressbookMobileProviderWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/mobileprovider/AddressbookMobileProviderWebRequestBean.java @@ -17,11 +17,15 @@ package org.mxchange.addressbook.beans.mobileprovider; import java.text.MessageFormat; +import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import javax.annotation.PostConstruct; +import javax.cache.Cache; import javax.ejb.EJB; -import javax.enterprise.context.SessionScoped; +import javax.enterprise.context.RequestScoped; import javax.enterprise.event.Observes; +import javax.inject.Inject; import javax.inject.Named; import org.mxchange.addressbook.beans.BaseAddressbookController; import org.mxchange.jphone.events.mobileprovider.added.AdminAddedMobileProviderEvent; @@ -34,7 +38,7 @@ import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProviderSingl * @author Roland Häder */ @Named ("mobileProviderController") -@SessionScoped +@RequestScoped public class AddressbookMobileProviderWebRequestBean extends BaseAddressbookController implements AddressbookMobileProviderWebRequestController { /** @@ -45,13 +49,15 @@ public class AddressbookMobileProviderWebRequestBean extends BaseAddressbookCont /** * "Cached" list of mobile providers */ - private List mobileProviders; + @Inject + @Cached (cacheName = "mobileProviderCache") + private transient Cache mobileProviderCache; /** * Remote EJB for mobile providers (regular) */ @EJB (lookup = "java:global/addressbook-ejb/mobileprovider!org.mxchange.jphone.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote") - private MobileProviderSingletonBeanRemote mobileRemoteBean; + private MobileProviderSingletonBeanRemote mobileProviderBean; /** * Default constructor @@ -84,13 +90,29 @@ public class AddressbookMobileProviderWebRequestBean extends BaseAddressbookCont } // Add it to the list - this.mobileProviders.add(event.getAddedMobileProvider()); + this.mobileProviderCache.put(event.getAddedMobileProvider().getProviderId(), event.getAddedMobileProvider()); } @Override @SuppressWarnings ("ReturnOfCollectionOrArrayField") public List allMobileProviders () { - return this.mobileProviders; + // Init list + List list = new LinkedList<>(); + + // Get iterator + Iterator> iterator = this.mobileProviderCache.iterator(); + + // Loop over all + while (iterator.hasNext()) { + // Get next entry + final Cache.Entry next = iterator.next(); + + // Add value to list + list.add(next.getValue()); + } + + // Return it + return list; } /** @@ -98,8 +120,20 @@ public class AddressbookMobileProviderWebRequestBean extends BaseAddressbookCont */ @PostConstruct public void init () { - // Init list of mobile providers - this.mobileProviders = this.mobileRemoteBean.allMobileProviders(); + // Is cache there? + if (!this.mobileProviderCache.iterator().hasNext()) { + // Get whole list + List list = this.mobileProviderBean.allMobileProviders(); + + // Add all + for (final Iterator iterator = list.iterator(); iterator.hasNext();) { + // Get next element + final MobileProvider next = iterator.next(); + + // Add it to cache + this.mobileProviderCache.put(next.getProviderId(), next); + } + } } } diff --git a/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminPhoneWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminPhoneWebRequestBean.java index 1425e38d..0ee37a8f 100644 --- a/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminPhoneWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminPhoneWebRequestBean.java @@ -155,7 +155,7 @@ public class AddressbookAdminPhoneWebRequestBean extends BaseAddressbookControll * Generic hone controller */ @Inject - private AddressbookPhoneWebApplicationController phoneController; + private AddressbookPhoneWebRequestController phoneController; /** * Country (for dial prefix) diff --git a/src/java/org/mxchange/addressbook/beans/phone/AddressbookPhoneWebApplicationBean.java b/src/java/org/mxchange/addressbook/beans/phone/AddressbookPhoneWebRequestBean.java similarity index 88% rename from src/java/org/mxchange/addressbook/beans/phone/AddressbookPhoneWebApplicationBean.java rename to src/java/org/mxchange/addressbook/beans/phone/AddressbookPhoneWebRequestBean.java index ab996357..002b0cc1 100644 --- a/src/java/org/mxchange/addressbook/beans/phone/AddressbookPhoneWebApplicationBean.java +++ b/src/java/org/mxchange/addressbook/beans/phone/AddressbookPhoneWebRequestBean.java @@ -17,6 +17,7 @@ package org.mxchange.addressbook.beans.phone; import java.text.MessageFormat; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Objects; @@ -24,6 +25,7 @@ import javax.annotation.PostConstruct; import javax.ejb.EJB; import javax.enterprise.context.ApplicationScoped; import javax.enterprise.event.Observes; +import javax.inject.Inject; import javax.inject.Named; import org.mxchange.addressbook.beans.BaseAddressbookController; import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent; @@ -51,7 +53,7 @@ import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; */ @Named ("phoneController") @ApplicationScoped -public class AddressbookPhoneWebApplicationBean extends BaseAddressbookController implements AddressbookPhoneWebApplicationController { +public class AddressbookPhoneWebRequestBean extends BaseAddressbookController implements AddressbookPhoneWebRequestController { /** * Serial number @@ -61,17 +63,23 @@ public class AddressbookPhoneWebApplicationBean extends BaseAddressbookControlle /** * All fax numbers */ - private final List faxNumbers; + @Inject + @Cached(cacheName = "faxNumberCache") + private transient Cache faxNumberCache; /** * All land-line numbers */ - private final List landLineNumbers; + @Inject + @Cached(cacheName = "landLineNumberCache") + private transient Cache landLineNumberCache; /** * All mobile numbers */ - private final List mobileNumbers; + @Inject + @Cached(cacheName = "mobileNumberCache") + private transient Cache mobileNumberCache; /** * General EJB for phone numbers @@ -82,14 +90,9 @@ public class AddressbookPhoneWebApplicationBean extends BaseAddressbookControlle /** * Default constructor */ - public AddressbookPhoneWebApplicationBean () { + public AddressbookPhoneWebRequestBean () { // Call super constructor super(); - - // Init all lists - this.mobileNumbers = new LinkedList<>(); - this.faxNumbers = new LinkedList<>(); - this.landLineNumbers = new LinkedList<>(); } /** @@ -478,19 +481,67 @@ public class AddressbookPhoneWebApplicationBean extends BaseAddressbookControlle @Override @SuppressWarnings ("ReturnOfCollectionOrArrayField") public List allFaxNumbers () { - return this.faxNumbers; + // Init list + List list = new LinkedList<>(); + + // Get iterator + Iterator> iterator = this.faxNumberCache.iterator(); + + // Loop over all + while (iterator.hasNext()) { + // Get next entry + final Cache.Entry next = iterator.next(); + + // Add value to list + list.add(next.getValue()); + } + + // Return it + return list; } @Override @SuppressWarnings ("ReturnOfCollectionOrArrayField") public List allLandLineNumbers () { - return this.landLineNumbers; + // Init list + List list = new LinkedList<>(); + + // Get iterator + Iterator> iterator = this.landLineNumberCache.iterator(); + + // Loop over all + while (iterator.hasNext()) { + // Get next entry + final Cache.Entry next = iterator.next(); + + // Add value to list + list.add(next.getValue()); + } + + // Return it + return list; } @Override @SuppressWarnings ("ReturnOfCollectionOrArrayField") public List allMobileNumbers () { - return this.mobileNumbers; + // Init list + List list = new LinkedList<>(); + + // Get iterator + Iterator> iterator = this.mobileNumberCache.iterator(); + + // Loop over all + while (iterator.hasNext()) { + // Get next entry + final Cache.Entry next = iterator.next(); + + // Add value to list + list.add(next.getValue()); + } + + // Return it + return list; } /** @@ -498,10 +549,50 @@ public class AddressbookPhoneWebApplicationBean extends BaseAddressbookControlle */ @PostConstruct public void init () { - // All phone numbers - this.allMobileNumbers().addAll(this.phoneBean.allMobileNumbers()); - this.allFaxNumbers().addAll(this.phoneBean.allFaxNumbers()); - this.allLandLineNumbers().addAll(this.phoneBean.allLandLineNumbers()); + // Is cache there? + if (!this.faxNumberCache.iterator().hasNext()) { + // Get whole list + List list = this.phoneBean.allFaxNumbers(); + + // Add all + for (final Iterator iterator = list.iterator(); iterator.hasNext();) { + // Get next element + final DialableFaxNumber next = iterator.next(); + + // Add it to cache + this.faxNumberCache.put(next.getPhoneId(), next); + } + } + + // Is cache there? + if (!this.landLineNumberCache.iterator().hasNext()) { + // Get whole list + List list = this.phoneBean.allLandLineNumbers(); + + // Add all + for (final Iterator iterator = list.iterator(); iterator.hasNext();) { + // Get next element + final DialableLandLineNumber next = iterator.next(); + + // Add it to cache + this.landLineNumberCache.put(next.getPhoneId(), next); + } + } + + // Is cache there? + if (!this.mobileNumberCache.iterator().hasNext()) { + // Get whole list + List list = this.phoneBean.allMobileNumbers(); + + // Add all + for (final Iterator iterator = list.iterator(); iterator.hasNext();) { + // Get next element + final DialableMobileNumber next = iterator.next(); + + // Add it to cache + this.mobileNumberCache.put(next.getPhoneId(), next); + } + } } /** diff --git a/src/java/org/mxchange/addressbook/beans/phone/AddressbookPhoneWebApplicationController.java b/src/java/org/mxchange/addressbook/beans/phone/AddressbookPhoneWebRequestController.java similarity index 96% rename from src/java/org/mxchange/addressbook/beans/phone/AddressbookPhoneWebApplicationController.java rename to src/java/org/mxchange/addressbook/beans/phone/AddressbookPhoneWebRequestController.java index 2d2fb587..d824d079 100644 --- a/src/java/org/mxchange/addressbook/beans/phone/AddressbookPhoneWebApplicationController.java +++ b/src/java/org/mxchange/addressbook/beans/phone/AddressbookPhoneWebRequestController.java @@ -28,7 +28,7 @@ import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; *

* @author Roland Häder */ -public interface AddressbookPhoneWebApplicationController extends Serializable { +public interface AddressbookPhoneWebRequestController extends Serializable { /** * Returns a list of all mobile numbers. For performance reasons, the diff --git a/src/java/org/mxchange/addressbook/beans/profile/AddressbookUserProfileWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/profile/AddressbookUserProfileWebRequestBean.java index 4b46e971..887483f7 100644 --- a/src/java/org/mxchange/addressbook/beans/profile/AddressbookUserProfileWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/profile/AddressbookUserProfileWebRequestBean.java @@ -17,17 +17,16 @@ package org.mxchange.addressbook.beans.profile; import java.text.MessageFormat; -import javax.annotation.PostConstruct; import javax.enterprise.context.RequestScoped; import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; import javax.inject.Named; import org.mxchange.addressbook.beans.BaseAddressbookController; -import org.mxchange.addressbook.beans.user.AddressbookUserWebSessionController; import org.mxchange.addressbook.beans.user.login.AddressbookUserLoginWebSessionController; import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.model.user.User; import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; +import org.mxchange.addressbook.beans.user.AddressbookUserWebRequestController; /** * A web request bean for user profiles @@ -47,7 +46,7 @@ public class AddressbookUserProfileWebRequestBean extends BaseAddressbookControl * User controller */ @Inject - private AddressbookUserWebSessionController userController; + private AddressbookUserWebRequestController userController; /** * Login controller @@ -63,13 +62,6 @@ public class AddressbookUserProfileWebRequestBean extends BaseAddressbookControl super(); } - /** - * Post-construction method - */ - @PostConstruct - public void init () { - } - @Override public boolean isProfileLinkVisibleById (final Long userId) { // Init user instance diff --git a/src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestBean.java index 4713ca3c..1a3e537f 100644 --- a/src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestBean.java @@ -29,12 +29,12 @@ import javax.faces.context.FacesContext; import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; import javax.inject.Named; -import org.mxchange.addressbook.beans.BaseAddressbookController; -import org.mxchange.addressbook.beans.contact.AddressbookAdminContactWebRequestController; -import org.mxchange.addressbook.beans.contact.AddressbookContactWebSessionController; import org.mxchange.addressbook.beans.localization.AddressbookLocalizationSessionController; import org.mxchange.jcontacts.model.contact.Contact; import org.mxchange.jcoreee.utils.FacesUtils; +<<<<<<< HEAD:src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestBean.java +import org.mxchange.addressbook.beans.BaseAddressbookController; +import org.mxchange.addressbook.beans.contact.AddressbookAdminContactWebRequestController; import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent; @@ -64,6 +64,7 @@ import org.mxchange.juserlogincore.container.login.UserLoginContainer; import org.mxchange.juserlogincore.events.registration.ObservableUserRegisteredEvent; import org.mxchange.juserlogincore.exceptions.UserPasswordRepeatMismatchException; import org.mxchange.juserlogincore.login.UserLoginUtils; +import org.mxchange.addressbook.beans.contact.AddressbookContactWebRequestController; /** * A user bean (controller) @@ -107,7 +108,7 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle * Regular contact controller */ @Inject - private AddressbookContactWebSessionController contactController; + private AddressbookContactWebRequestController contactController; /** * Event being fired when administrator has deleted user @@ -144,7 +145,7 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle * Regular user controller */ @Inject - private AddressbookUserWebSessionController userController; + private AddressbookUserWebRequestController userController; /** * Delete reason @@ -277,7 +278,7 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle return ""; //NOI18N } else if ((this.getUserPassword() == null && (this.getUserPasswordRepeat() == null)) || ((this.getUserPassword().isEmpty()) && (this.getUserPasswordRepeat().isEmpty()))) { // Empty password entered, then generate one - password = UserLoginUtils.createRandomPassword(AddressbookUserWebSessionController.MINIMUM_PASSWORD_LENGTH); + password = UserLoginUtils.createRandomPassword(AddressbookUserWebRequestController.MINIMUM_PASSWORD_LENGTH); } else if (!this.isSamePasswordEntered()) { // Both passwords don't match throw new FaceletException(new UserPasswordRepeatMismatchException(newUser)); @@ -288,7 +289,7 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle // The password should not be null and at least 5 characters long assert (password != null) : "password is null"; //NOI18N - assert (password.length() >= AddressbookUserWebSessionController.MINIMUM_PASSWORD_LENGTH) : "Password is not long enough."; //NOI18N + assert (password.length() >= AddressbookUserWebRequestController.MINIMUM_PASSWORD_LENGTH) : "Password is not long enough."; //NOI18N // Encrypt password and set it newUser.setUserEncryptedPassword(UserLoginUtils.encryptPassword(password)); diff --git a/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebRequestBean.java similarity index 91% rename from src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java rename to src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebRequestBean.java index e9ae01c2..d7e4050e 100644 --- a/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebRequestBean.java @@ -18,12 +18,13 @@ package org.mxchange.addressbook.beans.user; import java.text.MessageFormat; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Objects; import javax.annotation.PostConstruct; import javax.ejb.EJB; -import javax.enterprise.context.SessionScoped; +import javax.enterprise.context.RequestScoped; import javax.enterprise.event.Event; import javax.enterprise.event.Observes; import javax.enterprise.inject.Any; @@ -32,7 +33,7 @@ import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; import javax.inject.Named; import org.mxchange.addressbook.beans.BaseAddressbookController; -import org.mxchange.addressbook.beans.contact.AddressbookContactWebSessionController; +import org.mxchange.addressbook.beans.contact.AddressbookContactWebRequestController; import org.mxchange.addressbook.beans.features.AddressbookFeaturesWebApplicationController; import org.mxchange.addressbook.beans.localization.AddressbookLocalizationSessionController; import org.mxchange.addressbook.beans.user.login.AddressbookUserLoginWebSessionController; @@ -68,8 +69,8 @@ import org.mxchange.juserlogincore.login.UserLoginUtils; * @author Roland Häder */ @Named ("userController") -@SessionScoped -public class AddressbookUserWebSessionBean extends BaseAddressbookController implements AddressbookUserWebSessionController { +@RequestScoped +public class AddressbookUserWebRequestBean extends BaseAddressbookController implements AddressbookUserWebRequestController { /** * Serial number @@ -80,7 +81,7 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp * General contact controller */ @Inject - private AddressbookContactWebSessionController contactController; + private AddressbookContactWebRequestController contactController; /** * Features controller @@ -120,7 +121,9 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp /** * A list of all user profiles */ - private List userList; + @Inject + @Cached (cacheName = "userCache") + private transient Cache userCache; /** * Login controller (bean) @@ -136,7 +139,9 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp /** * User name list */ - private List userNameList; + @Inject + @Cached (cacheName = "userNameCache") + private transient Cache userNameCache; /** * User password (clear-text from web form) @@ -153,18 +158,10 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp */ private ProfileMode userProfileMode; - /** - * A list of all public user profiles - *

- * @TODO Hmm, makes that sense? Having visible user list in current - * (session-scoped) user's visible user list? - */ - private List visibleUserList; - /** * Default constructor */ - public AddressbookUserWebSessionBean () { + public AddressbookUserWebRequestBean () { // Call super constructor super(); } @@ -438,12 +435,6 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp // Copy all data to this bean this.copyUser(loggedInUser); - - // Is the user visible? - if (Objects.equals(loggedInUser.getUserProfileMode(), ProfileMode.PUBLIC)) { - // Yes, then add user - this.visibleUserList.add(loggedInUser); - } } /** @@ -505,12 +496,6 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp // Add user name this.addUserName(registeredUser); - // Is the account public? - if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) { - // Also add it to this list - this.visibleUserList.add(registeredUser); - } - // Set user id again this.setUserId(registeredUser.getUserId()); } @@ -569,15 +554,23 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp @Override @SuppressWarnings ("ReturnOfCollectionOrArrayField") public List allUsers () { - // Return it - return this.userList; - } + // Init list + List list = new LinkedList<>(); + + // Get iterator + Iterator> iterator = this.userCache.iterator(); + + // Loop over all + while (iterator.hasNext()) { + // Get next entry + final Cache.Entry next = iterator.next(); + + // Add value to list + list.add(next.getValue()); + } - @Override - @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public List allVisibleUsers () { // Return it - return this.visibleUserList; + return list; } /** @@ -633,7 +626,7 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp this.setUserProfileMode(ProfileMode.INVISIBLE); // Generate random password - String randomPassword = UserLoginUtils.createRandomPassword(AddressbookUserWebSessionController.MINIMUM_PASSWORD_LENGTH); + String randomPassword = UserLoginUtils.createRandomPassword(AddressbookUserWebRequestController.MINIMUM_PASSWORD_LENGTH); // Set random password this.setUserPassword(randomPassword); @@ -831,19 +824,20 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp */ @PostConstruct public void init () { - // Initialize user list - this.userList = this.userBean.allUsers(); - - // Get full user name list for reducing EJB calls - this.userNameList = this.userBean.getUserNameList(); - - // Is the user logged-in? - if (this.userLoginController.isUserLoggedIn()) { - // Is logged-in, so load also users visible to memebers - this.visibleUserList = this.userBean.allMemberPublicVisibleUsers(); - } else { - // Initialize user list - this.visibleUserList = this.userBean.allPublicUsers(); + // Is cache there? + if (!this.userCache.iterator().hasNext()) { + // Get whole list + List list = this.userBean.allUsers(); + + // Add all + for (final Iterator iterator = list.iterator(); iterator.hasNext();) { + // Get next element + final User next = iterator.next(); + + // Add it to cache + this.userCache.put(next.getUserId(), next); + this.userNameCache.put(next.getUserId(), next.getUserName()); + } } } @@ -936,7 +930,7 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp @Override public boolean isUserNameRegistered (final User user) { - return ((this.userNameList instanceof List) && (this.userNameList.contains(user.getUserName()))); + return ((this.userNameCache instanceof List) && (this.userNameCache.containsKey(user.getUserId()))); } @Override @@ -951,11 +945,6 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp return isRequired; } - @Override - public boolean isVisibleUserFound () { - return ((this.visibleUserList instanceof List) && (this.visibleUserList.size() > 0)); - } - @Override public User lookupUserByEmailAddress (final String emailAddress) throws UserEmailAddressNotFoundException { // Parameter must be valid @@ -971,23 +960,23 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp User user = null; // Try to lookup it in visible user list - for (final Iterator iterator = this.userList.iterator(); iterator.hasNext();) { + for (final Iterator> iterator = this.userCache.iterator(); iterator.hasNext();) { // Get next user - User next = iterator.next(); + Cache.Entry next = iterator.next(); // Contact should be set - if (next.getUserContact() == null) { + if (next.getValue().getUserContact() == null) { // Contact is null - throw new NullPointerException(MessageFormat.format("next.userContact is null for user id {0}", next.getUserId())); //NOI18N - } else if (next.getUserContact().getContactEmailAddress() == null) { + throw new NullPointerException(MessageFormat.format("next.userContact is null for user id {0}", next.getKey())); //NOI18N + } else if (next.getValue().getUserContact().getContactEmailAddress() == null) { // Email address should be set - throw new NullPointerException(MessageFormat.format("next.userContact.contactEmailAddress is null for user id {0}", next.getUserId())); //NOI18N + throw new NullPointerException(MessageFormat.format("next.userContact.contactEmailAddress is null for user id {0}", next.getKey())); //NOI18N } // Is the email address found? - if (Objects.equals(next.getUserContact().getContactEmailAddress(), emailAddress)) { + if (Objects.equals(next.getValue().getUserContact().getContactEmailAddress(), emailAddress)) { // Copy to other variable - user = next; + user = next.getValue(); break; } } @@ -1017,14 +1006,14 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp User user = null; // Try to lookup it in visible user list - for (final Iterator iterator = this.userList.iterator(); iterator.hasNext();) { + for (final Iterator> iterator = this.userCache.iterator(); iterator.hasNext();) { // Get next user - User next = iterator.next(); + Cache.Entry next = iterator.next(); // Is the user id found? - if (Objects.equals(next.getUserId(), userId)) { + if (Objects.equals(next.getKey(), userId)) { // Copy to other variable - user = next; + user = next.getValue(); break; } } @@ -1047,13 +1036,13 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp */ private void addUserName (final User user) { // Make sure the entry is not added yet - if (this.userNameList.contains(user.getUserName())) { + if (this.userNameCache.containsKey(user.getUserId())) { // Abort here throw new IllegalArgumentException(MessageFormat.format("User name {0} already added.", user.getUserName())); //NOI18N } // Add user name - this.userNameList.add(user.getUserName()); + this.userNameCache.put(user.getUserId(), user.getUserName()); } /** @@ -1146,11 +1135,10 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp } // Remove it from lists - this.userList.remove(user); - this.visibleUserList.remove(user); + this.userCache.remove(user.getUserId()); // Remove name from list - this.userNameList.remove(user.getUserName()); + this.userNameCache.remove(user.getUserId()); } /** @@ -1180,24 +1168,8 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp throw new NullPointerException(MessageFormat.format("user.userContact.contactId={0} is invalid.", user.getUserContact().getContactId())); //NOI18N } - // Get iterator from list - Iterator iterator = this.userList.iterator(); - - // "Walk" through all entries - while (iterator.hasNext()) { - // Get next element - User next = iterator.next(); - - // Is user id number the same? - if (Objects.equals(user.getUserId(), next.getUserId())) { - // Found entry, so remove it and abort - this.userList.remove(next); - break; - } - } - - // Re-add user - this.userList.add(user); + // Add/update user + this.userCache.put(user.getUserId(), user); } } diff --git a/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionController.java b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebRequestController.java similarity index 91% rename from src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionController.java rename to src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebRequestController.java index 3809a656..5a9b253d 100644 --- a/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionController.java +++ b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebRequestController.java @@ -28,7 +28,7 @@ import org.mxchange.jusercore.model.user.User; *

* @author Roland Häder */ -public interface AddressbookUserWebSessionController extends Serializable { +public interface AddressbookUserWebRequestController extends Serializable { /** * Minimum password length @@ -61,13 +61,6 @@ public interface AddressbookUserWebSessionController extends Serializable { */ List allUsers (); - /** - * All public user profiles - *

- * @return A list of all public user profiles - */ - List allVisibleUsers (); - /** * Checks whether the given contact is a user *

@@ -77,14 +70,6 @@ public interface AddressbookUserWebSessionController extends Serializable { */ boolean isContactFound (final Contact contact); - /** - * Checks whether a public user account is registered. This means that at - * least one user profile has its flag "public user profile" enabled. - *

- * @return Whether at least one user has a public profile - */ - boolean isVisibleUserFound (); - /** * Checks whether given user instance's name is used *

diff --git a/src/java/org/mxchange/addressbook/beans/user/activity/AddressbookUserActivityWebApplicationBean.java b/src/java/org/mxchange/addressbook/beans/user/activity/AddressbookUserActivityWebRequestBean.java similarity index 95% rename from src/java/org/mxchange/addressbook/beans/user/activity/AddressbookUserActivityWebApplicationBean.java rename to src/java/org/mxchange/addressbook/beans/user/activity/AddressbookUserActivityWebRequestBean.java index 28b6d53a..aaa04f01 100644 --- a/src/java/org/mxchange/addressbook/beans/user/activity/AddressbookUserActivityWebApplicationBean.java +++ b/src/java/org/mxchange/addressbook/beans/user/activity/AddressbookUserActivityWebRequestBean.java @@ -19,14 +19,13 @@ package org.mxchange.addressbook.beans.user.activity; import java.text.MessageFormat; import java.util.Collections; import java.util.GregorianCalendar; -import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; -import java.util.Map; import javax.annotation.PostConstruct; import javax.ejb.EJB; -import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.context.RequestScoped; import javax.enterprise.event.Observes; +import javax.inject.Inject; import javax.inject.Named; import org.mxchange.addressbook.beans.BaseAddressbookController; import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; @@ -55,8 +54,8 @@ import org.mxchange.juserlogincore.events.user.password_change.ObservableUpdated * @author Roland Häder */ @Named ("userActivityController") -@ApplicationScoped -public class AddressbookUserActivityWebApplicationBean extends BaseAddressbookController implements AddressbookUserActivityWebApplicationController { +@RequestScoped +public class AddressbookUserActivityWebRequestBean extends BaseAddressbookController implements AddressbookUserActivityWebRequestController { /** * Serial number @@ -77,15 +76,17 @@ public class AddressbookUserActivityWebApplicationBean extends BaseAddressbookCo /** * "Cache" for activity log per user */ - private final Map> usersActivity; + @Inject + @Cached(cacheName = "usersActivityCache") + private transient Cache> usersActivityCache; /** * Default constructor */ @SuppressWarnings ("CollectionWithoutInitialCapacity") - public AddressbookUserActivityWebApplicationBean () { - // Init cache - this.usersActivity = new LinkedHashMap<>(); + public AddressbookUserActivityWebRequestBean () { + // Call super constructor + super(); } /** @@ -505,9 +506,9 @@ public class AddressbookUserActivityWebApplicationBean extends BaseAddressbookCo List list = new LinkedList<>(); // Is the user set? - if (this.usersActivity.containsKey(this.getUser())) { + if (this.usersActivityCache.containsKey(this.getUser())) { // Return it - list.addAll(this.usersActivity.get(this.getUser())); + list.addAll(this.usersActivityCache.get(this.getUser())); // Sort list and reverse it Collections.sort(list, new UserActivityLogTimestampComparator()); @@ -547,13 +548,13 @@ public class AddressbookUserActivityWebApplicationBean extends BaseAddressbookCo // Put all in map, per-user for (final LogableUserActivity userActivity : list) { // Is the list there? - if (!this.usersActivity.containsKey(userActivity.getActivityUser())) { + if (!this.usersActivityCache.containsKey(userActivity.getActivityUser())) { // Init list - this.usersActivity.put(userActivity.getActivityUser(), new LinkedList()); + this.usersActivityCache.put(userActivity.getActivityUser(), new LinkedList()); } // Add by user instance - boolean added = this.usersActivity.get(userActivity.getActivityUser()).add(userActivity); + boolean added = this.usersActivityCache.get(userActivity.getActivityUser()).add(userActivity); // Should be added assert (added) : "Activity log not added"; //NOI18N @@ -662,13 +663,13 @@ public class AddressbookUserActivityWebApplicationBean extends BaseAddressbookCo } // Is it there? - if (!this.usersActivity.containsKey(userActivity.getActivityUser())) { + if (!this.usersActivityCache.containsKey(userActivity.getActivityUser())) { // Init it - this.usersActivity.put(userActivity.getActivityUser(), new LinkedList()); + this.usersActivityCache.put(userActivity.getActivityUser(), new LinkedList()); } // Add activity to log - this.usersActivity.get(userActivity.getActivityUser()).add(userActivity); + this.usersActivityCache.get(userActivity.getActivityUser()).add(userActivity); } } diff --git a/src/java/org/mxchange/addressbook/beans/user/activity/AddressbookUserActivityWebApplicationController.java b/src/java/org/mxchange/addressbook/beans/user/activity/AddressbookUserActivityWebRequestController.java similarity index 91% rename from src/java/org/mxchange/addressbook/beans/user/activity/AddressbookUserActivityWebApplicationController.java rename to src/java/org/mxchange/addressbook/beans/user/activity/AddressbookUserActivityWebRequestController.java index e048d81f..57560c64 100644 --- a/src/java/org/mxchange/addressbook/beans/user/activity/AddressbookUserActivityWebApplicationController.java +++ b/src/java/org/mxchange/addressbook/beans/user/activity/AddressbookUserActivityWebRequestController.java @@ -23,6 +23,6 @@ import java.io.Serializable; *

* @author Roland Häder */ -public interface AddressbookUserActivityWebApplicationController extends Serializable { +public interface AddressbookUserActivityWebRequestController extends Serializable { } diff --git a/src/java/org/mxchange/addressbook/beans/user/confirmlink/AddressbookConfirmationLinkWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/user/confirmlink/AddressbookConfirmationLinkWebRequestBean.java index d3b28b64..0f1ff869 100644 --- a/src/java/org/mxchange/addressbook/beans/user/confirmlink/AddressbookConfirmationLinkWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/user/confirmlink/AddressbookConfirmationLinkWebRequestBean.java @@ -27,11 +27,11 @@ import javax.enterprise.inject.Any; import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; import javax.inject.Named; -import org.mxchange.addressbook.beans.BaseAddressbookController; -import org.mxchange.addressbook.beans.user.AddressbookUserWebSessionController; import org.mxchange.jcoreee.events.helper.clear.HelperCleanupEvent; import org.mxchange.jcoreee.events.helper.clear.ObservableHelperCleanupEvent; import org.mxchange.jcoreee.utils.FacesUtils; +<<<<<<< HEAD:src/java/org/mxchange/addressbook/beans/user/confirmlink/AddressbookConfirmationLinkWebRequestBean.java +import org.mxchange.addressbook.beans.BaseAddressbookController; import org.mxchange.jusercore.events.user.created.CreatedUserEvent; import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent; import org.mxchange.jusercore.exceptions.UserStatusConfirmedException; @@ -41,6 +41,7 @@ import org.mxchange.jusercore.model.user.UserSessionBeanRemote; import org.mxchange.jusercore.model.user.status.UserAccountStatus; import org.mxchange.juserlogincore.events.confirmation.ObservableUserConfirmedAccountEvent; import org.mxchange.juserlogincore.events.confirmation.UserConfirmedAccountEvent; +import org.mxchange.addressbook.beans.user.AddressbookUserWebRequestController; /** * A web request bean for confirmation link handling @@ -85,7 +86,7 @@ public class AddressbookConfirmationLinkWebRequestBean extends BaseAddressbookCo * User controller */ @Inject - private AddressbookUserWebSessionController userController; + private AddressbookUserWebRequestController userController; /** * Event for when a user instance was created diff --git a/src/java/org/mxchange/addressbook/beans/user/email_address/AddressbookEmailChangeWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/user/email_address/AddressbookEmailChangeWebRequestBean.java similarity index 90% rename from src/java/org/mxchange/addressbook/beans/user/email_address/AddressbookEmailChangeWebSessionBean.java rename to src/java/org/mxchange/addressbook/beans/user/email_address/AddressbookEmailChangeWebRequestBean.java index 67a7c0c3..90579dd7 100644 --- a/src/java/org/mxchange/addressbook/beans/user/email_address/AddressbookEmailChangeWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/user/email_address/AddressbookEmailChangeWebRequestBean.java @@ -17,6 +17,7 @@ package org.mxchange.addressbook.beans.user.email_address; import java.text.MessageFormat; +import java.util.Iterator; import java.util.List; import java.util.Objects; import javax.annotation.PostConstruct; @@ -43,7 +44,7 @@ import org.mxchange.juserlogincore.exceptions.UserPasswordMismatchException; */ @Named ("userEmailChangeController") @SessionScoped -public class AddressbookEmailChangeWebSessionBean extends BaseAddressbookController implements AddressbookEmailChangeWebSessionController { +public class AddressbookEmailChangeWebRequestBean extends BaseAddressbookController implements AddressbookEmailChangeWebRequestController { /** * Serial number @@ -60,11 +61,6 @@ public class AddressbookEmailChangeWebSessionBean extends BaseAddressbookControl */ private String emailAddressRepeat; - /** - * Local list of already queued email addresses - */ - private List emailAddresses; - /** * Remote email change bean */ @@ -77,6 +73,13 @@ public class AddressbookEmailChangeWebSessionBean extends BaseAddressbookControl @Inject private AddressbookFeaturesWebApplicationController featureController; + /** + * Local list of already queued email addresses + */ + @Inject + @Cached (cacheName = "queuedEmailCache") + private transient Cache queuedEmailCache; + /** * Login controller (bean) */ @@ -86,7 +89,7 @@ public class AddressbookEmailChangeWebSessionBean extends BaseAddressbookControl /** * Default constructor */ - public AddressbookEmailChangeWebSessionBean () { + public AddressbookEmailChangeWebRequestBean () { // Call super constructor super(); } @@ -196,8 +199,20 @@ public class AddressbookEmailChangeWebSessionBean extends BaseAddressbookControl */ @PostConstruct public void init () { - // Init list - this.emailAddresses = this.emailChangeBean.allQueuedAddresses(); + // Is cache there? + if (!this.queuedEmailCache.iterator().hasNext()) { + // Get whole list + List list = this.emailChangeBean.allQueuedAddresses(); + + // Add all + for (final Iterator iterator = list.iterator(); iterator.hasNext();) { + // Get next element + final String next = iterator.next(); + + // Add it to cache + this.queuedEmailCache.put(next, Boolean.TRUE); + } + } } @Override @@ -230,7 +245,7 @@ public class AddressbookEmailChangeWebSessionBean extends BaseAddressbookControl assert (!emailAddress.trim().isEmpty()) : "emailAddress should not be empty"; //NOI18N // Check list - if (this.emailAddresses.contains(emailAddress)) { + if (this.queuedEmailCache.containsKey(emailAddress)) { // Okay, found it return true; } @@ -241,7 +256,7 @@ public class AddressbookEmailChangeWebSessionBean extends BaseAddressbookControl // Is it there? if (isQueued) { // Add to list - this.emailAddresses.add(emailAddress); + this.queuedEmailCache.put(emailAddress, Boolean.TRUE); } // Return status diff --git a/src/java/org/mxchange/addressbook/beans/user/email_address/AddressbookEmailChangeWebSessionController.java b/src/java/org/mxchange/addressbook/beans/user/email_address/AddressbookEmailChangeWebRequestController.java similarity index 94% rename from src/java/org/mxchange/addressbook/beans/user/email_address/AddressbookEmailChangeWebSessionController.java rename to src/java/org/mxchange/addressbook/beans/user/email_address/AddressbookEmailChangeWebRequestController.java index 9f75c211..0ae35e05 100644 --- a/src/java/org/mxchange/addressbook/beans/user/email_address/AddressbookEmailChangeWebSessionController.java +++ b/src/java/org/mxchange/addressbook/beans/user/email_address/AddressbookEmailChangeWebRequestController.java @@ -23,7 +23,7 @@ import java.io.Serializable; *

* @author Roland Häder */ -public interface AddressbookEmailChangeWebSessionController extends Serializable { +public interface AddressbookEmailChangeWebRequestController extends Serializable { /** * Checks whether all required are set for changing email address diff --git a/src/java/org/mxchange/addressbook/beans/user/login/AddressbookUserLoginWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/user/login/AddressbookUserLoginWebSessionBean.java index ff6b4beb..981d523f 100644 --- a/src/java/org/mxchange/addressbook/beans/user/login/AddressbookUserLoginWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/user/login/AddressbookUserLoginWebSessionBean.java @@ -29,7 +29,7 @@ import javax.faces.context.FacesContext; import javax.inject.Inject; import javax.inject.Named; import org.mxchange.addressbook.beans.BaseAddressbookController; -import org.mxchange.addressbook.beans.user.AddressbookUserWebSessionController; +import org.mxchange.addressbook.beans.user.AddressbookUserWebRequestController; import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.exceptions.UserStatusLockedException; import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException; @@ -88,7 +88,7 @@ public class AddressbookUserLoginWebSessionBean extends BaseAddressbookControlle * User controller */ @Inject - private AddressbookUserWebSessionController userController; + private AddressbookUserWebRequestController userController; /** * Current password diff --git a/src/java/org/mxchange/addressbook/beans/user/register/AddressbookUserRegisterWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/user/register/AddressbookUserRegisterWebRequestBean.java similarity index 95% rename from src/java/org/mxchange/addressbook/beans/user/register/AddressbookUserRegisterWebSessionBean.java rename to src/java/org/mxchange/addressbook/beans/user/register/AddressbookUserRegisterWebRequestBean.java index 0040b6dc..d9436457 100644 --- a/src/java/org/mxchange/addressbook/beans/user/register/AddressbookUserRegisterWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/user/register/AddressbookUserRegisterWebRequestBean.java @@ -17,17 +17,16 @@ package org.mxchange.addressbook.beans.user.register; import javax.ejb.EJB; -import javax.enterprise.context.SessionScoped; +import javax.enterprise.context.RequestScoped; import javax.enterprise.event.Event; import javax.enterprise.inject.Any; import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; import javax.inject.Named; import org.mxchange.addressbook.beans.BaseAddressbookController; -import org.mxchange.addressbook.beans.contact.AddressbookContactWebSessionController; +import org.mxchange.addressbook.beans.contact.AddressbookContactWebRequestController; import org.mxchange.addressbook.beans.features.AddressbookFeaturesWebApplicationController; import org.mxchange.addressbook.beans.user.AddressbookAdminUserWebRequestController; -import org.mxchange.addressbook.beans.user.AddressbookUserWebSessionController; import org.mxchange.jcontacts.model.contact.Contact; import org.mxchange.jcontacts.model.contact.UserContact; import org.mxchange.jcoreee.utils.FacesUtils; @@ -48,6 +47,7 @@ import org.mxchange.juserlogincore.events.user.password_change.ObservableUpdated import org.mxchange.juserlogincore.events.user.password_change.UpdatedUserPasswordEvent; import org.mxchange.juserlogincore.login.UserLoginUtils; import org.mxchange.juserlogincore.model.user.register.UserRegistrationSessionBeanRemote; +import org.mxchange.addressbook.beans.user.AddressbookUserWebRequestController; /** * A web bean for user registration @@ -55,8 +55,8 @@ import org.mxchange.juserlogincore.model.user.register.UserRegistrationSessionBe * @author Roland Häder */ @Named ("userRegistrationController") -@SessionScoped -public class AddressbookUserRegisterWebSessionBean extends BaseAddressbookController implements AddressbookUserRegisterWebSessionController { +@RequestScoped +public class AddressbookUserRegisterWebRequestBean extends BaseAddressbookController implements AddressbookUserRegisterWebRequestController { /** * Serial number @@ -87,7 +87,7 @@ public class AddressbookUserRegisterWebSessionBean extends BaseAddressbookContro * Contact controller */ @Inject - private AddressbookContactWebSessionController contactController; + private AddressbookContactWebRequestController contactController; /** * Features controller @@ -105,7 +105,7 @@ public class AddressbookUserRegisterWebSessionBean extends BaseAddressbookContro * User controller */ @Inject - private AddressbookUserWebSessionController userController; + private AddressbookUserWebRequestController userController; /** * An event being fired when a user password was changed @@ -124,7 +124,7 @@ public class AddressbookUserRegisterWebSessionBean extends BaseAddressbookContro /** * Default constructor */ - public AddressbookUserRegisterWebSessionBean () { + public AddressbookUserRegisterWebRequestBean () { // Call super constructor super(); } @@ -197,7 +197,7 @@ public class AddressbookUserRegisterWebSessionBean extends BaseAddressbookContro throw new FaceletException(new DataRepeatMismatchException("Passwords not matching.")); //NOI18N } else if (this.userController.ifBothPasswordsEmptyAllowed()) { // Both passwords are left empty and is allowed, then generate a random password - randomPassword = UserLoginUtils.createRandomPassword(AddressbookUserWebSessionController.MINIMUM_PASSWORD_LENGTH); + randomPassword = UserLoginUtils.createRandomPassword(AddressbookUserWebRequestController.MINIMUM_PASSWORD_LENGTH); // Generate (ignored) password-history PasswordHistory passwordHistory = new UserPasswordHistory(randomPassword, user); @@ -294,7 +294,7 @@ public class AddressbookUserRegisterWebSessionBean extends BaseAddressbookContro return ""; //NOI18N } else if (this.userController.ifBothPasswordsEmptyAllowed()) { // Both passwords are left empty and is allowed, then generate a random password - String randomPassword = UserLoginUtils.createRandomPassword(AddressbookUserWebSessionController.MINIMUM_PASSWORD_LENGTH); + String randomPassword = UserLoginUtils.createRandomPassword(AddressbookUserWebRequestController.MINIMUM_PASSWORD_LENGTH); // Generate (ignored) password-history PasswordHistory passwordHistory = new UserPasswordHistory(randomPassword, user); diff --git a/src/java/org/mxchange/addressbook/beans/user/register/AddressbookUserRegisterWebSessionController.java b/src/java/org/mxchange/addressbook/beans/user/register/AddressbookUserRegisterWebRequestController.java similarity index 93% rename from src/java/org/mxchange/addressbook/beans/user/register/AddressbookUserRegisterWebSessionController.java rename to src/java/org/mxchange/addressbook/beans/user/register/AddressbookUserRegisterWebRequestController.java index 7171c240..dc9a6429 100644 --- a/src/java/org/mxchange/addressbook/beans/user/register/AddressbookUserRegisterWebSessionController.java +++ b/src/java/org/mxchange/addressbook/beans/user/register/AddressbookUserRegisterWebRequestController.java @@ -23,6 +23,6 @@ import java.io.Serializable; *

* @author Roland Häder */ -public interface AddressbookUserRegisterWebSessionController extends Serializable { +public interface AddressbookUserRegisterWebRequestController extends Serializable { } diff --git a/src/java/org/mxchange/addressbook/beans/user/resendlink/AddressbookResendLinkWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/user/resendlink/AddressbookResendLinkWebRequestBean.java similarity index 94% rename from src/java/org/mxchange/addressbook/beans/user/resendlink/AddressbookResendLinkWebSessionBean.java rename to src/java/org/mxchange/addressbook/beans/user/resendlink/AddressbookResendLinkWebRequestBean.java index 6d926c15..fc66e68a 100644 --- a/src/java/org/mxchange/addressbook/beans/user/resendlink/AddressbookResendLinkWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/user/resendlink/AddressbookResendLinkWebRequestBean.java @@ -18,7 +18,7 @@ package org.mxchange.addressbook.beans.user.resendlink; import java.util.Locale; import javax.ejb.EJB; -import javax.enterprise.context.SessionScoped; +import javax.enterprise.context.RequestScoped; import javax.enterprise.event.Event; import javax.enterprise.event.Observes; import javax.enterprise.inject.Any; @@ -26,7 +26,7 @@ import javax.inject.Inject; import javax.inject.Named; import org.mxchange.addressbook.beans.BaseAddressbookController; import org.mxchange.addressbook.beans.localization.AddressbookLocalizationSessionController; -import org.mxchange.addressbook.beans.user.AddressbookUserWebSessionController; +import org.mxchange.addressbook.beans.user.AddressbookUserWebRequestController; import org.mxchange.jcoreee.events.locale.ObservableLocaleChangeEvent; import org.mxchange.jcoreee.utils.FacesUtils; import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException; @@ -45,8 +45,8 @@ import org.mxchange.juserlogincore.model.user.resendlink.ResendLinkSessionBeanRe * @author Roland Häder */ @Named ("userResendConfirmationController") -@SessionScoped -public class AddressbookResendLinkWebSessionBean extends BaseAddressbookController implements AddressbookResendLinkWebSessionController { +@RequestScoped +public class AddressbookResendLinkWebRequestBean extends BaseAddressbookController implements AddressbookResendLinkWebRequestController { /** * Serial number @@ -79,7 +79,7 @@ public class AddressbookResendLinkWebSessionBean extends BaseAddressbookControll * Regular user controller */ @Inject - private AddressbookUserWebSessionController userController; + private AddressbookUserWebRequestController userController; /** * Event being fired after confirmation link is being sent @@ -91,7 +91,7 @@ public class AddressbookResendLinkWebSessionBean extends BaseAddressbookControll /** * Default constructor */ - public AddressbookResendLinkWebSessionBean () { + public AddressbookResendLinkWebRequestBean () { // Call super constructor super(); } diff --git a/src/java/org/mxchange/addressbook/beans/user/resendlink/AddressbookResendLinkWebSessionController.java b/src/java/org/mxchange/addressbook/beans/user/resendlink/AddressbookResendLinkWebRequestController.java similarity index 93% rename from src/java/org/mxchange/addressbook/beans/user/resendlink/AddressbookResendLinkWebSessionController.java rename to src/java/org/mxchange/addressbook/beans/user/resendlink/AddressbookResendLinkWebRequestController.java index 185ee381..946c7bf2 100644 --- a/src/java/org/mxchange/addressbook/beans/user/resendlink/AddressbookResendLinkWebSessionController.java +++ b/src/java/org/mxchange/addressbook/beans/user/resendlink/AddressbookResendLinkWebRequestController.java @@ -23,6 +23,6 @@ import java.io.Serializable; *

* @author Roland Häder */ -public interface AddressbookResendLinkWebSessionController extends Serializable { +public interface AddressbookResendLinkWebRequestController extends Serializable { } diff --git a/src/java/org/mxchange/addressbook/converter/business/basicdata/AddressbookBusinessContactConverter.java b/src/java/org/mxchange/addressbook/converter/business/basicdata/AddressbookBusinessContactConverter.java index 9c7ebb95..f6b80ea5 100644 --- a/src/java/org/mxchange/addressbook/converter/business/basicdata/AddressbookBusinessContactConverter.java +++ b/src/java/org/mxchange/addressbook/converter/business/basicdata/AddressbookBusinessContactConverter.java @@ -37,7 +37,7 @@ public class AddressbookBusinessContactConverter implements Converter /** * CompanyEmployee EJB */ - @EJB (lookup = "java:global/jfinancials-ejb/companyEmployee!org.mxchange.jcontactsbusiness.employee.CompanyEmployeeSessionBeanRemote") + @EJB (lookup = "java:global/addressbook-ejb/companyEmployee!org.mxchange.jcontactsbusiness.employee.CompanyEmployeeSessionBeanRemote") private CompanyEmployeeSessionBeanRemote companyEmployeeBean; /** diff --git a/src/java/org/mxchange/addressbook/converter/business/headquarters/AddressbookCompanyHeadquartersConverter.java b/src/java/org/mxchange/addressbook/converter/business/headquarters/AddressbookCompanyHeadquartersConverter.java index e26d48d7..e9f2b4e7 100644 --- a/src/java/org/mxchange/addressbook/converter/business/headquarters/AddressbookCompanyHeadquartersConverter.java +++ b/src/java/org/mxchange/addressbook/converter/business/headquarters/AddressbookCompanyHeadquartersConverter.java @@ -37,7 +37,7 @@ public class AddressbookCompanyHeadquartersConverter implements Converter { /** * User EJB */ - @EJB (lookup = "java:global/jfinancials-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote") + @EJB (lookup = "java:global/addressbook-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote") private ContactSessionBeanRemote contactBean; /** diff --git a/src/java/org/mxchange/addressbook/converter/country/AddressbookCountryConverter.java b/src/java/org/mxchange/addressbook/converter/country/AddressbookCountryConverter.java index 43085de5..667e43cf 100644 --- a/src/java/org/mxchange/addressbook/converter/country/AddressbookCountryConverter.java +++ b/src/java/org/mxchange/addressbook/converter/country/AddressbookCountryConverter.java @@ -38,7 +38,7 @@ public class AddressbookCountryConverter implements Converter { /** * Country bean */ - @EJB (lookup = "java:global/jfinancials-ejb/country!org.mxchange.jcountry.data.CountrySingletonBeanRemote") + @EJB (lookup = "java:global/addressbook-ejb/country!org.mxchange.jcountry.data.CountrySingletonBeanRemote") private CountrySingletonBeanRemote countryBean; /** diff --git a/src/java/org/mxchange/addressbook/converter/fax/AddressbookFaxNumberConverter.java b/src/java/org/mxchange/addressbook/converter/fax/AddressbookFaxNumberConverter.java index 7f304aec..72fa8328 100644 --- a/src/java/org/mxchange/addressbook/converter/fax/AddressbookFaxNumberConverter.java +++ b/src/java/org/mxchange/addressbook/converter/fax/AddressbookFaxNumberConverter.java @@ -37,7 +37,7 @@ public class AddressbookFaxNumberConverter implements Converter { /** * User EJB */ - @EJB(lookup = "java:global/jfinancials-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote") + @EJB(lookup = "java:global/addressbook-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote") private UserSessionBeanRemote userBean; /** diff --git a/src/java/org/mxchange/addressbook/validator/business/basicdata/AddressbookCompanyNameValidator.java b/src/java/org/mxchange/addressbook/validator/business/basicdata/AddressbookCompanyNameValidator.java index 6fc5a143..9268f034 100644 --- a/src/java/org/mxchange/addressbook/validator/business/basicdata/AddressbookCompanyNameValidator.java +++ b/src/java/org/mxchange/addressbook/validator/business/basicdata/AddressbookCompanyNameValidator.java @@ -42,7 +42,7 @@ public class AddressbookCompanyNameValidator extends BaseStringValidator { /** * Business contact EJB */ - @EJB (lookup = "java:global/jfinancials-ejb/businessData!org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote") + @EJB (lookup = "java:global/addressbook-ejb/businessData!org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote") private BusinessDataSessionBeanRemote basicDataBean; @Override diff --git a/src/java/org/mxchange/addressbook/validator/emailaddress/AddressbookEmailAddressValidator.java b/src/java/org/mxchange/addressbook/validator/emailaddress/AddressbookEmailAddressValidator.java index d5ef9c06..c8ed7676 100644 --- a/src/java/org/mxchange/addressbook/validator/emailaddress/AddressbookEmailAddressValidator.java +++ b/src/java/org/mxchange/addressbook/validator/emailaddress/AddressbookEmailAddressValidator.java @@ -38,7 +38,7 @@ public class AddressbookEmailAddressValidator extends BaseStringValidator { /** * Contact session-scoped bean */ - @EJB (lookup = "java:global/jfinancials-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote") + @EJB (lookup = "java:global/addressbook-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote") private ContactSessionBeanRemote contactBean; /** diff --git a/src/java/org/mxchange/addressbook/validator/user/AddressbookUserIdValidator.java b/src/java/org/mxchange/addressbook/validator/user/AddressbookUserIdValidator.java index d97488d1..40739a9b 100644 --- a/src/java/org/mxchange/addressbook/validator/user/AddressbookUserIdValidator.java +++ b/src/java/org/mxchange/addressbook/validator/user/AddressbookUserIdValidator.java @@ -42,7 +42,7 @@ public class AddressbookUserIdValidator extends BaseNumberValidator { /** * Remote bean */ - @EJB (lookup = "java:global/jfinancials-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote") + @EJB (lookup = "java:global/addressbook-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote") private UserSessionBeanRemote userBean; /** diff --git a/web/guest/user/user_list.xhtml b/web/guest/user/user_list.xhtml index ba2287d6..b1726a33 100644 --- a/web/guest/user/user_list.xhtml +++ b/web/guest/user/user_list.xhtml @@ -22,22 +22,24 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + > -- 2.39.5