X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Fjava%2Forg%2Fmxchange%2Fpizzaapplication%2Fapplication%2FPizzaApplication.java;h=09993d40a28168e02561b2c89f63e799627d9fa8;hb=ad3a217eb62ab36fab7004786b42e44edc063171;hp=8d16f755bd0214d7a430f678c09754e74372f165;hpb=481fca14e3e4dd31d33a891c667c77653fbe81b9;p=pizzaservice-war.git diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java index 8d16f755..09993d40 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java @@ -16,11 +16,20 @@ */ package org.mxchange.pizzaapplication.application; +import java.io.IOException; +import java.sql.SQLException; import java.util.Iterator; -import java.util.Map; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.mxchange.jcore.application.Application; +import org.mxchange.jcore.exceptions.BadTokenException; +import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException; +import org.mxchange.pizzaapplication.category.Category; +import org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException; +import org.mxchange.pizzaapplication.exceptions.ProductTitleAlreadyUsedException; import org.mxchange.pizzaapplication.product.Product; /** @@ -31,29 +40,29 @@ public interface PizzaApplication extends Application { /** * HTTP parameter "amount" */ - public static final String HTTP_PARAM_AMOUNT = "amount"; + public static final String HTTP_PARAM_AMOUNT = "amount"; //NOI18N /** - * HTTP parameter "choose" + * HTTP parameter "id" */ - public static final String HTTP_PARAM_CHOOSE = "choose"; + public static final String HTTP_PARAM_ITEM_ID = "id"; //NOI18N /** - * Session key "ordered" + * HTTP parameter "type" */ - public static final String SESSION_ORDERED = "ordered"; + public static final String HTTP_PARAM_ITEM_TYPE = "type"; //NOI18N /** - * Mask for all parameters + * Session key "ordered" */ - public static final String HTTP_PARAM_MASK = "%s[%s]"; + public static final String SESSION_ORDERED = "ordered"; //NOI18N /** - * Getter for product iterator - * - * @return Iterator for all products + * Mask for all parameters + * @deprecated Please refacture! */ - public Iterator> getProductsIterator (); + @Deprecated + static final String HTTP_PARAM_MASK = "%s[%s]"; //NOI18N /** * Some "getter" for amount from session @@ -83,16 +92,6 @@ public interface PizzaApplication extends Application { */ public String handleAmountFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session); - /** - * Handler for choosen (checkbox) from request or session - * - * @param product Product instance - * @param request Request instance - * @param session Session instance - * @return Amount as string - */ - public String handleChooseFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session); - /** * Some "getter" for printable choosen (checkbox) from request or session * @@ -114,6 +113,17 @@ public interface PizzaApplication extends Application { */ public float getTotalPositionPriceFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session); + /** + * Initializes this instance with given ServletContext + * + * @param context Servlet context + * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the backend is unsupported + * @throws java.sql.SQLException If an SQL error occurs + * @throws java.io.IOException If an IO error occurs + * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found + */ + public void init (final ServletContext context) throws UnsupportedDatabaseBackendException, SQLException, IOException, BadTokenException; + /** * Checks whether the given product is choosen, request overules session. * @@ -130,8 +140,9 @@ public interface PizzaApplication extends Application { * @param request Request instance * @param session Session instance * @return Total price of all choosen products + * @throws javax.servlet.ServletException If something unexpected happened */ - public float calculateTotalPrice (final HttpServletRequest request, final HttpSession session); + public float calculateTotalPrice (final HttpServletRequest request, final HttpSession session) throws ServletException; /** * Calculates total amount of all choosen products @@ -139,8 +150,9 @@ public interface PizzaApplication extends Application { * @param request Request instance * @param session Session instance * @return Total amount of all choosen products + * @throws javax.servlet.ServletException If something unexpected happened */ - public int calculateTotalAmount (final HttpServletRequest request, final HttpSession session); + public int calculateTotalAmount (final HttpServletRequest request, final HttpSession session) throws ServletException; /** * Some "getter" for HTML code 'checked="checked"' if the product is choosen @@ -158,8 +170,9 @@ public interface PizzaApplication extends Application { * @param request Request instance * @param session Session instance * @return Whether the product is choosen + * @throws javax.servlet.ServletException If something unexpected happened */ - public String getDisabledHtmlFromSession (final HttpServletRequest request, final HttpSession session); + public String getDisabledHtmlFromSession (final HttpServletRequest request, final HttpSession session) throws ServletException; /** * Marks given product as ordered in session @@ -169,6 +182,14 @@ public interface PizzaApplication extends Application { */ public void markProductAsOrdered(final Product product, final HttpSession session); + /** + * Marks given product as choosen in session + * + * @param product Product to mark as ordered + * @param session Session instance + */ + public void markProductAsChoosen(final Product product, final HttpSession session); + /** * Unmarks given product as ordered in session * @@ -177,6 +198,14 @@ public interface PizzaApplication extends Application { */ public void unmarkProductAsOrdered(final Product product, final HttpSession session); + /** + * Unmarks given product as choosen in session + * + * @param product Product to unmark as choosen + * @param session Session instance + */ + public void unmarkProductAsChoosen(final Product product, final HttpSession session); + /** * Some getter for printable value from session or an empty string for null. * @@ -196,17 +225,98 @@ public interface PizzaApplication extends Application { public void setValueInSession (final HttpSession session, final String key, final Object value); /** - * Some "getter" for a an array of unmarked products + * Some "getter" for a an array of only available products * - * @param session HttpSession instance - * @return Unmarked products + * @return Only available products + * @throws javax.servlet.ServletException If anything went wrong */ - public Product[] getUnmarkedProducts (final HttpSession session); + public Iterator getAvailableProducts () throws ServletException; /** * Some "getter" for a an array of all products + * + * @return All products + * @throws javax.servlet.ServletException If anything went wrong + */ + public Iterator getAllProducts () throws ServletException; + + /** + * Some "getter" for a an array of all categories + * + * @return All categories + * @throws javax.servlet.ServletException If anything went wrong + */ + public Iterator getCategories () throws ServletException; + + /** + * Checks if given Product instance is available and returns a printable + * (human-readable) string. + * + * @param product Product instance to check + * @return Human-readable version of product availability + */ + public String getPrintableProduktAvailability (final Product product); + + /** + * Returns a printable (human-readable) string of product's category * - * @return Unmarked products + * @param product Product instance to check + * @return Human-readable version of product availability + * @throws javax.servlet.ServletException If something unexpected happened + */ + public String getPrintableProduktCategory (final Product product) throws ServletException; + + /** + * Marks all choosen products as ordered + * + * @param request Request instance + * @param session Session instance + * @throws javax.servlet.ServletException If something unexpected happened + */ + public void markAllChoosenProductsAsOrdered (final HttpServletRequest request, final HttpSession session) throws ServletException; + + /** + * Adds given category data from request to database + * + * @param request Request instance + * @throws javax.servlet.ServletException If something unexpected happened + * @throws org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException If the given title is already used + */ + public void doAdminAddCategory (final HttpServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException; + + /** + * Adds given product data from request to database + * + * @param request Request instance + * @throws javax.servlet.ServletException If something unexpected happened + * @throws org.mxchange.pizzaapplication.exceptions.ProductTitleAlreadyUsedException If the given product title is already used + */ + public void doAdminAddProduct (final HttpServletRequest request) throws ServletException, ProductTitleAlreadyUsedException; + + /** + * Generates link HTML code for given category's parent id, if set. This + * link then points to products.jsp?category_id=x + * + * @param category Category instance + * @return HTML code + */ + public String generateLinkForParent (final Category category); + + /** + * Handles admin product form requests + * + * @param request Request instance + * @param response Response instance + * @throws ServletException If something unexpected happened + */ + public void doAdminHandleProductForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException; + + /** + * Handles admin category form requests + * + * @param request Request instance + * @param response Response instance + * @throws ServletException If something unexpected happened */ - public Product[] getProducts (); + public void doAdminHandleCategoryForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException; }