import org.mxchange.jcore.exceptions.BadTokenException;
import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
+import org.mxchange.jshop.category.Category;
+import org.mxchange.jshop.database.frontend.category.CategoryDatabaseFrontend;
+import org.mxchange.jshop.database.frontend.category.CategoryFrontend;
+import org.mxchange.jshop.database.frontend.product.ProductDatabaseFrontend;
+import org.mxchange.jshop.database.frontend.product.ProductFrontend;
+import org.mxchange.jshop.exceptions.CategoryTitleAlreadyUsedException;
+import org.mxchange.jshop.exceptions.ProductTitleAlreadyUsedException;
+import org.mxchange.jshop.item.AddableBasketItem;
+import org.mxchange.jshop.product.Product;
import org.mxchange.pizzaapplication.BasePizzaServiceSystem;
-import org.mxchange.pizzaapplication.category.Category;
-import org.mxchange.pizzaapplication.database.frontend.category.CategoryFrontend;
-import org.mxchange.pizzaapplication.database.frontend.category.PizzaCategoryDatabaseFrontend;
-import org.mxchange.pizzaapplication.database.frontend.product.PizzaProductDatabaseFrontend;
-import org.mxchange.pizzaapplication.database.frontend.product.ProductFrontend;
-import org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException;
-import org.mxchange.pizzaapplication.exceptions.ProductTitleAlreadyUsedException;
-import org.mxchange.pizzaapplication.product.Product;
/**
* Main application class
* @param request Request instance
* @param session Session instance
* @return Total amount of all choosen products
+ * @deprecated Old lost
*/
- @Override
- public int calculateTotalAmount (final HttpServletRequest request, final HttpSession session) throws ServletException {
+ @Deprecated
+ private int calculateTotalAmount (final HttpServletRequest request, final HttpSession session) throws ServletException {
// Trace message
this.getLogger().trace(MessageFormat.format("request={0},session={1} - CALLED!", request, session)); //NOI18N
return totalAmount;
}
- /**
- * Calculates total price of all choosen products
- *
- * @param request Request instance
- * @param session Session instance
- * @return Total price of all choosen products
- */
- @Override
- public float calculateTotalPrice (final HttpServletRequest request, final HttpSession session) throws ServletException {
- // Trace message
- this.getLogger().trace(MessageFormat.format("request={0},session={1} - CALLED!", request, session)); //NOI18N
-
- // Is product and session set?
- if (null == request) {
- // Not set
- throw new NullPointerException("request is null"); //NOI18N
- } else if (null == session) {
- // Not set
- throw new NullPointerException("session is null"); //NOI18N
- }
-
- // Init total price
- float totalPrice = 0.00f;
-
- // Get iterator
- Iterator<Product> iterator = this.getAvailableProducts();
-
- // "Walk" over all products
- while (iterator.hasNext()) {
- // Get next product
- Product product = iterator.next();
-
- // Is this choosen?
- if (this.isProductChoosen(product, request, session)) {
- // Then add product's total price
- this.getLogger().debug(MessageFormat.format("Calling getTotalPositionPriceFromRequestSession({0},request,session) ...", product.getItemId())); //NOI18N
- totalPrice += this.getTotalPositionPriceFromRequestSession(product, request, session);
- }
- this.getLogger().debug(MessageFormat.format("product={0},totalPrice={1}", product.getItemId(), totalPrice)); //NOI18N
- }
-
- // Trace message
- this.getLogger().trace(MessageFormat.format(" totalPrice={0} - EXIT!", totalPrice)); //NOI18N
-
- // Return total price
- return totalPrice;
- }
-
@Override
public void doBootstrap () {
throw new UnsupportedOperationException("Not supported yet."); //NOI18N
* @param product Product instance
* @param session Session instance
* @return Amount as string
+ * @deprecated Old lost code
*/
- @Override
@Deprecated
- public String getAmountFromSession (final Product product, final HttpSession session) {
+ private String getAmountFromSession (final Product product, final HttpSession session) {
// Trace message
this.getLogger().trace(MessageFormat.format("product={0},session={1} - CALLED!", product, session)); //NOI18N
}
}
- /**
- * Some "getter" for choose from session
- *
- * @param product Product instance
- * @param session Session instance
- * @return Choose as string
- */
- @Override
- @Deprecated
- public String getChooseFromSession (final Product product, final HttpSession session) {
- // Trace message
- this.getLogger().trace(MessageFormat.format("product={0},session={1} - CALLED!", product, session)); //NOI18N
-
- // Is product and session set?
- if (null == product) {
- // Not set
- throw new NullPointerException("product is null"); //NOI18N
- } else if (null == session) {
- // Not set
- throw new NullPointerException("session is null"); //NOI18N
- }
-
- // Get attribute
- Object object = this.getValueFromSession(product, session, HTTP_PARAM_ITEM_ID);
-
- // Is the object null?
- if (null == object) {
- // Not found
- this.getLogger().debug(MessageFormat.format("Returning empty string for product={0} ...", product.getItemId())); //NOI18N
- return ""; //NOI18N
- }
-
- // Trace message
- this.getLogger().trace(MessageFormat.format("object={0} - CALLED!", object)); //NOI18N
-
- // Cast to string and return it
- return (String) object;
- }
-
/**
* Some "getter" for HTML code 'disabled="disabled"' for e.g. submit buttons
*
}
}
- /**
- * Some "getter" for choosen (checkbox) from session
- *
- * @param product Product instance
- * @param request Request instance
- * @param session Session instance
- * @return Amount as string
- */
- @Override
- @Deprecated
- public String getPrintableChoosenFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session) {
- // Trace message
- this.getLogger().trace(MessageFormat.format("product={0},request={1},session={2} - CALLED!", product, request, session)); //NOI18N
-
- // Is product and session set?
- if (null == product) {
- // Not set
- throw new NullPointerException("product is null"); //NOI18N
- } else if (null == request) {
- // Not set
- throw new NullPointerException("request is null"); //NOI18N
- } else if (null == session) {
- // Not set
- throw new NullPointerException("session is null"); //NOI18N
- }
-
- // Get element
- this.getLogger().debug(MessageFormat.format("Calling handleChooseFromRequestSession({0},{1},{2}) ...", product.getItemId(), request, session)); //NOI18N
- String choosen = this.handleChooseFromRequestSession(product, request, session);
- this.getLogger().debug(MessageFormat.format("product={0},choosen={1}", product.getItemId(), choosen)); //NOI18N
-
- // Must not be null
- assert(choosen instanceof String): "choosen is null"; //NOI18N
-
- // Is it empty?
- if (choosen.isEmpty()) {
- // Not choosen
- return "Nein";
- }
-
- // Get amount
- String amount = this.handleAmountFromRequestSession(product, request, session);
- this.getLogger().debug(MessageFormat.format("product={0},amount={1}", product.getItemId(), amount)); //NOI18N
-
- // Must not be null
- assert(amount instanceof String): "amount is null"; //NOI18N
-
- // Is it empty?
- if (amount.isEmpty() || "0".equals(amount)) { //NOI18N
- // Choosen, but no amount
- return "Nein";
- } else {
- // Is choosen
- return "Ja";
- }
- }
-
/**
* Checks if given Product instance is available and returns a printable
* (human-readable) string.
}
}
- /**
- * Some getter for printable value from session or an empty string for null.
- *
- * @param session Session instance
- * @param key Key to get
- * @return Value from key, empty string for null
- */
- @Override
- public Object getPrintableValeFromSession (final HttpSession session, final String key) {
- // Trace message
- this.getLogger().trace(MessageFormat.format("session={0},key={1} - CALLED", session, key)); //NOI18N
-
- // Are both parameter not null?
- if (null == session) {
- // Abort here
- throw new NullPointerException("session is null"); //NOI18N
- } else if (null == key) {
- // Abort here
- throw new NullPointerException("key is null"); //NOI18N
- }
-
- // Now get it
- Object value = this.getValueFromSession(session, key);
-
- // Debug message
- this.getLogger().debug(MessageFormat.format("value={0}", value)); //NOI18N
-
- // Trace message
- this.getLogger().trace(MessageFormat.format("Calling this.convertNullToEmpty({0}) ... - EXIT!", value)); //NOI18N
-
- // Return actual value
- return this.convertNullToEmpty(value);
- }
-
/**
* Some "getter" for a an array of only available products
*
* @return All categories
*/
@Override
- public Iterator<Category> getCategories () throws ServletException {
+ public Iterator<Category> getAllCategories () throws ServletException {
// Trace message
this.getLogger().trace("CALLED!");
try {
// Ask frontend for a list of categories
- return this.categoryFrontend.getCategories();
+ return this.categoryFrontend.getAllCategories();
} catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
throw new ServletException(ex);
}
}
- /**
- * Some "getter" for total price of position from request or session.
- * Single price and amount is multiplyed.
- *
- * @param product Product instance
- * @param request Request instance
- * @param session Session instance
- * @return Amount as string
- */
- @Override
- @Deprecated
- public float getTotalPositionPriceFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session) {
- // Trace message
- this.getLogger().trace(MessageFormat.format("product={0},request={1},session={2} - CALLED!", product, request, session)); //NOI18N
-
- // Is product and session set?
- if (null == product) {
- // Not set
- throw new NullPointerException("product is null"); //NOI18N
- } else if (null == request) {
- // Not set
- throw new NullPointerException("request is null"); //NOI18N
- } else if (null == session) {
- // Not set
- throw new NullPointerException("session is null"); //NOI18N
- }
-
- // Get choosen
- this.getLogger().debug(MessageFormat.format("Calling handleChooseFromRequestSession({0},{1},{2}) ...", product.getItemId(), request, session)); //NOI18N
- String choosen = this.handleChooseFromRequestSession(product, request, session);
- this.getLogger().debug(MessageFormat.format("product={0},choosen={1}", product.getItemId(), choosen)); //NOI18N
-
- // Must not be null
- assert(choosen instanceof String): "choosen is null"; //NOI18N
-
- // Is it set?
- if (choosen.isEmpty()) {
- // Is empty
- this.getLogger().debug(MessageFormat.format("product={0},choosen={1} - returning zero ...", product.getItemId(), choosen)); //NOI18N
- return 0.00f;
- }
-
- // Get amount
- String amount = this.handleAmountFromRequestSession(product, request, session);
- this.getLogger().debug(MessageFormat.format("product={0},amount={1}", product.getItemId(), amount)); //NOI18N
-
- // Must not be null
- assert(amount instanceof String): "amount is null"; //NOI18N
-
- // Is it empty?
- if (amount.isEmpty() || "0".equals(amount)) { //NOI18N
- // Is empty
- this.getLogger().debug(MessageFormat.format("product={0},amount={1} - returning zero ...", product.getItemId(), amount)); //NOI18N
- return 0.00f;
- }
-
- // Init variable
- Integer value = null;
-
- // Try it
- try {
- // Get amount as integer
- value = Integer.valueOf(amount);
- } catch (final NumberFormatException e) {
- // Bat input
- throw new IllegalArgumentException(e);
- }
-
- // Calculate price
- float price = (product.getPrice() * value);
-
- // Trace message
- this.getLogger().trace(MessageFormat.format("product={0},price={1} - EXIT!", product.getItemId(), price)); //NOI18N
-
- // Then multiply it with price
- return price;
- }
-
- /**
- * Handler for amount from request or session
- *
- * @param product Product instance
- * @param request Request instance
- * @param session Session instance
- * @return Amount as string
- */
- @Override
- @Deprecated
- public String handleAmountFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session) {
- // Trace message
- this.getLogger().trace(MessageFormat.format("product={0},request={1},session={2} - CALLED!", product, request, session)); //NOI18N
-
- // Is product and session set?
- if (null == product) {
- // Not set
- throw new NullPointerException("product is null"); //NOI18N
- } else if (null == request) {
- // Not set
- throw new NullPointerException("request is null"); //NOI18N
- } else if (null == session) {
- // Not set
- throw new NullPointerException("session is null"); //NOI18N
- }
-
- // Init variabke
- Object object;
-
- // Check request method
- if (!"POST".equals(request.getMethod())) { //NOI18N
- // Not POST, so get from session
- return this.getAmountFromSession(product, session);
- } else if (this.handleChooseFromRequestSession(product, request, session).isEmpty()) {
- // Not choosen
- this.clearSessionAttribute(product, session, HTTP_PARAM_AMOUNT);
- this.getLogger().debug(MessageFormat.format("Unsetting for product={0} in session, returning zero ...", product.getItemId())); //NOI18N
- return "0"; //NOI18N
- }
-
- // Get attribute from request
- object = request.getParameter(String.format(HTTP_PARAM_MASK, HTTP_PARAM_AMOUNT, product.getItemId()));
-
- // Is it set?
- if (object instanceof String) {
- // Try to parse it to integer
- try {
- Integer value = Integer.valueOf((String) object);
- } catch (final NumberFormatException ex) {
- // Not valid input
- this.getLogger().warn(ex);
- return "0"; //NOI18N
- }
-
- // Then set it in session
- this.setValueInSession(product, session, HTTP_PARAM_AMOUNT, object);
-
- // And return it
- return (String) object;
- }
-
- // Trace message
- this.getLogger().trace("Calling getAmountFromSession() ..."); //NOI18N
-
- // Get attribute from session
- return this.getAmountFromSession(product, session);
- }
-
/**
* Checks whether the given product is choosen, request overules session.
*
@Override
@Deprecated
public boolean isProductChoosen (final Product product, final HttpServletRequest request, final HttpSession session) {
- // Trace message
- this.getLogger().trace(MessageFormat.format("product={0},request={1},session={2} - CALLED!", product, request, session)); //NOI18N
-
- // Is product and session set?
- if (null == product) {
- // Not set
- throw new NullPointerException("product is null"); //NOI18N
- } else if (null == request) {
- // Not set
- throw new NullPointerException("request is null"); //NOI18N
- } else if (null == session) {
- // Not set
- throw new NullPointerException("session is null"); //NOI18N
- }
-
- // Get choosen
- this.getLogger().debug(MessageFormat.format("Calling handleChooseFromRequestSession({0},{1},{2}) ...", product.getItemId(), request, session)); //NOI18N
- String choosen = this.handleChooseFromRequestSession(product, request, session);
- this.getLogger().debug(MessageFormat.format("product={0},choosen={1}", product.getItemId(), choosen)); //NOI18N
-
- // Must not be null
- assert(choosen instanceof String): "choosen is null"; //NOI18N
-
- // Is it not choosen?
- if (choosen.isEmpty()) {
- // Not choosen
- return false;
- }
-
- // Get amount
- String amount = this.handleAmountFromRequestSession(product, request, session);
-
- // Must not be null
- assert(amount instanceof String): "amount is not set"; //NOI18N
-
- // Trace message
- this.getLogger().trace(MessageFormat.format("amount={0} - EXIT!", amount)); //NOI18N
-
- // Must not be empty and not 0
- return (!amount.isEmpty() && !"0".equals(amount)); //NOI18N
- }
-
- /**
- * Marks all choosen products as ordered
- *
- * @param request Request instance
- * @param session Session instance
- */
- @Override
- @Deprecated
- public void markAllChoosenProductsAsOrdered (final HttpServletRequest request, final HttpSession session) throws ServletException {
- // Trace message
- this.getLogger().trace(MessageFormat.format("request={0},session={1} - CALLED!", request, session)); //NOI18N
-
- // Init iterator
- Iterator<Product> iterator = this.getAvailableProducts();
-
- // "Walk" over all products
- while (iterator.hasNext()) {
- // Get next product
- Product product = iterator.next();
-
- // Debug message
- this.getLogger().debug(MessageFormat.format("product={0}", product)); //NOI18N
-
- // Is it choosen?
- if (this.isProductChoosen(product, request, session)) {
- // Mark product as ordered
- this.markProductAsOrdered(product, session);
- }
- }
-
- // Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
- }
-
- /**
- * Marks given product as choosen in session
- *
- * @param product Product to mark as ordered
- * @param session Session instance
- */
- @Override
- @Deprecated
- public void markProductAsChoosen (final Product product, final HttpSession session) {
- // Trace message
- this.getLogger().trace(MessageFormat.format("product={0},session={1} - CALLED!", product, session)); //NOI18N
-
- // Is product and session set?
- if (null == product) {
- // Not set
- throw new NullPointerException("product is null"); //NOI18N
- } else if (null == session) {
- // Not set
- throw new NullPointerException("session is null"); //NOI18N
- }
-
- // Mark it as ordered by setting flag
- this.getLogger().debug(MessageFormat.format("Marking product={0} as choosen.", product.getItemId())); //NOI18N
- this.setValueInSession(product, session, HTTP_PARAM_ITEM_ID, "1"); //NOI18N
-
- // Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
- }
-
- /**
- * Marks given product as ordered in session
- *
- * @param product Product to mark as ordered
- * @param session Session instance
- */
- @Override
- @Deprecated
- public void markProductAsOrdered (final Product product, final HttpSession session) {
- // Trace message
- this.getLogger().trace(MessageFormat.format("product={0},session={1} - CALLED!", product, session)); //NOI18N
-
- // Is product and session set?
- if (null == product) {
- // Not set
- throw new NullPointerException("product is null"); //NOI18N
- } else if (null == session) {
- // Not set
- throw new NullPointerException("session is null"); //NOI18N
- }
-
- // Mark it as ordered by setting flag
- this.getLogger().debug(MessageFormat.format("Marking product={0} as ordered.", product.getItemId())); //NOI18N
- this.setValueInSession(product, session, SESSION_ORDERED, "true"); //NOI18N
-
- // Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
+ throw new UnsupportedOperationException("This method is deprecated and shall not be called");
}
/**
this.getLogger().trace("EXIT!"); //NOI18N
}
- /**
- * Unmarks given product as choosen in session
- *
- * @param product Product to unmark as choosen
- * @param session Session instance
- */
- @Override
- @Deprecated
- public void unmarkProductAsChoosen (final Product product, final HttpSession session) {
- // Trace message
- this.getLogger().trace(MessageFormat.format("product={0},session={1} - CALLED!", product, session)); //NOI18N
-
- // Is product and session set?
- if (null == product) {
- // Not set
- throw new NullPointerException("product is null"); //NOI18N
- } else if (null == session) {
- // Not set
- throw new NullPointerException("session is null"); //NOI18N
- }
-
- // Mark it as ordered by setting flag
- this.getLogger().debug(MessageFormat.format("Unmarking product={0} as choosen.", product.getItemId())); //NOI18N
- this.clearSessionAttribute(product, session, HTTP_PARAM_ITEM_ID);
-
- // Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
- }
-
- /**
- * Unmarks given product as ordered in session
- *
- * @param product Product to unmark as ordered
- * @param session Session instance
- */
- @Override
- @Deprecated
- public void unmarkProductAsOrdered (final Product product, final HttpSession session) {
- // Trace message
- this.getLogger().trace(MessageFormat.format("product={0},session={1} - CALLED!", product, session)); //NOI18N
-
- // Is product and session set?
- if (null == product) {
- // Not set
- throw new NullPointerException("product is null"); //NOI18N
- } else if (null == session) {
- // Not set
- throw new NullPointerException("session is null"); //NOI18N
- }
-
- // Mark it as ordered by setting flag
- this.getLogger().debug(MessageFormat.format("Unmarking product={0} as ordered.", product.getItemId())); //NOI18N
- this.clearSessionAttribute(product, session, SESSION_ORDERED);
-
- // Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
- }
-
/**
* Clears given parameter for product in session
*
return value;
}
- /**
- * Handler for choosen (checkbox) from request or session
- *
- * @param product Product instance
- * @param request Request instance
- * @param session Session instance
- * @return Amount as string
- */
- private String handleChooseFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session) {
- // Trace message
- this.getLogger().trace(MessageFormat.format("product={0},request={1},session={2} - CALLED!", product, request, session)); //NOI18N
-
- // Is product and session set?
- if (null == product) {
- // Not set
- throw new NullPointerException("product is null"); //NOI18N
- } else if (null == request) {
- // Not set
- throw new NullPointerException("request is null"); //NOI18N
- } else if (null == session) {
- // Not set
- throw new NullPointerException("session is null"); //NOI18N
- }
-
- // Init variabke
- Object object;
-
- // Check request method
- if (!"POST".equals(request.getMethod())) { //NOI18N
- // Not POST, so get from session
- this.getLogger().trace(MessageFormat.format("Calling this.getChooseFromSession({0},{1}) ... - EXIT!", product.getItemId(), session)); //NOI18N
- return this.getChooseFromSession(product, session);
- } else if (this.isProductOrdered(product, session)) {
- // Product is ordered
- this.getLogger().trace(MessageFormat.format("Calling this.getChooseFromSession({0},{1}) ... - EXIT!", product.getItemId(), session)); //NOI18N
- return this.getChooseFromSession(product, session);
- } else if (!this.getChooseFromSession(product, session).isEmpty()) {
- // Found in session
- this.getLogger().trace(MessageFormat.format("Calling this.getChooseFromSession({0},{1}) ... - EXIT!", product.getItemId(), session)); //NOI18N
- return this.getChooseFromSession(product, session);
- }
-
- // Get reqzest element
- object = request.getParameter(String.format(HTTP_PARAM_MASK, HTTP_PARAM_ITEM_ID, product.getItemId()));
- this.getLogger().debug(MessageFormat.format("product={0},object={1}", product.getItemId(), object)); //NOI18N
-
- // Is it null?
- if (null == object) {
- // Unset session
- this.getLogger().debug(MessageFormat.format("Unsetting session for product={0} ...", product.getItemId())); //NOI18N
- this.clearSessionAttribute(product, session, HTTP_PARAM_ITEM_ID);
- this.clearSessionAttribute(product, session, HTTP_PARAM_AMOUNT);
-
- // Return empty string
- return ""; //NOI18N
- }
-
- // Then set it in session
- this.setValueInSession(product, session, HTTP_PARAM_ITEM_ID, object);
-
- // Cast to string and return it
- this.getLogger().debug(MessageFormat.format("product={0} - Returning {1} ...", product.getItemId(), object)); //NOI18N
- return (String) object;
- }
-
/**
* Initializes database frontends.
*/
this.getLogger().trace("CALLED!"); //NOI18N
// Product frontend
- this.productFrontend = new PizzaProductDatabaseFrontend();
+ this.productFrontend = new ProductDatabaseFrontend();
// Category frontend
- this.categoryFrontend = new PizzaCategoryDatabaseFrontend();
+ this.categoryFrontend = new CategoryDatabaseFrontend();
// Trace message
this.getLogger().trace("EXIT!"); //NOI18N
String title = null;
try {
// Now get title from it and return it
- title = category.decodedTitle();
+ title = category.getDecodedTitle();
} catch (final UnsupportedEncodingException ex) {
// Continue to throw as cause
throw new ServletException(ex);
// 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;
+ }
}