From: Roland Haeder Date: Wed, 13 Apr 2016 20:10:40 +0000 (+0200) Subject: Split of shop controller into category and product X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d4f94b4ea1e24f87958c170341eeebd7f4a50788;p=pizzaservice-war.git Split of shop controller into category and product --- 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 index 00000000..f71ac756 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/category/PizzaCategoryWebApplicationBean.java @@ -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 . + */ +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 + *

+ * @author Roland Haeder + */ +@Named ("categoryController") +@ApplicationScoped +public class PizzaCategoryWebApplicationBean implements PizzaCategoryWebApplicationController { + + /** + * Serial number + */ + private static final long serialVersionUID = 58_137_539_530_279L; + + /** + * All categories + */ + private List 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 getAllCategories () throws FacesException { + // Return it + return this.categories; + } + + @Override + public List getAllCategoriesParent () throws FaceletException { + // Get regular list + List 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 index 00000000..886c061c --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/category/PizzaCategoryWebApplicationController.java @@ -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 . + */ +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 + *

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

+ * @param category Category instance + */ + void addCategory (final Category category); + + /** + * Some "getter" for a linked list of all categories + *

+ * @return All categories + *

+ * @throws javax.faces.view.facelets.FaceletException If anything went wrong + */ + List getAllCategories () throws FaceletException; + + /** + * Some "getter" for a linked list of all categories including "Has no + * parent" fake category. + *

+ * @return All categories + *

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

+ * @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 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/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java deleted file mode 100644 index a502e025..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java +++ /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 . - */ -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 - *

- * @author Roland Haeder - */ -@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 availableProducts; - - /** - * All categories - */ - private List 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 getAllCategories () throws FacesException { - // Return it - return this.categories; - } - - @Override - public List getAllCategoriesParent () throws FaceletException { - // Get regular list - List list = new LinkedList<>(this.getAllCategories()); - - // Return it - return list; - } - - @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 - 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 index 74b43691..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java +++ /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 . - */ -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 - *

- * @author Roland Haeder - */ -public interface PizzaShopWebApplicationController 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; - - /** - * Some "getter" for a linked list of all categories including "Has no - * parent" fake category. - *

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