From: Roland Haeder Date: Mon, 4 Apr 2016 16:11:03 +0000 (+0200) Subject: renamed files to make difference to other war-projects X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5d1a525c51f8b70e5aac9e23beb809e35d97cfaf;p=pizzaservice-war.git renamed files to make difference to other war-projects --- diff --git a/src/java/org/mxchange/jshopcore/model/category/CategoryConverter.java b/src/java/org/mxchange/jshopcore/model/category/CategoryConverter.java deleted file mode 100644 index 1ba13948..00000000 --- a/src/java/org/mxchange/jshopcore/model/category/CategoryConverter.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jshopcore.model.category; - -import java.text.MessageFormat; -import java.util.List; -import java.util.Objects; -import javax.annotation.PostConstruct; -import javax.faces.component.UIComponent; -import javax.faces.context.FacesContext; -import javax.faces.convert.Converter; -import javax.faces.convert.FacesConverter; -import javax.inject.Inject; -import javax.naming.Context; -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.ShopWebApplicationController; - -/** - * A converter for transfering category objects - *

- * @author Roland Haeder - */ -@FacesConverter (value = "category") -public class CategoryConverter implements Converter { - - /** - * Logger instance - */ - @Log - private LoggerBeanLocal loggerBeanLocal; - - /** - * Category bean - */ - @Inject - private ShopWebApplicationController shopController; - - @Override - public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { - // Trace message - this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: context={0},component={1},submittedValue={2} - CALLED!", context, component, submittedValue)); //NOI18N - - // Get full list - List categoryList = this.shopController.getAllCategories(); - - // Is the value null or empty? - if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { - // Trace message - this.loggerBeanLocal.logTrace("getAsObject: submittedValue is null or empty - EXIT!"); //NOI18N - - // Return null - return null; - } - - // Init value - Category category = null; - - // Try this better - try { - // Convert it to long - Long categoryId = Long.parseLong(submittedValue); - - // Category id should not be below 1 - assert (categoryId > 0) : "categoryId is smaller than one: " + categoryId; //NOI18N - - // Debug message - this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: categoryId={0}", categoryId)); //NOI18N - - // Try to find it - for (final Category cat : categoryList) { - // Is the id the same? (null-safe) - if (Objects.equals(cat.getCategoryId(), categoryId)) { - // Found it - category = cat; - break; - } - } - } catch (final NumberFormatException ex) { - // Log exception (maybe to much?) - this.loggerBeanLocal.logException(ex); - } - - // Trace message - this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: category={0} - EXIT!", category)); //NOI18N - - // Return it - return category; - } - - @Override - public String getAsString (final FacesContext context, final UIComponent component, final Object value) { - // Is the object null? - if (null == value) { - // Is null - return ""; //NOI18N - } else if (!(value instanceof Category)) { - // Not same interface - throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement Category.", value)); //NOI18N - } - - // Return category id - return String.valueOf(((Category) value).getCategoryId()); - } - - /** - * Initialization of this converter - */ - @PostConstruct - public void init () { - // Try to get it - try { - // Get initial context - Context context = new InitialContext(); - - // Lookup logger - this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N - } catch (final NamingException ex) { - // Continue to throw it - throw new RuntimeException("context.lookup() failed.", ex); //NOI18N - } - } -} diff --git a/src/java/org/mxchange/jshopcore/model/category/PizzaCategoryConverter.java b/src/java/org/mxchange/jshopcore/model/category/PizzaCategoryConverter.java new file mode 100644 index 00000000..48cdb27a --- /dev/null +++ b/src/java/org/mxchange/jshopcore/model/category/PizzaCategoryConverter.java @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jshopcore.model.category; + +import java.text.MessageFormat; +import java.util.List; +import java.util.Objects; +import javax.annotation.PostConstruct; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.FacesConverter; +import javax.inject.Inject; +import javax.naming.Context; +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.PizzaShopWebApplicationController; + +/** + * A converter for transfering category objects + *

+ * @author Roland Haeder + */ +@FacesConverter (value = "category") +public class PizzaCategoryConverter implements Converter { + + /** + * Logger instance + */ + @Log + private LoggerBeanLocal loggerBeanLocal; + + /** + * Category bean + */ + @Inject + private PizzaShopWebApplicationController shopController; + + @Override + public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { + // Trace message + this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: context={0},component={1},submittedValue={2} - CALLED!", context, component, submittedValue)); //NOI18N + + // Get full list + List categoryList = this.shopController.getAllCategories(); + + // Is the value null or empty? + if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { + // Trace message + this.loggerBeanLocal.logTrace("getAsObject: submittedValue is null or empty - EXIT!"); //NOI18N + + // Return null + return null; + } + + // Init value + Category category = null; + + // Try this better + try { + // Convert it to long + Long categoryId = Long.parseLong(submittedValue); + + // Category id should not be below 1 + assert (categoryId > 0) : "categoryId is smaller than one: " + categoryId; //NOI18N + + // Debug message + this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: categoryId={0}", categoryId)); //NOI18N + + // Try to find it + for (final Category cat : categoryList) { + // Is the id the same? (null-safe) + if (Objects.equals(cat.getCategoryId(), categoryId)) { + // Found it + category = cat; + break; + } + } + } catch (final NumberFormatException ex) { + // Log exception (maybe to much?) + this.loggerBeanLocal.logException(ex); + } + + // Trace message + this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: category={0} - EXIT!", category)); //NOI18N + + // Return it + return category; + } + + @Override + public String getAsString (final FacesContext context, final UIComponent component, final Object value) { + // Is the object null? + if (null == value) { + // Is null + return ""; //NOI18N + } else if (!(value instanceof Category)) { + // Not same interface + throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement Category.", value)); //NOI18N + } + + // Return category id + return String.valueOf(((Category) value).getCategoryId()); + } + + /** + * Initialization of this converter + */ + @PostConstruct + public void init () { + // Try to get it + try { + // Get initial context + Context context = new InitialContext(); + + // Lookup logger + this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N + } catch (final NamingException ex) { + // Continue to throw it + throw new RuntimeException("context.lookup() failed.", ex); //NOI18N + } + } +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebSessionBean.java deleted file mode 100644 index 5e26f345..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebSessionBean.java +++ /dev/null @@ -1,483 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero 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 void clear () { - // Clear bean as well - this.basketBean.clear(); - - // Deligate to basket instance - this.basket.clear(); - } - - @Override - public String doChangeItem (final AddableBasketItem item) { - // Trace message - //this.getLogger().logTrace(MessageFormat.format("doChangeItem: 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("doChangeItem: targetPage={0} - EXIT!", targetPage)); - // Return page - return targetPage; - } - - @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 deleted file mode 100644 index 5317e9c0..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebSessionController.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero 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 doChangeItem (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/PizzaBasketWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/basket/PizzaBasketWebSessionBean.java new file mode 100644 index 00000000..56bdc6e0 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/basket/PizzaBasketWebSessionBean.java @@ -0,0 +1,483 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero 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 PizzaBasketWebSessionBean implements PizzaBasketWebSessionController { + + /** + * 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 PizzaBasketWebSessionBean () { + // 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 void clear () { + // Clear bean as well + this.basketBean.clear(); + + // Deligate to basket instance + this.basket.clear(); + } + + @Override + public String doChangeItem (final AddableBasketItem item) { + // Trace message + //this.getLogger().logTrace(MessageFormat.format("doChangeItem: 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("doChangeItem: targetPage={0} - EXIT!", targetPage)); + // Return page + return targetPage; + } + + @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/PizzaBasketWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/basket/PizzaBasketWebSessionController.java new file mode 100644 index 00000000..1c20c118 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/basket/PizzaBasketWebSessionController.java @@ -0,0 +1,170 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero 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 PizzaBasketWebSessionController 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 doChangeItem (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/AdminCategoryWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebRequestBean.java deleted file mode 100644 index 65637e90..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebRequestBean.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero 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 deleted file mode 100644 index 7670dd45..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/category/AdminCategoryWebRequestController.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero 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/category/PizzaAdminCategoryWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/category/PizzaAdminCategoryWebRequestBean.java new file mode 100644 index 00000000..ef700192 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/category/PizzaAdminCategoryWebRequestBean.java @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero 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.PizzaShopWebApplicationController; + +/** + * Main application class + *

+ * @author Roland Haeder + */ +@Named ("admin_category") +@RequestScoped +public class PizzaAdminCategoryWebRequestBean implements PizzaAdminCategoryWebRequestController { + + /** + * 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 PizzaShopWebApplicationController shopController; + + /** + * Default constructor + */ + public PizzaAdminCategoryWebRequestBean () { + // 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/PizzaAdminCategoryWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/category/PizzaAdminCategoryWebRequestController.java new file mode 100644 index 00000000..2e130ba0 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/category/PizzaAdminCategoryWebRequestController.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero 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 PizzaAdminCategoryWebRequestController { + + /** + * 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/CheckoutWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebSessionBean.java deleted file mode 100644 index 617d7283..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebSessionBean.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero 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 deleted file mode 100644 index 585dbab6..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebSessionController.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero 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/checkout/PizzaCheckoutWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/checkout/PizzaCheckoutWebSessionBean.java new file mode 100644 index 00000000..a2e3e96a --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/checkout/PizzaCheckoutWebSessionBean.java @@ -0,0 +1,230 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero 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.PizzaBasketWebSessionController; +import org.mxchange.pizzaapplication.beans.customer.PizzaCustomerWebSessionController; +import org.mxchange.pizzaapplication.beans.receipt.PizzaReceiptWebSessionController; + +/** + * Checkout controller + *

+ * @author Roland Haeder + */ +@Named ("checkoutController") +@SessionScoped +public class PizzaCheckoutWebSessionBean implements PizzaCheckoutWebSessionController { + + /** + * Serial number + */ + private static final long serialVersionUID = 51_987_348_347_183L; + + ////////////////////// Bean injections /////////////////////// + /** + * Basket bean + */ + @Inject + private PizzaBasketWebSessionController basketController; + + /** + * Connection + */ + private Connection connection; + + /** + * Customer instance + */ + private Customer customer; + + /** + * Customer bean + */ + @Inject + private PizzaCustomerWebSessionController customerController; + + /** + * Object message + */ + private ObjectMessage message; + + /** + * Message producer + */ + private MessageProducer messageProducer; + + /** + * Queue instance + */ + private Queue queue; + + /** + * Receipt bean + */ + @Inject + private PizzaReceiptWebSessionController 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/PizzaCheckoutWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/checkout/PizzaCheckoutWebSessionController.java new file mode 100644 index 00000000..633c00b0 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/checkout/PizzaCheckoutWebSessionController.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero 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 PizzaCheckoutWebSessionController 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 deleted file mode 100644 index 552dbab5..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/country/CountryWebApplicationBean.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.pizzaapplication.beans.country; - -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); - } - - /** - * Post-initialization of this class - */ - @PostConstruct - public void init () { - // "Cache" country list as this will not change so often. - 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 deleted file mode 100644 index bdeca746..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/country/CountryWebApplicationController.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.pizzaapplication.beans.country; - -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/PizzaCountryWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/country/PizzaCountryWebApplicationBean.java new file mode 100644 index 00000000..c60e7975 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/country/PizzaCountryWebApplicationBean.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.country; + +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 PizzaCountryWebApplicationBean implements PizzaCountryWebApplicationController { + + /** + * 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 PizzaCountryWebApplicationBean () { + // 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); + } + + /** + * Post-initialization of this class + */ + @PostConstruct + public void init () { + // "Cache" country list as this will not change so often. + this.countryList = this.countryBean.allCountries(); + } +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/country/PizzaCountryWebApplicationController.java b/src/java/org/mxchange/pizzaapplication/beans/country/PizzaCountryWebApplicationController.java new file mode 100644 index 00000000..616891d4 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/country/PizzaCountryWebApplicationController.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.country; + +import java.io.Serializable; +import java.util.List; +import org.mxchange.jcountry.data.Country; + +/** + * An interface for country beans + *

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

+ * @return All countries + */ + List allCountries (); +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebSessionBean.java deleted file mode 100644 index a2b4e49c..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebSessionBean.java +++ /dev/null @@ -1,296 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero 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.setContactLandLineNumber(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 deleted file mode 100644 index 080a8bd0..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebSessionController.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero 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/customer/PizzaCustomerWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionBean.java new file mode 100644 index 00000000..6b3b64b5 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionBean.java @@ -0,0 +1,296 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero 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 PizzaCustomerWebSessionBean implements PizzaCustomerWebSessionController { + + /** + * 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 PizzaCustomerWebSessionBean () { + // 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.setContactLandLineNumber(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/PizzaCustomerWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionController.java new file mode 100644 index 00000000..825192fd --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionController.java @@ -0,0 +1,215 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero 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 PizzaCustomerWebSessionController 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 deleted file mode 100644 index e59e4cdc..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/gender/GenderWebApplicationBean.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero 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 deleted file mode 100644 index 536eaeae..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/gender/GenderWebApplicationController.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero 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/PizzaGenderWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/gender/PizzaGenderWebApplicationBean.java new file mode 100644 index 00000000..eb956f1e --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/gender/PizzaGenderWebApplicationBean.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero 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 PizzaGenderWebApplicationBean implements PizzaGenderWebApplicationController { + + /** + * Serial number + */ + private static final long serialVersionUID = 835_482_364_189L; + + /** + * Default constructor + */ + public PizzaGenderWebApplicationBean () { + } + + @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/PizzaGenderWebApplicationController.java b/src/java/org/mxchange/pizzaapplication/beans/gender/PizzaGenderWebApplicationController.java new file mode 100644 index 00000000..9e0b9d82 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/gender/PizzaGenderWebApplicationController.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero 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 PizzaGenderWebApplicationController 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/localization/LocalizationSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/localization/LocalizationSessionController.java deleted file mode 100644 index 7383bdd1..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/localization/LocalizationSessionController.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.pizzaapplication.beans.localization; - -import java.io.Serializable; -import java.util.Locale; - -/** - * An interface for localization change beans - *

- * @author Roland Haeder - */ -public interface LocalizationSessionController extends Serializable { - - /** - * Getter for locale - *

- * @return Locale - */ - Locale getLocale (); - - /** - * Setter for locale - *

- * @param locale Locale - */ - void setLocale (final Locale locale); - -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/localization/PizzaLocalizationSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/localization/PizzaLocalizationSessionBean.java index 8c107ed4..b8fb5cde 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/localization/PizzaLocalizationSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/localization/PizzaLocalizationSessionBean.java @@ -33,7 +33,7 @@ import org.mxchange.jcoreee.database.BaseDatabaseBean; */ @Named ("localization") @SessionScoped -public class PizzaLocalizationSessionBean extends BaseDatabaseBean implements LocalizationSessionController { +public class PizzaLocalizationSessionBean extends BaseDatabaseBean implements PizzaLocalizationSessionController { /** * Serial number diff --git a/src/java/org/mxchange/pizzaapplication/beans/localization/PizzaLocalizationSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/localization/PizzaLocalizationSessionController.java new file mode 100644 index 00000000..e4c98139 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/localization/PizzaLocalizationSessionController.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.localization; + +import java.io.Serializable; +import java.util.Locale; + +/** + * An interface for localization change beans + *

+ * @author Roland Haeder + */ +public interface PizzaLocalizationSessionController extends Serializable { + + /** + * Getter for locale + *

+ * @return Locale + */ + Locale getLocale (); + + /** + * Setter for locale + *

+ * @param locale Locale + */ + void setLocale (final Locale locale); + +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebRequestBean.java deleted file mode 100644 index 3f0516c1..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebRequestBean.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero 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 deleted file mode 100644 index e0bbda86..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/product/AdminProductWebRequestController.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero 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/product/PizzaAdminProductWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/product/PizzaAdminProductWebRequestBean.java new file mode 100644 index 00000000..b329e098 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/product/PizzaAdminProductWebRequestBean.java @@ -0,0 +1,174 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero 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.PizzaShopWebApplicationController; + +/** + * Main application class + *

+ * @author Roland Haeder + */ +@Named ("adminProductController") +@RequestScoped +public class PizzaAdminProductWebRequestBean implements PizzaAdminProductWebRequestController { + + /** + * 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 PizzaShopWebApplicationController shopController; + + /** + * Default constructor + */ + public PizzaAdminProductWebRequestBean () { + // 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/PizzaAdminProductWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/product/PizzaAdminProductWebRequestController.java new file mode 100644 index 00000000..3a9a67a4 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/product/PizzaAdminProductWebRequestController.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero 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 PizzaAdminProductWebRequestController { + + /** + * 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/PizzaReceiptWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/receipt/PizzaReceiptWebSessionBean.java new file mode 100644 index 00000000..7239b81e --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/receipt/PizzaReceiptWebSessionBean.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero 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 PizzaReceiptWebSessionBean implements PizzaReceiptWebSessionController { + + /** + * 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 PizzaReceiptWebSessionBean () { + 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/PizzaReceiptWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/receipt/PizzaReceiptWebSessionController.java new file mode 100644 index 00000000..0b5fb546 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/receipt/PizzaReceiptWebSessionController.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero 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 PizzaReceiptWebSessionController 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 deleted file mode 100644 index eab1ba67..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/receipt/ReceiptWebSessionBean.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero 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 deleted file mode 100644 index 2238bc19..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/receipt/ReceiptWebSessionController.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero 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/PizzaShopWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java new file mode 100644 index 00000000..f85638b8 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationBean.java @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero 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 PizzaShopWebApplicationBean implements PizzaShopWebApplicationController { + + /** + * 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/PizzaShopWebApplicationController.java b/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java new file mode 100644 index 00000000..5cbe8fcc --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/shop/PizzaShopWebApplicationController.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero 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 PizzaShopWebApplicationController 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/ShopWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/shop/ShopWebApplicationBean.java deleted file mode 100644 index 52d60820..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/shop/ShopWebApplicationBean.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero 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 deleted file mode 100644 index 69ded40a..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/shop/ShopWebApplicationController.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero 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/servlet/receipt/PdfReceiptServlet.java b/src/java/org/mxchange/pizzaapplication/servlet/receipt/PdfReceiptServlet.java deleted file mode 100644 index 9d55184e..00000000 --- a/src/java/org/mxchange/pizzaapplication/servlet/receipt/PdfReceiptServlet.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.pizzaapplication.servlet.receipt; - -import java.io.IOException; -import javax.faces.view.facelets.FaceletException; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.mxchange.jshopcore.model.receipt.ReceiptBeanRemote; -import org.mxchange.jshopcore.model.receipt.WrapableReceipt; - -/** - * A servlet for a PDF receipt (official) - *

- * @author Roland Haeder - */ -public class PdfReceiptServlet extends HttpServlet { - - /** - * Serial number - */ - private static final long serialVersionUID = 497_345_834_783_781L; - - /** - * Remote bean - */ - private ReceiptBeanRemote receiptBean; - - /** - * Public constructor - */ - public PdfReceiptServlet () { - // Try it - try { - // Get initial context - Context context = new InitialContext(); - - // Set instance - this.receiptBean = (ReceiptBeanRemote) context.lookup("ejb/pdf-receipt"); //NOI18N - } catch (final NamingException e) { - // Throw again - throw new FaceletException(e); - } - } - - @Override - public String getServletInfo () { - return "Produces a receipt as PDF file for given access key."; - } - - @Override - protected void doGet (final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { - // Is the key set? - if (request.getParameter("key") == null) { //NOI18N - // No more processing here - super.doGet(request, response); - return; - } - - // Get PDF from bean - WrapableReceipt receipt = this.receiptBean.createReceiptFromAccessKey(request.getParameter("key")); //NOI18N - - // TODO Write it's content to response output - } - - @Override - protected void doPost (final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { - // Deligate to getter method - this.doGet(request, response); - } - -} diff --git a/src/java/org/mxchange/pizzaapplication/servlet/receipt/PizzaPdfReceiptServlet.java b/src/java/org/mxchange/pizzaapplication/servlet/receipt/PizzaPdfReceiptServlet.java new file mode 100644 index 00000000..3d374cdb --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/servlet/receipt/PizzaPdfReceiptServlet.java @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.servlet.receipt; + +import java.io.IOException; +import javax.faces.view.facelets.FaceletException; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.mxchange.jshopcore.model.receipt.ReceiptBeanRemote; +import org.mxchange.jshopcore.model.receipt.WrapableReceipt; + +/** + * A servlet for a PDF receipt (official) + *

+ * @author Roland Haeder + */ +public class PizzaPdfReceiptServlet extends HttpServlet { + + /** + * Serial number + */ + private static final long serialVersionUID = 497_345_834_783_781L; + + /** + * Remote bean + */ + private ReceiptBeanRemote receiptBean; + + /** + * Public constructor + */ + public PizzaPdfReceiptServlet () { + // Try it + try { + // Get initial context + Context context = new InitialContext(); + + // Set instance + this.receiptBean = (ReceiptBeanRemote) context.lookup("ejb/pdf-receipt"); //NOI18N + } catch (final NamingException e) { + // Throw again + throw new FaceletException(e); + } + } + + @Override + public String getServletInfo () { + return "Produces a receipt as PDF file for given access key."; + } + + @Override + protected void doGet (final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { + // Is the key set? + if (request.getParameter("key") == null) { //NOI18N + // No more processing here + super.doGet(request, response); + return; + } + + // Get PDF from bean + WrapableReceipt receipt = this.receiptBean.createReceiptFromAccessKey(request.getParameter("key")); //NOI18N + + // TODO Write it's content to response output + } + + @Override + protected void doPost (final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { + // Deligate to getter method + this.doGet(request, response); + } + +} diff --git a/web/WEB-INF/web.xml b/web/WEB-INF/web.xml index 0e403f6c..288c1c7c 100644 --- a/web/WEB-INF/web.xml +++ b/web/WEB-INF/web.xml @@ -1,36 +1,36 @@ - - javax.faces.PROJECT_STAGE - Development - - - Faces Servlet - javax.faces.webapp.FacesServlet - 1 - - - pdf - org.mxchange.pizzaapplication.servlet.receipt.PdfReceiptServlet - - - Faces Servlet - /faces/* - - - tpl - text/plain - - - pdf - /customer/recipt.pdf - - - + + javax.faces.PROJECT_STAGE + Development + + + Faces Servlet + javax.faces.webapp.FacesServlet + 1 + + + pdf + org.mxchange.pizzaapplication.servlet.receipt.PizzaPdfReceiptServlet + + + Faces Servlet + /faces/* + + + tpl + text/plain + + + pdf + /customer/recipt.pdf + + + 30 - - - faces/index.xhtml - + + + faces/index.xhtml +