]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Split of shop controller into category and product
authorRoland Haeder <roland@mxchange.org>
Wed, 13 Apr 2016 20:10:40 +0000 (22:10 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 13 Apr 2016 20:12:22 +0000 (22:12 +0200)
src/java/org/mxchange/pizzaapplication/beans/category/PizzaCategoryWebApplicationBean.java [new file with mode: 0644]
src/java/org/mxchange/pizzaapplication/beans/category/PizzaCategoryWebApplicationController.java [new file with mode: 0644]
src/java/org/mxchange/pizzaapplication/beans/product/PizzaProductWebApplicationBean.java [new file with mode: 0644]
src/java/org/mxchange/pizzaapplication/beans/product/PizzaProductWebApplicationController.java [new file with mode: 0644]
src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java [deleted file]
src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java [deleted file]
web/WEB-INF/templates/admin/admin_category_selection_box.tpl
web/WEB-INF/templates/admin/admin_parent_category_selection_box.tpl
web/admin/admin_category_list.xhtml
web/index.xhtml

diff --git a/src/java/org/mxchange/pizzaapplication/beans/category/PizzaCategoryWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/category/PizzaCategoryWebApplicationBean.java
new file mode 100644 (file)
index 0000000..f71ac75
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.pizzaapplication.beans.category;
+
+import java.util.LinkedList;
+import java.util.List;
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+import javax.faces.FacesException;
+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.jshopcore.events.category.AddedCategoryEvent;
+import org.mxchange.jshopcore.model.category.Category;
+import org.mxchange.jshopcore.model.category.CategorySessionBeanRemote;
+
+/**
+ * General (product) category controller
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Named ("categoryController")
+@ApplicationScoped
+public class PizzaCategoryWebApplicationBean implements PizzaCategoryWebApplicationController {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 58_137_539_530_279L;
+
+       /**
+        * All categories
+        */
+       private List<Category> categories;
+
+       @Override
+       public void addCategory (final Category category) {
+               // Add the category
+               this.categories.add(category);
+       }
+
+       @Override
+       public void afterShopCategoryAdded (@Observes final AddedCategoryEvent event) {
+               // Add it here, too.
+               this.addCategory(event.getAddedCategory());
+       }
+
+       @Override
+       @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+       public List<Category> getAllCategories () throws FacesException {
+               // Return it
+               return this.categories;
+       }
+
+       @Override
+       public List<Category> getAllCategoriesParent () throws FaceletException {
+               // Get regular list
+               List<Category> list = new LinkedList<>(this.getAllCategories());
+
+               // Return it
+               return list;
+       }
+
+       /**
+        * Initialization of this bean
+        */
+       @PostConstruct
+       public void init () {
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Try to lookup the bean
+                       CategorySessionBeanRemote categoryBean = (CategorySessionBeanRemote) context.lookup("java:global/jshop-ejb/category!org.mxchange.jshopcore.model.category.CategorySessionBeanRemote"); //NOI18N
+
+                       // Get all categories
+                       this.categories = categoryBean.getAllCategories();
+               } catch (final NamingException e) {
+                       // Continued to throw
+                       throw new FacesException(e);
+               }
+       }
+
+}
diff --git a/src/java/org/mxchange/pizzaapplication/beans/category/PizzaCategoryWebApplicationController.java b/src/java/org/mxchange/pizzaapplication/beans/category/PizzaCategoryWebApplicationController.java
new file mode 100644 (file)
index 0000000..886c061
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.pizzaapplication.beans.category;
+
+import java.io.Serializable;
+import java.util.List;
+import javax.faces.view.facelets.FaceletException;
+import org.mxchange.jshopcore.events.category.AddedCategoryEvent;
+import org.mxchange.jshopcore.model.category.Category;
+
+/**
+ * An interface for (product) categories
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+public interface PizzaCategoryWebApplicationController extends Serializable {
+
+       /**
+        * Adds given category to the "cached" instance
+        * <p>
+        * @param category Category instance
+        */
+       void addCategory (final Category category);
+
+       /**
+        * Some "getter" for a linked list of all categories
+        * <p>
+        * @return All categories
+        * <p>
+        * @throws javax.faces.view.facelets.FaceletException If anything went wrong
+        */
+       List<Category> getAllCategories () throws FaceletException;
+
+       /**
+        * Some "getter" for a linked list of all categories including "Has no
+        * parent" fake category.
+        * <p>
+        * @return All categories
+        * <p>
+        * @throws javax.faces.view.facelets.FaceletException If anything went wrong
+        */
+       List<Category> getAllCategoriesParent () throws FaceletException;
+
+       /**
+        * Observes events fired after a new product category has been added
+        * <p>
+        * @param event Event to be observed
+        */
+       void afterShopCategoryAdded (final AddedCategoryEvent event);
+
+}
diff --git a/src/java/org/mxchange/pizzaapplication/beans/product/PizzaProductWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/product/PizzaProductWebApplicationBean.java
new file mode 100644 (file)
index 0000000..4e600f9
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.pizzaapplication.beans.product;
+
+import java.util.Collections;
+import java.util.List;
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+import javax.faces.FacesException;
+import javax.inject.Named;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.mxchange.jshopcore.events.product.AddedProductEvent;
+import org.mxchange.jshopcore.model.product.Product;
+import org.mxchange.jshopcore.model.product.ProductSessionBeanRemote;
+
+/**
+ * General product controller
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Named ("productController")
+@ApplicationScoped
+public class PizzaProductWebApplicationBean implements PizzaProductWebApplicationController {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 58_137_539_530_279L;
+
+       /**
+        * "Cache" for all available products
+        */
+       private List<Product> availableProducts;
+
+       @Override
+       public void addProduct (final Product product) {
+               // Is the product available?
+               if (product.getProductAvailability()) {
+                       // Add it
+                       this.availableProducts.add(product);
+               }
+       }
+
+       @Override
+       public void afterShopProductAdded (@Observes final AddedProductEvent event) {
+               // Add it here, too.
+               this.addProduct(event.getAddedProduct());
+       }
+
+       @Override
+       public List<Product> getAvailableProducts () throws FacesException {
+               // Return it
+               return Collections.unmodifiableList(this.availableProducts);
+       }
+
+       /**
+        * Initialization of this bean
+        */
+       @PostConstruct
+       public void init () {
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Try to lookup the bean
+                       ProductSessionBeanRemote productBean = (ProductSessionBeanRemote) context.lookup("java:global/jshop-ejb/product!org.mxchange.jshopcore.model.product.ProductSessionBeanRemote"); //NOI18N
+
+                       // Get available products list
+                       this.availableProducts = productBean.getAvailableProducts();
+               } catch (final NamingException e) {
+                       // Continued to throw
+                       throw new FacesException(e);
+               }
+       }
+
+}
diff --git a/src/java/org/mxchange/pizzaapplication/beans/product/PizzaProductWebApplicationController.java b/src/java/org/mxchange/pizzaapplication/beans/product/PizzaProductWebApplicationController.java
new file mode 100644 (file)
index 0000000..5d25598
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.pizzaapplication.beans.product;
+
+import java.io.Serializable;
+import java.util.List;
+import javax.faces.view.facelets.FaceletException;
+import org.mxchange.jshopcore.events.product.AddedProductEvent;
+import org.mxchange.jshopcore.model.product.Product;
+
+/**
+ * An interface for products
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+public interface PizzaProductWebApplicationController extends Serializable {
+
+       /**
+        * Adds given product to the "cached" instance
+        * <p>
+        * @param product Product instance
+        */
+       void addProduct (final Product product);
+
+       /**
+        * Some "getter" for a linked list of only available products
+        * <p>
+        * @return Only available products
+        * <p>
+        * @throws javax.faces.view.facelets.FaceletException If anything went wrong
+        */
+       List<Product> getAvailableProducts () throws FaceletException;
+
+       /**
+        * Observes events fired after a new product has been added
+        * <p>
+        * @param event Event to be observed
+        * @todo Move this to own controller
+        */
+       void afterShopProductAdded (final AddedProductEvent event);
+
+}
diff --git a/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java
deleted file mode 100644 (file)
index a502e02..0000000
+++ /dev/null
@@ -1,137 +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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.pizzaapplication.beans.shop;
-
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import javax.annotation.PostConstruct;
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.event.Observes;
-import javax.faces.FacesException;
-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.jshopcore.events.category.AddedCategoryEvent;
-import org.mxchange.jshopcore.events.product.AddedProductEvent;
-import org.mxchange.jshopcore.model.category.Category;
-import org.mxchange.jshopcore.model.category.CategorySessionBeanRemote;
-import org.mxchange.jshopcore.model.product.Product;
-import org.mxchange.jshopcore.model.product.ProductSessionBeanRemote;
-
-/**
- * General shop controller
- * <p>
- * @author Roland Haeder<roland@mxchange.org>
- */
-@Named ("shopController")
-@ApplicationScoped
-public class PizzaShopWebApplicationBean implements PizzaShopWebApplicationController {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 58_137_539_530_279L;
-
-       /**
-        * "Cache" for all available products
-        */
-       private List<Product> availableProducts;
-
-       /**
-        * All categories
-        */
-       private List<Category> categories;
-
-       @Override
-       public void addCategory (final Category category) {
-               // Add the category
-               this.categories.add(category);
-       }
-
-       @Override
-       public void addProduct (final Product product) {
-               // Is the product available?
-               if (product.getProductAvailability()) {
-                       // Add it
-                       this.availableProducts.add(product);
-               }
-       }
-
-       @Override
-       public void afterShopCategoryAdded (@Observes final AddedCategoryEvent event) {
-               // Add it here, too.
-               this.addCategory(event.getAddedCategory());
-       }
-
-       @Override
-       public void afterShopProductAdded (@Observes final AddedProductEvent event) {
-               // Add it here, too.
-               this.addProduct(event.getAddedProduct());
-       }
-
-       @Override
-       @SuppressWarnings ("ReturnOfCollectionOrArrayField")
-       public List<Category> getAllCategories () throws FacesException {
-               // Return it
-               return this.categories;
-       }
-
-       @Override
-       public List<Category> getAllCategoriesParent () throws FaceletException {
-               // Get regular list
-               List<Category> list = new LinkedList<>(this.getAllCategories());
-
-               // Return it
-               return list;
-       }
-
-       @Override
-       public List<Product> getAvailableProducts () throws FacesException {
-               // Return it
-               return Collections.unmodifiableList(this.availableProducts);
-       }
-
-       /**
-        * Initialization of this bean
-        */
-       @PostConstruct
-       public void init () {
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup the bean
-                       CategorySessionBeanRemote categoryBean = (CategorySessionBeanRemote) context.lookup("java:global/jshop-ejb/category!org.mxchange.jshopcore.model.category.CategorySessionBeanRemote"); //NOI18N
-
-                       // Get all categories
-                       this.categories = categoryBean.getAllCategories();
-
-                       // Try to lookup the bean
-                       ProductSessionBeanRemote productBean = (ProductSessionBeanRemote) context.lookup("java:global/jshop-ejb/product!org.mxchange.jshopcore.model.product.ProductSessionBeanRemote"); //NOI18N
-
-                       // Get available products list
-                       this.availableProducts = productBean.getAvailableProducts();
-               } catch (final NamingException e) {
-                       // Continued to throw
-                       throw new FacesException(e);
-               }
-       }
-
-}
diff --git a/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java b/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java
deleted file mode 100644 (file)
index 74b4369..0000000
+++ /dev/null
@@ -1,95 +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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.pizzaapplication.beans.shop;
-
-import java.io.Serializable;
-import java.util.List;
-import javax.faces.view.facelets.FaceletException;
-import org.mxchange.jshopcore.events.category.AddedCategoryEvent;
-import org.mxchange.jshopcore.events.product.AddedProductEvent;
-import org.mxchange.jshopcore.model.category.Category;
-import org.mxchange.jshopcore.model.product.Product;
-
-/**
- * An interface for the shop
- * <p>
- * @author Roland Haeder<roland@mxchange.org>
- */
-public interface PizzaShopWebApplicationController extends Serializable {
-
-       /**
-        * Adds given category to the "cached" instance
-        * <p>
-        * @param category Category instance
-        * @todo Move this to own controller
-        */
-       void addCategory (final Category category);
-
-       /**
-        * Adds given product to the "cached" instance
-        * <p>
-        * @param product Product instance
-        */
-       void addProduct (final Product product);
-
-       /**
-        * Some "getter" for a linked list of all categories
-        * <p>
-        * @return All categories
-        * <p>
-        * @throws javax.faces.view.facelets.FaceletException If anything went wrong
-        * @todo Move this to own controller
-        */
-       List<Category> getAllCategories () throws FaceletException;
-
-       /**
-        * Some "getter" for a linked list of all categories including "Has no
-        * parent" fake category.
-        * <p>
-        * @return All categories
-        * <p>
-        * @throws javax.faces.view.facelets.FaceletException If anything went wrong
-        * @todo Move this to own controller
-        */
-       List<Category> getAllCategoriesParent () throws FaceletException;
-
-       /**
-        * Some "getter" for a linked list of only available products
-        * <p>
-        * @return Only available products
-        * <p>
-        * @throws javax.faces.view.facelets.FaceletException If anything went wrong
-        */
-       List<Product> getAvailableProducts () throws FaceletException;
-
-       /**
-        * Observes events fired after a new product category has been added
-        * <p>
-        * @param event Event to be observed
-        * @todo Move this to own controller
-        */
-       void afterShopCategoryAdded (final AddedCategoryEvent event);
-
-       /**
-        * Observes events fired after a new product has been added
-        * <p>
-        * @param event Event to be observed
-        * @todo Move this to own controller
-        */
-       void afterShopProductAdded (final AddedProductEvent event);
-
-}
index fff96a5a6c2af39236f229fda611c2db5747b438..67fc7b5e977bfa9a5c047715cb4ccede2d9e36f6 100644 (file)
@@ -5,6 +5,6 @@
        xmlns:ui="http://java.sun.com/jsf/facelets">
 
        <h:selectOneMenu class="select" id="product_category" value="#{adminProductController.productCategory}" required="true" requiredMessage="#{msg.ADMIN_CATEGORY_MUST_BE_SELECTED}" converter="CategoryConverter">
-               <f:selectItems value="#{shopController.allCategories}" var="cat" itemValue="#{cat}" itemLabel="#{cat.categoryTitle}" />
+               <f:selectItems value="#{categoryController.allCategories}" var="cat" itemValue="#{cat}" itemLabel="#{cat.categoryTitle}" />
        </h:selectOneMenu>
 </ui:composition>
index d711ed70f06c870eb9cff232813a2f466b27c0e5..c5a4d5e1c063accdc895f4587e7f7eac8fb85fcc 100644 (file)
@@ -6,6 +6,6 @@
 
        <h:selectOneMenu class="select" id="parentCategory" value="#{adminCategoryController.parentCategory}">
                <f:selectItem itemValue="" itemLabel="#{msg.ADMIN_CATEGORY_HAS_NO_PARENT}" />
-               <f:selectItems value="#{shopController.allCategoriesParent}" var="parent_category" itemValue="#{parent_category.categoryId}" itemLabel="#{parent_category.categoryTitle}" />
+               <f:selectItems value="#{categoryController.allCategoriesParent}" var="parent_category" itemValue="#{parent_category.categoryId}" itemLabel="#{parent_category.categoryTitle}" />
        </h:selectOneMenu>
 </ui:composition>
index 87c0c0b739dd32d00b91f82299359df55414bb21..9044182a78873f763cc3e25cc7ffb7b7b241b236 100644 (file)
@@ -15,7 +15,7 @@
 
                <ui:define name="content">
                        <div class="para">
-                               <h:dataTable id="categories" var="cat" value="#{shopController.allCategories}" styleClass="table" headerClass="table_header_column" summary="#{msg.TABLE_SUMMARY_ADMIN_CATEGORY}">
+                               <h:dataTable id="categories" var="cat" value="#{categoryController.allCategories}" styleClass="table" headerClass="table_header_column" summary="#{msg.TABLE_SUMMARY_ADMIN_CATEGORY}">
                                        <h:column>
                                                <f:facet name="header">#{msg.ADMIN_CATEGORY_ID}</f:facet>
                                                <h:link outcome="admin_edit_category" title="#{msg.ADMIN_LINK_EDIT_DELETE_CATEGORY_TITLE}" value="#{cat.categoryId}">
index 9b75d18a44e9cd4a08c36e078f6ac28625ba913f..d769335f48debb3773660b9709d05be5e110ff34 100644 (file)
@@ -25,7 +25,7 @@
                                </div>
                        </div>
 
-                       <h:dataTable id="table_show_available_products" var="product" value="#{shopController.availableProducts}" styleClass="table" summary="#{msg.TABLE_SUMMARY_INDEX_PRODUCTS}">
+                       <h:dataTable id="table_show_available_products" var="product" value="#{productController.availableProducts}" styleClass="table" summary="#{msg.TABLE_SUMMARY_INDEX_PRODUCTS}">
                                <h:column>
                                        <div id="main_item_container">
                                                <div class="item_title">