From: Roland Haeder Date: Sun, 10 Apr 2016 13:56:50 +0000 (+0200) Subject: Continued a bit: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3b1f76fed100ca994989f075adbf92bd2fb9be24;p=pizzaservice-war.git Continued a bit: - replaced "static add-call" to event-based approach. This is much more flexible and easier to expand - updated jar(s) --- diff --git a/lib/jcoreee.jar b/lib/jcoreee.jar index 3a32dfff..ad61871d 100644 Binary files a/lib/jcoreee.jar and b/lib/jcoreee.jar differ diff --git a/lib/jshop-core.jar b/lib/jshop-core.jar index 30d16dd5..4a5a142a 100644 Binary files a/lib/jshop-core.jar and b/lib/jshop-core.jar differ diff --git a/src/java/org/mxchange/pizzaapplication/beans/basket/PizzaBasketWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/basket/PizzaBasketWebSessionBean.java index 890f7116..08e2b7ad 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/basket/PizzaBasketWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/basket/PizzaBasketWebSessionBean.java @@ -125,6 +125,7 @@ public class PizzaBasketWebSessionBean implements PizzaBasketWebSessionControlle // Trace message //this.getLogger().logTrace(MessageFormat.format("addItem: item {0} - has been added to basket. - EXIT!", item)); + // Added return "item_added"; //NOI18N } catch (final BasketItemAlreadyAddedException ex) { @@ -197,6 +198,7 @@ public class PizzaBasketWebSessionBean implements PizzaBasketWebSessionControlle // Trace message //this.getLogger().logTrace(MessageFormat.format("calculateItemPrice: totalPrice={0} - EXIT!", totalPrice)); + // Return it return totalPrice; } @@ -228,7 +230,7 @@ public class PizzaBasketWebSessionBean implements PizzaBasketWebSessionControlle @Override public void clear () { // Clear bean as well - this.basketBean.clear(); + this.getBasketBean().clear(); // Deligate to basket instance this.basket.clear(); @@ -260,6 +262,7 @@ public class PizzaBasketWebSessionBean implements PizzaBasketWebSessionControlle // Trace message //this.getLogger().logTrace(MessageFormat.format("doChangeItem: targetPage={0} - EXIT!", targetPage)); + // Return page return targetPage; } @@ -306,6 +309,7 @@ public class PizzaBasketWebSessionBean implements PizzaBasketWebSessionControlle // Trace message //this.getLogger().logTrace(MessageFormat.format("getItemAmount: itemAmount={0} - EXIT!", itemAmount)); + // Return it return itemAmount; } @@ -360,11 +364,13 @@ public class PizzaBasketWebSessionBean implements PizzaBasketWebSessionControlle // Debug message //this.getLogger().logDebug(MessageFormat.format("isProductAdded: fake={0}", fake)); + // Ask bean about it boolean isAdded = this.basket.isAdded(fake); // Debug message //this.getLogger().logDebug(MessageFormat.format("isProductAdded: isAdded={0}", isAdded)); + // Is it added? if (isAdded) { // Get item @@ -378,6 +384,7 @@ public class PizzaBasketWebSessionBean implements PizzaBasketWebSessionControlle // Trace message //this.getLogger().logTrace(MessageFormat.format("isProductAdded: isAdded={0} - EXIT!", isAdded)); + // Return status return isAdded; } @@ -411,6 +418,7 @@ public class PizzaBasketWebSessionBean implements PizzaBasketWebSessionControlle // Trace message //this.getLogger().logTrace(MessageFormat.format("outputLastAddedItem: lastItem={0} - EXIT!", lastItem)); + // Return it return lastItem; } @@ -451,11 +459,13 @@ public class PizzaBasketWebSessionBean implements PizzaBasketWebSessionControlle // Debug message //this.getLogger().logDebug(MessageFormat.format("getItemFromProduct: fake={0}", fake)); + // Get all items List list = this.basket.getAll(); // Debug message //this.getLogger().logDebug(MessageFormat.format("getItemFromProduct: list={0}", list)); + // Check all entries for (final AddableBasketItem item : list) { // Debug message @@ -477,6 +487,7 @@ public class PizzaBasketWebSessionBean implements PizzaBasketWebSessionControlle // Trace message //this.getLogger().logTrace(MessageFormat.format("getItemFromProduct: foundItem={0} - EXIT!", foundItem)); + // Return it return foundItem; } diff --git a/src/java/org/mxchange/pizzaapplication/beans/category/PizzaAdminCategoryWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/category/PizzaAdminCategoryWebRequestBean.java index e1a067bc..35df9066 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/category/PizzaAdminCategoryWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/category/PizzaAdminCategoryWebRequestBean.java @@ -17,18 +17,21 @@ package org.mxchange.pizzaapplication.beans.category; import javax.enterprise.context.RequestScoped; +import javax.enterprise.event.Event; +import javax.enterprise.inject.Any; import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; 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.category.ShopCategoryAddedEvent; import org.mxchange.jshopcore.exceptions.CannotAddCategoryException; import org.mxchange.jshopcore.exceptions.CategoryTitleAlreadyUsedException; import org.mxchange.jshopcore.model.category.AdminCategorySessionBeanRemote; import org.mxchange.jshopcore.model.category.Category; import org.mxchange.jshopcore.model.category.ProductCategory; -import org.mxchange.pizzaapplication.beans.shop.PizzaShopWebApplicationController; /** * Main application class @@ -44,6 +47,13 @@ public class PizzaAdminCategoryWebRequestBean implements PizzaAdminCategoryWebRe */ private static final long serialVersionUID = 5_819_375_183_472_871L; + /** + * Event for added shop categories + */ + @Inject + @Any + private Event categoryAddedEvent; + /** * Remote bean for categories */ @@ -60,14 +70,6 @@ public class PizzaAdminCategoryWebRequestBean implements PizzaAdminCategoryWebRe */ private Category parentCategory; - ////////////////////// Bean injections /////////////////////// - - /** - * Shop bean - */ - @Inject - private PizzaShopWebApplicationController shopController; - /** * Default constructor */ @@ -96,8 +98,8 @@ public class PizzaAdminCategoryWebRequestBean implements PizzaAdminCategoryWebRe // Deligate to remote bean Category updatedCategory = this.categoryBean.doAdminAddCategory(category); - // Also send it to the controller bean - this.shopController.addCategory(updatedCategory); + // Fire event + this.categoryAddedEvent.fire(new ShopCategoryAddedEvent(updatedCategory)); // Unset all older values this.setCategoryTitle(""); //NOI18N diff --git a/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java index 29dbdfb2..4992bfeb 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java @@ -21,12 +21,14 @@ 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; import org.mxchange.jshopcore.model.product.Product; @@ -71,6 +73,12 @@ public class PizzaShopWebApplicationBean implements PizzaShopWebApplicationContr } } + @Override + public void afterShopCategoryAdded (@Observes final AddedCategoryEvent event) { + // Add it here, too. + this.addCategory(event.getAddedCategory()); + } + @Override public List getAllCategories () throws FacesException { // Return it @@ -90,7 +98,6 @@ public class PizzaShopWebApplicationBean implements PizzaShopWebApplicationContr @Override public List getAvailableProducts () throws FacesException { // Return it - // TODO Find something better here to prevent warning return Collections.unmodifiableList(this.availableProducts); } diff --git a/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java b/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java index b7ccb5c8..992d5dc7 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java @@ -19,6 +19,7 @@ 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.model.category.Category; import org.mxchange.jshopcore.model.product.Product; @@ -33,6 +34,7 @@ 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); @@ -49,6 +51,7 @@ 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 getAllCategories () throws FaceletException; @@ -59,6 +62,7 @@ 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; @@ -71,4 +75,11 @@ public interface PizzaShopWebApplicationController extends Serializable { */ 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); }