]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Continued a bit:
authorRoland Haeder <roland@mxchange.org>
Sun, 10 Apr 2016 13:56:50 +0000 (15:56 +0200)
committerRoland Haeder <roland@mxchange.org>
Sun, 10 Apr 2016 13:56:50 +0000 (15:56 +0200)
- replaced "static add-call" to event-based approach. This is much more flexible and easier to expand
- updated jar(s)

lib/jcoreee.jar
lib/jshop-core.jar
src/java/org/mxchange/pizzaapplication/beans/basket/PizzaBasketWebSessionBean.java
src/java/org/mxchange/pizzaapplication/beans/category/PizzaAdminCategoryWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java
src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java

index 3a32dfff27965a3b537e31aae5fea9bcc5de3288..ad61871dc3c447ae7b78f28e4fee6bf4892cb44f 100644 (file)
Binary files a/lib/jcoreee.jar and b/lib/jcoreee.jar differ
index 30d16dd5106fa2ca4a9653284740c7d1fcb565b4..4a5a142ab616548f87024661db78d6cf318311fd 100644 (file)
Binary files a/lib/jshop-core.jar and b/lib/jshop-core.jar differ
index 890f7116b07050b8f8d4dbe44fbc265755bb4b36..08e2b7ad70d680d2e17c82f71b7a86cc8df9954d 100644 (file)
@@ -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<AddableBasketItem> 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;
        }
index e1a067bc6cf97a58d411cb889d353055585e4215..35df9066701ca13d449f7c5c13220e1ff477bb1a 100644 (file)
 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<AddedCategoryEvent> 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
index 29dbdfb2a5260d62b4355b8a4051e4516cd4f424..4992bfeb84086ff0cd020510ecc7488ea31f81c4 100644 (file)
@@ -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<Category> getAllCategories () throws FacesException {
                // Return it
@@ -90,7 +98,6 @@ public class PizzaShopWebApplicationBean implements PizzaShopWebApplicationContr
        @Override
        public List<Product> getAvailableProducts () throws FacesException {
                // Return it
-               // TODO Find something better here to prevent warning
                return Collections.unmodifiableList(this.availableProducts);
        }
 
index b7ccb5c817017d843db6c3816473241069865748..992d5dc746909d30723b43c9f10ab178e8e8a333 100644 (file)
@@ -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
         * <p>
         * @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
         * <p>
         * @throws javax.faces.view.facelets.FaceletException If anything went wrong
+        * @todo Move this to own controller
         */
        List<Category> getAllCategories () throws FaceletException;
 
@@ -59,6 +62,7 @@ public interface PizzaShopWebApplicationController extends Serializable {
         * @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;
 
@@ -71,4 +75,11 @@ public interface PizzaShopWebApplicationController extends Serializable {
         */
        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);
 }