BaseContact.gender.female.text=Frau
BaseContact.gender.company.text=Firma
MiniBasketTag.basket_is_empty=Der Warenkorb ist leer.
+MiniBasketTag.last_item=Zuletzt hinzugefügt: {0}
+MiniBasketTag.additional_items=Es befinden sich noch {0} weitere Produkte im Warenkorb.
+MiniBasketTag.to_basket=Zum Warenkorb
BaseContact.gender.female.text=Mrs.
BaseContact.gender.company.text=Company
MiniBasketTag.basket_is_empty=Der Warenkorb ist leer.
+MiniBasketTag.last_item=Zuletzt hinzugefügt: {0}
+MiniBasketTag.additional_items=Es befinden sich noch {0} weitere Produkte im Warenkorb.
+MiniBasketTag.to_basket=Zum Warenkorb
import org.mxchange.pizzaapplication.category.Category;
import org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException;
import org.mxchange.pizzaapplication.exceptions.ProductTitleAlreadyUsedException;
+import org.mxchange.pizzaapplication.item.AddableBasketItem;
import org.mxchange.pizzaapplication.product.Product;
/**
* @throws ServletException If something unexpected happened
*/
public void doAdminHandleCategoryForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException;
+
+ /**
+ * Some "getter" for a Product instance from given item
+ * @param item Item instance
+ * @return A Product instance
+ * @throws ServletException If something unexpected happened
+ */
+ public Product getProduct (final AddableBasketItem item) throws ServletException;
}
import org.mxchange.pizzaapplication.database.frontend.product.ProductFrontend;
import org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException;
import org.mxchange.pizzaapplication.exceptions.ProductTitleAlreadyUsedException;
+import org.mxchange.pizzaapplication.item.AddableBasketItem;
import org.mxchange.pizzaapplication.product.Product;
/**
// Return it
return isUsed;
}
+
+ @Override
+ public Product getProduct (final AddableBasketItem item) throws ServletException {
+ // Trace message
+ this.getLogger().trace("item=" + item + " - CALLED!");
+
+ // item should not be null
+ if (null == item) {
+ // Abort here
+ throw new NullPointerException("item is null");
+ } else if (null == this.productFrontend) {
+ // Abort here
+ throw new NullPointerException("productFrontend is null");
+ }
+
+ // Init product instance
+ Product product = null;
+
+ try {
+ // Call frontend
+ product = this.productFrontend.getProduct(item);
+ } catch (final SQLException | IOException | BadTokenException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
+ // Continue to throw
+ throw new ServletException(ex);
+ }
+
+ // Trace message
+ this.getLogger().trace("product=" + product + " - EXIT!");
+
+ // Return it
+ return product;
+ }
}
import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
import java.text.MessageFormat;
+import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import org.mxchange.jcore.exceptions.BadTokenException;
// Return it
return isAdded;
}
+
+ @Override
+ public Map<Long, T> getAll () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+ // Trace message
+ this.getLogger().trace("CALLED!");
+
+ // Init map
+ @SuppressWarnings("unchecked")
+ Map<Long, T> map = (Map<Long, T>) ((BasketFrontend) this.getFrontend()).getAll();
+
+ // Trace message
+ this.getLogger().trace("map=" + map);
+
+ // Return it
+ return map;
+ }
+
+ @Override
+ public AddableBasketItem getLast () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+ // Deligate to frontend
+ return ((BasketFrontend) this.getFrontend()).getLast();
+ }
+
+ @Override
+ public int getLastNumRows () {
+ // Deligate to frontend
+ return this.getFrontend().getLastNumRows();
+ }
}
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
+import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import org.mxchange.jcore.FrameworkInterface;
* @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
*/
public void init (final ServletContext context, final HttpSession session) throws UnsupportedDatabaseBackendException, SQLException, IOException, BadTokenException;
+
+ /**
+ * Some "getter" for all entries in this basket
+ *
+ * @return Map on all basket items
+ * @throws java.io.IOException If an IO error occurs
+ * @throws java.sql.SQLException If an SQL error occurs
+ * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+ * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If a corrupted database file was found
+ * @throws java.lang.NoSuchMethodException If a method was not found
+ * @throws java.lang.IllegalAccessException If the invoked method is not public
+ * @throws java.lang.reflect.InvocationTargetException If anything else happened?
+ */
+ public Map<Long, T> getAll () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
+
+ /**
+ * Getter for last entry
+ *
+ * @return Last added item in basket
+ * @throws java.io.IOException If an IO error occurs
+ * @throws java.sql.SQLException If an SQL error occurs
+ * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+ * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If a corrupted database file was found
+ * @throws java.lang.NoSuchMethodException If a method was not found
+ * @throws java.lang.IllegalAccessException If the invoked method is not public
+ * @throws java.lang.reflect.InvocationTargetException If anything else happened?
+ */
+ public AddableBasketItem getLast () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
+
+ /**
+ * Getter for last num rows
+ *
+ * @return Last num rows
+ */
+ public int getLastNumRows ();
}
import org.mxchange.pizzaapplication.category.Category;
import org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException;
import org.mxchange.pizzaapplication.exceptions.ProductTitleAlreadyUsedException;
+import org.mxchange.pizzaapplication.item.AddableBasketItem;
import org.mxchange.pizzaapplication.product.Product;
/**
* @param application the application to set
*/
public void setApplication (final ServletContext application);
+
+ /**
+ * Some "getter" for a product from given item
+ * @param item Item instance
+ * @return A Product instance
+ * @throws javax.servlet.ServletException If something bad happens
+ */
+ public Product getProduct (final AddableBasketItem item) throws ServletException;
}
import org.mxchange.pizzaapplication.category.Category;
import org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException;
import org.mxchange.pizzaapplication.exceptions.ProductTitleAlreadyUsedException;
+import org.mxchange.pizzaapplication.item.AddableBasketItem;
import org.mxchange.pizzaapplication.product.Product;
/**
@Override
public BasketBean getBasket () {
// Trace message
- this.getLogger().trace("basked=" + this.basket + " - EXIT!");
+ this.getLogger().trace("basket=" + this.basket + " - EXIT!");
// Return it
return this.basket;
@Override
public void setBasket (final BasketBean basket) {
// Trace message
- this.getLogger().trace("basked=" + basket + " - CALLED!");
+ this.getLogger().trace("basket=" + basket + " - CALLED!");
// Set it here
this.basket = basket;
// Set it here
this.application = application;
}
+
+ @Override
+ public Product getProduct (final AddableBasketItem item) throws ServletException {
+ // Deligate to application
+ return this.app.getProduct(item);
+ }
}
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
+import java.util.Map;
import javax.faces.FacesException;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
* @param session the session to set
*/
public void setSession (final HttpSession session);
+
+ /**
+ * Some "getter" for all entries in this basket
+ *
+ * @return Map on all basket items
+ * @throws java.io.IOException If an IO error occurs
+ * @throws java.sql.SQLException If an SQL error occurs
+ * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+ * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If a corrupted database file was found
+ * @throws java.lang.NoSuchMethodException If a method was not found
+ * @throws java.lang.IllegalAccessException If the invoked method is not public
+ * @throws java.lang.reflect.InvocationTargetException If anything else happened?
+ */
+ public Map<Long, AddableBasketItem> getAll () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
+
+ /**
+ * Getter for last entry
+ *
+ * @return Last added item in basket
+ * @throws java.io.IOException If an IO error occurs
+ * @throws java.sql.SQLException If an SQL error occurs
+ * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+ * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If a corrupted database file was found
+ * @throws java.lang.NoSuchMethodException If a method was not found
+ * @throws java.lang.IllegalAccessException If the invoked method is not public
+ * @throws java.lang.reflect.InvocationTargetException If anything else happened?
+ */
+ public AddableBasketItem getLast () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
+
+ /**
+ * Getter for last num rows
+ *
+ * @return Last num rows
+ */
+ public int getLastNumRows ();
}
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
+import java.util.Map;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.faces.FacesException;
public void setSession (final HttpSession session) {
this.session = session;
}
+
+ @Override
+ public Map<Long, AddableBasketItem> getAll () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+ // Deligate to basket instance
+ return this.basket.getAll();
+ }
+
+ @Override
+ public AddableBasketItem getLast () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+ // Deligate to basket instance
+ return this.basket.getLast();
+ }
+
+ @Override
+ public int getLastNumRows () {
+ // Delegate to basket
+ return this.basket.getLastNumRows();
+ }
}
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.Set;
import org.mxchange.jcore.criteria.logical.and.AndLogicalMatcher;
import org.mxchange.jcore.criteria.searchable.SearchCriteria;
import org.mxchange.jcore.criteria.searchable.SearchableCriteria;
// Return it
return result;
}
+
+ @Override
+ public Map<Long, AddableBasketItem> getAll () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+ // Trace message
+ this.getLogger().trace("CALLED!");
+
+ // Session should be set here
+ if (this.getSessionId() == null) {
+ // Abort here
+ throw new NullPointerException("sessionId is null");
+ }
+
+ // Init seaerch instance
+ SearchableCriteria criteria = new SearchCriteria();
+
+ // Add only session id
+ criteria.addCriteria(BasketDatabaseConstants.COLUMN_SESSION_ID, this.getSessionId());
+
+ // Now run it on backend
+ Result<? extends Storeable> result = this.getBackend().doSelectByCriteria(criteria);
+
+ // Now convert it to a map
+ Set<? extends Storeable> set = result.resultSet();
+
+ // Debug message
+ this.getLogger().debug("set=" + set);
+
+ // Init map
+ Map<Long, AddableBasketItem> map = new LinkedHashMap<>(set.size());
+
+ // Add all entries
+ for (final Storeable storeable : set) {
+ // Debug message
+ this.getLogger().debug("storeable=" + storeable);
+
+ // Check on AddableBasketItem
+ if (!(storeable instanceof AddableBasketItem)) {
+ // Not correct instance
+ throw new IllegalStateException("storeable=" + storeable + " does not implement AddableBasketItem.");
+ }
+
+ // Get id
+ Long id = ((AddableBasketItem) storeable).getItemId();
+
+ // Debug message
+ this.getLogger().debug("id=" + id);
+
+ // Add it
+ map.put(id, (AddableBasketItem) storeable);
+ }
+
+ // Trace message
+ this.getLogger().trace("map=" + map + " - EXIT!");
+
+ // Return it
+ return map;
+ }
+
+ @Override
+ public AddableBasketItem getLast () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+ // Trace message
+ this.getLogger().trace("CALLED!");
+
+ // Session should be set here
+ if (this.getSessionId() == null) {
+ // Abort here
+ throw new NullPointerException("sessionId is null");
+ }
+
+ // Init seaerch instance
+ SearchableCriteria criteria = new SearchCriteria();
+
+ // Add only session id
+ criteria.addCriteria(BasketDatabaseConstants.COLUMN_SESSION_ID, this.getSessionId());
+
+ // Get number of rows
+ int rows = this.getBackend().numRows(criteria);
+
+ // Debug message
+ this.getLogger().debug("rows=" + rows);
+
+ // Nothing found?
+ if (rows == 0) {
+ // Debug message
+ this.getLogger().debug("Nothing found, returning null ... - EXIT!");
+
+ // Return null
+ return null;
+ }
+
+ // Debug message
+ this.getLogger().debug("rows=" + rows);
+
+ // Set last num rows
+ this.setLastNumRows(rows);
+
+ // Now set this -1 as skip value and limit to 1
+ criteria.setSkip(rows);
+ criteria.setLimit(1);
+
+ // And run it ...
+ Result<? extends Storeable> result = this.getBackend().doSelectByCriteria(criteria);
+
+ // Debug message
+ this.getLogger().debug("result=" + result);
+
+ // Init instance
+ AddableBasketItem item;
+
+ // There should be something!
+ if (!result.hasNext()) {
+ // Something isn't working here ...
+ throw new IllegalStateException("result has zero entries, but rows=" + rows);
+ }
+
+ // Get next element
+ Storeable storeable = result.next();
+
+ // Is it still castable?
+ if (!(storeable instanceof AddableBasketItem)) {
+ // Opps!
+ throw new IllegalStateException("storeable=" + storeable + " does not implement AddableBasketItem.");
+ }
+
+ // Cast it
+ item = (AddableBasketItem) storeable;
+
+ // Trace message
+ this.getLogger().trace("item=" + item + " - EXIT!");
+
+ // Return it
+ return item;
+ }
}
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
+import java.util.Map;
import org.mxchange.jcore.database.frontend.DatabaseFrontend;
import org.mxchange.jcore.exceptions.BadTokenException;
import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
* @throws java.lang.reflect.InvocationTargetException If anything else happened?
*/
public boolean isItemAdded (final AddableBasketItem item, final String sessionId) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
+
+ /**
+ * Some "getter" for all entries in this basket
+ *
+ * @return Map on all basket items
+ * @throws java.io.IOException If an IO error occurs
+ * @throws java.sql.SQLException If an SQL error occurs
+ * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+ * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If a corrupted database file was found
+ * @throws java.lang.NoSuchMethodException If a method was not found
+ * @throws java.lang.IllegalAccessException If the invoked method is not public
+ * @throws java.lang.reflect.InvocationTargetException If anything else happened?
+ */
+ public Map<Long, AddableBasketItem> getAll () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
+
+ /**
+ * Getter for last entry
+ *
+ * @return Last added item in basket
+ * @throws java.io.IOException If an IO error occurs
+ * @throws java.sql.SQLException If an SQL error occurs
+ * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+ * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If a corrupted database file was found
+ * @throws java.lang.NoSuchMethodException If a method was not found
+ * @throws java.lang.IllegalAccessException If the invoked method is not public
+ * @throws java.lang.reflect.InvocationTargetException If anything else happened?
+ */
+ public AddableBasketItem getLast () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
}
import org.mxchange.jcore.exceptions.BadTokenException;
import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
+import org.mxchange.pizzaapplication.item.AddableBasketItem;
import org.mxchange.pizzaapplication.product.Product;
import org.mxchange.pizzaapplication.product.pizza.PizzaProduct;
/**
* Default constrcutor
- * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the configured backend is not supported
+ *
+ * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException
+ * If the configured backend is not supported
* @throws java.sql.SQLException If any SQL error occurs
*/
public PizzaProductDatabaseFrontend () throws UnsupportedDatabaseBackendException, SQLException {
/**
* Adds product to database by given title, price and category id
+ *
* @param title Product title
* @param price Product price
* @param category Product category id
public void addProduct (final String title, final Float price, final Long category, final Boolean available) throws SQLException, IOException {
// Trace message
this.getLogger().trace(MessageFormat.format("title={0},price={1},category={2} - CALLED!", title, price, category)); //NOI18N
-
+
// Title should not be null
if (null == title) {
// Abort here
// Abort here
throw new NullPointerException("available is null"); //NOI18N
}
-
+
// Clear dataset from previous usage
this.clearDataSet();
-
+
// Add title and parent
this.addToDataSet(ProductFrontend.COLUMN_TITLE, title);
this.addToDataSet(ProductFrontend.COLUMN_PRICE, price);
this.addToDataSet(ProductFrontend.COLUMN_CATEGORY, category);
this.addToDataSet(ProductFrontend.COLUMN_AVAILABLE, available);
-
+
// Handle this over to the backend
// @todo Nothing is done yet!
Result<? extends Storeable> result = this.doInsertDataSet();
-
+
// Debug message
this.getLogger().debug(MessageFormat.format("result={0}", result)); //NOI18N
-
+
// Trace message
this.getLogger().trace("EXIT!"); //NOI18N
}
/**
* Shuts down the database layer
- *
+ *
* @throws java.sql.SQLException If an SQL error occurs
* @throws java.io.IOException If any IO error occurs
*/
*
* @return Iterator on all products
* @throws java.io.IOException If any IO error occurs
- * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found in a file-based database backend's file ... ;-)
+ * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token
+ * was found in a file-based database backend's file ... ;-)
* @throws java.sql.SQLException If any SQL errors occur
*/
@Override
- @SuppressWarnings ("unchecked")
+ @SuppressWarnings("unchecked")
public Iterator<Product> getAllProducts () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// Trace message
this.getLogger().trace("CALLED!"); //NOI18N
}
@Override
- @SuppressWarnings ("unchecked")
+ @SuppressWarnings("unchecked")
public Iterator<Product> getAvailableProducts () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// Trace message
this.getLogger().trace("CALLED!"); //NOI18N
// Add criteria
criteria.addCriteria(ProductFrontend.COLUMN_AVAILABLE, true);
-
+
// Run the query
Result<? extends Storeable> result = this.getBackend().doSelectByCriteria(criteria);
* @param title Product title
* @return Whether the product title is already used
* @throws java.io.IOException If any IO error occurs
- * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found in a file-based database backend's file ... ;-)
+ * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token
+ * was found in a file-based database backend's file ... ;-)
* @throws java.sql.SQLException If any SQL errors occur
*/
@Override
public boolean isProductTitleUsed (String title) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// Trace message
this.getLogger().trace(MessageFormat.format("title={0} - CALLED!", title)); //NOI18N
-
+
// Get search criteria
SearchableCriteria criteria = new SearchCriteria();
-
+
// Add criteria
criteria.addCriteria(ProductFrontend.COLUMN_TITLE, title);
-
+
// Only one entry is find
criteria.setLimit(1);
-
+
// Run it on backend
Result<? extends Storeable> result = this.getBackend().doSelectByCriteria(criteria);
-
+
// Debug log
this.getLogger().debug(MessageFormat.format("result({0}={1}", result, result.size())); //NOI18N
-
+
// Now check size of the result
boolean isFound = (result.size() == 1);
-
+
// Trace message
this.getLogger().trace(MessageFormat.format("isFound={0} - EXIT!", isFound)); //NOI18N
-
+
// Return it
return isFound;
}
/**
- * Converts the given map into a Storeable instance, depending on which class implements it. All
- * keys are being interpreted as class fields/attributes and their respective setters are being searched for. As
- * this method may fail to find one or access it, this method throws some exception.
+ * Converts the given map into a Storeable instance, depending on which
+ * class implements it. All keys are being interpreted as class
+ * fields/attributes and their respective setters are being searched for. As
+ * this method may fail to find one or access it, this method throws some
+ * exception.
*
* @param map Map instance to convert to Storeable
* @return An instance of a Storeable implementation
// Return it
return instance;
}
+
+ @Override
+ public Product getProduct (final AddableBasketItem item) throws SQLException, IOException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ // Trace message
+ this.getLogger().trace("item=" + item + " - CALLED!");
+
+ // item should not be null
+ if (null == item) {
+ // Abort here
+ throw new NullPointerException("item is null");
+ }
+
+ // Get search criteria
+ SearchableCriteria criteria = new SearchCriteria();
+
+ // Add criteria
+ criteria.addCriteria(ProductFrontend.COLUMN_ITEM_ID, item.getItemId());
+
+ // Only one entry is find
+ criteria.setLimit(1);
+
+ // Run it on backend
+ Result<? extends Storeable> result = this.getBackend().doSelectByCriteria(criteria);
+
+ // Debug log
+ this.getLogger().debug(MessageFormat.format("result({0}={1}", result, result.size())); //NOI18N
+
+ // Init product instance
+ Product product = null;
+
+ // Is there one entry?
+ if (result.hasNext()) {
+ // Get item
+ Storeable storeable = result.next();
+
+ // Is it Product?
+ if (!(storeable instanceof Product)) {
+ // Cannot cast!
+ throw new IllegalStateException("storeable=" + storeable + " does not implement Product.");
+ }
+
+ // Cast it
+ product = (Product) storeable;
+ }
+
+ // Trace message
+ this.getLogger().trace("product=" + product + " - EXIT!");
+
+ // Return it
+ return product;
+ }
}
import org.mxchange.jcore.database.frontend.DatabaseFrontend;
import org.mxchange.jcore.exceptions.BadTokenException;
import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
+import org.mxchange.pizzaapplication.item.AddableBasketItem;
import org.mxchange.pizzaapplication.product.Product;
/**
* @throws java.lang.reflect.InvocationTargetException Any other problems?
*/
public boolean isProductTitleUsed (String title) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException;
+
+ /**
+ * Some "getter" for a Product instance from given item
+ *
+ * @param item Item instance
+ * @return A Product instance
+ * @throws java.io.IOException If any IO error occurs
+ * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found in a file-based database backend's file ... ;-)
+ * @throws java.sql.SQLException If any SQL errors occur
+ * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged
+ * @throws java.lang.NoSuchMethodException If a method was not found
+ * @throws java.lang.IllegalAccessException If the method cannot be accessed
+ * @throws java.lang.reflect.InvocationTargetException Any other problems?
+ */
+ public Product getProduct (final AddableBasketItem item) throws SQLException, IOException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException;
}
import javax.servlet.http.HttpSession;
import org.mxchange.jcore.exceptions.BadTokenException;
import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
-import org.mxchange.pizzaapplication.basket.Basket;
+import org.mxchange.pizzaapplication.beans.PizzaBean;
+import org.mxchange.pizzaapplication.beans.basket.BasketBean;
import org.mxchange.pizzaapplication.filter.servlet.BaseServletFilter;
import org.mxchange.pizzaapplication.item.AddableBasketItem;
this.getLogger().debug(MessageFormat.format("item.id={0},item.itemId={1},item.itemType={2},item.amount={3}", item.getId(), item.getItemId(), item.getItemType(), item.getAmount())); //NOI18N
// Init instance
- Basket<AddableBasketItem> basket;
+ BasketBean basket;
try {
// Get session instance
HttpSession session = ((HttpServletRequest) request).getSession();
throw new NullPointerException("session is null"); //NOI18N
}
+ // Get man controller
+ PizzaBean bean = (PizzaBean) session.getAttribute("controller"); //NOI18N
+
+ // Debug message
+ this.getLogger().debug("bean=" + bean);
+
// Get basket instance
- basket = (Basket<AddableBasketItem>) session.getAttribute("basket"); //NOI18N
+ basket = bean.getBasket();
+
+ // Debug message
+ this.getLogger().debug("basket=" + basket);
// Is the item already added?
if (item.getItemId() == null) {
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
+import java.text.MessageFormat;
+import javax.servlet.ServletException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mxchange.jcore.exceptions.BadTokenException;
import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
+import org.mxchange.pizzaapplication.beans.PizzaBean;
import org.mxchange.pizzaapplication.beans.basket.BasketBean;
+import org.mxchange.pizzaapplication.item.AddableBasketItem;
+import org.mxchange.pizzaapplication.product.Product;
/**
* A basket tag that outputs a small basket and a link to the full basket website.
// Some entries found?
if (this.getBasket().isEmpty()) {
// Empty basket
- out.append("<div class=\"mini_basket_info\">\n");
+ out.append("<div class=\"mini_basket_box\">\n");
out.append(this.getBasket().getMessageStringFromKey("MiniBasketTag.basket_is_empty")).append("\n");
out.append("</div>\n");
} else {
- // Some times were found
- out.append("FOUND!");
+ // Get all items
+ AddableBasketItem item = this.getBasket().getLast();
+
+ // item cannot be null here
+ if (null == item) {
+ // Abort here
+ throw new NullPointerException("item is null");
+ }
+
+ // Get application bean from session
+ PizzaBean bean = (PizzaBean) this.getBasket().getSession().getAttribute("controller");
+
+ // Debug log
+ this.LOG.debug("bean=" + bean);
+
+ // Should not be null
+ if (null == bean) {
+ // Abort here
+ throw new NullPointerException("bean is null");
+ }
+
+ // Get product instance
+ Product product = bean.getProduct(item);
+
+ // Debug message
+ this.LOG.debug("product=" + product);
+
+ // Get last num rows
+ int lastNumRows = this.getBasket().getLastNumRows();
+
+ // Debug message
+ this.LOG.debug("lastNumRows=" + lastNumRows);
+
+ // Output all
+ out.append("<div class=\"mini_basket_box\">\n");
+ out.append(" <div class=\"mini_basket_last\">\n");
+ out.append(" ").append(MessageFormat.format(this.getBasket().getMessageStringFromKey("MiniBasketTag.last_item"), product.getTitle()));
+ out.append(" </div>\n");
+ out.append(" <div class=\"mini_basket_more\">\n");
+ out.append(" ").append(MessageFormat.format(this.getBasket().getMessageStringFromKey("MiniBasketTag.additional_items"), (lastNumRows - 1)));
+ out.append(" </div>\n");
+ out.append(" <div class=\"mini_basket_link\">\n");
+ out.append(" <a href=\"").append(this.getBasket().getApplication().getContextPath()).append("/basket.jsp\">").append(this.getBasket().getMessageStringFromKey("MiniBasketTag.to_basket")).append("</a>\n");
+ out.append(" </div>\n");
+ out.append("</div>\n");
}
- } catch (final IOException | SQLException | BadTokenException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
+ } catch (final ServletException | IOException | SQLException | BadTokenException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
// Continue to throw
throw new JspException(ex);
}
@Override
public BasketBean getBasket () {
// Trace message
- this.LOG.trace("basket=" + this.basket + " - EXIT!");
+ //* NOISY-DEBUG: */ this.LOG.trace("basket=" + this.basket + " - EXIT!");
// Return it
return this.basket;
@Override
public void setBasket (final BasketBean basket) {
// Trace message
- this.LOG.trace("basked=" + basket + " - CALLED!");
+ //* NOISY-DEBUG: */ this.LOG.trace("basked=" + basket + " - CALLED!");
// Set it here
this.basket = basket;
<jsp:useBean id="controller" scope="session" class="org.mxchange.pizzaapplication.beans.PizzaServiceBean" type="org.mxchange.pizzaapplication.beans.PizzaBean" />
+<jsp:setProperty name="controller" property="application" value="${pageContext.servletContext}" />
+<jsp:setProperty name="controller" property="basket" value="${basket}" />
+<%controller.init();%>
+
<jsp:useBean id="item" scope="request" class="org.mxchange.pizzaapplication.item.basket.BasketItem" type="AddableBasketItem" />
<jsp:setProperty name="item" property="*" />