2 * Copyright (C) 2015 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.pizzaapplication.application;
19 import org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException;
20 import java.util.Iterator;
21 import javax.servlet.ServletException;
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpSession;
24 import org.mxchange.jcore.application.Application;
25 import org.mxchange.pizzaapplication.category.Category;
26 import org.mxchange.pizzaapplication.product.Product;
30 * @author Roland Haeder
32 public interface PizzaApplication extends Application {
34 * HTTP parameter "amount"
36 public static final String HTTP_PARAM_AMOUNT = "amount"; //NOI18N
39 * HTTP parameter "choose"
41 public static final String HTTP_PARAM_CHOOSE = "choose"; //NOI18N
44 * Session key "ordered"
46 public static final String SESSION_ORDERED = "ordered"; //NOI18N
49 * Mask for all parameters
51 public static final String HTTP_PARAM_MASK = "%s[%s]"; //NOI18N
54 * Some "getter" for amount from session
56 * @param product Product instance
57 * @param session Session instance
58 * @return Amount as string
60 public String getAmountFromSession (final Product product, final HttpSession session);
63 * Some "getter" for choose from session
65 * @param product Product instance
66 * @param session Session instance
67 * @return Choose as string
69 public String getChooseFromSession (final Product product, final HttpSession session);
72 * Handler for amount from session
74 * @param product Product instance
75 * @param request Request instance
76 * @param session Session instance
77 * @return Amount as string
79 public String handleAmountFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session);
82 * Some "getter" for printable choosen (checkbox) from request or session
84 * @param product Product instance
85 * @param request Request instance
86 * @param session Session instance
87 * @return Amount as string
89 public String getPrintableChoosenFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session);
92 * Some "getter" for total price of position from request or session.
93 * Single price and amount is multiplyed.
95 * @param product Product instance
96 * @param request Request instance
97 * @param session Session instance
98 * @return Amount as string
100 public float getTotalPositionPriceFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session);
103 * Checks whether the given product is choosen, request overules session.
105 * @param product Product instance
106 * @param request Request instance
107 * @param session Session instance
108 * @return Whether the product is choosen
110 public boolean isProductChoosen (final Product product, final HttpServletRequest request, final HttpSession session);
113 * Calculates total price of all choosen products
115 * @param request Request instance
116 * @param session Session instance
117 * @return Total price of all choosen products
118 * @throws javax.servlet.ServletException If something unexpected happened
120 public float calculateTotalPrice (final HttpServletRequest request, final HttpSession session) throws ServletException;
123 * Calculates total amount of all choosen products
125 * @param request Request instance
126 * @param session Session instance
127 * @return Total amount of all choosen products
128 * @throws javax.servlet.ServletException If something unexpected happened
130 public int calculateTotalAmount (final HttpServletRequest request, final HttpSession session) throws ServletException;
133 * Some "getter" for HTML code 'checked="checked"' if the product is choosen
135 * @param product Product instance
136 * @param request Request instance
137 * @param session Session instance
138 * @return Whether the product is choosen
140 public String getCheckedHtmlFromProduct (final Product product, final HttpServletRequest request, final HttpSession session);
143 * Some "getter" for HTML code 'disabled="disabled"' for e.g. submit buttons
145 * @param request Request instance
146 * @param session Session instance
147 * @return Whether the product is choosen
148 * @throws javax.servlet.ServletException If something unexpected happened
150 public String getDisabledHtmlFromSession (final HttpServletRequest request, final HttpSession session) throws ServletException;
153 * Marks given product as ordered in session
155 * @param product Product to mark as ordered
156 * @param session Session instance
158 public void markProductAsOrdered(final Product product, final HttpSession session);
161 * Marks given product as choosen in session
163 * @param product Product to mark as ordered
164 * @param session Session instance
166 public void markProductAsChoosen(final Product product, final HttpSession session);
169 * Unmarks given product as ordered in session
171 * @param product Product to unmark as ordered
172 * @param session Session instance
174 public void unmarkProductAsOrdered(final Product product, final HttpSession session);
177 * Unmarks given product as choosen in session
179 * @param product Product to unmark as choosen
180 * @param session Session instance
182 public void unmarkProductAsChoosen(final Product product, final HttpSession session);
185 * Some getter for printable value from session or an empty string for null.
187 * @param session Session instance
188 * @param key Key to get
189 * @return Value from key, empty string for null
191 public Object getPrintableValeFromSession (final HttpSession session, final String key);
194 * Somewhat setter in session
196 * @param session Session instance
197 * @param key Session key to set
198 * @param value Value to set
200 public void setValueInSession (final HttpSession session, final String key, final Object value);
203 * Some "getter" for a an array of all products
205 * @return All products
206 * @throws javax.servlet.ServletException If anything went wrong
208 public Iterator<Product> getProducts () throws ServletException;
211 * Some "getter" for a an array of all categories
213 * @return All categories
214 * @throws javax.servlet.ServletException If anything went wrong
216 public Iterator<Category> getCategories () throws ServletException;
219 * Checks if given Product instance is available and returns a printable
220 * (human-readable) string.
222 * @param product Product instance to check
223 * @return Human-readable version of product availability
225 public String getPrintableProduktAvailability (final Product product);
228 * Marks all choosen products as ordered
230 * @param request Request instance
231 * @param session Session instance
232 * @throws javax.servlet.ServletException If something unexpected happened
234 public void markAllChoosenProductsAsOrdered (final HttpServletRequest request, final HttpSession session) throws ServletException;
237 * Adds given category data from request to database
239 * @param request Request instance
240 * @throws javax.servlet.ServletException If something unexpected happened
241 * @throws org.mxchange.pizzaapplication.application.CategoryTitleAlreadyUsedException If the given title is already used
243 public void doAdminAddCategory (final HttpServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException;
246 * Adds given product data from request to database
248 * @param request Request instance
249 * @throws javax.servlet.ServletException If something unexpected happened
251 public void doAdminAddProduct (final HttpServletRequest request) throws ServletException;
254 * Generates link HTML code for given category's parent id, if set. This
255 * link then points to products.jsp?category_id=x
257 * @param category Category instance
260 public String generateLinkForParent (final Category category);