From: Roland Haeder Date: Sun, 17 Apr 2016 15:37:32 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=799f8beffff66848e76e342892e7694f9d094e0d;p=jfinancials-war.git Continued: - renamed bean/controller as they are session-scoped, else all admins will use the same - fixed object->id converting (opps, forgot it) Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebRequestBean.java deleted file mode 100644 index b422fead..00000000 --- a/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebRequestBean.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.addressbook.beans.phone; - -import java.util.List; -import javax.enterprise.context.RequestScoped; -import javax.faces.view.facelets.FaceletException; -import javax.inject.Named; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import org.mxchange.jcontacts.contact.Contact; -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 - *

- * @author Roland Haeder - */ -@Named ("adminContactPhoneController") -@RequestScoped -public class AddressbookAdminContactPhoneWebRequestBean implements AddressbookAdminContactPhoneWebRequestController { - - /** - * Serial number - */ - private static final long serialVersionUID = 184_598_175_371_269_016L; - - /** - * Remote EJB for phone number (administrative) - */ - private AdminContactsPhoneSessionBeanRemote adminRemoteBean; - - /** - * Cell phone number - */ - private DialableCellphoneNumber cellPhone; - - /** - * Fax number - */ - private DialableFaxNumber fax; - - /** - * Land-line number - */ - private DialableLandLineNumber landLine; - - /** - * Instance of linked user account - */ - private User user; - - /** - * Default constructor - */ - public AddressbookAdminContactPhoneWebRequestBean () { - // 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 - } catch (final NamingException e) { - // Throw it again - throw new FaceletException(e); - } - } - - @Override - public List allCellphoneContacts () { - return this.adminRemoteBean.allContacts(this.getCellPhone()); - } - - @Override - public DialableCellphoneNumber getCellPhone () { - return this.cellPhone; - } - - @Override - public void setCellPhone (final DialableCellphoneNumber cellPhone) { - this.cellPhone = cellPhone; - } - - @Override - public DialableFaxNumber getFax () { - return this.fax; - } - - @Override - public void setFax (final DialableFaxNumber fax) { - this.fax = fax; - } - - @Override - public DialableLandLineNumber getLandLine () { - return this.landLine; - } - - @Override - public void setLandLine (final DialableLandLineNumber landLine) { - this.landLine = landLine; - } - - @Override - public User getUser () { - return this.user; - } - - @Override - public void setUser (final User user) { - this.user = user; - } - - /** - * Clears this bean - */ - private void clear () { - // Clear all instances - this.setCellPhone(null); - this.setFax(null); - this.setLandLine(null); - this.setUser(null); - } - -} diff --git a/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebRequestController.java b/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebRequestController.java deleted file mode 100644 index 63c1a348..00000000 --- a/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebRequestController.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.addressbook.beans.phone; - -import java.io.Serializable; -import java.util.List; -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 - * number purposes. - *

- * @author Roland Haeder - */ -public interface AddressbookAdminContactPhoneWebRequestController extends Serializable { - - List allCellphoneContacts (); - - /** - * Getter for dialable cellphone number instance - *

- * @return Dialable cellphone number instance - */ - DialableCellphoneNumber getCellPhone (); - - /** - * Setter for dialable land-line number instance - *

- * @param landLine Dialable land-line number instance - */ - void setLandLine (final DialableLandLineNumber landLine); - - /** - * Getter for dialable land-line number instance - *

- * @return Dialable land-line number instance - */ - DialableLandLineNumber getLandLine (); - - /** - * Setter for dialable fax number instance - *

- * @param fax Dialable fax number instance - */ - void setFax (final DialableFaxNumber fax); - - /** - * Getter for dialable fax number instance - *

- * @return Dialable fax number instance - */ - DialableFaxNumber getFax (); - - /** - * Setter for dialable cellphone number instance - *

- * @param cellPhone Dialable cellphone number instance - */ - void setCellPhone (final DialableCellphoneNumber cellPhone); - - /** - * Getter for linked user account - *

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

- * @param user Linked user account - */ - void setUser (final User user); - -} diff --git a/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebSessionBean.java new file mode 100644 index 00000000..2d6718bf --- /dev/null +++ b/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebSessionBean.java @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.addressbook.beans.phone; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.enterprise.context.SessionScoped; +import javax.faces.view.facelets.FaceletException; +import javax.inject.Named; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import org.mxchange.jcontacts.contact.Contact; +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; + +/** + * Administrative bean (controller) for contact's phone numbers + *

+ * @author Roland Haeder + */ +@Named ("adminContactPhoneController") +@SessionScoped +public class AddressbookAdminContactPhoneWebSessionBean implements AddressbookAdminContactPhoneWebSessionController { + + /** + * Serial number + */ + private static final long serialVersionUID = 184_598_175_371_269_016L; + + /** + * Remote EJB for phone number (administrative) + */ + private AdminContactsPhoneSessionBeanRemote adminRemoteBean; + + /** + * Cell phone number + */ + 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 + */ + private DialableFaxNumber fax; + + /** + * Land-line number + */ + private DialableLandLineNumber landLine; + + /** + * Default constructor + */ + public AddressbookAdminContactPhoneWebSessionBean () { + // Try it + try { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup the beans + 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 () { + // 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 + public DialableCellphoneNumber getCellPhone () { + return this.cellPhone; + } + + @Override + public void setCellPhone (final DialableCellphoneNumber cellPhone) { + 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; + } + + @Override + public void setFax (final DialableFaxNumber fax) { + this.fax = fax; + } + + @Override + public DialableLandLineNumber getLandLine () { + return this.landLine; + } + + @Override + public void setLandLine (final DialableLandLineNumber landLine) { + this.landLine = landLine; + } + + /** + * Clears this bean + */ + private void clear () { + // Clear all instances + this.setCellPhone(null); + this.setFax(null); + this.setLandLine(null); + this.setContact(null); + } + +} diff --git a/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebSessionController.java b/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebSessionController.java new file mode 100644 index 00000000..b9442338 --- /dev/null +++ b/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebSessionController.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.addressbook.beans.phone; + +import java.io.Serializable; +import java.util.List; +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; + +/** + * An interface for a request web controller (bean) for administrative phone + * number purposes. + *

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

+ * @return List of all linked contacts + */ + List allCellphoneContacts (); + + /** + * Getter for dialable cellphone number instance + *

+ * @return Dialable cellphone number instance + */ + DialableCellphoneNumber getCellPhone (); + + /** + * Setter for dialable land-line number instance + *

+ * @param landLine Dialable land-line number instance + */ + void setLandLine (final DialableLandLineNumber landLine); + + /** + * Getter for dialable land-line number instance + *

+ * @return Dialable land-line number instance + */ + DialableLandLineNumber getLandLine (); + + /** + * Setter for dialable fax number instance + *

+ * @param fax Dialable fax number instance + */ + void setFax (final DialableFaxNumber fax); + + /** + * Getter for dialable fax number instance + *

+ * @return Dialable fax number instance + */ + DialableFaxNumber getFax (); + + /** + * Setter for dialable cellphone number instance + *

+ * @param cellPhone Dialable cellphone number instance + */ + void setCellPhone (final DialableCellphoneNumber cellPhone); + + /** + * Getter for linked contact account + *

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

+ * @param contact Linked contact account + */ + 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()); } }