From c816e222013119da5a8e4d27e18b5924f0212c66 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 12 Aug 2017 16:18:57 +0200 Subject: [PATCH] Opps, 'abstract' went in by using "move-up" from NetBeans IDE ... Well, at the end, NB is no aritificial intelligence that 100% understood your code, right? MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Also fixed naming-convention, project's short name must be prefixed on all classes Signed-off-by: Roland Häder --- .../PizzaUserActivitySessionBean.java | 134 +------- .../model/category/CategorySessionBean.java | 206 ------------- ...ava => PizzaAdminCategorySessionBean.java} | 136 +-------- .../category/PizzaCategorySessionBean.java | 74 +++++ ...ean.java => PizzaCheckoutMessageBean.java} | 136 +-------- .../customer/ShopCustomerSessionBean.java | 285 ------------------ ...java => PizzaAdminProductSessionBean.java} | 136 +-------- .../product/PizzaProductSessionBean.java | 105 +++++++ .../model/product/ProductSessionBean.java | 237 --------------- 9 files changed, 186 insertions(+), 1263 deletions(-) delete mode 100644 src/java/org/mxchange/pizzaapplication/model/category/CategorySessionBean.java rename src/java/org/mxchange/pizzaapplication/model/category/{AdminCategorySessionBean.java => PizzaAdminCategorySessionBean.java} (50%) create mode 100644 src/java/org/mxchange/pizzaapplication/model/category/PizzaCategorySessionBean.java rename src/java/org/mxchange/pizzaapplication/model/checkout/{CheckoutMessageBean.java => PizzaCheckoutMessageBean.java} (58%) delete mode 100644 src/java/org/mxchange/pizzaapplication/model/customer/ShopCustomerSessionBean.java rename src/java/org/mxchange/pizzaapplication/model/product/{AdminProductSessionBean.java => PizzaAdminProductSessionBean.java} (53%) create mode 100644 src/java/org/mxchange/pizzaapplication/model/product/PizzaProductSessionBean.java delete mode 100644 src/java/org/mxchange/pizzaapplication/model/product/ProductSessionBean.java diff --git a/src/java/org/mxchange/jusercore/model/user/activity/PizzaUserActivitySessionBean.java b/src/java/org/mxchange/jusercore/model/user/activity/PizzaUserActivitySessionBean.java index 3f4aa6c..f802f91 100644 --- a/src/java/org/mxchange/jusercore/model/user/activity/PizzaUserActivitySessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/activity/PizzaUserActivitySessionBean.java @@ -19,13 +19,8 @@ package org.mxchange.jusercore.model.user.activity; import java.text.MessageFormat; import java.util.Arrays; import java.util.List; -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; import javax.ejb.EJBException; import javax.ejb.Stateless; -import javax.faces.application.FacesMessage; -import javax.faces.context.FacesContext; import javax.jms.JMSException; import javax.jms.ObjectMessage; import javax.persistence.Query; @@ -40,7 +35,7 @@ import org.mxchange.jusercore.model.user.User; * @author Roland Häder */ @Stateless (name = "userActivity", description = "A bean handling the user data") -public abstract class PizzaUserActivitySessionBean extends BaseDatabaseBean implements UserActivityLogSessionBeanRemote { +public class PizzaUserActivitySessionBean extends BaseDatabaseBean implements UserActivityLogSessionBeanRemote { /** * Serial number @@ -232,131 +227,4 @@ public abstract class PizzaUserActivitySessionBean extends BaseDatabaseBean impl return list; } - /** - * Returns given property key or throws an exception if not found. - *

- * @param parameterKey Property key - *

- * @return Property value - *

- * @throws NullPointerException If given key is not found - * @throws NumberFormatException If no number is given in context parameter - */ - protected int getIntegerContextParameter (final String parameterKey) throws NullPointerException, NumberFormatException { - // Get context parameter - Integer contextValue = Integer.parseInt(this.getStringContextParameter(parameterKey)); - // Return it - return contextValue; - } - - /** - * Returns given property key or throws an exception if not found. - *

- * @param parameterKey Property key - *

- * @return Property value - *

- * @throws NullPointerException If given key is not found - */ - protected String getStringContextParameter (final String parameterKey) throws NullPointerException { - // Get context parameter - String contextValue = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(parameterKey); - // Is it null? - if (null == contextValue) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("parameterKey={0} is not set.", parameterKey)); //NOI18N - } - // Return it - return contextValue; - } - - /** - * Checks whether debug mode is enabled for given controller - *

- * @param controllerName Name of controller - *

- * @return Whether debug mode is enabled - */ - protected boolean isDebugModeEnabled (final String controllerName) { - // Parameters should be valid - if (null == controllerName) { - // Throw NPE - throw new NullPointerException("controllerName is null"); //NOI18N - } else if (controllerName.isEmpty()) { - // Is empty - throw new IllegalArgumentException("controllerName is empty"); //NOI18N - } - // Try to get context parameter - String contextParameter = this.getStringContextParameter(String.format("is_debug_%s_enabled", controllerName)); //NOI18N - // Is it set and true? - boolean isEnabled = Boolean.parseBoolean(contextParameter) == Boolean.TRUE; - // Return it - return isEnabled; - } - - /** - * Loads resource bundle for given locale. This must be implemented per - * project so all projects can still customize their methods. Calling - * ResourceBundleloadBundle() in this class means that also the bundle files - * must be present here. - *

- * @param locale Locale from e.g. FacesContext - *

- * @return Initialized and loaded resource bundle - */ - protected abstract ResourceBundle loadResourceBundle (final Locale locale); - - /** - * Shows a faces message for given causing exception. The message from the - * exception is being inserted into the message. - *

- * @param clientId Client id to send message to - * @param cause Causing exception - */ - protected void showFacesMessage (final String clientId, final Throwable cause) { - // Get context and add message - this.showFacesMessage(clientId, cause.getMessage()); - } - - /** - * Shows a faces message with given message (i18n) key. - *

- * @param clientId Client id to send message to - * @param i18nKey Message key - *

- * @throws NullPointerException If clientId or i18nKey is null - * @throws IllegalArgumentException If clientId or i18nKey is empty - */ - protected void showFacesMessage (final String clientId, final String i18nKey) throws NullPointerException, IllegalArgumentException { - // Both parameter must be valid - if (null == clientId) { - // Throw NPE - throw new NullPointerException("clientId is null"); //NOI18N - } else if (clientId.isEmpty()) { - // Is empty - throw new IllegalArgumentException("clientId is null"); //NOI18N - } else if (null == i18nKey) { - // Throw NPE - throw new NullPointerException("i18nKey is null"); //NOI18N - } else if (i18nKey.isEmpty()) { - // Is empty - throw new IllegalArgumentException("i18nKey is null"); //NOI18N - } - // Get current locale - Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); - // Get bundle bundle - ResourceBundle bundle = this.loadResourceBundle(locale); - // Default is i18nKey - String message = MessageFormat.format("!{0}!", i18nKey); //NOI18N - // Try it - try { - // Get message - message = bundle.getString(i18nKey); - } catch (final MissingResourceException ex) { - // Did not find it, ignored - } - // Get context and add message - FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(message)); - } - } diff --git a/src/java/org/mxchange/pizzaapplication/model/category/CategorySessionBean.java b/src/java/org/mxchange/pizzaapplication/model/category/CategorySessionBean.java deleted file mode 100644 index 683246f..0000000 --- a/src/java/org/mxchange/pizzaapplication/model/category/CategorySessionBean.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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.pizzaapplication.model.category; - -import java.text.MessageFormat; -import java.util.List; -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; -import javax.ejb.Stateless; -import javax.faces.application.FacesMessage; -import javax.faces.context.FacesContext; -import javax.persistence.Query; -import org.mxchange.jcoreee.database.BaseDatabaseBean; -import org.mxchange.jproduct.model.category.Category; -import org.mxchange.jproduct.model.category.ProductCategory; -import org.mxchange.jshopcore.model.category.CategorySessionBeanRemote; - -/** - * Main shop class - *

- * @author Roland Häder - */ -@Stateless (name = "category", description = "A bean handling categories for all others (non-admin)") -public abstract class CategorySessionBean extends BaseDatabaseBean implements CategorySessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 58_137_539_530_279L; - - /** - * Default constructor - */ - public CategorySessionBean () { - // Call super constructor - super(); - } - - @Override - @SuppressWarnings ("unchecked") - public List getAllCategories () { - // Trace message - this.getLoggerBeanLocal().logTrace("getAllCategories: CALLED!"); //NOI18N - - // The connection must be there - if (this.getEntityManager() == null) { - // Connection is not there - throw new NullPointerException("connection is null"); //NOI18N - } - - // Create statement - Query query = this.getEntityManager().createQuery("SELECT c FROM category AS c ORDER BY c.categoryId ASC", ProductCategory.class); - - // Get result - List list = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("getAllCategories: list({0})={1} - EXIT!", list.size(), list)); //NOI18N - - // Return it - return list; - } - - /** - * Returns given property key or throws an exception if not found. - *

- * @param parameterKey Property key - *

- * @return Property value - *

- * @throws NullPointerException If given key is not found - * @throws NumberFormatException If no number is given in context parameter - */ - protected int getIntegerContextParameter (final String parameterKey) throws NullPointerException, NumberFormatException { - // Get context parameter - Integer contextValue = Integer.parseInt(this.getStringContextParameter(parameterKey)); - // Return it - return contextValue; - } - - /** - * Returns given property key or throws an exception if not found. - *

- * @param parameterKey Property key - *

- * @return Property value - *

- * @throws NullPointerException If given key is not found - */ - protected String getStringContextParameter (final String parameterKey) throws NullPointerException { - // Get context parameter - String contextValue = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(parameterKey); - // Is it null? - if (null == contextValue) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("parameterKey={0} is not set.", parameterKey)); //NOI18N - } - // Return it - return contextValue; - } - - /** - * Checks whether debug mode is enabled for given controller - *

- * @param controllerName Name of controller - *

- * @return Whether debug mode is enabled - */ - protected boolean isDebugModeEnabled (final String controllerName) { - // Parameters should be valid - if (null == controllerName) { - // Throw NPE - throw new NullPointerException("controllerName is null"); //NOI18N - } else if (controllerName.isEmpty()) { - // Is empty - throw new IllegalArgumentException("controllerName is empty"); //NOI18N - } - // Try to get context parameter - String contextParameter = this.getStringContextParameter(String.format("is_debug_%s_enabled", controllerName)); //NOI18N - // Is it set and true? - boolean isEnabled = Boolean.parseBoolean(contextParameter) == Boolean.TRUE; - // Return it - return isEnabled; - } - - /** - * Loads resource bundle for given locale. This must be implemented per - * project so all projects can still customize their methods. Calling - * ResourceBundleloadBundle() in this class means that also the bundle files - * must be present here. - *

- * @param locale Locale from e.g. FacesContext - *

- * @return Initialized and loaded resource bundle - */ - protected abstract ResourceBundle loadResourceBundle (final Locale locale); - - /** - * Shows a faces message for given causing exception. The message from the - * exception is being inserted into the message. - *

- * @param clientId Client id to send message to - * @param cause Causing exception - */ - protected void showFacesMessage (final String clientId, final Throwable cause) { - // Get context and add message - this.showFacesMessage(clientId, cause.getMessage()); - } - - /** - * Shows a faces message with given message (i18n) key. - *

- * @param clientId Client id to send message to - * @param i18nKey Message key - *

- * @throws NullPointerException If clientId or i18nKey is null - * @throws IllegalArgumentException If clientId or i18nKey is empty - */ - protected void showFacesMessage (final String clientId, final String i18nKey) throws NullPointerException, IllegalArgumentException { - // Both parameter must be valid - if (null == clientId) { - // Throw NPE - throw new NullPointerException("clientId is null"); //NOI18N - } else if (clientId.isEmpty()) { - // Is empty - throw new IllegalArgumentException("clientId is null"); //NOI18N - } else if (null == i18nKey) { - // Throw NPE - throw new NullPointerException("i18nKey is null"); //NOI18N - } else if (i18nKey.isEmpty()) { - // Is empty - throw new IllegalArgumentException("i18nKey is null"); //NOI18N - } - // Get current locale - Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); - // Get bundle bundle - ResourceBundle bundle = this.loadResourceBundle(locale); - // Default is i18nKey - String message = MessageFormat.format("!{0}!", i18nKey); //NOI18N - // Try it - try { - // Get message - message = bundle.getString(i18nKey); - } catch (final MissingResourceException ex) { - // Did not find it, ignored - } - // Get context and add message - FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(message)); - } - -} diff --git a/src/java/org/mxchange/pizzaapplication/model/category/AdminCategorySessionBean.java b/src/java/org/mxchange/pizzaapplication/model/category/PizzaAdminCategorySessionBean.java similarity index 50% rename from src/java/org/mxchange/pizzaapplication/model/category/AdminCategorySessionBean.java rename to src/java/org/mxchange/pizzaapplication/model/category/PizzaAdminCategorySessionBean.java index 9e68174..e2a7ca5 100644 --- a/src/java/org/mxchange/pizzaapplication/model/category/AdminCategorySessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/model/category/PizzaAdminCategorySessionBean.java @@ -17,12 +17,7 @@ package org.mxchange.pizzaapplication.model.category; import java.text.MessageFormat; -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; import javax.ejb.Stateless; -import javax.faces.application.FacesMessage; -import javax.faces.context.FacesContext; import javax.persistence.EntityNotFoundException; import javax.persistence.NoResultException; import javax.persistence.Query; @@ -39,7 +34,7 @@ import org.mxchange.jshopcore.model.category.AdminCategorySessionBeanRemote; * @author Roland Häder */ @Stateless (name = "admin_category", description = "An administrative bean handling product categories") -public abstract class AdminCategorySessionBean extends BaseDatabaseBean implements AdminCategorySessionBeanRemote { +public class PizzaAdminCategorySessionBean extends BaseDatabaseBean implements AdminCategorySessionBeanRemote { /** * Serial number @@ -49,7 +44,7 @@ public abstract class AdminCategorySessionBean extends BaseDatabaseBean implemen /** * Default constructor */ - public AdminCategorySessionBean () { + public PizzaAdminCategorySessionBean () { // Call super constructor super(); } @@ -140,131 +135,4 @@ public abstract class AdminCategorySessionBean extends BaseDatabaseBean implemen return isUsed; } - /** - * Returns given property key or throws an exception if not found. - *

- * @param parameterKey Property key - *

- * @return Property value - *

- * @throws NullPointerException If given key is not found - * @throws NumberFormatException If no number is given in context parameter - */ - protected int getIntegerContextParameter (final String parameterKey) throws NullPointerException, NumberFormatException { - // Get context parameter - Integer contextValue = Integer.parseInt(this.getStringContextParameter(parameterKey)); - // Return it - return contextValue; - } - - /** - * Returns given property key or throws an exception if not found. - *

- * @param parameterKey Property key - *

- * @return Property value - *

- * @throws NullPointerException If given key is not found - */ - protected String getStringContextParameter (final String parameterKey) throws NullPointerException { - // Get context parameter - String contextValue = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(parameterKey); - // Is it null? - if (null == contextValue) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("parameterKey={0} is not set.", parameterKey)); //NOI18N - } - // Return it - return contextValue; - } - - /** - * Checks whether debug mode is enabled for given controller - *

- * @param controllerName Name of controller - *

- * @return Whether debug mode is enabled - */ - protected boolean isDebugModeEnabled (final String controllerName) { - // Parameters should be valid - if (null == controllerName) { - // Throw NPE - throw new NullPointerException("controllerName is null"); //NOI18N - } else if (controllerName.isEmpty()) { - // Is empty - throw new IllegalArgumentException("controllerName is empty"); //NOI18N - } - // Try to get context parameter - String contextParameter = this.getStringContextParameter(String.format("is_debug_%s_enabled", controllerName)); //NOI18N - // Is it set and true? - boolean isEnabled = Boolean.parseBoolean(contextParameter) == Boolean.TRUE; - // Return it - return isEnabled; - } - - /** - * Loads resource bundle for given locale. This must be implemented per - * project so all projects can still customize their methods. Calling - * ResourceBundleloadBundle() in this class means that also the bundle files - * must be present here. - *

- * @param locale Locale from e.g. FacesContext - *

- * @return Initialized and loaded resource bundle - */ - protected abstract ResourceBundle loadResourceBundle (final Locale locale); - - /** - * Shows a faces message for given causing exception. The message from the - * exception is being inserted into the message. - *

- * @param clientId Client id to send message to - * @param cause Causing exception - */ - protected void showFacesMessage (final String clientId, final Throwable cause) { - // Get context and add message - this.showFacesMessage(clientId, cause.getMessage()); - } - - /** - * Shows a faces message with given message (i18n) key. - *

- * @param clientId Client id to send message to - * @param i18nKey Message key - *

- * @throws NullPointerException If clientId or i18nKey is null - * @throws IllegalArgumentException If clientId or i18nKey is empty - */ - protected void showFacesMessage (final String clientId, final String i18nKey) throws NullPointerException, IllegalArgumentException { - // Both parameter must be valid - if (null == clientId) { - // Throw NPE - throw new NullPointerException("clientId is null"); //NOI18N - } else if (clientId.isEmpty()) { - // Is empty - throw new IllegalArgumentException("clientId is null"); //NOI18N - } else if (null == i18nKey) { - // Throw NPE - throw new NullPointerException("i18nKey is null"); //NOI18N - } else if (i18nKey.isEmpty()) { - // Is empty - throw new IllegalArgumentException("i18nKey is null"); //NOI18N - } - // Get current locale - Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); - // Get bundle bundle - ResourceBundle bundle = this.loadResourceBundle(locale); - // Default is i18nKey - String message = MessageFormat.format("!{0}!", i18nKey); //NOI18N - // Try it - try { - // Get message - message = bundle.getString(i18nKey); - } catch (final MissingResourceException ex) { - // Did not find it, ignored - } - // Get context and add message - FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(message)); - } - } diff --git a/src/java/org/mxchange/pizzaapplication/model/category/PizzaCategorySessionBean.java b/src/java/org/mxchange/pizzaapplication/model/category/PizzaCategorySessionBean.java new file mode 100644 index 0000000..dddbc24 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/model/category/PizzaCategorySessionBean.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * 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.pizzaapplication.model.category; + +import java.text.MessageFormat; +import java.util.List; +import javax.ejb.Stateless; +import javax.persistence.Query; +import org.mxchange.jcoreee.database.BaseDatabaseBean; +import org.mxchange.jproduct.model.category.Category; +import org.mxchange.jproduct.model.category.ProductCategory; +import org.mxchange.jshopcore.model.category.CategorySessionBeanRemote; + +/** + * Main shop class + *

+ * @author Roland Häder + */ +@Stateless (name = "category", description = "A bean handling categories for all others (non-admin)") +public class PizzaCategorySessionBean extends BaseDatabaseBean implements CategorySessionBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 58_137_539_530_279L; + + /** + * Default constructor + */ + public PizzaCategorySessionBean () { + // Call super constructor + super(); + } + + @Override + @SuppressWarnings ("unchecked") + public List getAllCategories () { + // Trace message + this.getLoggerBeanLocal().logTrace("getAllCategories: CALLED!"); //NOI18N + + // The connection must be there + if (this.getEntityManager() == null) { + // Connection is not there + throw new NullPointerException("connection is null"); //NOI18N + } + + // Create statement + Query query = this.getEntityManager().createQuery("SELECT c FROM category AS c ORDER BY c.categoryId ASC", ProductCategory.class); + + // Get result + List list = query.getResultList(); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("getAllCategories: list({0})={1} - EXIT!", list.size(), list)); //NOI18N + + // Return it + return list; + } + +} diff --git a/src/java/org/mxchange/pizzaapplication/model/checkout/CheckoutMessageBean.java b/src/java/org/mxchange/pizzaapplication/model/checkout/PizzaCheckoutMessageBean.java similarity index 58% rename from src/java/org/mxchange/pizzaapplication/model/checkout/CheckoutMessageBean.java rename to src/java/org/mxchange/pizzaapplication/model/checkout/PizzaCheckoutMessageBean.java index b2bfcbb..723653d 100644 --- a/src/java/org/mxchange/pizzaapplication/model/checkout/CheckoutMessageBean.java +++ b/src/java/org/mxchange/pizzaapplication/model/checkout/PizzaCheckoutMessageBean.java @@ -19,14 +19,9 @@ package org.mxchange.pizzaapplication.model.checkout; import java.io.Serializable; import java.text.MessageFormat; import java.util.List; -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; import javax.ejb.ActivationConfigProperty; import javax.ejb.EJB; import javax.ejb.MessageDriven; -import javax.faces.application.FacesMessage; -import javax.faces.context.FacesContext; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageListener; @@ -58,7 +53,7 @@ import org.mxchange.jshopcore.wrapper.WrapableCheckout; @ActivationConfigProperty (propertyName = "destinationLookup", propertyValue = "jms/shopCheckoutQueue") } ) -public abstract class CheckoutMessageBean extends BaseBean implements MessageListener { +public class PizzaCheckoutMessageBean extends BaseBean implements MessageListener { /** * Serial number @@ -92,7 +87,7 @@ public abstract class CheckoutMessageBean extends BaseBean implements MessageLis /** * Default constructor */ - public CheckoutMessageBean () { + public PizzaCheckoutMessageBean () { // Call super constructor super(); @@ -217,131 +212,4 @@ public abstract class CheckoutMessageBean extends BaseBean implements MessageLis this.loggerBeanLocal.logTrace("onMessage: EXIT!"); //NOI18N } - /** - * Returns given property key or throws an exception if not found. - *

- * @param parameterKey Property key - *

- * @return Property value - *

- * @throws NullPointerException If given key is not found - * @throws NumberFormatException If no number is given in context parameter - */ - protected int getIntegerContextParameter (final String parameterKey) throws NullPointerException, NumberFormatException { - // Get context parameter - Integer contextValue = Integer.parseInt(this.getStringContextParameter(parameterKey)); - // Return it - return contextValue; - } - - /** - * Returns given property key or throws an exception if not found. - *

- * @param parameterKey Property key - *

- * @return Property value - *

- * @throws NullPointerException If given key is not found - */ - protected String getStringContextParameter (final String parameterKey) throws NullPointerException { - // Get context parameter - String contextValue = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(parameterKey); - // Is it null? - if (null == contextValue) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("parameterKey={0} is not set.", parameterKey)); //NOI18N - } - // Return it - return contextValue; - } - - /** - * Checks whether debug mode is enabled for given controller - *

- * @param controllerName Name of controller - *

- * @return Whether debug mode is enabled - */ - protected boolean isDebugModeEnabled (final String controllerName) { - // Parameters should be valid - if (null == controllerName) { - // Throw NPE - throw new NullPointerException("controllerName is null"); //NOI18N - } else if (controllerName.isEmpty()) { - // Is empty - throw new IllegalArgumentException("controllerName is empty"); //NOI18N - } - // Try to get context parameter - String contextParameter = this.getStringContextParameter(String.format("is_debug_%s_enabled", controllerName)); //NOI18N - // Is it set and true? - boolean isEnabled = Boolean.parseBoolean(contextParameter) == Boolean.TRUE; - // Return it - return isEnabled; - } - - /** - * Loads resource bundle for given locale. This must be implemented per - * project so all projects can still customize their methods. Calling - * ResourceBundleloadBundle() in this class means that also the bundle files - * must be present here. - *

- * @param locale Locale from e.g. FacesContext - *

- * @return Initialized and loaded resource bundle - */ - protected abstract ResourceBundle loadResourceBundle (final Locale locale); - - /** - * Shows a faces message for given causing exception. The message from the - * exception is being inserted into the message. - *

- * @param clientId Client id to send message to - * @param cause Causing exception - */ - protected void showFacesMessage (final String clientId, final Throwable cause) { - // Get context and add message - this.showFacesMessage(clientId, cause.getMessage()); - } - - /** - * Shows a faces message with given message (i18n) key. - *

- * @param clientId Client id to send message to - * @param i18nKey Message key - *

- * @throws NullPointerException If clientId or i18nKey is null - * @throws IllegalArgumentException If clientId or i18nKey is empty - */ - protected void showFacesMessage (final String clientId, final String i18nKey) throws NullPointerException, IllegalArgumentException { - // Both parameter must be valid - if (null == clientId) { - // Throw NPE - throw new NullPointerException("clientId is null"); //NOI18N - } else if (clientId.isEmpty()) { - // Is empty - throw new IllegalArgumentException("clientId is null"); //NOI18N - } else if (null == i18nKey) { - // Throw NPE - throw new NullPointerException("i18nKey is null"); //NOI18N - } else if (i18nKey.isEmpty()) { - // Is empty - throw new IllegalArgumentException("i18nKey is null"); //NOI18N - } - // Get current locale - Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); - // Get bundle bundle - ResourceBundle bundle = this.loadResourceBundle(locale); - // Default is i18nKey - String message = MessageFormat.format("!{0}!", i18nKey); //NOI18N - // Try it - try { - // Get message - message = bundle.getString(i18nKey); - } catch (final MissingResourceException ex) { - // Did not find it, ignored - } - // Get context and add message - FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(message)); - } - } diff --git a/src/java/org/mxchange/pizzaapplication/model/customer/ShopCustomerSessionBean.java b/src/java/org/mxchange/pizzaapplication/model/customer/ShopCustomerSessionBean.java deleted file mode 100644 index b5be173..0000000 --- a/src/java/org/mxchange/pizzaapplication/model/customer/ShopCustomerSessionBean.java +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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.pizzaapplication.model.customer; - -import java.text.MessageFormat; -import java.util.GregorianCalendar; -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; -import javax.ejb.Stateless; -import javax.faces.application.FacesMessage; -import javax.faces.context.FacesContext; -import javax.persistence.EntityNotFoundException; -import org.mxchange.jcoreee.database.BaseDatabaseBean; -import org.mxchange.jcustomercore.exceptions.CustomerAlreadyRegisteredException; -import org.mxchange.jcustomercore.exceptions.CustomerNotFoundException; -import org.mxchange.jcustomercore.model.customer.Customer; -import org.mxchange.jcustomercore.model.customer.CustomerSessionBeanRemote; - -/** - * A customer bean which hides the customer instance - *

- * @author Roland Häder - */ -@Stateless (name = "shop_customer", description = "A bean handling the customer data") -public abstract class ShopCustomerSessionBean extends BaseDatabaseBean implements CustomerSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 542_145_347_916L; - - /** - * Default constructor - */ - public ShopCustomerSessionBean () { - // Call super constructor - super(); - } - - @Override - public Customer fillCustomerData (final Customer customer) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("fillCustomerData: customer={0} - CALLED!", customer)); //NOI18N - - // customer should not be null - if (null == customer) { - // Abort here - throw new NullPointerException("customer is null"); //NOI18N - } - - // Try it - try { - // Try to locate it - Customer cat = this.getEntityManager().getReference(Customer.class, customer); - - // Copy all data - customer.copyAll(cat); - } catch (final EntityNotFoundException ex) { - // Log it - this.getLoggerBeanLocal().logException(ex); - - // Return null - return null; - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("fillCustomerData: customer={0} - EXIT!", customer)); //NOI18N - - // Return prepared instance - return customer; - } - - @Override - public Customer findCustomerById (final Long customerId) throws CustomerNotFoundException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public boolean isRegistered (final Customer customer) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("isRegistered: customer={0} - CALLED!", customer)); //NOI18N - - // customer should not be null - if (null == customer) { - // Abort here - throw new NullPointerException("customer is null"); //NOI18N - } - - // Try this - try { - Customer c = this.getEntityManager().getReference(Customer.class, customer); - } catch (final EntityNotFoundException ex) { - // Log it - this.getLoggerBeanLocal().logException(ex); - - // Did not finish - return false; - } - - // Found it - return true; - } - - @Override - public Customer registerCustomer (final Customer customer) throws CustomerAlreadyRegisteredException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("registerCustomer: customer={0} - CALLED!", customer)); //NOI18N - - // customer should not be null - if (null == customer) { - // Abort here - throw new NullPointerException("customer is null"); //NOI18N - } - - // Is the customer registered? - if (this.isRegistered(customer)) { - // Already registered - throw new CustomerAlreadyRegisteredException(customer); - } - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("registerCustomer: Preparing statement for customer={0}", customer)); //NOI18N - - // Set creation timestamp - customer.setCustomerCreated(new GregorianCalendar()); - - // Try to persist it - this.getEntityManager().persist(customer); - - // Flush it as the id might be needed - this.getEntityManager().flush(); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("registerCustomer: customer.id={0}", customer.getCustomerId())); //NOI18N - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("registerCustomer: customer={0} - CALLED!", customer)); //NOI18N - - // Return prepared instance - return customer; - } - - /** - * Returns given property key or throws an exception if not found. - *

- * @param parameterKey Property key - *

- * @return Property value - *

- * @throws NullPointerException If given key is not found - * @throws NumberFormatException If no number is given in context parameter - */ - protected int getIntegerContextParameter (final String parameterKey) throws NullPointerException, NumberFormatException { - // Get context parameter - Integer contextValue = Integer.parseInt(this.getStringContextParameter(parameterKey)); - // Return it - return contextValue; - } - - /** - * Returns given property key or throws an exception if not found. - *

- * @param parameterKey Property key - *

- * @return Property value - *

- * @throws NullPointerException If given key is not found - */ - protected String getStringContextParameter (final String parameterKey) throws NullPointerException { - // Get context parameter - String contextValue = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(parameterKey); - // Is it null? - if (null == contextValue) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("parameterKey={0} is not set.", parameterKey)); //NOI18N - } - // Return it - return contextValue; - } - - /** - * Checks whether debug mode is enabled for given controller - *

- * @param controllerName Name of controller - *

- * @return Whether debug mode is enabled - */ - protected boolean isDebugModeEnabled (final String controllerName) { - // Parameters should be valid - if (null == controllerName) { - // Throw NPE - throw new NullPointerException("controllerName is null"); //NOI18N - } else if (controllerName.isEmpty()) { - // Is empty - throw new IllegalArgumentException("controllerName is empty"); //NOI18N - } - // Try to get context parameter - String contextParameter = this.getStringContextParameter(String.format("is_debug_%s_enabled", controllerName)); //NOI18N - // Is it set and true? - boolean isEnabled = Boolean.parseBoolean(contextParameter) == Boolean.TRUE; - // Return it - return isEnabled; - } - - /** - * Loads resource bundle for given locale. This must be implemented per - * project so all projects can still customize their methods. Calling - * ResourceBundleloadBundle() in this class means that also the bundle files - * must be present here. - *

- * @param locale Locale from e.g. FacesContext - *

- * @return Initialized and loaded resource bundle - */ - protected abstract ResourceBundle loadResourceBundle (final Locale locale); - - /** - * Shows a faces message for given causing exception. The message from the - * exception is being inserted into the message. - *

- * @param clientId Client id to send message to - * @param cause Causing exception - */ - protected void showFacesMessage (final String clientId, final Throwable cause) { - // Get context and add message - this.showFacesMessage(clientId, cause.getMessage()); - } - - /** - * Shows a faces message with given message (i18n) key. - *

- * @param clientId Client id to send message to - * @param i18nKey Message key - *

- * @throws NullPointerException If clientId or i18nKey is null - * @throws IllegalArgumentException If clientId or i18nKey is empty - */ - protected void showFacesMessage (final String clientId, final String i18nKey) throws NullPointerException, IllegalArgumentException { - // Both parameter must be valid - if (null == clientId) { - // Throw NPE - throw new NullPointerException("clientId is null"); //NOI18N - } else if (clientId.isEmpty()) { - // Is empty - throw new IllegalArgumentException("clientId is null"); //NOI18N - } else if (null == i18nKey) { - // Throw NPE - throw new NullPointerException("i18nKey is null"); //NOI18N - } else if (i18nKey.isEmpty()) { - // Is empty - throw new IllegalArgumentException("i18nKey is null"); //NOI18N - } - // Get current locale - Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); - // Get bundle bundle - ResourceBundle bundle = this.loadResourceBundle(locale); - // Default is i18nKey - String message = MessageFormat.format("!{0}!", i18nKey); //NOI18N - // Try it - try { - // Get message - message = bundle.getString(i18nKey); - } catch (final MissingResourceException ex) { - // Did not find it, ignored - } - // Get context and add message - FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(message)); - } - -} diff --git a/src/java/org/mxchange/pizzaapplication/model/product/AdminProductSessionBean.java b/src/java/org/mxchange/pizzaapplication/model/product/PizzaAdminProductSessionBean.java similarity index 53% rename from src/java/org/mxchange/pizzaapplication/model/product/AdminProductSessionBean.java rename to src/java/org/mxchange/pizzaapplication/model/product/PizzaAdminProductSessionBean.java index d584147..389885c 100644 --- a/src/java/org/mxchange/pizzaapplication/model/product/AdminProductSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/model/product/PizzaAdminProductSessionBean.java @@ -18,12 +18,7 @@ package org.mxchange.pizzaapplication.model.product; import java.text.MessageFormat; import java.util.List; -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; import javax.ejb.Stateless; -import javax.faces.application.FacesMessage; -import javax.faces.context.FacesContext; import javax.persistence.EntityExistsException; import javax.persistence.EntityNotFoundException; import javax.persistence.NoResultException; @@ -41,7 +36,7 @@ import org.mxchange.jshopcore.model.product.AdminProductSessionBeanRemote; * @author Roland Häder */ @Stateless (name = "admin_product", description = "An administrative bean handling products") -public abstract class AdminProductSessionBean extends BaseDatabaseBean implements AdminProductSessionBeanRemote { +public class PizzaAdminProductSessionBean extends BaseDatabaseBean implements AdminProductSessionBeanRemote { /** * Serial number @@ -51,7 +46,7 @@ public abstract class AdminProductSessionBean extends BaseDatabaseBean implement /** * Default constructor */ - public AdminProductSessionBean () { + public PizzaAdminProductSessionBean () { // Call super constructor super(); } @@ -167,131 +162,4 @@ public abstract class AdminProductSessionBean extends BaseDatabaseBean implement return isUsed; } - /** - * Returns given property key or throws an exception if not found. - *

- * @param parameterKey Property key - *

- * @return Property value - *

- * @throws NullPointerException If given key is not found - * @throws NumberFormatException If no number is given in context parameter - */ - protected int getIntegerContextParameter (final String parameterKey) throws NullPointerException, NumberFormatException { - // Get context parameter - Integer contextValue = Integer.parseInt(this.getStringContextParameter(parameterKey)); - // Return it - return contextValue; - } - - /** - * Returns given property key or throws an exception if not found. - *

- * @param parameterKey Property key - *

- * @return Property value - *

- * @throws NullPointerException If given key is not found - */ - protected String getStringContextParameter (final String parameterKey) throws NullPointerException { - // Get context parameter - String contextValue = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(parameterKey); - // Is it null? - if (null == contextValue) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("parameterKey={0} is not set.", parameterKey)); //NOI18N - } - // Return it - return contextValue; - } - - /** - * Checks whether debug mode is enabled for given controller - *

- * @param controllerName Name of controller - *

- * @return Whether debug mode is enabled - */ - protected boolean isDebugModeEnabled (final String controllerName) { - // Parameters should be valid - if (null == controllerName) { - // Throw NPE - throw new NullPointerException("controllerName is null"); //NOI18N - } else if (controllerName.isEmpty()) { - // Is empty - throw new IllegalArgumentException("controllerName is empty"); //NOI18N - } - // Try to get context parameter - String contextParameter = this.getStringContextParameter(String.format("is_debug_%s_enabled", controllerName)); //NOI18N - // Is it set and true? - boolean isEnabled = Boolean.parseBoolean(contextParameter) == Boolean.TRUE; - // Return it - return isEnabled; - } - - /** - * Loads resource bundle for given locale. This must be implemented per - * project so all projects can still customize their methods. Calling - * ResourceBundleloadBundle() in this class means that also the bundle files - * must be present here. - *

- * @param locale Locale from e.g. FacesContext - *

- * @return Initialized and loaded resource bundle - */ - protected abstract ResourceBundle loadResourceBundle (final Locale locale); - - /** - * Shows a faces message for given causing exception. The message from the - * exception is being inserted into the message. - *

- * @param clientId Client id to send message to - * @param cause Causing exception - */ - protected void showFacesMessage (final String clientId, final Throwable cause) { - // Get context and add message - this.showFacesMessage(clientId, cause.getMessage()); - } - - /** - * Shows a faces message with given message (i18n) key. - *

- * @param clientId Client id to send message to - * @param i18nKey Message key - *

- * @throws NullPointerException If clientId or i18nKey is null - * @throws IllegalArgumentException If clientId or i18nKey is empty - */ - protected void showFacesMessage (final String clientId, final String i18nKey) throws NullPointerException, IllegalArgumentException { - // Both parameter must be valid - if (null == clientId) { - // Throw NPE - throw new NullPointerException("clientId is null"); //NOI18N - } else if (clientId.isEmpty()) { - // Is empty - throw new IllegalArgumentException("clientId is null"); //NOI18N - } else if (null == i18nKey) { - // Throw NPE - throw new NullPointerException("i18nKey is null"); //NOI18N - } else if (i18nKey.isEmpty()) { - // Is empty - throw new IllegalArgumentException("i18nKey is null"); //NOI18N - } - // Get current locale - Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); - // Get bundle bundle - ResourceBundle bundle = this.loadResourceBundle(locale); - // Default is i18nKey - String message = MessageFormat.format("!{0}!", i18nKey); //NOI18N - // Try it - try { - // Get message - message = bundle.getString(i18nKey); - } catch (final MissingResourceException ex) { - // Did not find it, ignored - } - // Get context and add message - FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(message)); - } - } diff --git a/src/java/org/mxchange/pizzaapplication/model/product/PizzaProductSessionBean.java b/src/java/org/mxchange/pizzaapplication/model/product/PizzaProductSessionBean.java new file mode 100644 index 0000000..241176d --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/model/product/PizzaProductSessionBean.java @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * 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.pizzaapplication.model.product; + +import java.text.MessageFormat; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import javax.ejb.EJB; +import javax.ejb.Stateless; +import org.mxchange.jcoreee.database.BaseDatabaseBean; +import org.mxchange.jproduct.model.product.Product; +import org.mxchange.jshopcore.model.product.AdminProductSessionBeanRemote; +import org.mxchange.jshopcore.model.product.ProductSessionBeanRemote; + +/** + * A session-scoped bean for non-administrative roles for products + *

+ * @author Roland Häder + */ +@Stateless (name = "product", description = "A bean handling products for all others (non-admin)") +public class PizzaProductSessionBean extends BaseDatabaseBean implements ProductSessionBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 65_173_487_394_812L; + + /** + * Administrative bean + */ + @EJB + private AdminProductSessionBeanRemote productBean; + + /** + * Default constructor + */ + public PizzaProductSessionBean () { + // Call super constructor + super(); + } + + @Override + public List getAvailableProducts () { + // Trace message + this.getLoggerBeanLocal().logTrace("getAvailableProducts: CALLED!"); //NOI18N + + // The connection must be there + if (this.getEntityManager() == null) { + // Connection is not there + throw new NullPointerException("connection is null"); //NOI18N + } + + // Get all products + List allProducts = this.productBean.getAllProducts(); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("getAvailableProducts: allProducts({0})={1}", allProducts.size(), allProducts)); //NOI18N + + // Init deque + List deque = new LinkedList<>(); + + // Get iterator + Iterator iterator = allProducts.iterator(); + + // Walk through all and add only available + while (iterator.hasNext()) { + // Get element + Product localProduct = iterator.next(); + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("getAvailableProducts: localProduct={0}", localProduct)); //NOI18N + + // Is this available? + if (localProduct.getProductAvailability()) { + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("getAvailableProducts: localProduct={0} - ADDED!", localProduct)); //NOI18N + + // Add it + deque.add(localProduct); + } + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("getAvailableProducts: deque({0})={1} - EXIT!", deque.size(), deque)); //NOI18N + + // Return it + return deque; + } + +} diff --git a/src/java/org/mxchange/pizzaapplication/model/product/ProductSessionBean.java b/src/java/org/mxchange/pizzaapplication/model/product/ProductSessionBean.java deleted file mode 100644 index 96fdb09..0000000 --- a/src/java/org/mxchange/pizzaapplication/model/product/ProductSessionBean.java +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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.pizzaapplication.model.product; - -import java.text.MessageFormat; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; -import javax.ejb.EJB; -import javax.ejb.Stateless; -import javax.faces.application.FacesMessage; -import javax.faces.context.FacesContext; -import org.mxchange.jcoreee.database.BaseDatabaseBean; -import org.mxchange.jproduct.model.product.Product; -import org.mxchange.jshopcore.model.product.AdminProductSessionBeanRemote; -import org.mxchange.jshopcore.model.product.ProductSessionBeanRemote; - -/** - * A session-scoped bean for non-administrative roles for products - *

- * @author Roland Häder - */ -@Stateless (name = "product", description = "A bean handling products for all others (non-admin)") -public abstract class ProductSessionBean extends BaseDatabaseBean implements ProductSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 65_173_487_394_812L; - - /** - * Administrative bean - */ - @EJB - private AdminProductSessionBeanRemote productBean; - - /** - * Default constructor - */ - public ProductSessionBean () { - // Call super constructor - super(); - } - - @Override - public List getAvailableProducts () { - // Trace message - this.getLoggerBeanLocal().logTrace("getAvailableProducts: CALLED!"); //NOI18N - - // The connection must be there - if (this.getEntityManager() == null) { - // Connection is not there - throw new NullPointerException("connection is null"); //NOI18N - } - - // Get all products - List allProducts = this.productBean.getAllProducts(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("getAvailableProducts: allProducts({0})={1}", allProducts.size(), allProducts)); //NOI18N - - // Init deque - List deque = new LinkedList<>(); - - // Get iterator - Iterator iterator = allProducts.iterator(); - - // Walk through all and add only available - while (iterator.hasNext()) { - // Get element - Product localProduct = iterator.next(); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("getAvailableProducts: localProduct={0}", localProduct)); //NOI18N - - // Is this available? - if (localProduct.getProductAvailability()) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("getAvailableProducts: localProduct={0} - ADDED!", localProduct)); //NOI18N - - // Add it - deque.add(localProduct); - } - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("getAvailableProducts: deque({0})={1} - EXIT!", deque.size(), deque)); //NOI18N - - // Return it - return deque; - } - - /** - * Returns given property key or throws an exception if not found. - *

- * @param parameterKey Property key - *

- * @return Property value - *

- * @throws NullPointerException If given key is not found - * @throws NumberFormatException If no number is given in context parameter - */ - protected int getIntegerContextParameter (final String parameterKey) throws NullPointerException, NumberFormatException { - // Get context parameter - Integer contextValue = Integer.parseInt(this.getStringContextParameter(parameterKey)); - // Return it - return contextValue; - } - - /** - * Returns given property key or throws an exception if not found. - *

- * @param parameterKey Property key - *

- * @return Property value - *

- * @throws NullPointerException If given key is not found - */ - protected String getStringContextParameter (final String parameterKey) throws NullPointerException { - // Get context parameter - String contextValue = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(parameterKey); - // Is it null? - if (null == contextValue) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("parameterKey={0} is not set.", parameterKey)); //NOI18N - } - // Return it - return contextValue; - } - - /** - * Checks whether debug mode is enabled for given controller - *

- * @param controllerName Name of controller - *

- * @return Whether debug mode is enabled - */ - protected boolean isDebugModeEnabled (final String controllerName) { - // Parameters should be valid - if (null == controllerName) { - // Throw NPE - throw new NullPointerException("controllerName is null"); //NOI18N - } else if (controllerName.isEmpty()) { - // Is empty - throw new IllegalArgumentException("controllerName is empty"); //NOI18N - } - // Try to get context parameter - String contextParameter = this.getStringContextParameter(String.format("is_debug_%s_enabled", controllerName)); //NOI18N - // Is it set and true? - boolean isEnabled = Boolean.parseBoolean(contextParameter) == Boolean.TRUE; - // Return it - return isEnabled; - } - - /** - * Loads resource bundle for given locale. This must be implemented per - * project so all projects can still customize their methods. Calling - * ResourceBundleloadBundle() in this class means that also the bundle files - * must be present here. - *

- * @param locale Locale from e.g. FacesContext - *

- * @return Initialized and loaded resource bundle - */ - protected abstract ResourceBundle loadResourceBundle (final Locale locale); - - /** - * Shows a faces message for given causing exception. The message from the - * exception is being inserted into the message. - *

- * @param clientId Client id to send message to - * @param cause Causing exception - */ - protected void showFacesMessage (final String clientId, final Throwable cause) { - // Get context and add message - this.showFacesMessage(clientId, cause.getMessage()); - } - - /** - * Shows a faces message with given message (i18n) key. - *

- * @param clientId Client id to send message to - * @param i18nKey Message key - *

- * @throws NullPointerException If clientId or i18nKey is null - * @throws IllegalArgumentException If clientId or i18nKey is empty - */ - protected void showFacesMessage (final String clientId, final String i18nKey) throws NullPointerException, IllegalArgumentException { - // Both parameter must be valid - if (null == clientId) { - // Throw NPE - throw new NullPointerException("clientId is null"); //NOI18N - } else if (clientId.isEmpty()) { - // Is empty - throw new IllegalArgumentException("clientId is null"); //NOI18N - } else if (null == i18nKey) { - // Throw NPE - throw new NullPointerException("i18nKey is null"); //NOI18N - } else if (i18nKey.isEmpty()) { - // Is empty - throw new IllegalArgumentException("i18nKey is null"); //NOI18N - } - // Get current locale - Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); - // Get bundle bundle - ResourceBundle bundle = this.loadResourceBundle(locale); - // Default is i18nKey - String message = MessageFormat.format("!{0}!", i18nKey); //NOI18N - // Try it - try { - // Get message - message = bundle.getString(i18nKey); - } catch (final MissingResourceException ex) { - // Did not find it, ignored - } - // Get context and add message - FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(message)); - } - -} -- 2.39.5