From: Roland Haeder Date: Mon, 19 Oct 2015 07:34:28 +0000 (+0200) Subject: Renamed beans to their proper scope + renamed bean mappedName to always end with... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=eccea36f65a917177858636b45ac6543616b6c05;p=pizzaservice-war.git Renamed beans to their proper scope + renamed bean mappedName to always end with "Controller" Signed-off-by:Roland Häder --- diff --git a/src/java/org/mxchange/jshopcore/model/category/CategoryConverter.java b/src/java/org/mxchange/jshopcore/model/category/CategoryConverter.java index b811c9b5..8ada3709 100644 --- a/src/java/org/mxchange/jshopcore/model/category/CategoryConverter.java +++ b/src/java/org/mxchange/jshopcore/model/category/CategoryConverter.java @@ -30,7 +30,7 @@ import javax.naming.InitialContext; import javax.naming.NamingException; import org.mxchange.jcoreeelogger.beans.local.logger.Log; import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal; -import org.mxchange.pizzaapplication.beans.shop.ShopWebController; +import org.mxchange.pizzaapplication.beans.shop.ShopWebApplicationController; /** * A converter for transfering category objects @@ -50,7 +50,7 @@ public class CategoryConverter implements Converter { * Category bean */ @Inject - private ShopWebController shopController; + private ShopWebApplicationController shopController; @Override public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { diff --git a/src/java/org/mxchange/pizzaapplication/beans/AbstractWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/AbstractWebBean.java deleted file mode 100644 index 1e632c58..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/AbstractWebBean.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.pizzaapplication.beans; - -import java.io.Serializable; -import java.util.ResourceBundle; - -/** - * An abstract web web bean for web applications. This class currently only - * handles loading the resource bundle (i18n). - *

- * @author Roland Haeder - */ -public abstract class AbstractWebBean implements Serializable { - - /** - * Serial number - */ - private static final long serialVersionUID = 48_475_834_783_473_187L; - - /** - * Bundle instance - */ - private final ResourceBundle bundle; - - /** - * Protectd constructor - */ - protected AbstractWebBean () { - // Load resource bundle - this.bundle = ResourceBundle.getBundle("org/mxchange/localization/bundle"); - } - - /** - * Getter for bundle instance - *

- * @return Bundle instance - */ - protected ResourceBundle getBundle () { - return this.bundle; - } - - /** - * Getter for message from given key - *

- * @param key Key to get message from - *

- * @return Message - */ - protected String getMessageStringFromKey (final String key) { - // Is the bundle loaded? - if (this.getBundle() == null) { - // Abort here - throw new NullPointerException("bundle is null"); //NOI18N - } - - // Return message - return this.getBundle().getString(key); - } -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java deleted file mode 100644 index edf197f1..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java +++ /dev/null @@ -1,479 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.pizzaapplication.beans.basket; - -import java.text.MessageFormat; -import java.util.List; -import javax.enterprise.context.SessionScoped; -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.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.basket.items.BasketItem; -import org.mxchange.jshopcore.model.product.Product; - -/** - * A bean for the basket - *

- * @author Roland Haeder - */ -@Named ("basketController") -@SessionScoped -public class BasketWebBean implements BasketWebController { - - /** - * Serial number - */ - private static final long serialVersionUID = 5_476_347_320_198L; - - /** - * Instance of wrapped basket - */ - private final Basket basket; - - /** - * Basket bean - */ - private final BasketSessionBeanRemote basketBean; - - - /** - * Current item - */ - private AddableBasketItem currentItem; - - /////////////////////// Properties ///////////////////// - /** - * Ordered orderedAmount - */ - private Long orderedAmount; - - /** - * Default constructor - */ - public BasketWebBean () { - // Get new application instance - this.basket = new ShopBasket(); - - try { - // Get initial context - Context context = new InitialContext(); - - // Try to lookup - this.basketBean = (BasketSessionBeanRemote) context.lookup("ejb/stateless-basket"); //NOI18N - } catch (final NamingException ex) { - // Continue to throw - throw new FaceletException(ex); - } - } - - @Override - public String addItem (final Product product) { - // Trace message - //this.getLogger().logTrace(MessageFormat.format("addItem: product={0} - CALLED!", product)); - - // product should not be null - if (null == product) { - // Abort here - throw new NullPointerException("product is null"); - } - - // Generate item instance - AddableBasketItem item = new BasketItem(product, this.getOrderedAmount()); - - // Is orderedAmount set? - if (this.getOrderedAmount() == null) { - // Trace message - //this.getLogger().logTrace("addItem: orderedAmount not specified, returning null ... - EXIT!"); - - // No orderedAmount specified?! - return null; - } - - try { - // item should not be null - if (null == item) { - // Abort here - throw new NullPointerException("item is null"); //NOI18N - } - - // Deligate to model - this.basket.addItem(item); - - // Remove orderedAmount - this.setOrderedAmount(null); - - // 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) { - // Throw unchecked exception - throw new FacesException(ex); - } - } - - @Override - public List allItems () { - // Trace message - //this.getLogger().logTrace("allItems: CALLED!"); - - // Deligate to basket instance - List list = this.basket.getAll(); - - // Trace message - //this.getLogger().logTrace(MessageFormat.format("allItems: list={0} - EXIT!", list)); - // Return it - return list; - } - - @Override - public Float calculateCurrentItemPrice () { - // Trace message - //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().getItemProduct() == null) { - // Product is null - throw new NullPointerException("currentItem.product is null"); //NOI18N - } 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().getItemProduct().getProductPrice() * this.getCurrentItem().getOrderedAmount()); - - // Trace message - //this.getLogger().logTrace(MessageFormat.format("calculateCurrentItemPrice: totalPrice={0} - EXIT!", totalPrice)); - // Return it - return totalPrice; - } - - @Override - public Float calculateItemPrice (final AddableBasketItem item) { - // Trace message - //this.getLogger().logTrace(MessageFormat.format("calculateItemPrice: item={0} - CALLED!", item)); - - // item must not be null - if (null == item) { - // Abort here - throw new NullPointerException("item is null"); - } - - // Default value - Float totalPrice = 0.0f; - - // Is it a product? - if (item.isProductType()) { - // Caculate item's price - totalPrice = (item.getItemProduct().getProductPrice() * item.getOrderedAmount()); - } - - // Trace message - //this.getLogger().logTrace(MessageFormat.format("calculateItemPrice: totalPrice={0} - EXIT!", totalPrice)); - // Return it - return totalPrice; - } - - @Override - public Float calculateTotalPrice () { - // Trace message - //this.getLogger().logTrace("calculateTotalPrice: CALLED!"); - - // Init total price - Float totalPrice = 0.0f; - - // Iterate over all items - for (final AddableBasketItem item : this.allItems()) { - // Is the item a product? - if (item.isProductType()) { - // Calculate single price and add it - totalPrice += this.calculateItemPrice(item); - } - } - - // Trace message - //this.getLogger().logTrace(MessageFormat.format("calculateTotalPrice: totalPrice={0} - EXIT!", totalPrice)); - // Return final sum - return totalPrice; - } - - @Override - public String changeItem (final AddableBasketItem item) { - // Trace message - //this.getLogger().logTrace(MessageFormat.format("changeItem: item={0} - CALLED!", item)); - - // item shall not be null - if (null == item) { - // Abort here - throw new NullPointerException("item is null"); - } - - // Default is not found - String targetPage = "item_not_changed"; //NOI18N - - // Lookup item in basket - for (final AddableBasketItem basketItem : this.allItems()) { - // Is it the same? - if (basketItem.equals(item)) { - // Found it, so allow redirect to proper page - targetPage = "basket"; //NOI18N - break; - } - } - - // Trace message - //this.getLogger().logTrace(MessageFormat.format("changeItem: targetPage={0} - EXIT!", targetPage)); - // Return page - return targetPage; - } - - @Override - public void clear () { - // @TODO Also clear EJB - // Deligate to basket instance - this.basket.clear(); - } - - @Override - public AddableBasketItem getCurrentItem () { - return this.currentItem; - } - - @Override - public void setCurrentItem (final AddableBasketItem currentItem) { - this.currentItem = currentItem; - } - - @Override - public Long getItemAmount (final Product product) { - // Trace message - //this.getLogger().logTrace(MessageFormat.format("getItemAmount: product={0} - CALLED!", product)); - - // product should not be null - if (null == product) { - // Abort here - throw new NullPointerException("product is null"); - } - - // Initial value is zero - Long itemAmount = 0L; - - // Iterate over all - for (final AddableBasketItem item : this.allItems()) { - // Debug message - //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.getItemProduct().equals(product))) { - // Found it - itemAmount = item.getOrderedAmount(); - break; - } - } - - // Trace message - //this.getLogger().logTrace(MessageFormat.format("getItemAmount: itemAmount={0} - EXIT!", itemAmount)); - // Return it - return itemAmount; - } - - @Override - public AddableBasketItem getLast () { - // Deligate to basket instance - return this.basket.getLast(); - } - - @Override - public int getLastNumRows () { - // Deligate to basket instance - return this.basket.getLastNumRows(); - } - - @Override - public Long getOrderedAmount () { - return this.orderedAmount; - } - - @Override - public void setOrderedAmount (final Long orderedAmount) { - this.orderedAmount = orderedAmount; - } - - @Override - public boolean hasItems () { - // Call above and invert it - return (!this.isEmpty()); - } - - @Override - public boolean isEmpty () { - // Deligate to basket instance - return this.basket.isEmpty(); - } - - @Override - public boolean isProductAdded (final Product product) { - // Trace message - //this.getLogger().logTrace(MessageFormat.format("isProductAdded: product={0} - EXIT!", product)); - - // Must not be null - if (null == product) { - // Abort here - throw new NullPointerException("product is null"); //NOI18N - } - - // Generate fake instance - AddableBasketItem fake = new BasketItem(product); - - // 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 - AddableBasketItem item = this.getItemFromProduct(product); - - // Debug message - //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)); - // Return status - return isAdded; - } - - @Override - public String outputLastAddedItem () { - // Trace message - //this.getLogger().logTrace("outputLastAddedItem: CALLED!"); - - // Default message - String lastItem = ""; //NOI18N - - // Get instance - AddableBasketItem item = this.getLast(); - - // Is it set? - if (item instanceof AddableBasketItem) { - // Get type - switch (item.getItemType()) { - case "product": // Sellable product //NOI18N - assert (item.getItemProduct() instanceof Product) : MessageFormat.format("item {0} has no product instance set.", item); //NOI18N - - // Get title - lastItem = item.getItemProduct().getProductTitle(); - break; - - default: // Not supported - throw new FacesException(MessageFormat.format("item type {0} is not supported.", item.getItemType())); //NOI18N - } - } - - // Trace message - //this.getLogger().logTrace(MessageFormat.format("outputLastAddedItem: lastItem={0} - EXIT!", lastItem)); - // Return it - return lastItem; - } - - /** - * Getter for basket bean instance - *

- * @return Basket bean instance - */ - private BasketSessionBeanRemote getBasketBean () { - return this.basketBean; - } - - /** - * 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 - *

- * @param product Product instance - *

- * @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)); - - // Product must not be null - if (null == product) { - // Abort here - throw new NullPointerException("product is null"); //NOI18N - } - - // Create item instance - AddableBasketItem foundItem = null; - - // Create fake instance - AddableBasketItem fake = new BasketItem(product); - - // 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 - //this.getLogger().logDebug(MessageFormat.format("getItemFromProduct: item={0}", item)); - - // item must not be null - if (null == item) { - // Abort here - throw new NullPointerException("item is null"); //NOI18N - } - - // Is it the same? - if (item.equals(fake)) { - // Set found item and abort look - foundItem = item; - break; - } - } - - // 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/basket/BasketWebController.java b/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebController.java deleted file mode 100644 index 04b3cd6b..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebController.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.pizzaapplication.beans.basket; - -import java.io.Serializable; -import java.util.List; -import org.mxchange.jshopcore.model.basket.AddableBasketItem; -import org.mxchange.jshopcore.model.product.Product; - -/** - * An interface for a basket - *

- * @author Roland Haeder - */ -public interface BasketWebController extends Serializable { - - /** - * Adds given product instance to basket by adding amount from form data to - * it. - *

- * @param product Product instance to add - *

- * @return Redirect target or null - */ - String addItem (final Product product); - - /** - * Gets for all added items - *

- * @return A list of all added items - */ - List allItems (); - - /** - * Calculates total price (no tax added) of current item. If no current item - * is set and no amount, a NPE is thrown. - *

- * @return Current item's total price - */ - Float calculateCurrentItemPrice (); - - /** - * Calculates total price (no tax added) for given item. - *

- * @param item Item instance to calculate total price for - *

- * @return Total price - */ - Float calculateItemPrice (final AddableBasketItem item); - - /** - * Calculates total sum (no tax added) for all items - *

- * @return Total price of all items - */ - Float calculateTotalPrice (); - - /** - * Changes given item instance's amount in basket and redirects to proper - * page. If the item is not found, another "error" page is called. - *

- * @param item Item instance to change - *

- * @return Page redirection - */ - String changeItem (final AddableBasketItem item); - - /** - * Clears this basket instance - */ - void clear (); - - /** - * Getter for item amount property - *

- * @return Item amount property - */ - Long getOrderedAmount (); - - /** - * Setter for item amount property - *

- * @param amount Item amount property - */ - void setOrderedAmount (final Long amount); - - /** - * Getter for current item - *

- * @return Current item - */ - AddableBasketItem getCurrentItem (); - - /** - * Setter for current item - *

- * @param currentItem Current item - */ - void setCurrentItem (final AddableBasketItem currentItem); - - /** - * Some getter for item amount of given product. This method requires a full - * iteration over all items in the basket to look for proper product - * instance. - *

- * @param product Product instance - *

- * @return Item amount of given product - */ - Long getItemAmount (final Product product); - - /** - * Getter for last entry - *

- * @return Last added item in basket - */ - AddableBasketItem getLast (); - - /** - * Getter for last num rows - *

- * @return Last num rows - */ - int getLastNumRows (); - - /** - * Checks whether the basket has items in it. This method is wrapper to - * isEmpty() - *

- * @return Whether the basket is empty - */ - boolean hasItems (); - - /** - * Checks whether the basket is empty - *

- * @return Whether the basket is empty - */ - boolean isEmpty (); - - /** - * Checks whether the currently set product is added in basked - *

- * @param product Product instance - *

- * @return Whether the product is added - */ - boolean isProductAdded (final Product product); - - /** - * Outputs last added item in the basket. - *

- * @return Last added item - */ - String outputLastAddedItem (); -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebSessionBean.java new file mode 100644 index 00000000..5b10a767 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebSessionBean.java @@ -0,0 +1,479 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.basket; + +import java.text.MessageFormat; +import java.util.List; +import javax.enterprise.context.SessionScoped; +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.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.basket.items.BasketItem; +import org.mxchange.jshopcore.model.product.Product; + +/** + * A bean for the basket + *

+ * @author Roland Haeder + */ +@Named ("basketController") +@SessionScoped +public class BasketWebSessionBean implements BasketWebSessionController { + + /** + * Serial number + */ + private static final long serialVersionUID = 5_476_347_320_198L; + + /** + * Instance of wrapped basket + */ + private final Basket basket; + + /** + * Basket bean + */ + private final BasketSessionBeanRemote basketBean; + + + /** + * Current item + */ + private AddableBasketItem currentItem; + + /////////////////////// Properties ///////////////////// + /** + * Ordered orderedAmount + */ + private Long orderedAmount; + + /** + * Default constructor + */ + public BasketWebSessionBean () { + // Get new application instance + this.basket = new ShopBasket(); + + try { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup + this.basketBean = (BasketSessionBeanRemote) context.lookup("ejb/stateless-basket"); //NOI18N + } catch (final NamingException ex) { + // Continue to throw + throw new FaceletException(ex); + } + } + + @Override + public String addItem (final Product product) { + // Trace message + //this.getLogger().logTrace(MessageFormat.format("addItem: product={0} - CALLED!", product)); + + // product should not be null + if (null == product) { + // Abort here + throw new NullPointerException("product is null"); + } + + // Generate item instance + AddableBasketItem item = new BasketItem(product, this.getOrderedAmount()); + + // Is orderedAmount set? + if (this.getOrderedAmount() == null) { + // Trace message + //this.getLogger().logTrace("addItem: orderedAmount not specified, returning null ... - EXIT!"); + + // No orderedAmount specified?! + return null; + } + + try { + // item should not be null + if (null == item) { + // Abort here + throw new NullPointerException("item is null"); //NOI18N + } + + // Deligate to model + this.basket.addItem(item); + + // Remove orderedAmount + this.setOrderedAmount(null); + + // 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) { + // Throw unchecked exception + throw new FacesException(ex); + } + } + + @Override + public List allItems () { + // Trace message + //this.getLogger().logTrace("allItems: CALLED!"); + + // Deligate to basket instance + List list = this.basket.getAll(); + + // Trace message + //this.getLogger().logTrace(MessageFormat.format("allItems: list={0} - EXIT!", list)); + // Return it + return list; + } + + @Override + public Float calculateCurrentItemPrice () { + // Trace message + //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().getItemProduct() == null) { + // Product is null + throw new NullPointerException("currentItem.product is null"); //NOI18N + } 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().getItemProduct().getProductPrice() * this.getCurrentItem().getOrderedAmount()); + + // Trace message + //this.getLogger().logTrace(MessageFormat.format("calculateCurrentItemPrice: totalPrice={0} - EXIT!", totalPrice)); + // Return it + return totalPrice; + } + + @Override + public Float calculateItemPrice (final AddableBasketItem item) { + // Trace message + //this.getLogger().logTrace(MessageFormat.format("calculateItemPrice: item={0} - CALLED!", item)); + + // item must not be null + if (null == item) { + // Abort here + throw new NullPointerException("item is null"); + } + + // Default value + Float totalPrice = 0.0f; + + // Is it a product? + if (item.isProductType()) { + // Caculate item's price + totalPrice = (item.getItemProduct().getProductPrice() * item.getOrderedAmount()); + } + + // Trace message + //this.getLogger().logTrace(MessageFormat.format("calculateItemPrice: totalPrice={0} - EXIT!", totalPrice)); + // Return it + return totalPrice; + } + + @Override + public Float calculateTotalPrice () { + // Trace message + //this.getLogger().logTrace("calculateTotalPrice: CALLED!"); + + // Init total price + Float totalPrice = 0.0f; + + // Iterate over all items + for (final AddableBasketItem item : this.allItems()) { + // Is the item a product? + if (item.isProductType()) { + // Calculate single price and add it + totalPrice += this.calculateItemPrice(item); + } + } + + // Trace message + //this.getLogger().logTrace(MessageFormat.format("calculateTotalPrice: totalPrice={0} - EXIT!", totalPrice)); + // Return final sum + return totalPrice; + } + + @Override + public String changeItem (final AddableBasketItem item) { + // Trace message + //this.getLogger().logTrace(MessageFormat.format("changeItem: item={0} - CALLED!", item)); + + // item shall not be null + if (null == item) { + // Abort here + throw new NullPointerException("item is null"); + } + + // Default is not found + String targetPage = "item_not_changed"; //NOI18N + + // Lookup item in basket + for (final AddableBasketItem basketItem : this.allItems()) { + // Is it the same? + if (basketItem.equals(item)) { + // Found it, so allow redirect to proper page + targetPage = "basket"; //NOI18N + break; + } + } + + // Trace message + //this.getLogger().logTrace(MessageFormat.format("changeItem: targetPage={0} - EXIT!", targetPage)); + // Return page + return targetPage; + } + + @Override + public void clear () { + // @TODO Also clear EJB + // Deligate to basket instance + this.basket.clear(); + } + + @Override + public AddableBasketItem getCurrentItem () { + return this.currentItem; + } + + @Override + public void setCurrentItem (final AddableBasketItem currentItem) { + this.currentItem = currentItem; + } + + @Override + public Long getItemAmount (final Product product) { + // Trace message + //this.getLogger().logTrace(MessageFormat.format("getItemAmount: product={0} - CALLED!", product)); + + // product should not be null + if (null == product) { + // Abort here + throw new NullPointerException("product is null"); + } + + // Initial value is zero + Long itemAmount = 0L; + + // Iterate over all + for (final AddableBasketItem item : this.allItems()) { + // Debug message + //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.getItemProduct().equals(product))) { + // Found it + itemAmount = item.getOrderedAmount(); + break; + } + } + + // Trace message + //this.getLogger().logTrace(MessageFormat.format("getItemAmount: itemAmount={0} - EXIT!", itemAmount)); + // Return it + return itemAmount; + } + + @Override + public AddableBasketItem getLast () { + // Deligate to basket instance + return this.basket.getLast(); + } + + @Override + public int getLastNumRows () { + // Deligate to basket instance + return this.basket.getLastNumRows(); + } + + @Override + public Long getOrderedAmount () { + return this.orderedAmount; + } + + @Override + public void setOrderedAmount (final Long orderedAmount) { + this.orderedAmount = orderedAmount; + } + + @Override + public boolean hasItems () { + // Call above and invert it + return (!this.isEmpty()); + } + + @Override + public boolean isEmpty () { + // Deligate to basket instance + return this.basket.isEmpty(); + } + + @Override + public boolean isProductAdded (final Product product) { + // Trace message + //this.getLogger().logTrace(MessageFormat.format("isProductAdded: product={0} - EXIT!", product)); + + // Must not be null + if (null == product) { + // Abort here + throw new NullPointerException("product is null"); //NOI18N + } + + // Generate fake instance + AddableBasketItem fake = new BasketItem(product); + + // 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 + AddableBasketItem item = this.getItemFromProduct(product); + + // Debug message + //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)); + // Return status + return isAdded; + } + + @Override + public String outputLastAddedItem () { + // Trace message + //this.getLogger().logTrace("outputLastAddedItem: CALLED!"); + + // Default message + String lastItem = ""; //NOI18N + + // Get instance + AddableBasketItem item = this.getLast(); + + // Is it set? + if (item instanceof AddableBasketItem) { + // Get type + switch (item.getItemType()) { + case "product": // Sellable product //NOI18N + assert (item.getItemProduct() instanceof Product) : MessageFormat.format("item {0} has no product instance set.", item); //NOI18N + + // Get title + lastItem = item.getItemProduct().getProductTitle(); + break; + + default: // Not supported + throw new FacesException(MessageFormat.format("item type {0} is not supported.", item.getItemType())); //NOI18N + } + } + + // Trace message + //this.getLogger().logTrace(MessageFormat.format("outputLastAddedItem: lastItem={0} - EXIT!", lastItem)); + // Return it + return lastItem; + } + + /** + * Getter for basket bean instance + *

+ * @return Basket bean instance + */ + private BasketSessionBeanRemote getBasketBean () { + return this.basketBean; + } + + /** + * 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 + *

+ * @param product Product instance + *

+ * @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)); + + // Product must not be null + if (null == product) { + // Abort here + throw new NullPointerException("product is null"); //NOI18N + } + + // Create item instance + AddableBasketItem foundItem = null; + + // Create fake instance + AddableBasketItem fake = new BasketItem(product); + + // 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 + //this.getLogger().logDebug(MessageFormat.format("getItemFromProduct: item={0}", item)); + + // item must not be null + if (null == item) { + // Abort here + throw new NullPointerException("item is null"); //NOI18N + } + + // Is it the same? + if (item.equals(fake)) { + // Set found item and abort look + foundItem = item; + break; + } + } + + // 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/basket/BasketWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebSessionController.java new file mode 100644 index 00000000..a2fd6fe8 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebSessionController.java @@ -0,0 +1,170 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.basket; + +import java.io.Serializable; +import java.util.List; +import org.mxchange.jshopcore.model.basket.AddableBasketItem; +import org.mxchange.jshopcore.model.product.Product; + +/** + * An interface for a basket + *

+ * @author Roland Haeder + */ +public interface BasketWebSessionController extends Serializable { + + /** + * Adds given product instance to basket by adding amount from form data to + * it. + *

+ * @param product Product instance to add + *

+ * @return Redirect target or null + */ + String addItem (final Product product); + + /** + * Gets for all added items + *

+ * @return A list of all added items + */ + List allItems (); + + /** + * Calculates total price (no tax added) of current item. If no current item + * is set and no amount, a NPE is thrown. + *

+ * @return Current item's total price + */ + Float calculateCurrentItemPrice (); + + /** + * Calculates total price (no tax added) for given item. + *

+ * @param item Item instance to calculate total price for + *

+ * @return Total price + */ + Float calculateItemPrice (final AddableBasketItem item); + + /** + * Calculates total sum (no tax added) for all items + *

+ * @return Total price of all items + */ + Float calculateTotalPrice (); + + /** + * Changes given item instance's amount in basket and redirects to proper + * page. If the item is not found, another "error" page is called. + *

+ * @param item Item instance to change + *

+ * @return Page redirection + */ + String changeItem (final AddableBasketItem item); + + /** + * Clears this basket instance + */ + void clear (); + + /** + * Getter for item amount property + *

+ * @return Item amount property + */ + Long getOrderedAmount (); + + /** + * Setter for item amount property + *

+ * @param amount Item amount property + */ + void setOrderedAmount (final Long amount); + + /** + * Getter for current item + *

+ * @return Current item + */ + AddableBasketItem getCurrentItem (); + + /** + * Setter for current item + *

+ * @param currentItem Current item + */ + void setCurrentItem (final AddableBasketItem currentItem); + + /** + * Some getter for item amount of given product. This method requires a full + * iteration over all items in the basket to look for proper product + * instance. + *

+ * @param product Product instance + *

+ * @return Item amount of given product + */ + Long getItemAmount (final Product product); + + /** + * Getter for last entry + *

+ * @return Last added item in basket + */ + AddableBasketItem getLast (); + + /** + * Getter for last num rows + *

+ * @return Last num rows + */ + int getLastNumRows (); + + /** + * Checks whether the basket has items in it. This method is wrapper to + * isEmpty() + *

+ * @return Whether the basket is empty + */ + boolean hasItems (); + + /** + * Checks whether the basket is empty + *

+ * @return Whether the basket is empty + */ + boolean isEmpty (); + + /** + * Checks whether the currently set product is added in basked + *

+ * @param product Product instance + *

+ * @return Whether the product is added + */ + boolean isProductAdded (final Product product); + + /** + * Outputs last added item in the basket. + *

+ * @return Last added item + */ + String outputLastAddedItem (); +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebBean.java deleted file mode 100644 index 33ceaca5..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebBean.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.pizzaapplication.beans.category; - -import javax.enterprise.context.RequestScoped; -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.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.ShopWebController; - -/** - * Main application class - *

- * @author Roland Haeder - */ -@Named ("admin_category") -@RequestScoped -public class AdminCategoryWebBean implements AdminCategoryWebController { - - /** - * Serial number - */ - private static final long serialVersionUID = 5_819_375_183_472_871L; - - /** - * Remote bean for categories - */ - private AdminCategorySessionBeanRemote categoryBean; - - /////////////////////// Properties ///////////////////// - /** - * Category categoryTitle - */ - private String categoryTitle; - - /** - * Parent category - */ - private Category parentCategory; - - ////////////////////// Bean injections /////////////////////// - - /** - * Shop bean - */ - @Inject - private ShopWebController shopController; - - /** - * Default constructor - */ - public AdminCategoryWebBean () { - // Try it - try { - // Get initial context - Context context = new InitialContext(); - - // Try to lookup the bean - this.categoryBean = (AdminCategorySessionBeanRemote) context.lookup("ejb/stateless-admin-category"); //NOI18N - } catch (final NamingException e) { - // Throw it again - throw new FaceletException(e); - } - } - - @Override - public void addCategory () throws FaceletException { - try { - // Create category - Category category = new ProductCategory(); - category.setParentCategory(this.getParentCategory()); - category.setCategoryTitle(this.getCategoryTitle()); - - // Deligate to remote bean - Category updatedCategory = this.categoryBean.doAdminAddCategory(category); - - // Also send it to the controller bean - this.shopController.addCategory(updatedCategory); - - // Unset all older values - this.setCategoryTitle(""); //NOI18N - this.setParentCategory(null); - } catch (final CategoryTitleAlreadyUsedException | CannotAddCategoryException ex) { - // Continue to throw - throw new FaceletException(ex); - } - } - - @Override - public String getCategoryTitle () { - return this.categoryTitle; - } - - @Override - public void setCategoryTitle (final String categoryTitle) { - this.categoryTitle = categoryTitle; - } - - @Override - public Category getParentCategory () { - return this.parentCategory; - } - - @Override - public void setParentCategory (final Category parentCategory) { - this.parentCategory = parentCategory; - } -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebController.java b/src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebController.java deleted file mode 100644 index 4cef66d8..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebController.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.pizzaapplication.beans.category; - -import javax.faces.view.facelets.FaceletException; -import org.mxchange.jshopcore.model.category.Category; - -/** - * An interface for product controllers for "ADMIN" role - *

- * @author Roland Haeder - */ -public interface AdminCategoryWebController { - - /** - * Adds given category data from request to database - *

- * @throws javax.faces.view.facelets.FaceletException If something - * unexpected happened - */ - void addCategory () throws FaceletException; - - /** - * Getter for parent id - *

- * @return Parent id - */ - Category getParentCategory (); - - /** - * Setter for parent category - *

- * @param parentCategory Parent category to set - */ - void setParentCategory (final Category parentCategory); - - /** - * Getter for category title - *

- * @return the title - */ - String getCategoryTitle (); - - /** - * Setter for category title - *

- * @param categoryTitle the title to set - */ - void setCategoryTitle (final String categoryTitle); -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebRequestBean.java new file mode 100644 index 00000000..6e18de4a --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebRequestBean.java @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.category; + +import javax.enterprise.context.RequestScoped; +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.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.ShopWebApplicationController; + +/** + * Main application class + *

+ * @author Roland Haeder + */ +@Named ("admin_category") +@RequestScoped +public class AdminCategoryWebRequestBean implements AdminCategoryWebRequestController { + + /** + * Serial number + */ + private static final long serialVersionUID = 5_819_375_183_472_871L; + + /** + * Remote bean for categories + */ + private AdminCategorySessionBeanRemote categoryBean; + + /////////////////////// Properties ///////////////////// + /** + * Category categoryTitle + */ + private String categoryTitle; + + /** + * Parent category + */ + private Category parentCategory; + + ////////////////////// Bean injections /////////////////////// + + /** + * Shop bean + */ + @Inject + private ShopWebApplicationController shopController; + + /** + * Default constructor + */ + public AdminCategoryWebRequestBean () { + // Try it + try { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup the bean + this.categoryBean = (AdminCategorySessionBeanRemote) context.lookup("ejb/stateless-admin-category"); //NOI18N + } catch (final NamingException e) { + // Throw it again + throw new FaceletException(e); + } + } + + @Override + public void addCategory () throws FaceletException { + try { + // Create category + Category category = new ProductCategory(); + category.setParentCategory(this.getParentCategory()); + category.setCategoryTitle(this.getCategoryTitle()); + + // Deligate to remote bean + Category updatedCategory = this.categoryBean.doAdminAddCategory(category); + + // Also send it to the controller bean + this.shopController.addCategory(updatedCategory); + + // Unset all older values + this.setCategoryTitle(""); //NOI18N + this.setParentCategory(null); + } catch (final CategoryTitleAlreadyUsedException | CannotAddCategoryException ex) { + // Continue to throw + throw new FaceletException(ex); + } + } + + @Override + public String getCategoryTitle () { + return this.categoryTitle; + } + + @Override + public void setCategoryTitle (final String categoryTitle) { + this.categoryTitle = categoryTitle; + } + + @Override + public Category getParentCategory () { + return this.parentCategory; + } + + @Override + public void setParentCategory (final Category parentCategory) { + this.parentCategory = parentCategory; + } +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebRequestController.java new file mode 100644 index 00000000..8cdc11a5 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebRequestController.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.category; + +import javax.faces.view.facelets.FaceletException; +import org.mxchange.jshopcore.model.category.Category; + +/** + * An interface for product controllers for "ADMIN" role + *

+ * @author Roland Haeder + */ +public interface AdminCategoryWebRequestController { + + /** + * Adds given category data from request to database + *

+ * @throws javax.faces.view.facelets.FaceletException If something + * unexpected happened + */ + void addCategory () throws FaceletException; + + /** + * Getter for parent id + *

+ * @return Parent id + */ + Category getParentCategory (); + + /** + * Setter for parent category + *

+ * @param parentCategory Parent category to set + */ + void setParentCategory (final Category parentCategory); + + /** + * Getter for category title + *

+ * @return the title + */ + String getCategoryTitle (); + + /** + * Setter for category title + *

+ * @param categoryTitle the title to set + */ + void setCategoryTitle (final String categoryTitle); +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebBean.java deleted file mode 100644 index 95b1bf6a..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebBean.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.pizzaapplication.beans.checkout; - -import java.util.List; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.enterprise.context.SessionScoped; -import javax.faces.FacesException; -import javax.inject.Inject; -import javax.inject.Named; -import javax.jms.Connection; -import javax.jms.JMSException; -import javax.jms.MessageProducer; -import javax.jms.ObjectMessage; -import javax.jms.Queue; -import javax.jms.QueueConnectionFactory; -import javax.jms.Session; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import org.mxchange.jshopcore.model.basket.AddableBasketItem; -import org.mxchange.jshopcore.model.customer.Customer; -import org.mxchange.jshopcore.wrapper.CheckoutWrapper; -import org.mxchange.jshopcore.wrapper.WrapableCheckout; -import org.mxchange.pizzaapplication.beans.basket.BasketWebController; -import org.mxchange.pizzaapplication.beans.customer.CustomerWebController; -import org.mxchange.pizzaapplication.beans.receipt.ReceiptWebController; - -/** - * Checkout controller - *

- * @author Roland Haeder - */ -@Named ("checkoutController") -@SessionScoped -public class CheckoutWebBean implements CheckoutWebController { - - /** - * Serial number - */ - private static final long serialVersionUID = 51_987_348_347_183L; - - ////////////////////// Bean injections /////////////////////// - /** - * Basket bean - */ - @Inject - private BasketWebController basketController; - - /** - * Connection - */ - private Connection connection; - - /** - * Customer instance - */ - private Customer customer; - - /** - * Customer bean - */ - @Inject - private CustomerWebController customerController; - - /** - * Object message - */ - private ObjectMessage message; - - /** - * Message producer - */ - private MessageProducer messageProducer; - - /** - * Queue instance - */ - private Queue queue; - - /** - * Receipt bean - */ - @Inject - private ReceiptWebController receiptController; - - /** - * Session instance - */ - private Session session; - - /** - * Destructor - */ - @PreDestroy - public void destroy () { - try { - // Try to close all - this.messageProducer.close(); - this.session.close(); - this.connection.close(); - } catch (final JMSException ex) { - // TODO: Continue to throw is fine? - throw new FacesException(ex); - } - } - - @Override - public String doCheckout () { - // Trace message - //this.getLogger().logTrace("doCheckout: CALLED!"); - - // Are the beans set? - if (null == this.basketController) { - // Abort here - throw new NullPointerException("basketController is null"); //NOI18N - } else if (null == this.customerController) { - // Abort here - throw new NullPointerException("customer is null"); //NOI18N - } - - // Are at least the required fields set? - if (!this.customerController.isRequiredPersonalDataSet()) { - // Trace message - //this.getLogger().logTrace("doCheckout: Not all required fields are set, returning checkout2 ... - EXIT!"); - - // Not set, should not happen - return "checkout2"; //NOI18N - } else if (this.basketController.isEmpty()) { - // Trace message - //this.getLogger().logTrace("doCheckout: basket is empty, returning empty_basket ... - EXIT!"); - - // Nothing to order - return "empty_basket"; //NOI18N - } - - // Create customer instance - this.setCustomer(this.customerController.createCustomerInstance()); - - // Debug message - //this.getLogger().logDebug(MessageFormat.format("doCheckout: customer={0}", this.getCustomer())); - // Get ordered list - List list = this.basketController.allItems(); - - // Debug message - //this.getLogger().logTrace(MessageFormat.format("doCheckout: list={0}", list)); - // Construct container - WrapableCheckout wrapper = new CheckoutWrapper(); - wrapper.setCustomer(this.getCustomer()); - wrapper.setList(list); - - try { - // Construct object message - this.message.setObject(wrapper); - - // Send message - this.messageProducer.send(this.message); - } catch (final JMSException ex) { - // TODO: Log exception? - // Not working - return "jms_failed"; //NOI18N - } - - // Clear basket - this.basketController.clear(); - - // Set customer in receipt controller for verification - this.receiptController.setCustomer(this.getCustomer()); - - // All fine - return "checkout_done"; //NOI18N - } - - @Override - public Customer getCustomer () { - return this.customer; - } - - @Override - public void setCustomer (final Customer customer) { - this.customer = customer; - } - - /** - * Initialization of this bean - */ - @PostConstruct - public void init () { - try { - // Get initial context - Context context = new InitialContext(); - - // Get factory from JMS resource - QueueConnectionFactory connectionFactory = (QueueConnectionFactory) context.lookup("jms/shopConnectionFactory"); //NOI18N - - // Lookup queue - this.queue = (Queue) context.lookup("jms/shopCheckoutQueue"); //NOI18N - - // Create connection - this.connection = connectionFactory.createConnection(); - - // Init session instance - this.session = this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - // And message producer - this.messageProducer = this.session.createProducer(this.queue); - - // Finally the message instance itself - this.message = this.session.createObjectMessage(); - } catch (final NamingException | JMSException e) { - // Continued to throw - throw new FacesException(e); - } - } -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebController.java b/src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebController.java deleted file mode 100644 index 513ed541..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebController.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.pizzaapplication.beans.checkout; - -import java.io.Serializable; -import org.mxchange.jshopcore.model.customer.Customer; - -/** - * An interface for the shop - *

- * @author Roland Haeder - */ -public interface CheckoutWebController extends Serializable { - - /** - * Runs the actual checkout and returns a proper page redirection target. - *

- * @return Page redirection target - */ - String doCheckout (); - - /** - * Getter for customer instance - *

- * @return Customer instance - */ - Customer getCustomer (); - - /** - * Setter for customer instance - *

- * @param customer Customer instance - */ - void setCustomer (final Customer customer); -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebSessionBean.java new file mode 100644 index 00000000..65fb3052 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebSessionBean.java @@ -0,0 +1,230 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.checkout; + +import java.util.List; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.enterprise.context.SessionScoped; +import javax.faces.FacesException; +import javax.inject.Inject; +import javax.inject.Named; +import javax.jms.Connection; +import javax.jms.JMSException; +import javax.jms.MessageProducer; +import javax.jms.ObjectMessage; +import javax.jms.Queue; +import javax.jms.QueueConnectionFactory; +import javax.jms.Session; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import org.mxchange.jshopcore.model.basket.AddableBasketItem; +import org.mxchange.jshopcore.model.customer.Customer; +import org.mxchange.jshopcore.wrapper.CheckoutWrapper; +import org.mxchange.jshopcore.wrapper.WrapableCheckout; +import org.mxchange.pizzaapplication.beans.basket.BasketWebSessionController; +import org.mxchange.pizzaapplication.beans.customer.CustomerWebSessionController; +import org.mxchange.pizzaapplication.beans.receipt.ReceiptWebSessionController; + +/** + * Checkout controller + *

+ * @author Roland Haeder + */ +@Named ("checkoutController") +@SessionScoped +public class CheckoutWebSessionBean implements CheckoutWebSessionController { + + /** + * Serial number + */ + private static final long serialVersionUID = 51_987_348_347_183L; + + ////////////////////// Bean injections /////////////////////// + /** + * Basket bean + */ + @Inject + private BasketWebSessionController basketController; + + /** + * Connection + */ + private Connection connection; + + /** + * Customer instance + */ + private Customer customer; + + /** + * Customer bean + */ + @Inject + private CustomerWebSessionController customerController; + + /** + * Object message + */ + private ObjectMessage message; + + /** + * Message producer + */ + private MessageProducer messageProducer; + + /** + * Queue instance + */ + private Queue queue; + + /** + * Receipt bean + */ + @Inject + private ReceiptWebSessionController receiptController; + + /** + * Session instance + */ + private Session session; + + /** + * Destructor + */ + @PreDestroy + public void destroy () { + try { + // Try to close all + this.messageProducer.close(); + this.session.close(); + this.connection.close(); + } catch (final JMSException ex) { + // TODO: Continue to throw is fine? + throw new FacesException(ex); + } + } + + @Override + public String doCheckout () { + // Trace message + //this.getLogger().logTrace("doCheckout: CALLED!"); + + // Are the beans set? + if (null == this.basketController) { + // Abort here + throw new NullPointerException("basketController is null"); //NOI18N + } else if (null == this.customerController) { + // Abort here + throw new NullPointerException("customer is null"); //NOI18N + } + + // Are at least the required fields set? + if (!this.customerController.isRequiredPersonalDataSet()) { + // Trace message + //this.getLogger().logTrace("doCheckout: Not all required fields are set, returning checkout2 ... - EXIT!"); + + // Not set, should not happen + return "checkout2"; //NOI18N + } else if (this.basketController.isEmpty()) { + // Trace message + //this.getLogger().logTrace("doCheckout: basket is empty, returning empty_basket ... - EXIT!"); + + // Nothing to order + return "empty_basket"; //NOI18N + } + + // Create customer instance + this.setCustomer(this.customerController.createCustomerInstance()); + + // Debug message + //this.getLogger().logDebug(MessageFormat.format("doCheckout: customer={0}", this.getCustomer())); + // Get ordered list + List list = this.basketController.allItems(); + + // Debug message + //this.getLogger().logTrace(MessageFormat.format("doCheckout: list={0}", list)); + // Construct container + WrapableCheckout wrapper = new CheckoutWrapper(); + wrapper.setCustomer(this.getCustomer()); + wrapper.setList(list); + + try { + // Construct object message + this.message.setObject(wrapper); + + // Send message + this.messageProducer.send(this.message); + } catch (final JMSException ex) { + // TODO: Log exception? + // Not working + return "jms_failed"; //NOI18N + } + + // Clear basket + this.basketController.clear(); + + // Set customer in receipt controller for verification + this.receiptController.setCustomer(this.getCustomer()); + + // All fine + return "checkout_done"; //NOI18N + } + + @Override + public Customer getCustomer () { + return this.customer; + } + + @Override + public void setCustomer (final Customer customer) { + this.customer = customer; + } + + /** + * Initialization of this bean + */ + @PostConstruct + public void init () { + try { + // Get initial context + Context context = new InitialContext(); + + // Get factory from JMS resource + QueueConnectionFactory connectionFactory = (QueueConnectionFactory) context.lookup("jms/shopConnectionFactory"); //NOI18N + + // Lookup queue + this.queue = (Queue) context.lookup("jms/shopCheckoutQueue"); //NOI18N + + // Create connection + this.connection = connectionFactory.createConnection(); + + // Init session instance + this.session = this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + // And message producer + this.messageProducer = this.session.createProducer(this.queue); + + // Finally the message instance itself + this.message = this.session.createObjectMessage(); + } catch (final NamingException | JMSException e) { + // Continued to throw + throw new FacesException(e); + } + } +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebSessionController.java new file mode 100644 index 00000000..68abb899 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebSessionController.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.checkout; + +import java.io.Serializable; +import org.mxchange.jshopcore.model.customer.Customer; + +/** + * An interface for the shop + *

+ * @author Roland Haeder + */ +public interface CheckoutWebSessionController extends Serializable { + + /** + * Runs the actual checkout and returns a proper page redirection target. + *

+ * @return Page redirection target + */ + String doCheckout (); + + /** + * Getter for customer instance + *

+ * @return Customer instance + */ + Customer getCustomer (); + + /** + * Setter for customer instance + *

+ * @param customer Customer instance + */ + void setCustomer (final Customer customer); +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/country/CountryWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/country/CountryWebApplicationBean.java new file mode 100644 index 00000000..186de997 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/country/CountryWebApplicationBean.java @@ -0,0 +1,82 @@ +package org.mxchange.pizzaapplication.beans.country; + +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU 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 General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ +import java.util.Collections; +import java.util.List; +import javax.annotation.PostConstruct; +import javax.enterprise.context.ApplicationScoped; +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.jcountry.data.Country; +import org.mxchange.jcountry.data.CountrySingletonBeanRemote; + +/** + * A country bean + *

+ * @author Roland Haeder + */ +@Named ("country") +@ApplicationScoped +public class CountryWebApplicationBean implements CountryWebApplicationController { + + /** + * Serial number + */ + private static final long serialVersionUID = 176_985_298_681_742_960L; + + /** + * Remote country EJB + */ + private CountrySingletonBeanRemote countryBean; + + /** + * List of all countries + */ + private List countryList; + + /** + * Default constructor + */ + public CountryWebApplicationBean () { + // Try this + try { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup the bean + this.countryBean = (CountrySingletonBeanRemote) context.lookup("java:global/addressbook-ejb/country!org.mxchange.jcountry.data.AddressbookCountrySingletonBeanLocal"); //NOI18N + } catch (final NamingException ex) { + // Continue to throw + throw new FaceletException(ex); + } + } + + @Override + public List allCountries () { + // Return "cached" version + return Collections.unmodifiableList(this.countryList); + } + + @PostConstruct + public void init () { + this.countryList = this.countryBean.allCountries(); + } +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/country/CountryWebApplicationController.java b/src/java/org/mxchange/pizzaapplication/beans/country/CountryWebApplicationController.java new file mode 100644 index 00000000..a26fc290 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/country/CountryWebApplicationController.java @@ -0,0 +1,36 @@ +package org.mxchange.pizzaapplication.beans.country; + +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU 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 General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ +import java.io.Serializable; +import java.util.List; +import org.mxchange.jcountry.data.Country; + +/** + * An interface for country beans + *

+ * @author Roland Haeder + */ +public interface CountryWebApplicationController extends Serializable { + + /** + * A list of all countries + *

+ * @return All countries + */ + List allCountries (); +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/country/CountryWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/country/CountryWebBean.java deleted file mode 100644 index e55683b3..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/country/CountryWebBean.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.mxchange.pizzaapplication.beans.country; - -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify it under - * the terms of the GNU 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 General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ -import java.util.Collections; -import java.util.List; -import javax.annotation.PostConstruct; -import javax.enterprise.context.ApplicationScoped; -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.jcountry.data.Country; -import org.mxchange.jcountry.data.CountrySingletonBeanRemote; - -/** - * A country bean - *

- * @author Roland Haeder - */ -@Named ("country") -@ApplicationScoped -public class CountryWebBean implements CountryWebController { - - /** - * Serial number - */ - private static final long serialVersionUID = 176_985_298_681_742_960L; - - /** - * Remote country EJB - */ - private CountrySingletonBeanRemote countryBean; - - /** - * List of all countries - */ - private List countryList; - - /** - * Default constructor - */ - public CountryWebBean () { - // Try this - try { - // Get initial context - Context context = new InitialContext(); - - // Try to lookup the bean - this.countryBean = (CountrySingletonBeanRemote) context.lookup("java:global/addressbook-ejb/country!org.mxchange.jcountry.data.AddressbookCountrySingletonBeanLocal"); //NOI18N - } catch (final NamingException ex) { - // Continue to throw - throw new FaceletException(ex); - } - } - - @Override - public List allCountries () { - // Return "cached" version - return Collections.unmodifiableList(this.countryList); - } - - @PostConstruct - public void init () { - this.countryList = this.countryBean.allCountries(); - } -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/country/CountryWebController.java b/src/java/org/mxchange/pizzaapplication/beans/country/CountryWebController.java deleted file mode 100644 index b9fac8c8..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/country/CountryWebController.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.mxchange.pizzaapplication.beans.country; - -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify it under - * the terms of the GNU 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 General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ -import java.io.Serializable; -import java.util.List; -import org.mxchange.jcountry.data.Country; - -/** - * An interface for country beans - *

- * @author Roland Haeder - */ -public interface CountryWebController extends Serializable { - - /** - * A list of all countries - *

- * @return All countries - */ - List allCountries (); -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebBean.java deleted file mode 100644 index 7e0710b9..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebBean.java +++ /dev/null @@ -1,296 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.pizzaapplication.beans.customer; - -import javax.enterprise.context.SessionScoped; -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.jcontacts.contact.Contact; -import org.mxchange.jcontacts.contact.UserContact; -import org.mxchange.jcontacts.contact.gender.Gender; -import org.mxchange.jcountry.data.Country; -import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jshopcore.model.customer.Customer; -import org.mxchange.jshopcore.model.customer.CustomerSessionBeanRemote; -import org.mxchange.jshopcore.model.customer.ShopCustomer; - -/** - * A customer bean which hides the customer instance - *

- * @author Roland Haeder - */ -@Named ("customerController") -@SessionScoped -public class CustomerWebBean implements CustomerWebController { - - /** - * Serial number - */ - private static final long serialVersionUID = 542_145_347_916L; - - /////////////////////// Properties ///////////////////// - /** - * Cellphone number - */ - private DialableCellphoneNumber cellphoneNumber; - - /** - * City - */ - private String city; - - /** - * Optional comments - */ - private String comment; - - /** - * Country code - */ - private Country country; - - /** - * Remote customer bean - */ - private CustomerSessionBeanRemote customerBean; - - /** - * Email address - */ - private String emailAddress; - - /** - * Family name - */ - private String familyName; - - /** - * Fax number - */ - private DialableFaxNumber faxNumber; - - /** - * First name - */ - private String firstName; - - /** - * Gender instance - */ - private Gender gender; - - /** - * House number - */ - private Short houseNumber; - - /** - * Phone number - */ - private DialableLandLineNumber phoneNumber; - - /** - * Street - */ - private String street; - - /** - * ZIP code - */ - private Integer zipCode; - - /** - * Default constructor - */ - public CustomerWebBean () { - // Set gender to UNKNOWN - this.gender = Gender.UNKNOWN; - - // Try it - try { - // Get initial context - Context context = new InitialContext(); - - // Try to lookup - this.customerBean = (CustomerSessionBeanRemote) context.lookup("ejb/stateless-customer"); - } catch (final NamingException e) { - // Throw again - throw new FaceletException(e); - } - } - - @Override - public Customer createCustomerInstance () { - // Trace message - //this.getLogger().logTrace("createInstance: CALLED!"); - - // Required personal data must be set - assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N - - // Create new customer instance - Customer customer = new ShopCustomer(); - - // Create new contact - Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName()); - contact.setContactStreet(this.getStreet()); - contact.setContactHouseNumber(this.getHouseNumber()); - contact.setContactZipCode(this.getZipCode()); - contact.setContactCity(this.getCity()); - contact.setContactCountry(this.getCountry()); - contact.setContactPhoneNumber(this.getPhoneNumber()); - contact.setContactFaxNumber(this.getFaxNumber()); - contact.setContactCellphoneNumber(this.getCellphoneNumber()); - - // Set contact in customer - customer.setContact(contact); - - // Trace message - //this.getLogger().logTrace(MessageFormat.format("createInstance: customer={0} - EXIT!", customer)); - // Return it - return customer; - } - - @Override - public DialableCellphoneNumber getCellphoneNumber () { - return this.cellphoneNumber; - } - - @Override - public void setCellphoneNumber (final DialableCellphoneNumber cellphoneNumber) { - this.cellphoneNumber = cellphoneNumber; - } - - @Override - public String getCity () { - return this.city; - } - - @Override - public void setCity (final String city) { - this.city = city; - } - - @Override - public Country getCountry () { - return this.country; - } - - @Override - public void setCountry (final Country country) { - this.country = country; - } - - @Override - public String getEmailAddress () { - return this.emailAddress; - } - - @Override - public void setEmailAddress (final String emailAddress) { - this.emailAddress = emailAddress; - } - - @Override - public String getFamilyName () { - return this.familyName; - } - - @Override - public void setFamilyName (final String familyName) { - this.familyName = familyName; - } - - @Override - public DialableFaxNumber getFaxNumber () { - return this.faxNumber; - } - - @Override - public void setFaxNumber (final DialableFaxNumber faxNumber) { - this.faxNumber = faxNumber; - } - - @Override - public String getFirstName () { - return this.firstName; - } - - @Override - public void setFirstName (final String firstName) { - this.firstName = firstName; - } - - @Override - public Gender getGender () { - return this.gender; - } - - @Override - public void setGender (final Gender gender) { - this.gender = gender; - } - - @Override - public Short getHouseNumber () { - return this.houseNumber; - } - - @Override - public void setHouseNumber (final Short houseNumber) { - this.houseNumber = houseNumber; - } - - @Override - public DialableLandLineNumber getPhoneNumber () { - return this.phoneNumber; - } - - @Override - public void setPhoneNumber (final DialableLandLineNumber phoneNumber) { - this.phoneNumber = phoneNumber; - } - - @Override - public String getStreet () { - return this.street; - } - - @Override - public void setStreet (final String street) { - this.street = street; - } - - @Override - public Integer getZipCode () { - return this.zipCode; - } - - @Override - public void setZipCode (final Integer zipCode) { - this.zipCode = zipCode; - } - - @Override - public boolean isRequiredPersonalDataSet () { - return ((this.getGender() != null) && (this.getFirstName() != null) && (this.getFamilyName() != null) && (this.getStreet() != null) && (this.getHouseNumber() != null) && (this.getZipCode() != null) && (this.getCity() != null)); - } -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebController.java b/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebController.java deleted file mode 100644 index 13d3fa72..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebController.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.pizzaapplication.beans.customer; - -import java.io.Serializable; -import org.mxchange.jcontacts.contact.gender.Gender; -import org.mxchange.jcountry.data.Country; -import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jshopcore.model.customer.Customer; - -/** - * An interface for customer beans - *

- * @author Roland Haeder - */ -public interface CustomerWebController extends Serializable { - - /** - * Creates an instance from all properties - *

- * @return A Customer instance - */ - Customer createCustomerInstance (); - - /** - * Cellphone number - *

- * @return the cellphoneNumber - */ - DialableCellphoneNumber getCellphoneNumber (); - - /** - * Cellphone number - *

- * @param cellphoneNumber the cellphoneNumber to set - */ - void setCellphoneNumber (final DialableCellphoneNumber cellphoneNumber); - - /** - * City - *

- * @return the city - */ - String getCity (); - - /** - * City - *

- * @param city the city to set - */ - void setCity (final String city); - - /** - * Getter for country instance - *

- * @return Country instance - */ - Country getCountry (); - - /** - * Setter for country instance - *

- * @param country Country instance - */ - void setCountry (final Country country); - - /** - * Email address - *

- * @return the emailAddress - */ - String getEmailAddress (); - - /** - * Email address - *

- * @param emailAddress the emailAddress to set - */ - void setEmailAddress (final String emailAddress); - - /** - * Family name - *

- * @return the familyName - */ - String getFamilyName (); - - /** - * Family name - *

- * @param familyName the familyName to set - */ - void setFamilyName (final String familyName); - - /** - * Fax number - *

- * @return the faxNumber - */ - DialableFaxNumber getFaxNumber (); - - /** - * Fax number - *

- * @param faxNumber the faxNumber to set - */ - void setFaxNumber (final DialableFaxNumber faxNumber); - - /** - * First name - *

- * @return the first name - */ - String getFirstName (); - - /** - * First name - *

- * @param firstName the first name to set - */ - void setFirstName (final String firstName); - - /** - * Gender of the contact - *

- * @return the gender - */ - Gender getGender (); - - /** - * Gender of the contact - *

- * @param gender the gender to set - */ - void setGender (final Gender gender); - - /** - * House number - *

- * @return the houseNumber - */ - Short getHouseNumber (); - - /** - * House number - *

- * @param houseNumber the houseNumber to set - */ - void setHouseNumber (final Short houseNumber); - - /** - * Phone number - *

- * @return the phoneNumber - */ - DialableLandLineNumber getPhoneNumber (); - - /** - * Phone number - *

- * @param phoneNumber the phoneNumber to set - */ - void setPhoneNumber (final DialableLandLineNumber phoneNumber); - - /** - * Street - *

- * @return the street - */ - String getStreet (); - - /** - * Street - *

- * @param street the street to set - */ - void setStreet (final String street); - - /** - * ZIP code - *

- * @return the zipCode - */ - Integer getZipCode (); - - /** - * ZIP code - *

- * @param zipCode the zipCode to set - */ - void setZipCode (final Integer zipCode); - - /** - * Checks whether all required personal data is set - *

- * @return Whether the required personal data is set - */ - boolean isRequiredPersonalDataSet (); -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebSessionBean.java new file mode 100644 index 00000000..f8a9a81b --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebSessionBean.java @@ -0,0 +1,296 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.customer; + +import javax.enterprise.context.SessionScoped; +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.jcontacts.contact.Contact; +import org.mxchange.jcontacts.contact.UserContact; +import org.mxchange.jcontacts.contact.gender.Gender; +import org.mxchange.jcountry.data.Country; +import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber; +import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jshopcore.model.customer.Customer; +import org.mxchange.jshopcore.model.customer.CustomerSessionBeanRemote; +import org.mxchange.jshopcore.model.customer.ShopCustomer; + +/** + * A customer bean which hides the customer instance + *

+ * @author Roland Haeder + */ +@Named ("customerController") +@SessionScoped +public class CustomerWebSessionBean implements CustomerWebSessionController { + + /** + * Serial number + */ + private static final long serialVersionUID = 542_145_347_916L; + + /////////////////////// Properties ///////////////////// + /** + * Cellphone number + */ + private DialableCellphoneNumber cellphoneNumber; + + /** + * City + */ + private String city; + + /** + * Optional comments + */ + private String comment; + + /** + * Country code + */ + private Country country; + + /** + * Remote customer bean + */ + private CustomerSessionBeanRemote customerBean; + + /** + * Email address + */ + private String emailAddress; + + /** + * Family name + */ + private String familyName; + + /** + * Fax number + */ + private DialableFaxNumber faxNumber; + + /** + * First name + */ + private String firstName; + + /** + * Gender instance + */ + private Gender gender; + + /** + * House number + */ + private Short houseNumber; + + /** + * Phone number + */ + private DialableLandLineNumber phoneNumber; + + /** + * Street + */ + private String street; + + /** + * ZIP code + */ + private Integer zipCode; + + /** + * Default constructor + */ + public CustomerWebSessionBean () { + // Set gender to UNKNOWN + this.gender = Gender.UNKNOWN; + + // Try it + try { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup + this.customerBean = (CustomerSessionBeanRemote) context.lookup("ejb/stateless-customer"); + } catch (final NamingException e) { + // Throw again + throw new FaceletException(e); + } + } + + @Override + public Customer createCustomerInstance () { + // Trace message + //this.getLogger().logTrace("createInstance: CALLED!"); + + // Required personal data must be set + assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N + + // Create new customer instance + Customer customer = new ShopCustomer(); + + // Create new contact + Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName()); + contact.setContactStreet(this.getStreet()); + contact.setContactHouseNumber(this.getHouseNumber()); + contact.setContactZipCode(this.getZipCode()); + contact.setContactCity(this.getCity()); + contact.setContactCountry(this.getCountry()); + contact.setContactPhoneNumber(this.getPhoneNumber()); + contact.setContactFaxNumber(this.getFaxNumber()); + contact.setContactCellphoneNumber(this.getCellphoneNumber()); + + // Set contact in customer + customer.setContact(contact); + + // Trace message + //this.getLogger().logTrace(MessageFormat.format("createInstance: customer={0} - EXIT!", customer)); + // Return it + return customer; + } + + @Override + public DialableCellphoneNumber getCellphoneNumber () { + return this.cellphoneNumber; + } + + @Override + public void setCellphoneNumber (final DialableCellphoneNumber cellphoneNumber) { + this.cellphoneNumber = cellphoneNumber; + } + + @Override + public String getCity () { + return this.city; + } + + @Override + public void setCity (final String city) { + this.city = city; + } + + @Override + public Country getCountry () { + return this.country; + } + + @Override + public void setCountry (final Country country) { + this.country = country; + } + + @Override + public String getEmailAddress () { + return this.emailAddress; + } + + @Override + public void setEmailAddress (final String emailAddress) { + this.emailAddress = emailAddress; + } + + @Override + public String getFamilyName () { + return this.familyName; + } + + @Override + public void setFamilyName (final String familyName) { + this.familyName = familyName; + } + + @Override + public DialableFaxNumber getFaxNumber () { + return this.faxNumber; + } + + @Override + public void setFaxNumber (final DialableFaxNumber faxNumber) { + this.faxNumber = faxNumber; + } + + @Override + public String getFirstName () { + return this.firstName; + } + + @Override + public void setFirstName (final String firstName) { + this.firstName = firstName; + } + + @Override + public Gender getGender () { + return this.gender; + } + + @Override + public void setGender (final Gender gender) { + this.gender = gender; + } + + @Override + public Short getHouseNumber () { + return this.houseNumber; + } + + @Override + public void setHouseNumber (final Short houseNumber) { + this.houseNumber = houseNumber; + } + + @Override + public DialableLandLineNumber getPhoneNumber () { + return this.phoneNumber; + } + + @Override + public void setPhoneNumber (final DialableLandLineNumber phoneNumber) { + this.phoneNumber = phoneNumber; + } + + @Override + public String getStreet () { + return this.street; + } + + @Override + public void setStreet (final String street) { + this.street = street; + } + + @Override + public Integer getZipCode () { + return this.zipCode; + } + + @Override + public void setZipCode (final Integer zipCode) { + this.zipCode = zipCode; + } + + @Override + public boolean isRequiredPersonalDataSet () { + return ((this.getGender() != null) && (this.getFirstName() != null) && (this.getFamilyName() != null) && (this.getStreet() != null) && (this.getHouseNumber() != null) && (this.getZipCode() != null) && (this.getCity() != null)); + } +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebSessionController.java new file mode 100644 index 00000000..9eac772f --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebSessionController.java @@ -0,0 +1,215 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.customer; + +import java.io.Serializable; +import org.mxchange.jcontacts.contact.gender.Gender; +import org.mxchange.jcountry.data.Country; +import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber; +import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jshopcore.model.customer.Customer; + +/** + * An interface for customer beans + *

+ * @author Roland Haeder + */ +public interface CustomerWebSessionController extends Serializable { + + /** + * Creates an instance from all properties + *

+ * @return A Customer instance + */ + Customer createCustomerInstance (); + + /** + * Cellphone number + *

+ * @return the cellphoneNumber + */ + DialableCellphoneNumber getCellphoneNumber (); + + /** + * Cellphone number + *

+ * @param cellphoneNumber the cellphoneNumber to set + */ + void setCellphoneNumber (final DialableCellphoneNumber cellphoneNumber); + + /** + * City + *

+ * @return the city + */ + String getCity (); + + /** + * City + *

+ * @param city the city to set + */ + void setCity (final String city); + + /** + * Getter for country instance + *

+ * @return Country instance + */ + Country getCountry (); + + /** + * Setter for country instance + *

+ * @param country Country instance + */ + void setCountry (final Country country); + + /** + * Email address + *

+ * @return the emailAddress + */ + String getEmailAddress (); + + /** + * Email address + *

+ * @param emailAddress the emailAddress to set + */ + void setEmailAddress (final String emailAddress); + + /** + * Family name + *

+ * @return the familyName + */ + String getFamilyName (); + + /** + * Family name + *

+ * @param familyName the familyName to set + */ + void setFamilyName (final String familyName); + + /** + * Fax number + *

+ * @return the faxNumber + */ + DialableFaxNumber getFaxNumber (); + + /** + * Fax number + *

+ * @param faxNumber the faxNumber to set + */ + void setFaxNumber (final DialableFaxNumber faxNumber); + + /** + * First name + *

+ * @return the first name + */ + String getFirstName (); + + /** + * First name + *

+ * @param firstName the first name to set + */ + void setFirstName (final String firstName); + + /** + * Gender of the contact + *

+ * @return the gender + */ + Gender getGender (); + + /** + * Gender of the contact + *

+ * @param gender the gender to set + */ + void setGender (final Gender gender); + + /** + * House number + *

+ * @return the houseNumber + */ + Short getHouseNumber (); + + /** + * House number + *

+ * @param houseNumber the houseNumber to set + */ + void setHouseNumber (final Short houseNumber); + + /** + * Phone number + *

+ * @return the phoneNumber + */ + DialableLandLineNumber getPhoneNumber (); + + /** + * Phone number + *

+ * @param phoneNumber the phoneNumber to set + */ + void setPhoneNumber (final DialableLandLineNumber phoneNumber); + + /** + * Street + *

+ * @return the street + */ + String getStreet (); + + /** + * Street + *

+ * @param street the street to set + */ + void setStreet (final String street); + + /** + * ZIP code + *

+ * @return the zipCode + */ + Integer getZipCode (); + + /** + * ZIP code + *

+ * @param zipCode the zipCode to set + */ + void setZipCode (final Integer zipCode); + + /** + * Checks whether all required personal data is set + *

+ * @return Whether the required personal data is set + */ + boolean isRequiredPersonalDataSet (); +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/gender/GenderWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/gender/GenderWebApplicationBean.java new file mode 100644 index 00000000..473b1413 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/gender/GenderWebApplicationBean.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.gender; + +import java.util.List; +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Named; +import org.mxchange.jcontacts.contact.gender.Gender; +import org.mxchange.jcontacts.contact.gender.GenderUtils; + +/** + * A gender bean (controller) + *

+ * @author Roland Haeder + */ +@Named ("gender") +@ApplicationScoped +public class GenderWebApplicationBean implements GenderWebApplicationController { + + /** + * Serial number + */ + private static final long serialVersionUID = 835_482_364_189L; + + /** + * Default constructor + */ + public GenderWebApplicationBean () { + } + + @Override + public Gender[] getAllGenders () { + // Return it + return Gender.values(); + } + + @Override + public List getSelectableGenders () { + // Init array + // TODO Call EJB here? + List genders = GenderUtils.selectableGenders(); + + // Return it + return genders; + } +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/gender/GenderWebApplicationController.java b/src/java/org/mxchange/pizzaapplication/beans/gender/GenderWebApplicationController.java new file mode 100644 index 00000000..d547f95b --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/gender/GenderWebApplicationController.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.gender; + +import java.io.Serializable; +import java.util.List; +import org.mxchange.jcontacts.contact.gender.Gender; + +/** + * An interface for data beans + *

+ * @author Roland Haeder + */ +public interface GenderWebApplicationController extends Serializable { + + /** + * Getter for all genders as array + *

+ * @return All genders as array + */ + Gender[] getAllGenders (); + + /** + * Getter for only selectable genders as array, UNKNOWN is not selectable + *

+ * @return All genders as array + */ + List getSelectableGenders (); +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/gender/GenderWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/gender/GenderWebBean.java deleted file mode 100644 index 72029bf1..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/gender/GenderWebBean.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.pizzaapplication.beans.gender; - -import java.util.List; -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Named; -import org.mxchange.jcontacts.contact.gender.Gender; -import org.mxchange.jcontacts.contact.gender.GenderUtils; - -/** - * A gender bean (controller) - *

- * @author Roland Haeder - */ -@Named ("gender") -@ApplicationScoped -public class GenderWebBean implements GenderWebController { - - /** - * Serial number - */ - private static final long serialVersionUID = 835_482_364_189L; - - /** - * Default constructor - */ - public GenderWebBean () { - } - - @Override - public Gender[] getAllGenders () { - // Return it - return Gender.values(); - } - - @Override - public List getSelectableGenders () { - // Init array - // TODO Call EJB here? - List genders = GenderUtils.selectableGenders(); - - // Return it - return genders; - } -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/gender/GenderWebController.java b/src/java/org/mxchange/pizzaapplication/beans/gender/GenderWebController.java deleted file mode 100644 index 5618aa6b..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/gender/GenderWebController.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.pizzaapplication.beans.gender; - -import java.io.Serializable; -import java.util.List; -import org.mxchange.jcontacts.contact.gender.Gender; - -/** - * An interface for data beans - *

- * @author Roland Haeder - */ -public interface GenderWebController extends Serializable { - - /** - * Getter for all genders as array - *

- * @return All genders as array - */ - Gender[] getAllGenders (); - - /** - * Getter for only selectable genders as array, UNKNOWN is not selectable - *

- * @return All genders as array - */ - List getSelectableGenders (); -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebBean.java deleted file mode 100644 index 8c7c9b02..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebBean.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.pizzaapplication.beans.product; - -import java.util.List; -import javax.enterprise.context.RequestScoped; -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.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.ShopWebController; - -/** - * Main application class - *

- * @author Roland Haeder - */ -@Named ("admin_product") -@RequestScoped -public class AdminProductWebBean implements AdminProductWebController { - - /** - * Serial number - */ - private static final long serialVersionUID = 5_819_375_183_472_871L; - - /////////////////////// Properties ///////////////////// - /** - * Available - */ - private Boolean productAvailability; - - /** - * Category instance - */ - private Category productCategory; - - /** - * Property productPrice - */ - private Float productPrice; - - /** - * Remote bean for products - */ - private AdminProductSessionBeanRemote productRemoteBean; - - /** - * Property productTitle - */ - private String productTitle; - - ////////////////////// Bean injections /////////////////////// - - /** - * Shop bean - */ - @Inject - private ShopWebController shopController; - - /** - * Default constructor - */ - public AdminProductWebBean () { - // Try it - try { - // Get initial context - Context context = new InitialContext(); - - // Try to lookup the bean - this.productRemoteBean = (AdminProductSessionBeanRemote) context.lookup("ejb/stateless-admin-product"); //NOI18N - } catch (final NamingException e) { - // Throw it again - throw new FaceletException(e); - } - } - - @Override - public void addProduct () throws FaceletException { - try { - // Create product instance - Product product = new GenericProduct(); - - // Add all - product.setProductAvailability(this.getProductAvailability()); - product.setProductCategory(this.getProductCategory()); - product.setProductPrice(this.getProductPrice()); - product.setProductTitle(this.getProductTitle()); - - // Call bean - Product updatedProduct = this.productRemoteBean.doAdminAddProduct(product); - - // Add to shop controller - this.shopController.addProduct(updatedProduct); - - // Set all to null - this.setProductAvailability(Boolean.FALSE); - this.setProductCategory(null); - this.setProductPrice(null); - this.setProductTitle(null); - } catch (final ProductTitleAlreadyUsedException | CannotAddProductException ex) { - // Continue to throw - throw new FaceletException(ex); - } - } - - @Override - public List getAllProducts () throws FaceletException { - // Call bean - return this.productRemoteBean.getAllProducts(); - } - - @Override - public Boolean getProductAvailability () { - return this.productAvailability; - } - - @Override - public void setProductAvailability (final Boolean productAvailability) { - this.productAvailability = productAvailability; - } - - @Override - public Category getProductCategory () { - return this.productCategory; - } - - @Override - public void setProductCategory (final Category productCategory) { - this.productCategory = productCategory; - } - - @Override - public Float getProductPrice () { - return this.productPrice; - } - - @Override - public void setProductPrice (final Float productPrice) { - this.productPrice = productPrice; - } - - @Override - public String getProductTitle () { - return this.productTitle; - } - - @Override - public void setProductTitle (final String productTitle) { - this.productTitle = productTitle; - } -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebController.java b/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebController.java deleted file mode 100644 index ac384d77..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebController.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.pizzaapplication.beans.product; - -import java.util.List; -import javax.faces.view.facelets.FaceletException; -import org.mxchange.jshopcore.model.category.Category; -import org.mxchange.jshopcore.model.product.Product; - -/** - * An interface for product controllers for "ADMIN" role - *

- * @author Roland Haeder - */ -public interface AdminProductWebController { - - /** - * Adds given product data from request to database - *

- * @throws javax.faces.view.facelets.FaceletException If something - * unexpected happened - */ - void addProduct () throws FaceletException; - - /** - * Some "getter" for a linked list of all products - *

- * @return All products - *

- * @throws javax.faces.view.facelets.FaceletException If anything went wrong - */ - List getAllProducts () throws FaceletException; - - /** - * Getter for product's available property - *

- * @return Product's available property - */ - Boolean getProductAvailability (); - - /** - * Setter for product's available property - *

- * @param available Product's available property - */ - void setProductAvailability (final Boolean available); - - /** - * Getter for product's category - *

- * @return Product's category - */ - Category getProductCategory (); - - /** - * Setter for product's category instance - *

- * @param productCategory Product's category instance - */ - void setProductCategory (final Category productCategory); - - /** - * Getter for product's price property - *

- * @return Product's price property - */ - Float getProductPrice (); - - /** - * Setter for product's price property - *

- * @param price Product's price property - */ - void setProductPrice (final Float price); - - /** - * Getter for product's title property - *

- * @return Product's title - */ - String getProductTitle (); - - /** - * Setter for product's title property - *

- * @param title Product's title - */ - void setProductTitle (final String title); -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebRequestBean.java new file mode 100644 index 00000000..2e3f50f0 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebRequestBean.java @@ -0,0 +1,174 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.product; + +import java.util.List; +import javax.enterprise.context.RequestScoped; +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.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.ShopWebApplicationController; + +/** + * Main application class + *

+ * @author Roland Haeder + */ +@Named ("adminProductController") +@RequestScoped +public class AdminProductWebRequestBean implements AdminProductWebRequestController { + + /** + * Serial number + */ + private static final long serialVersionUID = 5_819_375_183_472_871L; + + /////////////////////// Properties ///////////////////// + /** + * Available + */ + private Boolean productAvailability; + + /** + * Category instance + */ + private Category productCategory; + + /** + * Property productPrice + */ + private Float productPrice; + + /** + * Remote bean for products + */ + private AdminProductSessionBeanRemote productRemoteBean; + + /** + * Property productTitle + */ + private String productTitle; + + ////////////////////// Bean injections /////////////////////// + + /** + * Shop bean + */ + @Inject + private ShopWebApplicationController shopController; + + /** + * Default constructor + */ + public AdminProductWebRequestBean () { + // Try it + try { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup the bean + this.productRemoteBean = (AdminProductSessionBeanRemote) context.lookup("ejb/stateless-admin-product"); //NOI18N + } catch (final NamingException e) { + // Throw it again + throw new FaceletException(e); + } + } + + @Override + public void addProduct () throws FaceletException { + try { + // Create product instance + Product product = new GenericProduct(); + + // Add all + product.setProductAvailability(this.getProductAvailability()); + product.setProductCategory(this.getProductCategory()); + product.setProductPrice(this.getProductPrice()); + product.setProductTitle(this.getProductTitle()); + + // Call bean + Product updatedProduct = this.productRemoteBean.doAdminAddProduct(product); + + // Add to shop controller + this.shopController.addProduct(updatedProduct); + + // Set all to null + this.setProductAvailability(Boolean.FALSE); + this.setProductCategory(null); + this.setProductPrice(null); + this.setProductTitle(null); + } catch (final ProductTitleAlreadyUsedException | CannotAddProductException ex) { + // Continue to throw + throw new FaceletException(ex); + } + } + + @Override + public List getAllProducts () throws FaceletException { + // Call bean + return this.productRemoteBean.getAllProducts(); + } + + @Override + public Boolean getProductAvailability () { + return this.productAvailability; + } + + @Override + public void setProductAvailability (final Boolean productAvailability) { + this.productAvailability = productAvailability; + } + + @Override + public Category getProductCategory () { + return this.productCategory; + } + + @Override + public void setProductCategory (final Category productCategory) { + this.productCategory = productCategory; + } + + @Override + public Float getProductPrice () { + return this.productPrice; + } + + @Override + public void setProductPrice (final Float productPrice) { + this.productPrice = productPrice; + } + + @Override + public String getProductTitle () { + return this.productTitle; + } + + @Override + public void setProductTitle (final String productTitle) { + this.productTitle = productTitle; + } +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebRequestController.java new file mode 100644 index 00000000..95450068 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebRequestController.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.product; + +import java.util.List; +import javax.faces.view.facelets.FaceletException; +import org.mxchange.jshopcore.model.category.Category; +import org.mxchange.jshopcore.model.product.Product; + +/** + * An interface for product controllers for "ADMIN" role + *

+ * @author Roland Haeder + */ +public interface AdminProductWebRequestController { + + /** + * Adds given product data from request to database + *

+ * @throws javax.faces.view.facelets.FaceletException If something + * unexpected happened + */ + void addProduct () throws FaceletException; + + /** + * Some "getter" for a linked list of all products + *

+ * @return All products + *

+ * @throws javax.faces.view.facelets.FaceletException If anything went wrong + */ + List getAllProducts () throws FaceletException; + + /** + * Getter for product's available property + *

+ * @return Product's available property + */ + Boolean getProductAvailability (); + + /** + * Setter for product's available property + *

+ * @param available Product's available property + */ + void setProductAvailability (final Boolean available); + + /** + * Getter for product's category + *

+ * @return Product's category + */ + Category getProductCategory (); + + /** + * Setter for product's category instance + *

+ * @param productCategory Product's category instance + */ + void setProductCategory (final Category productCategory); + + /** + * Getter for product's price property + *

+ * @return Product's price property + */ + Float getProductPrice (); + + /** + * Setter for product's price property + *

+ * @param price Product's price property + */ + void setProductPrice (final Float price); + + /** + * Getter for product's title property + *

+ * @return Product's title + */ + String getProductTitle (); + + /** + * Setter for product's title property + *

+ * @param title Product's title + */ + void setProductTitle (final String title); +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/receipt/ReceiptWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/receipt/ReceiptWebBean.java deleted file mode 100644 index 7874c927..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/receipt/ReceiptWebBean.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.pizzaapplication.beans.receipt; - -import javax.enterprise.context.SessionScoped; -import javax.faces.FacesException; -import javax.inject.Named; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import org.mxchange.jshopcore.model.customer.Customer; -import org.mxchange.jshopcore.model.receipt.ReceiptBeanRemote; - -/** - * Checkout controller - *

- * @author Roland Haeder - */ -@Named ("receiptController") -@SessionScoped -public class ReceiptWebBean implements ReceiptWebController { - - /** - * Serial number - */ - private static final long serialVersionUID = 95_723_834_783_478_781L; - - /** - * Customer instance - */ - private Customer customer; - - /** - * Remote bean instance - */ - private ReceiptBeanRemote receiptBean; - - /** - * Default constructor - */ - public ReceiptWebBean () { - try { - // Get initial context - Context context = new InitialContext(); - - // Get factory from JMS resource - this.receiptBean = (ReceiptBeanRemote) context.lookup("ejb/stateless-receipt"); - } catch (final NamingException e) { - // Continued to throw - throw new FacesException(e); - } - } - - @Override - public String fetchAccessKey () { - return this.receiptBean.fetchAccessKey(this.getCustomer()); - } - - @Override - public Customer getCustomer () { - return this.customer; - } - - @Override - public void setCustomer (final Customer customer) { - this.customer = customer; - } -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/receipt/ReceiptWebController.java b/src/java/org/mxchange/pizzaapplication/beans/receipt/ReceiptWebController.java deleted file mode 100644 index 85e85e98..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/receipt/ReceiptWebController.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.pizzaapplication.beans.receipt; - -import java.io.Serializable; -import org.mxchange.jshopcore.model.customer.Customer; - -/** - * An interface for the shop - *

- * @author Roland Haeder - */ -public interface ReceiptWebController extends Serializable { - - /** - * Fetches last access key for given customer instance - *

- * @return Access key to receipt - */ - String fetchAccessKey (); - - /** - * Getter for customer instamce - *

- * @return Customer instance - */ - Customer getCustomer (); - - /** - * Setter for customer instamce - *

- * @param customer Customer instance - */ - void setCustomer (final Customer customer); -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/receipt/ReceiptWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/receipt/ReceiptWebSessionBean.java new file mode 100644 index 00000000..6d469334 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/receipt/ReceiptWebSessionBean.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.receipt; + +import javax.enterprise.context.SessionScoped; +import javax.faces.FacesException; +import javax.inject.Named; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import org.mxchange.jshopcore.model.customer.Customer; +import org.mxchange.jshopcore.model.receipt.ReceiptBeanRemote; + +/** + * Checkout controller + *

+ * @author Roland Haeder + */ +@Named ("receiptController") +@SessionScoped +public class ReceiptWebSessionBean implements ReceiptWebSessionController { + + /** + * Serial number + */ + private static final long serialVersionUID = 95_723_834_783_478_781L; + + /** + * Customer instance + */ + private Customer customer; + + /** + * Remote bean instance + */ + private ReceiptBeanRemote receiptBean; + + /** + * Default constructor + */ + public ReceiptWebSessionBean () { + try { + // Get initial context + Context context = new InitialContext(); + + // Get factory from JMS resource + this.receiptBean = (ReceiptBeanRemote) context.lookup("ejb/stateless-receipt"); + } catch (final NamingException e) { + // Continued to throw + throw new FacesException(e); + } + } + + @Override + public String fetchAccessKey () { + return this.receiptBean.fetchAccessKey(this.getCustomer()); + } + + @Override + public Customer getCustomer () { + return this.customer; + } + + @Override + public void setCustomer (final Customer customer) { + this.customer = customer; + } +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/receipt/ReceiptWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/receipt/ReceiptWebSessionController.java new file mode 100644 index 00000000..fa0f3fd1 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/receipt/ReceiptWebSessionController.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.receipt; + +import java.io.Serializable; +import org.mxchange.jshopcore.model.customer.Customer; + +/** + * An interface for the shop + *

+ * @author Roland Haeder + */ +public interface ReceiptWebSessionController extends Serializable { + + /** + * Fetches last access key for given customer instance + *

+ * @return Access key to receipt + */ + String fetchAccessKey (); + + /** + * Getter for customer instamce + *

+ * @return Customer instance + */ + Customer getCustomer (); + + /** + * Setter for customer instamce + *

+ * @param customer Customer instance + */ + void setCustomer (final Customer customer); +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/shop/ShopWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/shop/ShopWebApplicationBean.java new file mode 100644 index 00000000..daf67bb3 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/shop/ShopWebApplicationBean.java @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU 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.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.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 ("controller") +@ApplicationScoped +public class ShopWebApplicationBean implements ShopWebApplicationController { + + /** + * 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 List getAllCategories () throws FacesException { + // Return it + // TODO Find something better here to prevent warning + return Collections.unmodifiableList(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 + // TODO Find something better here to prevent warning + 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("ejb/stateless-category"); //NOI18N + + // Get all categories + this.categories = categoryBean.getAllCategories(); + + // Try to lookup the bean + ProductSessionBeanRemote productBean = (ProductSessionBeanRemote) context.lookup("ejb/stateless-product"); //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/ShopWebApplicationController.java b/src/java/org/mxchange/pizzaapplication/beans/shop/ShopWebApplicationController.java new file mode 100644 index 00000000..6968a175 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/shop/ShopWebApplicationController.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU 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.model.category.Category; +import org.mxchange.jshopcore.model.product.Product; + +/** + * An interface for the shop + *

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

+ * @param category Category instance + */ + 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 + */ + 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; + + /** + * 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; +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/shop/ShopWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/shop/ShopWebBean.java deleted file mode 100644 index d661a292..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/shop/ShopWebBean.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU 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.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.model.category.Category; -import org.mxchange.jshopcore.model.category.CategorySessionBeanRemote; -import org.mxchange.jshopcore.model.product.Product; -import org.mxchange.jshopcore.model.product.ProductSessionBeanRemote; -import org.mxchange.pizzaapplication.beans.AbstractWebBean; - -/** - * General shop controller - *

- * @author Roland Haeder - */ -@Named ("controller") -@ApplicationScoped -public class ShopWebBean extends AbstractWebBean implements ShopWebController { - - /** - * 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 List getAllCategories () throws FacesException { - // Return it - // TODO Find something better here to prevent warning - return Collections.unmodifiableList(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 - // TODO Find something better here to prevent warning - 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("ejb/stateless-category"); //NOI18N - - // Get all categories - this.categories = categoryBean.getAllCategories(); - - // Try to lookup the bean - ProductSessionBeanRemote productBean = (ProductSessionBeanRemote) context.lookup("ejb/stateless-product"); //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/ShopWebController.java b/src/java/org/mxchange/pizzaapplication/beans/shop/ShopWebController.java deleted file mode 100644 index 24a51d58..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/shop/ShopWebController.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU 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.model.category.Category; -import org.mxchange.jshopcore.model.product.Product; - -/** - * An interface for the shop - *

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

- * @param category Category instance - */ - 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 - */ - 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; - - /** - * 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; -} 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 62a2019a..8149afdb 100644 --- a/web/WEB-INF/templates/admin/admin_category_selection_box.tpl +++ b/web/WEB-INF/templates/admin/admin_category_selection_box.tpl @@ -4,7 +4,7 @@ xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets"> - + diff --git a/web/admin/product.xhtml b/web/admin/product.xhtml index 97cf68c8..ea8fc2a1 100644 --- a/web/admin/product.xhtml +++ b/web/admin/product.xhtml @@ -16,7 +16,7 @@

- + Produktnummer: #{product.productId}: @@ -45,8 +45,8 @@
@@ -105,7 +105,7 @@
- + @@ -117,7 +117,7 @@