From bdbb276995058f268b54b58cb4dbdabfdc68b87b Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sun, 10 Apr 2016 16:24:34 +0200 Subject: [PATCH] also fire an event when a new product has been added, rather than calling addProduct() statically --- lib/jshop-core.jar | Bin 48594 -> 51410 bytes .../PizzaAdminProductWebRequestBean.java | 25 +++++++++--------- .../shop/PizzaShopWebApplicationBean.java | 7 +++++ .../PizzaShopWebApplicationController.java | 10 +++++++ 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/lib/jshop-core.jar b/lib/jshop-core.jar index 4a5a142ab616548f87024661db78d6cf318311fd..9abcd77805e3afa5dee6aff49114f03c5c505c53 100644 GIT binary patch delta 2822 zcma)8du&u?7XRHlw=;KUE}iN0J=`)==xd;q5n7-vEu9uxv5M^$A6N)!n95@-tx#}% zmnNDl##lTnL;)Yf$I9aNNlRM@pqs^nxCq&YW{FYx!@t}>jM=PYSI_s&11|KBo#fne z@9+H1cOKtsF5gfu@3$E(%{I*i=)i&g{YFTAt$+Wrw^i!j|7B1-Z-n?sMamMP+LbDy z4k`^oeWQlxtm4S%+1VZ4y}5VM&5_u6MX41WQ>_&0A+=7Z*VV?DV|`48>DrV|8*MJ} zxy`mxsAIO(LS45-geupnS&crfZB~T-d&)t38ujnH`>B_&D5?Sosi8hCKbb`&8tsg> z#8RT5J%cW2hSRg9vsW6(oU?*H^Uv~U-O5|Nr*lVd+4hb-9SWAwUL)sKyFE8i)*VEO z1eVc6N}f#Q(+e+se%S#CiHJnf6Mk)5yL%FO%(mxl*x*7c7CKO-W04Cg!fxD!#V#yC zxdRnCmb&1Gfy;C(ccBthI;tI5;X(~+1$m{8IyWMy*U_M3l@nQ5?LeagO>{0C^1yqw zWMSwB1xAPH0ew?dMPKIbq^s$Eu4l%)4mt8X?0>g{J318f-%^0=!Oboi2w)9eDwsDv zLxzf%8QiujxMO!$moVSMqZ(+&y$;-GU@h*ae!ckldAHKbHh1)PZt33nlBpCOssi2{H!E*_XhWLbZv{4DW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#TgW{_98zq#Y-&3l8~M?_Ms*vn6(JQCa{jm^zj?YSwG^fJ(F2@6DHy*1$mBH# delta 1467 zcmZ8gduWqa6u-G&npa~Rt7f&ml1y#g=c9(z>Y8Y5ebri=>AJB&iLJOfWrD*AR;gJE zV_>n`dj2R{4Jz~fia5oz=_`GSg4Lp^_+T<+Fqp2wn9e`Cdro5XYv6pp+~4na&pG#e z_Zw;CEr^vsw+(7=7{ubi@Tt7Sx^+&aw>OKi>Psg>t@dWvd2m5I~c;+zJWHGMvtt$|GtrZBbTLpB>7@TAQPaD>N z(l(*9!G$*G3}2a!k5}UFX-lAfIeYInHTmDh{wgk${(Q%1&vcEaL3*Y^sM!FnC>8QX zh3*a(g0Rz^rY#2Es8_zY@nc8loC1fVd0?wEfZA?#j#gDo#gGES!5rA$o`L7u-7feu zWE@akWFDhA8$6NXM|vo?PXybqCUAC8hj|@>e}ilm1Tzfqw>f)niUAtpVv7{7r6k3$ z*#WOQGN>g>YwGKm!Wc$LvL(iTsatE68%kki7v-<)61?6fnW+%W&VrIIYV^8fpJpUj zGmHrPTfe(oaQ6gKYP;# z6a0aLSYMt6_RKKC<5>J04<{ekSt-we;nJizH#4ze49xGLG`=3ezjP&7Bh2<#Ak-62 z;~sHsE>B?$;}cDq4f)9pq2@Hu_fo3NUcqgJ?O@COq#_)}+UuVMZ2H3tswKRAvt z3~le$D%$*_ZyMgN%znW~HcKW4D*LmMsgaDbRWftnT0fP%Cz&6ACQtUjhv@MR2(AL< z`5x>r)EPg^u;WOlU(OukW6i*ZkC3^#C_QQZ_Y2WeB`1q9M`I2hlNSRo^aoIJHJ*80 loz+tzF9k+{#=PoG!fb-om+cU}YD!a?$_COH`{x`w{|8^m(6ayl diff --git a/src/java/org/mxchange/pizzaapplication/beans/product/PizzaAdminProductWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/product/PizzaAdminProductWebRequestBean.java index 8fe2033f..3d115e09 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/product/PizzaAdminProductWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/product/PizzaAdminProductWebRequestBean.java @@ -18,19 +18,22 @@ package org.mxchange.pizzaapplication.beans.product; import java.util.List; 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.product.AddedProductEvent; +import org.mxchange.jshopcore.events.product.ShopProductAddedEvent; import org.mxchange.jshopcore.exceptions.CannotAddProductException; import org.mxchange.jshopcore.exceptions.ProductTitleAlreadyUsedException; import org.mxchange.jshopcore.model.category.Category; import org.mxchange.jshopcore.model.product.AdminProductSessionBeanRemote; import org.mxchange.jshopcore.model.product.GenericProduct; import org.mxchange.jshopcore.model.product.Product; -import org.mxchange.pizzaapplication.beans.shop.PizzaShopWebApplicationController; /** * Main application class @@ -46,7 +49,13 @@ public class PizzaAdminProductWebRequestBean implements PizzaAdminProductWebRequ */ private static final long serialVersionUID = 5_819_375_183_472_871L; - /////////////////////// Properties ///////////////////// + /** + * Event for added product + */ + @Inject + @Any + private Event addedProductEvent; + /** * Available */ @@ -72,14 +81,6 @@ public class PizzaAdminProductWebRequestBean implements PizzaAdminProductWebRequ */ private String productTitle; - ////////////////////// Bean injections /////////////////////// - - /** - * Shop bean - */ - @Inject - private PizzaShopWebApplicationController shopController; - /** * Default constructor */ @@ -112,8 +113,8 @@ public class PizzaAdminProductWebRequestBean implements PizzaAdminProductWebRequ // Call bean Product updatedProduct = this.productRemoteBean.doAdminAddProduct(product); - // Add to shop controller - this.shopController.addProduct(updatedProduct); + // Fire event + this.addedProductEvent.fire(new ShopProductAddedEvent(updatedProduct)); // Set all to null this.setProductAvailability(Boolean.FALSE); diff --git a/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java index 4992bfeb..1fbe8458 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java @@ -29,6 +29,7 @@ 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; @@ -79,6 +80,12 @@ public class PizzaShopWebApplicationBean implements PizzaShopWebApplicationContr this.addCategory(event.getAddedCategory()); } + @Override + public void afterShopProductAdded (@Observes final AddedProductEvent event) { + // Add it here, too. + this.addProduct(event.getAddedProduct()); + } + @Override public List getAllCategories () throws FacesException { // Return it diff --git a/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java b/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java index 992d5dc7..74b43691 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java @@ -20,6 +20,7 @@ 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; @@ -82,4 +83,13 @@ public interface PizzaShopWebApplicationController extends Serializable { * @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); + } -- 2.39.5