From d4f94b4ea1e24f87958c170341eeebd7f4a50788 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 13 Apr 2016 22:10:40 +0200 Subject: [PATCH] Split of shop controller into category and product --- .../PizzaCategoryWebApplicationBean.java} | 44 +-------- ...izzaCategoryWebApplicationController.java} | 36 +------ .../PizzaProductWebApplicationBean.java | 93 +++++++++++++++++++ .../PizzaProductWebApplicationController.java | 56 +++++++++++ .../admin/admin_category_selection_box.tpl | 2 +- .../admin_parent_category_selection_box.tpl | 2 +- web/admin/admin_category_list.xhtml | 2 +- web/index.xhtml | 2 +- 8 files changed, 160 insertions(+), 77 deletions(-) rename src/java/org/mxchange/pizzaapplication/beans/{shop/PizzaShopWebApplicationBean.java => category/PizzaCategoryWebApplicationBean.java} (67%) rename src/java/org/mxchange/pizzaapplication/beans/{shop/PizzaShopWebApplicationController.java => category/PizzaCategoryWebApplicationController.java} (64%) create mode 100644 src/java/org/mxchange/pizzaapplication/beans/product/PizzaProductWebApplicationBean.java create mode 100644 src/java/org/mxchange/pizzaapplication/beans/product/PizzaProductWebApplicationController.java diff --git a/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/category/PizzaCategoryWebApplicationBean.java similarity index 67% rename from src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java rename to src/java/org/mxchange/pizzaapplication/beans/category/PizzaCategoryWebApplicationBean.java index a502e025..f71ac756 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/category/PizzaCategoryWebApplicationBean.java @@ -14,9 +14,8 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.mxchange.pizzaapplication.beans.shop; +package org.mxchange.pizzaapplication.beans.category; -import java.util.Collections; import java.util.LinkedList; import java.util.List; import javax.annotation.PostConstruct; @@ -29,31 +28,23 @@ 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 + * General (product) category controller *

* @author Roland Haeder */ -@Named ("shopController") +@Named ("categoryController") @ApplicationScoped -public class PizzaShopWebApplicationBean implements PizzaShopWebApplicationController { +public class PizzaCategoryWebApplicationBean implements PizzaCategoryWebApplicationController { /** * Serial number */ private static final long serialVersionUID = 58_137_539_530_279L; - /** - * "Cache" for all available products - */ - private List availableProducts; - /** * All categories */ @@ -65,27 +56,12 @@ public class PizzaShopWebApplicationBean implements PizzaShopWebApplicationContr 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 getAllCategories () throws FacesException { @@ -102,12 +78,6 @@ public class PizzaShopWebApplicationBean implements PizzaShopWebApplicationContr return list; } - @Override - public List getAvailableProducts () throws FacesException { - // Return it - return Collections.unmodifiableList(this.availableProducts); - } - /** * Initialization of this bean */ @@ -122,12 +92,6 @@ public class PizzaShopWebApplicationBean implements PizzaShopWebApplicationContr // 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/category/PizzaCategoryWebApplicationController.java similarity index 64% rename from src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java rename to src/java/org/mxchange/pizzaapplication/beans/category/PizzaCategoryWebApplicationController.java index 74b43691..886c061c 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/category/PizzaCategoryWebApplicationController.java @@ -14,45 +14,34 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.mxchange.pizzaapplication.beans.shop; +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.events.product.AddedProductEvent; import org.mxchange.jshopcore.model.category.Category; -import org.mxchange.jshopcore.model.product.Product; /** - * An interface for the shop + * An interface for (product) categories *

* @author Roland Haeder */ -public interface PizzaShopWebApplicationController extends Serializable { +public interface PizzaCategoryWebApplicationController extends Serializable { /** * Adds given category to the "cached" instance *

* @param category Category instance - * @todo Move this to own controller */ void addCategory (final Category category); - /** - * Adds given product to the "cached" instance - *

- * @param product Product instance - */ - void addProduct (final Product product); - /** * Some "getter" for a linked list of all categories *

* @return All categories *

* @throws javax.faces.view.facelets.FaceletException If anything went wrong - * @todo Move this to own controller */ List getAllCategories () throws FaceletException; @@ -63,33 +52,14 @@ public interface PizzaShopWebApplicationController extends Serializable { * @return All categories *

* @throws javax.faces.view.facelets.FaceletException If anything went wrong - * @todo Move this to own controller */ List getAllCategoriesParent () throws FaceletException; - /** - * Some "getter" for a linked list of only available products - *

- * @return Only available products - *

- * @throws javax.faces.view.facelets.FaceletException If anything went wrong - */ - List getAvailableProducts () throws FaceletException; - /** * Observes events fired after a new product category has been added *

* @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 - *

- * @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/product/PizzaProductWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/product/PizzaProductWebApplicationBean.java new file mode 100644 index 00000000..4e600f95 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/product/PizzaProductWebApplicationBean.java @@ -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 . + */ +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 + *

+ * @author Roland Haeder + */ +@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 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 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 index 00000000..5d255989 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/product/PizzaProductWebApplicationController.java @@ -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 . + */ +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 + *

+ * @author Roland Haeder + */ +public interface PizzaProductWebApplicationController extends Serializable { + + /** + * Adds given product to the "cached" instance + *

+ * @param product Product instance + */ + void addProduct (final Product product); + + /** + * Some "getter" for a linked list of only available products + *

+ * @return Only available products + *

+ * @throws javax.faces.view.facelets.FaceletException If anything went wrong + */ + List getAvailableProducts () throws FaceletException; + + /** + * Observes events fired after a new product has been added + *

+ * @param event Event to be observed + * @todo Move this to own controller + */ + void afterShopProductAdded (final AddedProductEvent event); + +} diff --git a/web/WEB-INF/templates/admin/admin_category_selection_box.tpl b/web/WEB-INF/templates/admin/admin_category_selection_box.tpl index fff96a5a..67fc7b5e 100644 --- a/web/WEB-INF/templates/admin/admin_category_selection_box.tpl +++ b/web/WEB-INF/templates/admin/admin_category_selection_box.tpl @@ -5,6 +5,6 @@ xmlns:ui="http://java.sun.com/jsf/facelets"> - + diff --git a/web/WEB-INF/templates/admin/admin_parent_category_selection_box.tpl b/web/WEB-INF/templates/admin/admin_parent_category_selection_box.tpl index d711ed70..c5a4d5e1 100644 --- a/web/WEB-INF/templates/admin/admin_parent_category_selection_box.tpl +++ b/web/WEB-INF/templates/admin/admin_parent_category_selection_box.tpl @@ -6,6 +6,6 @@ - + diff --git a/web/admin/admin_category_list.xhtml b/web/admin/admin_category_list.xhtml index 87c0c0b7..9044182a 100644 --- a/web/admin/admin_category_list.xhtml +++ b/web/admin/admin_category_list.xhtml @@ -15,7 +15,7 @@

- + #{msg.ADMIN_CATEGORY_ID} diff --git a/web/index.xhtml b/web/index.xhtml index 9b75d18a..d769335f 100644 --- a/web/index.xhtml +++ b/web/index.xhtml @@ -25,7 +25,7 @@
- +
-- 2.39.5