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 java.io.IOException;
20 import java.sql.SQLException;
21 import java.util.Iterator;
22 import javax.servlet.ServletContext;
23 import javax.servlet.ServletException;
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26 import javax.servlet.http.HttpSession;
27 import org.mxchange.jcore.application.Application;
28 import org.mxchange.jcore.exceptions.BadTokenException;
29 import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
30 import org.mxchange.pizzaapplication.category.Category;
31 import org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException;
32 import org.mxchange.pizzaapplication.exceptions.ProductTitleAlreadyUsedException;
33 import org.mxchange.pizzaapplication.product.Product;
37 * @author Roland Haeder
39 public interface PizzaApplication extends Application {
41 * HTTP parameter "amount"
43 public static final String HTTP_PARAM_AMOUNT = "amount"; //NOI18N
48 public static final String HTTP_PARAM_ITEM_ID = "id"; //NOI18N
51 * HTTP parameter "type"
53 public static final String HTTP_PARAM_ITEM_TYPE = "type"; //NOI18N
56 * Session key "ordered"
58 public static final String SESSION_ORDERED = "ordered"; //NOI18N
61 * Mask for all parameters
62 * @deprecated Please refacture!
65 static final String HTTP_PARAM_MASK = "%s[%s]"; //NOI18N
68 * Some "getter" for amount from session
70 * @param product Product instance
71 * @param session Session instance
72 * @return Amount as string
74 public String getAmountFromSession (final Product product, final HttpSession session);
77 * Some "getter" for choose from session
79 * @param product Product instance
80 * @param session Session instance
81 * @return Choose as string
83 public String getChooseFromSession (final Product product, final HttpSession session);
86 * Handler for amount from session
88 * @param product Product instance
89 * @param request Request instance
90 * @param session Session instance
91 * @return Amount as string
93 public String handleAmountFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session);
96 * Some "getter" for printable choosen (checkbox) from request or session
98 * @param product Product instance
99 * @param request Request instance
100 * @param session Session instance
101 * @return Amount as string
103 public String getPrintableChoosenFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session);
106 * Some "getter" for total price of position from request or session.
107 * Single price and amount is multiplyed.
109 * @param product Product instance
110 * @param request Request instance
111 * @param session Session instance
112 * @return Amount as string
114 public float getTotalPositionPriceFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session);
117 * Initializes this instance with given ServletContext
119 * @param context Servlet context
120 * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the backend is unsupported
121 * @throws java.sql.SQLException If an SQL error occurs
122 * @throws java.io.IOException If an IO error occurs
123 * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
125 public void init (final ServletContext context) throws UnsupportedDatabaseBackendException, SQLException, IOException, BadTokenException;
128 * Checks whether the given product is choosen, request overules session.
130 * @param product Product instance
131 * @param request Request instance
132 * @param session Session instance
133 * @return Whether the product is choosen
135 public boolean isProductChoosen (final Product product, final HttpServletRequest request, final HttpSession session);
138 * Calculates total price of all choosen products
140 * @param request Request instance
141 * @param session Session instance
142 * @return Total price of all choosen products
143 * @throws javax.servlet.ServletException If something unexpected happened
145 public float calculateTotalPrice (final HttpServletRequest request, final HttpSession session) throws ServletException;
148 * Calculates total amount of all choosen products
150 * @param request Request instance
151 * @param session Session instance
152 * @return Total amount of all choosen products
153 * @throws javax.servlet.ServletException If something unexpected happened
155 public int calculateTotalAmount (final HttpServletRequest request, final HttpSession session) throws ServletException;
158 * Some "getter" for HTML code 'checked="checked"' if the product is choosen
160 * @param product Product instance
161 * @param request Request instance
162 * @param session Session instance
163 * @return Whether the product is choosen
165 public String getCheckedHtmlFromProduct (final Product product, final HttpServletRequest request, final HttpSession session);
168 * Some "getter" for HTML code 'disabled="disabled"' for e.g. submit buttons
170 * @param request Request instance
171 * @param session Session instance
172 * @return Whether the product is choosen
173 * @throws javax.servlet.ServletException If something unexpected happened
175 public String getDisabledHtmlFromSession (final HttpServletRequest request, final HttpSession session) throws ServletException;
178 * Marks given product as ordered in session
180 * @param product Product to mark as ordered
181 * @param session Session instance
183 public void markProductAsOrdered(final Product product, final HttpSession session);
186 * Marks given product as choosen in session
188 * @param product Product to mark as ordered
189 * @param session Session instance
191 public void markProductAsChoosen(final Product product, final HttpSession session);
194 * Unmarks given product as ordered in session
196 * @param product Product to unmark as ordered
197 * @param session Session instance
199 public void unmarkProductAsOrdered(final Product product, final HttpSession session);
202 * Unmarks given product as choosen in session
204 * @param product Product to unmark as choosen
205 * @param session Session instance
207 public void unmarkProductAsChoosen(final Product product, final HttpSession session);
210 * Some getter for printable value from session or an empty string for null.
212 * @param session Session instance
213 * @param key Key to get
214 * @return Value from key, empty string for null
216 public Object getPrintableValeFromSession (final HttpSession session, final String key);
219 * Somewhat setter in session
221 * @param session Session instance
222 * @param key Session key to set
223 * @param value Value to set
225 public void setValueInSession (final HttpSession session, final String key, final Object value);
228 * Some "getter" for a an array of only available products
230 * @return Only available products
231 * @throws javax.servlet.ServletException If anything went wrong
233 public Iterator<Product> getAvailableProducts () throws ServletException;
236 * Some "getter" for a an array of all products
238 * @return All products
239 * @throws javax.servlet.ServletException If anything went wrong
241 public Iterator<Product> getAllProducts () throws ServletException;
244 * Some "getter" for a an array of all categories
246 * @return All categories
247 * @throws javax.servlet.ServletException If anything went wrong
249 public Iterator<Category> getCategories () throws ServletException;
252 * Checks if given Product instance is available and returns a printable
253 * (human-readable) string.
255 * @param product Product instance to check
256 * @return Human-readable version of product availability
258 public String getPrintableProduktAvailability (final Product product);
261 * Returns a printable (human-readable) string of product's category
263 * @param product Product instance to check
264 * @return Human-readable version of product availability
265 * @throws javax.servlet.ServletException If something unexpected happened
267 public String getPrintableProduktCategory (final Product product) throws ServletException;
270 * Marks all choosen products as ordered
272 * @param request Request instance
273 * @param session Session instance
274 * @throws javax.servlet.ServletException If something unexpected happened
276 public void markAllChoosenProductsAsOrdered (final HttpServletRequest request, final HttpSession session) throws ServletException;
279 * Adds given category data from request to database
281 * @param request Request instance
282 * @throws javax.servlet.ServletException If something unexpected happened
283 * @throws org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException If the given title is already used
285 public void doAdminAddCategory (final HttpServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException;
288 * Adds given product data from request to database
290 * @param request Request instance
291 * @throws javax.servlet.ServletException If something unexpected happened
292 * @throws org.mxchange.pizzaapplication.exceptions.ProductTitleAlreadyUsedException If the given product title is already used
294 public void doAdminAddProduct (final HttpServletRequest request) throws ServletException, ProductTitleAlreadyUsedException;
297 * Generates link HTML code for given category's parent id, if set. This
298 * link then points to products.jsp?category_id=x
300 * @param category Category instance
303 public String generateLinkForParent (final Category category);
306 * Handles admin product form requests
308 * @param request Request instance
309 * @param response Response instance
310 * @throws ServletException If something unexpected happened
312 public void doAdminHandleProductForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException;
315 * Handles admin category form requests
317 * @param request Request instance
318 * @param response Response instance
319 * @throws ServletException If something unexpected happened
321 public void doAdminHandleCategoryForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException;