]> git.mxchange.org Git - pizzaservice-ejb.git/commitdiff
Continued with fixing:
authorRoland Häder <roland@mxchange.org>
Sat, 12 Aug 2017 16:05:40 +0000 (18:05 +0200)
committerRoland Häder <roland@mxchange.org>
Sat, 12 Aug 2017 16:05:40 +0000 (18:05 +0200)
- renamed basket bean as the naming-convention requires project's short name in
  front of it
- fixed EJB portable name part (remember that mapped-name="someFooName" is not
  required by all EJB containers to handle)

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/pizzaapplication/model/basket/BasketSessionBean.java [deleted file]
src/java/org/mxchange/pizzaapplication/model/basket/PizzaBasketSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/pizzaapplication/model/category/PizzaAdminCategorySessionBean.java
src/java/org/mxchange/pizzaapplication/model/category/PizzaCategorySessionBean.java
src/java/org/mxchange/pizzaapplication/model/product/PizzaAdminProductSessionBean.java
src/java/org/mxchange/pizzaapplication/model/product/PizzaProductSessionBean.java

diff --git a/src/java/org/mxchange/pizzaapplication/model/basket/BasketSessionBean.java b/src/java/org/mxchange/pizzaapplication/model/basket/BasketSessionBean.java
deleted file mode 100644 (file)
index 53c2d12..0000000
+++ /dev/null
@@ -1,268 +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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.pizzaapplication.model.basket;
-
-import java.text.MessageFormat;
-import java.util.GregorianCalendar;
-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 org.mxchange.jcoreee.database.BaseDatabaseBean;
-import org.mxchange.jcustomercore.model.customer.Customer;
-import org.mxchange.jshopcore.model.basket.AddableBasketItem;
-import org.mxchange.jshopcore.model.basket.Basket;
-import org.mxchange.jshopcore.model.basket.BasketSessionBeanRemote;
-import org.mxchange.jshopcore.model.basket.ShopBasket;
-import org.mxchange.jshopcore.model.customer.ShopCustomerUtils;
-import org.mxchange.jshopcore.model.order.Orderable;
-import org.mxchange.jshopcore.model.order.ShopOrder;
-
-/**
- * A basket for orderable items
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Stateless (name = "basket", description = "A bean handling persisting baskets of logged-in customers")
-public abstract class BasketSessionBean extends BaseDatabaseBean implements BasketSessionBeanRemote {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 4_384_123_923_163_957L;
-
-       /**
-        * Default constructor
-        */
-       public BasketSessionBean () {
-               // Call super constructor
-               super();
-       }
-
-       @Override
-       public void clear () {
-               // @TODO Nothing done so far
-       }
-
-       @Override
-       public Basket<AddableBasketItem> getCurrentBasket () {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace("getCurrentBasket: CALLED!!"); //NOI18N
-
-               // @TODO For now this method returns only an empty basked until they are persitable
-               Basket<AddableBasketItem> basket = new ShopBasket();
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("getCurrentBasket: basket.size()={0} EXIT!!", basket.size())); //NOI18N
-
-               // Return it
-               return basket;
-       }
-
-       @Override
-       public String registerItems (final Customer customer, final List<AddableBasketItem> orderedItems) {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("registerItems: customer={0},itemList={1} - CALLED!", customer, orderedItems)); //NOI18N
-
-               // Init variable for access key
-               String accessKey;
-
-               // customer/itemList should not be null
-               if (null == customer) {
-                       // Abort here
-                       throw new NullPointerException("customer is null"); //NOI18N
-               } else if (null == orderedItems) {
-                       // Abort here
-                       throw new NullPointerException("itemList is null"); //NOI18N
-               } else if (customer.getCustomerId() == null) {
-                       // null pointer found
-                       throw new NullPointerException(MessageFormat.format("customer {0} id is null", customer)); //NOI18N
-               } else if (customer.getCustomerId() == 0) {
-                       // id not set
-                       throw new IllegalArgumentException(MessageFormat.format("customer {0} has no id set", customer)); //NOI18N
-               } else if (orderedItems.isEmpty()) {
-                       // Empty list
-                       throw new IllegalArgumentException("item list is empty"); //NOI18N
-               }
-
-               // First try to register the order (to get an id number from it)
-               try {
-                       // Generate access key
-                       accessKey = ShopCustomerUtils.generateAccessKey(this.getEntityManager(), customer);
-
-                       // Debug message
-                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("registerItems: accessKey={0}", accessKey)); //NOI18N
-
-                       // Create order object
-                       Orderable order = new ShopOrder();
-                       order.setCustomer(customer);
-                       order.setAccessKey(accessKey);
-                       order.setOrderedItems(orderedItems);
-                       order.setOrderCreated(new GregorianCalendar());
-
-                       // Persist it
-                       this.getEntityManager().persist(order);
-               } catch (final EntityExistsException ex) {
-                       // Log exception
-                       this.getLoggerBeanLocal().logException(ex);
-
-                       /*
-                        * Don't return an access key as the exception should never be
-                        * thrown.
-                        */
-                       accessKey = null;
-               }
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("registerItems: accessKey={0} - EXIT!", accessKey)); //NOI18N
-
-               // Return it
-               return accessKey;
-       }
-
-       /**
-        * Returns given property key or throws an exception if not found.
-        * <p>
-        * @param parameterKey Property key
-        * <p>
-        * @return Property value
-        * <p>
-        * @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.
-        * <p>
-        * @param parameterKey Property key
-        * <p>
-        * @return Property value
-        * <p>
-        * @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
-        * <p>
-        * @param controllerName Name of controller
-        * <p>
-        * @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.
-        * <p>
-        * @param locale Locale from e.g. FacesContext
-        * <p>
-        * @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.
-        * <p>
-        * @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.
-        * <p>
-        * @param clientId Client id to send message to
-        * @param i18nKey  Message key
-        * <p>
-        * @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/basket/PizzaBasketSessionBean.java b/src/java/org/mxchange/pizzaapplication/model/basket/PizzaBasketSessionBean.java
new file mode 100644 (file)
index 0000000..1d8e20c
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.pizzaapplication.model.basket;
+
+import java.text.MessageFormat;
+import java.util.GregorianCalendar;
+import java.util.List;
+import javax.ejb.Stateless;
+import javax.persistence.EntityExistsException;
+import org.mxchange.jcustomercore.model.customer.Customer;
+import org.mxchange.jshopcore.model.basket.AddableBasketItem;
+import org.mxchange.jshopcore.model.basket.Basket;
+import org.mxchange.jshopcore.model.basket.BasketSessionBeanRemote;
+import org.mxchange.jshopcore.model.basket.ShopBasket;
+import org.mxchange.jshopcore.model.customer.ShopCustomerUtils;
+import org.mxchange.jshopcore.model.order.Orderable;
+import org.mxchange.jshopcore.model.order.ShopOrder;
+import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean;
+
+/**
+ * A basket for orderable items
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Stateless (name = "basket", description = "A bean handling persisting baskets of logged-in customers")
+public class PizzaBasketSessionBean extends BasePizzaDatabaseBean implements BasketSessionBeanRemote {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 4_384_123_923_163_957L;
+
+       /**
+        * Default constructor
+        */
+       public PizzaBasketSessionBean () {
+               // Call super constructor
+               super();
+       }
+
+       @Override
+       public void clear () {
+               // @TODO Nothing done so far
+       }
+
+       @Override
+       public Basket<AddableBasketItem> getCurrentBasket () {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace("getCurrentBasket: CALLED!!"); //NOI18N
+
+               // @TODO For now this method returns only an empty basked until they are persitable
+               Basket<AddableBasketItem> basket = new ShopBasket();
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("getCurrentBasket: basket.size()={0} EXIT!!", basket.size())); //NOI18N
+
+               // Return it
+               return basket;
+       }
+
+       @Override
+       public String registerItems (final Customer customer, final List<AddableBasketItem> orderedItems) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("registerItems: customer={0},itemList={1} - CALLED!", customer, orderedItems)); //NOI18N
+
+               // Init variable for access key
+               String accessKey;
+
+               // customer/itemList should not be null
+               if (null == customer) {
+                       // Abort here
+                       throw new NullPointerException("customer is null"); //NOI18N
+               } else if (null == orderedItems) {
+                       // Abort here
+                       throw new NullPointerException("itemList is null"); //NOI18N
+               } else if (customer.getCustomerId() == null) {
+                       // null pointer found
+                       throw new NullPointerException(MessageFormat.format("customer {0} id is null", customer)); //NOI18N
+               } else if (customer.getCustomerId() == 0) {
+                       // id not set
+                       throw new IllegalArgumentException(MessageFormat.format("customer {0} has no id set", customer)); //NOI18N
+               } else if (orderedItems.isEmpty()) {
+                       // Empty list
+                       throw new IllegalArgumentException("item list is empty"); //NOI18N
+               }
+
+               // First try to register the order (to get an id number from it)
+               try {
+                       // Generate access key
+                       accessKey = ShopCustomerUtils.generateAccessKey(this.getEntityManager(), customer);
+
+                       // Debug message
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("registerItems: accessKey={0}", accessKey)); //NOI18N
+
+                       // Create order object
+                       Orderable order = new ShopOrder();
+                       order.setCustomer(customer);
+                       order.setAccessKey(accessKey);
+                       order.setOrderedItems(orderedItems);
+                       order.setOrderCreated(new GregorianCalendar());
+
+                       // Persist it
+                       this.getEntityManager().persist(order);
+               } catch (final EntityExistsException ex) {
+                       // Log exception
+                       this.getLoggerBeanLocal().logException(ex);
+
+                       /*
+                        * Don't return an access key as the exception should never be
+                        * thrown.
+                        */
+                       accessKey = null;
+               }
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("registerItems: accessKey={0} - EXIT!", accessKey)); //NOI18N
+
+               // Return it
+               return accessKey;
+       }
+
+}
index e2a7ca5db4267716bbf2cdf7edc9d6a413af25f0..049f8bdef016bfc48f09282fa668f6ff2b8db465 100644 (file)
@@ -21,20 +21,20 @@ import javax.ejb.Stateless;
 import javax.persistence.EntityNotFoundException;
 import javax.persistence.NoResultException;
 import javax.persistence.Query;
-import org.mxchange.jcoreee.database.BaseDatabaseBean;
 import org.mxchange.jproduct.exceptions.CannotAddCategoryException;
 import org.mxchange.jproduct.exceptions.CategoryTitleAlreadyUsedException;
 import org.mxchange.jproduct.model.category.Category;
 import org.mxchange.jproduct.model.category.ProductCategory;
 import org.mxchange.jshopcore.model.category.AdminCategorySessionBeanRemote;
+import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean;
 
 /**
  * An EJB for administrative access on categories
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-@Stateless (name = "admin_category", description = "An administrative bean handling product categories")
-public class PizzaAdminCategorySessionBean extends BaseDatabaseBean implements AdminCategorySessionBeanRemote {
+@Stateless (name = "adminCategory", description = "An administrative bean handling product categories")
+public class PizzaAdminCategorySessionBean extends BasePizzaDatabaseBean implements AdminCategorySessionBeanRemote {
 
        /**
         * Serial number
index dddbc24390b38cc6d3c73c733652e9442b18559f..1e7bb0ef7c968ddc67351bbf95d712cdb684c005 100644 (file)
@@ -20,10 +20,10 @@ 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;
+import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean;
 
 /**
  * Main shop class
@@ -31,7 +31,7 @@ import org.mxchange.jshopcore.model.category.CategorySessionBeanRemote;
  * @author Roland Häder<roland@mxchange.org>
  */
 @Stateless (name = "category", description = "A bean handling categories for all others (non-admin)")
-public class PizzaCategorySessionBean extends BaseDatabaseBean implements CategorySessionBeanRemote {
+public class PizzaCategorySessionBean extends BasePizzaDatabaseBean implements CategorySessionBeanRemote {
 
        /**
         * Serial number
index 389885c03a046d3c027016f6846e52bf51a4c680..5aa0c3e92da8a0d0f2539fb31208dab8e159dfc2 100644 (file)
@@ -23,20 +23,20 @@ import javax.persistence.EntityExistsException;
 import javax.persistence.EntityNotFoundException;
 import javax.persistence.NoResultException;
 import javax.persistence.Query;
-import org.mxchange.jcoreee.database.BaseDatabaseBean;
 import org.mxchange.jproduct.exceptions.CannotAddProductException;
 import org.mxchange.jproduct.exceptions.ProductTitleAlreadyUsedException;
 import org.mxchange.jproduct.model.product.GenericProduct;
 import org.mxchange.jproduct.model.product.Product;
 import org.mxchange.jshopcore.model.product.AdminProductSessionBeanRemote;
+import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean;
 
 /**
  * A session-scoped bean for non-administrative roles for products
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-@Stateless (name = "admin_product", description = "An administrative bean handling products")
-public class PizzaAdminProductSessionBean extends BaseDatabaseBean implements AdminProductSessionBeanRemote {
+@Stateless (name = "adminProduct", description = "An administrative bean handling products")
+public class PizzaAdminProductSessionBean extends BasePizzaDatabaseBean implements AdminProductSessionBeanRemote {
 
        /**
         * Serial number
index 241176d83a98295fdb8a9f0edfc14f90a1c6b74c..954d9634968548591579b6e8119c524c72be6971 100644 (file)
@@ -22,10 +22,10 @@ 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;
+import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean;
 
 /**
  * A session-scoped bean for non-administrative roles for products
@@ -33,7 +33,7 @@ import org.mxchange.jshopcore.model.product.ProductSessionBeanRemote;
  * @author Roland Häder<roland@mxchange.org>
  */
 @Stateless (name = "product", description = "A bean handling products for all others (non-admin)")
-public class PizzaProductSessionBean extends BaseDatabaseBean implements ProductSessionBeanRemote {
+public class PizzaProductSessionBean extends BasePizzaDatabaseBean implements ProductSessionBeanRemote {
 
        /**
         * Serial number
@@ -44,7 +44,7 @@ public class PizzaProductSessionBean extends BaseDatabaseBean implements Product
         * Administrative bean
         */
        @EJB
-       private AdminProductSessionBeanRemote productBean;
+       private AdminProductSessionBeanRemote adminProductBean;
 
        /**
         * Default constructor
@@ -66,7 +66,7 @@ public class PizzaProductSessionBean extends BaseDatabaseBean implements Product
                }
 
                // Get all products
-               List<Product> allProducts = this.productBean.getAllProducts();
+               List<Product> allProducts = this.adminProductBean.getAllProducts();
 
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("getAvailableProducts: allProducts({0})={1}", allProducts.size(), allProducts)); //NOI18N