import java.text.MessageFormat;
import java.util.List;
-import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.faces.FacesException;
import javax.faces.view.facelets.FaceletException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
-import org.mxchange.jcoreee.beans.BaseFrameworkBean;
import org.mxchange.jshopcore.exceptions.BasketItemAlreadyAddedException;
import org.mxchange.jshopcore.model.basket.AddableBasketItem;
import org.mxchange.jshopcore.model.basket.Basket;
import org.mxchange.jshopcore.model.basket.BasketSessionBeanRemote;
import org.mxchange.jshopcore.model.basket.ShopBasket;
-import org.mxchange.jshopcore.model.item.BasketItem;
+import org.mxchange.jshopcore.model.basket.items.BasketItem;
import org.mxchange.jshopcore.model.product.Product;
/**
* A bean for the basket
- *
+ * <p>
* @author Roland Haeder<roland@mxchange.org>
*/
@Named ("basketController")
@SessionScoped
-public class BasketWebBean extends BaseFrameworkBean implements BasketWebController {
+public class BasketWebBean implements BasketWebController {
/**
* Serial number
/////////////////////// Properties /////////////////////
/**
- * Ordered amount
+ * Ordered orderedAmount
*/
- private Long amount;
+ private Long orderedAmount;
/**
* Current item
@Override
public String addItem (final Product product) {
// Trace message
- this.getLogger().logTrace(MessageFormat.format("addItem: product={0} - CALLED!", product));
+ //this.getLogger().logTrace(MessageFormat.format("addItem: product={0} - CALLED!", product));
// product should not be null
if (null == product) {
}
// Generate item instance
- AddableBasketItem item = new BasketItem(product, this.getAmount());
+ AddableBasketItem item = new BasketItem(product, this.getOrderedAmount());
- // Is amount set?
- if (this.getAmount() == null) {
+ // Is orderedAmount set?
+ if (this.getOrderedAmount() == null) {
// Trace message
- this.getLogger().logTrace("addItem: amount not specified, returning null ... - EXIT!");
+ //this.getLogger().logTrace("addItem: orderedAmount not specified, returning null ... - EXIT!");
- // No amount specified?!
+ // No orderedAmount specified?!
return null;
}
// Deligate to model
this.basket.addItem(item);
- // Remove amount
- this.setAmount(null);
+ // Remove orderedAmount
+ this.setOrderedAmount(null);
// Trace message
- this.getLogger().logTrace(MessageFormat.format("addItem: item {0} - has been added to basket. - EXIT!", item));
-
+ //this.getLogger().logTrace(MessageFormat.format("addItem: item {0} - has been added to basket. - EXIT!", item));
// Added
return "item_added"; //NOI18N
} catch (final BasketItemAlreadyAddedException ex) {
@Override
public List<AddableBasketItem> allItems () {
// Trace message
- this.getLogger().logTrace("allItems: CALLED!");
+ //this.getLogger().logTrace("allItems: CALLED!");
// Deligate to basket instance
List<AddableBasketItem> list = this.basket.getAll();
// Trace message
- this.getLogger().logTrace(MessageFormat.format("allItems: list={0} - EXIT!", list));
-
+ //this.getLogger().logTrace(MessageFormat.format("allItems: list={0} - EXIT!", list));
// Return it
return list;
}
@Override
public Float calculateCurrentItemPrice () {
// Trace message
- this.getLogger().logTrace("calculateCurrentItemPrice: CALLED!");
+ //this.getLogger().logTrace("calculateCurrentItemPrice: CALLED!");
// Is the current item/amount set?
if (this.getCurrentItem() == null) {
// Current item is null
throw new NullPointerException("currentItem is null"); //NOI18N
- } else if (this.getCurrentItem().getProduct() == null) {
+ } else if (this.getCurrentItem().getItemProduct() == null) {
// Product is null
throw new NullPointerException("currentItem.product is null"); //NOI18N
- } else if (this.getCurrentItem().getAmount() == null) {
+ } else if (this.getCurrentItem().getOrderedAmount() == null) {
// Amount is null
throw new NullPointerException("currentItem.amount is null"); //NOI18N
}
// Caculate item's price
- Float totalPrice = (this.getCurrentItem().getProduct().getPrice() * this.getCurrentItem().getAmount());
+ Float totalPrice = (this.getCurrentItem().getItemProduct().getProductPrice() * this.getCurrentItem().getOrderedAmount());
// Trace message
- this.getLogger().logTrace(MessageFormat.format("calculateCurrentItemPrice: totalPrice={0} - EXIT!", totalPrice));
-
+ //this.getLogger().logTrace(MessageFormat.format("calculateCurrentItemPrice: totalPrice={0} - EXIT!", totalPrice));
// Return it
return totalPrice;
}
@Override
public Float calculateItemPrice (final AddableBasketItem item) {
// Trace message
- this.getLogger().logTrace(MessageFormat.format("calculateItemPrice: item={0} - CALLED!", item));
+ //this.getLogger().logTrace(MessageFormat.format("calculateItemPrice: item={0} - CALLED!", item));
// item must not be null
if (null == item) {
// Is it a product?
if (item.isProductType()) {
// Caculate item's price
- totalPrice = (item.getProduct().getPrice() * item.getAmount());
+ totalPrice = (item.getItemProduct().getProductPrice() * item.getOrderedAmount());
}
// Trace message
- this.getLogger().logTrace(MessageFormat.format("calculateItemPrice: totalPrice={0} - EXIT!", totalPrice));
-
+ //this.getLogger().logTrace(MessageFormat.format("calculateItemPrice: totalPrice={0} - EXIT!", totalPrice));
// Return it
return totalPrice;
}
@Override
public Float calculateTotalPrice () {
// Trace message
- this.getLogger().logTrace("calculateTotalPrice: CALLED!");
+ //this.getLogger().logTrace("calculateTotalPrice: CALLED!");
// Init total price
Float totalPrice = 0.0f;
}
// Trace message
- this.getLogger().logTrace(MessageFormat.format("calculateTotalPrice: totalPrice={0} - EXIT!", totalPrice));
-
+ //this.getLogger().logTrace(MessageFormat.format("calculateTotalPrice: totalPrice={0} - EXIT!", totalPrice));
// Return final sum
return totalPrice;
}
@Override
public String changeItem (final AddableBasketItem item) {
// Trace message
- this.getLogger().logTrace(MessageFormat.format("changeItem: item={0} - CALLED!", item));
+ //this.getLogger().logTrace(MessageFormat.format("changeItem: item={0} - CALLED!", item));
// item shall not be null
if (null == item) {
}
// Trace message
- this.getLogger().logTrace(MessageFormat.format("changeItem: targetPage={0} - EXIT!", targetPage));
-
+ //this.getLogger().logTrace(MessageFormat.format("changeItem: targetPage={0} - EXIT!", targetPage));
// Return page
return targetPage;
}
}
@Override
- public Long getAmount () {
- return this.amount;
+ public Long getOrderedAmount () {
+ return this.orderedAmount;
}
@Override
- public void setAmount (final Long amount) {
- this.amount = amount;
+ public void setOrderedAmount (final Long orderedAmount) {
+ this.orderedAmount = orderedAmount;
}
@Override
@Override
public Long getItemAmount (final Product product) {
// Trace message
- this.getLogger().logTrace(MessageFormat.format("getItemAmount: product={0} - CALLED!", product));
+ //this.getLogger().logTrace(MessageFormat.format("getItemAmount: product={0} - CALLED!", product));
// product should not be null
if (null == product) {
// Iterate over all
for (final AddableBasketItem item : this.allItems()) {
// Debug message
- this.getLogger().logDebug(MessageFormat.format("getItemAmount: item={0}", item));
+ //this.getLogger().logDebug(MessageFormat.format("getItemAmount: item={0}", item));
// Is this product instance and same?
if (null == item) {
// item is null
throw new NullPointerException("item is null");
- } else if ((item.isProductType()) && (item.getProduct().equals(product))) {
+ } else if ((item.isProductType()) && (item.getItemProduct().equals(product))) {
// Found it
- itemAmount = item.getAmount();
+ itemAmount = item.getOrderedAmount();
break;
}
}
// Trace message
- this.getLogger().logTrace(MessageFormat.format("getItemAmount: itemAmount={0} - EXIT!", itemAmount));
-
+ //this.getLogger().logTrace(MessageFormat.format("getItemAmount: itemAmount={0} - EXIT!", itemAmount));
// Return it
return itemAmount;
}
return (!this.isEmpty());
}
- @PostConstruct
- public void init () {
- // Call generic init first
- super.genericInit();
- }
-
@Override
public boolean isEmpty () {
// Deligate to basket instance
@Override
public boolean isProductAdded (final Product product) {
// Trace message
- this.getLogger().logTrace(MessageFormat.format("isProductAdded: product={0} - EXIT!", product));
+ //this.getLogger().logTrace(MessageFormat.format("isProductAdded: product={0} - EXIT!", product));
// Must not be null
if (null == product) {
AddableBasketItem fake = new BasketItem(product);
// Debug message
- this.getLogger().logDebug(MessageFormat.format("isProductAdded: fake={0}", fake));
-
+ //this.getLogger().logDebug(MessageFormat.format("isProductAdded: fake={0}", fake));
// Ask bean about it
boolean isAdded = this.basket.isAdded(fake);
// Debug message
- this.getLogger().logDebug(MessageFormat.format("isProductAdded: isAdded={0}", isAdded));
-
+ //this.getLogger().logDebug(MessageFormat.format("isProductAdded: isAdded={0}", isAdded));
// Is it added?
if (isAdded) {
// Get item
AddableBasketItem item = this.getItemFromProduct(product);
// Debug message
- this.getLogger().logDebug(MessageFormat.format("isProductAdded: item={0} - setting as current item.", item));
-
+ //this.getLogger().logDebug(MessageFormat.format("isProductAdded: item={0} - setting as current item.", item));
// Set this as current item
this.setCurrentItem(item);
}
// Trace message
- this.getLogger().logTrace(MessageFormat.format("isProductAdded: isAdded={0} - EXIT!", isAdded));
-
+ //this.getLogger().logTrace(MessageFormat.format("isProductAdded: isAdded={0} - EXIT!", isAdded));
// Return status
return isAdded;
}
@Override
public String outputLastAddedItem () {
// Trace message
- this.getLogger().logTrace("outputLastAddedItem: CALLED!");
+ //this.getLogger().logTrace("outputLastAddedItem: CALLED!");
// Default message
String lastItem = ""; //NOI18N
// Get type
switch (item.getItemType()) {
case "product": // Sellable product //NOI18N
- assert (item.getProduct() instanceof Product) : MessageFormat.format("item {0} has no product instance set.", item); //NOI18N
+ assert (item.getItemProduct() instanceof Product) : MessageFormat.format("item {0} has no product instance set.", item); //NOI18N
// Get title
- lastItem = item.getProduct().getTitle();
+ lastItem = item.getItemProduct().getProductTitle();
break;
default: // Not supported
}
// Trace message
- this.getLogger().logTrace(MessageFormat.format("outputLastAddedItem: lastItem={0} - EXIT!", lastItem));
-
+ //this.getLogger().logTrace(MessageFormat.format("outputLastAddedItem: lastItem={0} - EXIT!", lastItem));
// Return it
return lastItem;
}
/**
* Getter for basket bean instance
- *
+ * <p>
* @return Basket bean instance
*/
private BasketSessionBeanRemote getBasketBean () {
* Somewhat getter for an item instance from given product instance. This
* method returns null if no item was found to given product. The product is
* found by checking it's id and itemType=product
- *
+ * <p>
* @param product Product instance
+ * <p>
* @return Item instance or null if not found
*/
private AddableBasketItem getItemFromProduct (final Product product) {
// Trace message
- this.getLogger().logTrace(MessageFormat.format("getItemFromProduct: product={0} - CALLED!", product));
+ //this.getLogger().logTrace(MessageFormat.format("getItemFromProduct: product={0} - CALLED!", product));
// Product must not be null
if (null == product) {
AddableBasketItem fake = new BasketItem(product);
// Debug message
- this.getLogger().logDebug(MessageFormat.format("getItemFromProduct: fake={0}", fake));
-
+ //this.getLogger().logDebug(MessageFormat.format("getItemFromProduct: fake={0}", fake));
// Get all items
List<AddableBasketItem> list = this.basket.getAll();
// Debug message
- this.getLogger().logDebug(MessageFormat.format("getItemFromProduct: list={0}", list));
-
+ //this.getLogger().logDebug(MessageFormat.format("getItemFromProduct: list={0}", list));
// Check all entries
for (final AddableBasketItem item : list) {
// Debug message
- this.getLogger().logDebug(MessageFormat.format("getItemFromProduct: item={0}", item));
+ //this.getLogger().logDebug(MessageFormat.format("getItemFromProduct: item={0}", item));
// item must not be null
if (null == item) {
}
// Trace message
- this.getLogger().logTrace(MessageFormat.format("getItemFromProduct: foundItem={0} - EXIT!", foundItem));
-
+ //this.getLogger().logTrace(MessageFormat.format("getItemFromProduct: foundItem={0} - EXIT!", foundItem));
// Return it
return foundItem;
}