]> git.mxchange.org Git - pizzaservice-war.git/blobdiff - src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java
Auto-formatted whole project
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / beans / basket / BasketWebBean.java
index afc1020d897271d781f3f08159a116eaa67d471a..467033c469104cc872f0f6e6df3d56a100768cec 100644 (file)
@@ -18,7 +18,6 @@ package org.mxchange.pizzaapplication.beans.basket;
 
 import java.text.MessageFormat;
 import java.util.List;
-import javax.annotation.PostConstruct;
 import javax.enterprise.context.SessionScoped;
 import javax.faces.FacesException;
 import javax.faces.view.facelets.FaceletException;
@@ -26,23 +25,22 @@ import javax.inject.Named;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
-import org.mxchange.jcoreee.beans.BaseFrameworkBean;
 import org.mxchange.jshopcore.exceptions.BasketItemAlreadyAddedException;
 import org.mxchange.jshopcore.model.basket.AddableBasketItem;
 import org.mxchange.jshopcore.model.basket.Basket;
 import org.mxchange.jshopcore.model.basket.BasketSessionBeanRemote;
 import org.mxchange.jshopcore.model.basket.ShopBasket;
-import org.mxchange.jshopcore.model.item.BasketItem;
+import org.mxchange.jshopcore.model.basket.items.BasketItem;
 import org.mxchange.jshopcore.model.product.Product;
 
 /**
  * A bean for the basket
- *
+ * <p>
  * @author Roland Haeder<roland@mxchange.org>
  */
 @Named ("basketController")
 @SessionScoped
-public class BasketWebBean extends BaseFrameworkBean implements BasketWebController {
+public class BasketWebBean implements BasketWebController {
 
        /**
         * Serial number
@@ -61,9 +59,9 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
 
        /////////////////////// Properties /////////////////////
        /**
-        * Ordered amount
+        * Ordered orderedAmount
         */
-       private Long amount;
+       private Long orderedAmount;
 
        /**
         * Current item
@@ -92,7 +90,7 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
        @Override
        public String addItem (final Product product) {
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("addItem: product={0} - CALLED!", product));
+               //this.getLogger().logTrace(MessageFormat.format("addItem: product={0} - CALLED!", product));
 
                // product should not be null
                if (null == product) {
@@ -101,14 +99,14 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                }
 
                // Generate item instance
-               AddableBasketItem item = new BasketItem(product, this.getAmount());
+               AddableBasketItem item = new BasketItem(product, this.getOrderedAmount());
 
-               // Is amount set?
-               if (this.getAmount() == null) {
+               // Is orderedAmount set?
+               if (this.getOrderedAmount() == null) {
                        // Trace message
-                       this.getLogger().logTrace("addItem: amount not specified, returning null ... - EXIT!");
+                       //this.getLogger().logTrace("addItem: orderedAmount not specified, returning null ... - EXIT!");
 
-                       // No amount specified?!
+                       // No orderedAmount specified?!
                        return null;
                }
 
@@ -122,12 +120,11 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                        // Deligate to model
                        this.basket.addItem(item);
 
-                       // Remove amount
-                       this.setAmount(null);
+                       // Remove orderedAmount
+                       this.setOrderedAmount(null);
 
                        // Trace message
-                       this.getLogger().logTrace(MessageFormat.format("addItem: item {0} - has been added to basket. - EXIT!", item));
-
+                       //this.getLogger().logTrace(MessageFormat.format("addItem: item {0} - has been added to basket. - EXIT!", item));
                        // Added
                        return "item_added"; //NOI18N
                } catch (final BasketItemAlreadyAddedException ex) {
@@ -139,14 +136,13 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
        @Override
        public List<AddableBasketItem> allItems () {
                // Trace message
-               this.getLogger().logTrace("allItems: CALLED!");
+               //this.getLogger().logTrace("allItems: CALLED!");
 
                // Deligate to basket instance
                List<AddableBasketItem> list = this.basket.getAll();
 
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("allItems: list={0} - EXIT!", list));
-
+               //this.getLogger().logTrace(MessageFormat.format("allItems: list={0} - EXIT!", list));
                // Return it
                return list;
        }
@@ -154,26 +150,25 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
        @Override
        public Float calculateCurrentItemPrice () {
                // Trace message
-               this.getLogger().logTrace("calculateCurrentItemPrice: CALLED!");
+               //this.getLogger().logTrace("calculateCurrentItemPrice: CALLED!");
 
                // Is the current item/amount set?
                if (this.getCurrentItem() == null) {
                        // Current item is null
                        throw new NullPointerException("currentItem is null"); //NOI18N
-               } else if (this.getCurrentItem().getProduct() == null) {
+               } else if (this.getCurrentItem().getItemProduct() == null) {
                        // Product is null
                        throw new NullPointerException("currentItem.product is null"); //NOI18N
-               } else if (this.getCurrentItem().getAmount() == null) {
+               } else if (this.getCurrentItem().getOrderedAmount() == null) {
                        // Amount is null
                        throw new NullPointerException("currentItem.amount is null"); //NOI18N
                }
 
                // Caculate item's price
-               Float totalPrice = (this.getCurrentItem().getProduct().getPrice() * this.getCurrentItem().getAmount());
+               Float totalPrice = (this.getCurrentItem().getItemProduct().getProductPrice() * this.getCurrentItem().getOrderedAmount());
 
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("calculateCurrentItemPrice: totalPrice={0} - EXIT!", totalPrice));
-
+               //this.getLogger().logTrace(MessageFormat.format("calculateCurrentItemPrice: totalPrice={0} - EXIT!", totalPrice));
                // Return it
                return totalPrice;
        }
@@ -181,7 +176,7 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
        @Override
        public Float calculateItemPrice (final AddableBasketItem item) {
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("calculateItemPrice: item={0} - CALLED!", item));
+               //this.getLogger().logTrace(MessageFormat.format("calculateItemPrice: item={0} - CALLED!", item));
 
                // item must not be null
                if (null == item) {
@@ -195,12 +190,11 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                // Is it a product?
                if (item.isProductType()) {
                        // Caculate item's price
-                       totalPrice = (item.getProduct().getPrice() * item.getAmount());
+                       totalPrice = (item.getItemProduct().getProductPrice() * item.getOrderedAmount());
                }
 
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("calculateItemPrice: totalPrice={0} - EXIT!", totalPrice));
-
+               //this.getLogger().logTrace(MessageFormat.format("calculateItemPrice: totalPrice={0} - EXIT!", totalPrice));
                // Return it
                return totalPrice;
        }
@@ -208,7 +202,7 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
        @Override
        public Float calculateTotalPrice () {
                // Trace message
-               this.getLogger().logTrace("calculateTotalPrice: CALLED!");
+               //this.getLogger().logTrace("calculateTotalPrice: CALLED!");
 
                // Init total price
                Float totalPrice = 0.0f;
@@ -223,8 +217,7 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                }
 
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("calculateTotalPrice: totalPrice={0} - EXIT!", totalPrice));
-
+               //this.getLogger().logTrace(MessageFormat.format("calculateTotalPrice: totalPrice={0} - EXIT!", totalPrice));
                // Return final sum
                return totalPrice;
        }
@@ -232,7 +225,7 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
        @Override
        public String changeItem (final AddableBasketItem item) {
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("changeItem: item={0} - CALLED!", item));
+               //this.getLogger().logTrace(MessageFormat.format("changeItem: item={0} - CALLED!", item));
 
                // item shall not be null
                if (null == item) {
@@ -254,8 +247,7 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                }
 
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("changeItem: targetPage={0} - EXIT!", targetPage));
-
+               //this.getLogger().logTrace(MessageFormat.format("changeItem: targetPage={0} - EXIT!", targetPage));
                // Return page
                return targetPage;
        }
@@ -268,13 +260,13 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
        }
 
        @Override
-       public Long getAmount () {
-               return this.amount;
+       public Long getOrderedAmount () {
+               return this.orderedAmount;
        }
 
        @Override
-       public void setAmount (final Long amount) {
-               this.amount = amount;
+       public void setOrderedAmount (final Long orderedAmount) {
+               this.orderedAmount = orderedAmount;
        }
 
        @Override
@@ -290,7 +282,7 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
        @Override
        public Long getItemAmount (final Product product) {
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("getItemAmount: product={0} - CALLED!", product));
+               //this.getLogger().logTrace(MessageFormat.format("getItemAmount: product={0} - CALLED!", product));
 
                // product should not be null
                if (null == product) {
@@ -304,22 +296,21 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                // Iterate over all
                for (final AddableBasketItem item : this.allItems()) {
                        // Debug message
-                       this.getLogger().logDebug(MessageFormat.format("getItemAmount: item={0}", item));
+                       //this.getLogger().logDebug(MessageFormat.format("getItemAmount: item={0}", item));
 
                        // Is this product instance and same?
                        if (null == item) {
                                // item is null
                                throw new NullPointerException("item is null");
-                       } else if ((item.isProductType()) && (item.getProduct().equals(product))) {
+                       } else if ((item.isProductType()) && (item.getItemProduct().equals(product))) {
                                // Found it
-                               itemAmount = item.getAmount();
+                               itemAmount = item.getOrderedAmount();
                                break;
                        }
                }
 
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("getItemAmount: itemAmount={0} - EXIT!", itemAmount));
-
+               //this.getLogger().logTrace(MessageFormat.format("getItemAmount: itemAmount={0} - EXIT!", itemAmount));
                // Return it
                return itemAmount;
        }
@@ -342,12 +333,6 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                return (!this.isEmpty());
        }
 
-       @PostConstruct
-       public void init () {
-               // Call generic init first
-               super.genericInit();
-       }
-
        @Override
        public boolean isEmpty () {
                // Deligate to basket instance
@@ -357,7 +342,7 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
        @Override
        public boolean isProductAdded (final Product product) {
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("isProductAdded: product={0} - EXIT!", product));
+               //this.getLogger().logTrace(MessageFormat.format("isProductAdded: product={0} - EXIT!", product));
 
                // Must not be null
                if (null == product) {
@@ -369,29 +354,25 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                AddableBasketItem fake = new BasketItem(product);
 
                // Debug message
-               this.getLogger().logDebug(MessageFormat.format("isProductAdded: fake={0}", fake));
-
+               //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));
-
+               //this.getLogger().logDebug(MessageFormat.format("isProductAdded: isAdded={0}", isAdded));
                // Is it added?
                if (isAdded) {
                        // Get item
                        AddableBasketItem item = this.getItemFromProduct(product);
 
                        // Debug message
-                       this.getLogger().logDebug(MessageFormat.format("isProductAdded: item={0} - setting as current item.", item));
-
+                       //this.getLogger().logDebug(MessageFormat.format("isProductAdded: item={0} - setting as current item.", item));
                        // Set this as current item
                        this.setCurrentItem(item);
                }
 
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("isProductAdded: isAdded={0} - EXIT!", isAdded));
-
+               //this.getLogger().logTrace(MessageFormat.format("isProductAdded: isAdded={0} - EXIT!", isAdded));
                // Return status
                return isAdded;
        }
@@ -399,7 +380,7 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
        @Override
        public String outputLastAddedItem () {
                // Trace message
-               this.getLogger().logTrace("outputLastAddedItem: CALLED!");
+               //this.getLogger().logTrace("outputLastAddedItem: CALLED!");
 
                // Default message
                String lastItem = ""; //NOI18N
@@ -412,10 +393,10 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                        // Get type
                        switch (item.getItemType()) {
                                case "product": // Sellable product //NOI18N
-                                       assert (item.getProduct() instanceof Product) : MessageFormat.format("item {0} has no product instance set.", item); //NOI18N
+                                       assert (item.getItemProduct() instanceof Product) : MessageFormat.format("item {0} has no product instance set.", item); //NOI18N
 
                                        // Get title
-                                       lastItem = item.getProduct().getTitle();
+                                       lastItem = item.getItemProduct().getProductTitle();
                                        break;
 
                                default: // Not supported
@@ -424,15 +405,14 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                }
 
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("outputLastAddedItem: lastItem={0} - EXIT!", lastItem));
-
+               //this.getLogger().logTrace(MessageFormat.format("outputLastAddedItem: lastItem={0} - EXIT!", lastItem));
                // Return it
                return lastItem;
        }
 
        /**
         * Getter for basket bean instance
-        *
+        * <p>
         * @return Basket bean instance
         */
        private BasketSessionBeanRemote getBasketBean () {
@@ -443,13 +423,14 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
         * Somewhat getter for an item instance from given product instance. This
         * method returns null if no item was found to given product. The product is
         * found by checking it's id and itemType=product
-        *
+        * <p>
         * @param product Product instance
+        * <p>
         * @return Item instance or null if not found
         */
        private AddableBasketItem getItemFromProduct (final Product product) {
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("getItemFromProduct: product={0} - CALLED!", product));
+               //this.getLogger().logTrace(MessageFormat.format("getItemFromProduct: product={0} - CALLED!", product));
 
                // Product must not be null
                if (null == product) {
@@ -464,18 +445,16 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                AddableBasketItem fake = new BasketItem(product);
 
                // Debug message
-               this.getLogger().logDebug(MessageFormat.format("getItemFromProduct: fake={0}", fake));
-
+               //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));
-
+               //this.getLogger().logDebug(MessageFormat.format("getItemFromProduct: list={0}", list));
                // Check all entries
                for (final AddableBasketItem item : list) {
                        // Debug message
-                       this.getLogger().logDebug(MessageFormat.format("getItemFromProduct: item={0}", item));
+                       //this.getLogger().logDebug(MessageFormat.format("getItemFromProduct: item={0}", item));
 
                        // item must not be null
                        if (null == item) {
@@ -492,8 +471,7 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                }
 
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("getItemFromProduct: foundItem={0} - EXIT!", foundItem));
-
+               //this.getLogger().logTrace(MessageFormat.format("getItemFromProduct: foundItem={0} - EXIT!", foundItem));
                // Return it
                return foundItem;
        }