From ada0db60b4e854f31403f5104b8b92a23755aa4e Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sun, 17 Apr 2016 17:37:32 +0200 Subject: [PATCH] Continued: - renamed bean/controller as they are session-scoped, else all admins will use the same - fixed object->id converting (opps, forgot it) --- ...PizzaAdminContactPhoneWebSessionBean.java} | 70 +++++++++++++------ ...dminContactPhoneWebSessionController.java} | 20 +++--- .../contact/PizzaContactConverter.java | 17 +++-- 3 files changed, 68 insertions(+), 39 deletions(-) rename src/java/org/mxchange/pizzaapplication/beans/phone/{PizzaAdminContactPhoneWebRequestBean.java => PizzaAdminContactPhoneWebSessionBean.java} (73%) rename src/java/org/mxchange/pizzaapplication/beans/phone/{PizzaAdminContactPhoneWebRequestController.java => PizzaAdminContactPhoneWebSessionController.java} (84%) diff --git a/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebSessionBean.java similarity index 73% rename from src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebRequestBean.java rename to src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebSessionBean.java index c308f40c..5928351b 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebSessionBean.java @@ -16,8 +16,10 @@ */ package org.mxchange.pizzaapplication.beans.phone; +import java.util.HashMap; import java.util.List; -import javax.enterprise.context.RequestScoped; +import java.util.Map; +import javax.enterprise.context.SessionScoped; import javax.faces.view.facelets.FaceletException; import javax.inject.Named; import javax.naming.Context; @@ -28,7 +30,6 @@ import org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote; import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber; import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jusercore.model.user.User; /** * Administrative bean (controller) for contact's phone numbers @@ -36,8 +37,8 @@ import org.mxchange.jusercore.model.user.User; * @author Roland Haeder */ @Named ("adminContactPhoneController") -@RequestScoped -public class PizzaAdminContactPhoneWebRequestBean implements PizzaAdminContactPhoneWebRequestController { +@SessionScoped +public class PizzaAdminContactPhoneWebSessionBean implements PizzaAdminContactPhoneWebSessionController { /** * Serial number @@ -54,6 +55,17 @@ public class PizzaAdminContactPhoneWebRequestBean implements PizzaAdminContactPh */ private DialableCellphoneNumber cellPhone; + /** + * Instance of linked contact account + */ + private Contact contact; + + /** + * "Cache" for contact lists, mostly only one is assigned. So this cache + * shouldn't grow beyond control. + */ + private final Map> contacts; + /** * Fax number */ @@ -64,15 +76,10 @@ public class PizzaAdminContactPhoneWebRequestBean implements PizzaAdminContactPh */ private DialableLandLineNumber landLine; - /** - * Instance of linked user account - */ - private User user; - /** * Default constructor */ - public PizzaAdminContactPhoneWebRequestBean () { + public PizzaAdminContactPhoneWebSessionBean () { // Try it try { // Get initial context @@ -84,11 +91,30 @@ public class PizzaAdminContactPhoneWebRequestBean implements PizzaAdminContactPh // Throw it again throw new FaceletException(e); } + + // Init map + this.contacts = new HashMap<>(10); } @Override public List allCellphoneContacts () { - return this.adminRemoteBean.allContacts(this.getCellPhone()); + // Get id + Long phoneId = this.getCellPhone().getPhoneId(); + + // Is cache there? + if (this.contacts.containsKey(phoneId)) { + // Return cached version + return this.contacts.get(phoneId); + } else { + // Ask bean + List list = this.adminRemoteBean.allContacts(this.getCellPhone()); + + // Store result in cache + this.contacts.put(phoneId, list); + + // Return now-cached list + return list; + } } @Override @@ -101,6 +127,16 @@ public class PizzaAdminContactPhoneWebRequestBean implements PizzaAdminContactPh this.cellPhone = cellPhone; } + @Override + public Contact getContact () { + return this.contact; + } + + @Override + public void setContact (final Contact contact) { + this.contact = contact; + } + @Override public DialableFaxNumber getFax () { return this.fax; @@ -121,16 +157,6 @@ public class PizzaAdminContactPhoneWebRequestBean implements PizzaAdminContactPh this.landLine = landLine; } - @Override - public User getUser () { - return this.user; - } - - @Override - public void setUser (final User user) { - this.user = user; - } - /** * Clears this bean */ @@ -139,7 +165,7 @@ public class PizzaAdminContactPhoneWebRequestBean implements PizzaAdminContactPh this.setCellPhone(null); this.setFax(null); this.setLandLine(null); - this.setUser(null); + this.setContact(null); } } diff --git a/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebSessionController.java similarity index 84% rename from src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebRequestController.java rename to src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebSessionController.java index e39e2043..97321ad7 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebRequestController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebSessionController.java @@ -22,7 +22,6 @@ import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber; import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jusercore.model.user.User; /** * An interface for a request web controller (bean) for administrative phone @@ -30,8 +29,13 @@ import org.mxchange.jusercore.model.user.User; *

* @author Roland Haeder */ -public interface PizzaAdminContactPhoneWebRequestController extends Serializable { +public interface PizzaAdminContactPhoneWebSessionController extends Serializable { + /** + * Getter for all contacts having current cellphone instance linked + *

+ * @return List of all linked contacts + */ List allCellphoneContacts (); /** @@ -77,17 +81,17 @@ public interface PizzaAdminContactPhoneWebRequestController extends Serializable void setCellPhone (final DialableCellphoneNumber cellPhone); /** - * Getter for linked user account + * Getter for linked contact account *

- * @return Linked user account + * @return Linked contact account */ - User getUser (); + Contact getContact (); /** - * Setter for linked user account + * Setter for linked contact account *

- * @param user Linked user account + * @param contact Linked contact account */ - void setUser (final User user); + void setContact (final Contact contact); } diff --git a/src/java/org/mxchange/pizzaapplication/converter/contact/PizzaContactConverter.java b/src/java/org/mxchange/pizzaapplication/converter/contact/PizzaContactConverter.java index c47b7cd8..690eb4e4 100644 --- a/src/java/org/mxchange/pizzaapplication/converter/contact/PizzaContactConverter.java +++ b/src/java/org/mxchange/pizzaapplication/converter/contact/PizzaContactConverter.java @@ -30,7 +30,6 @@ import org.mxchange.jcontacts.contact.ContactSessionBeanRemote; import org.mxchange.jcontacts.exceptions.ContactNotFoundException; import org.mxchange.jcoreeelogger.beans.local.logger.Log; import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal; -import org.mxchange.jusercore.model.user.User; /** * Converter for contact id <-> valid contact instance @@ -41,15 +40,15 @@ import org.mxchange.jusercore.model.user.User; public class PizzaContactConverter implements Converter { /** - * Logger instance + * User EJB */ - @Log - private LoggerBeanLocal loggerBeanLocal; + private ContactSessionBeanRemote contactBean; /** - * User EJB + * Logger instance */ - private ContactSessionBeanRemote contactBean; + @Log + private LoggerBeanLocal loggerBeanLocal; /** * Initialization of this converter @@ -121,13 +120,13 @@ public class PizzaContactConverter implements Converter { if ((null == value) || ((String.valueOf(value)).isEmpty())) { // Is null return ""; //NOI18N - } else if (!(value instanceof User)) { + } else if (!(value instanceof Contact)) { // Not same interface - throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement User.", value)); //NOI18N + throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement Contact.", value)); //NOI18N } // Return category id - return String.valueOf(((User) value).getUserId()); + return String.valueOf(((Contact) value).getContactId()); } } -- 2.39.5