From 799f8beffff66848e76e342892e7694f9d094e0d 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) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- ...sbookAdminContactPhoneWebSessionBean.java} | 72 +++++++++++++------ ...dminContactPhoneWebSessionController.java} | 20 +++--- .../contact/AddressbookContactConverter.java | 17 +++-- 3 files changed, 69 insertions(+), 40 deletions(-) rename src/java/org/mxchange/addressbook/beans/phone/{AddressbookAdminContactPhoneWebRequestBean.java => AddressbookAdminContactPhoneWebSessionBean.java} (70%) rename src/java/org/mxchange/addressbook/beans/phone/{AddressbookAdminContactPhoneWebRequestController.java => AddressbookAdminContactPhoneWebSessionController.java} (84%) diff --git a/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebSessionBean.java similarity index 70% rename from src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebRequestBean.java rename to src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebSessionBean.java index b422fead..2d6718bf 100644 --- a/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebSessionBean.java @@ -16,8 +16,10 @@ */ package org.mxchange.addressbook.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 AddressbookAdminContactPhoneWebRequestBean implements AddressbookAdminContactPhoneWebRequestController { +@SessionScoped +public class AddressbookAdminContactPhoneWebSessionBean implements AddressbookAdminContactPhoneWebSessionController { /** * Serial number @@ -54,6 +55,17 @@ public class AddressbookAdminContactPhoneWebRequestBean implements AddressbookAd */ 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,31 +76,45 @@ public class AddressbookAdminContactPhoneWebRequestBean implements AddressbookAd */ private DialableLandLineNumber landLine; - /** - * Instance of linked user account - */ - private User user; - /** * Default constructor */ - public AddressbookAdminContactPhoneWebRequestBean () { + public AddressbookAdminContactPhoneWebSessionBean () { // Try it try { // Get initial context Context context = new InitialContext(); // Try to lookup the beans - this.adminRemoteBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/addressbook-ejb/admincontactphone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N + this.adminRemoteBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/PizzaService-ejb/admincontactphone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N } catch (final NamingException e) { // 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 AddressbookAdminContactPhoneWebRequestBean implements AddressbookAd 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 AddressbookAdminContactPhoneWebRequestBean implements AddressbookAd 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 AddressbookAdminContactPhoneWebRequestBean implements AddressbookAd this.setCellPhone(null); this.setFax(null); this.setLandLine(null); - this.setUser(null); + this.setContact(null); } } diff --git a/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebRequestController.java b/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebSessionController.java similarity index 84% rename from src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebRequestController.java rename to src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebSessionController.java index 63c1a348..b9442338 100644 --- a/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebRequestController.java +++ b/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebSessionController.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 AddressbookAdminContactPhoneWebRequestController extends Serializable { +public interface AddressbookAdminContactPhoneWebSessionController 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 AddressbookAdminContactPhoneWebRequestController extends Serial 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/addressbook/converter/contact/AddressbookContactConverter.java b/src/java/org/mxchange/addressbook/converter/contact/AddressbookContactConverter.java index f0c67ab4..f77e3391 100644 --- a/src/java/org/mxchange/addressbook/converter/contact/AddressbookContactConverter.java +++ b/src/java/org/mxchange/addressbook/converter/contact/AddressbookContactConverter.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 AddressbookContactConverter 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 AddressbookContactConverter 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