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.util.Iterator;
20 import javax.servlet.ServletException;
21 import javax.servlet.http.HttpServletRequest;
22 import javax.servlet.http.HttpServletResponse;
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.exceptions.CategoryTitleAlreadyUsedException;
27 import org.mxchange.pizzaapplication.exceptions.ProductTitleAlreadyUsedException;
28 import org.mxchange.pizzaapplication.product.Product;
32 * @author Roland Haeder
34 public interface PizzaApplication extends Application {
36 * HTTP parameter "amount"
38 public static final String HTTP_PARAM_AMOUNT = "amount"; //NOI18N
41 * HTTP parameter "choose"
43 public static final String HTTP_PARAM_CHOOSE = "choose"; //NOI18N
46 * Session key "ordered"
48 public static final String SESSION_ORDERED = "ordered"; //NOI18N
51 * Mask for all parameters
53 public static final String HTTP_PARAM_MASK = "%s[%s]"; //NOI18N
56 * Some "getter" for amount from session
58 * @param product Product instance
59 * @param session Session instance
60 * @return Amount as string
62 public String getAmountFromSession (final Product product, final HttpSession session);
65 * Some "getter" for choose from session
67 * @param product Product instance
68 * @param session Session instance
69 * @return Choose as string
71 public String getChooseFromSession (final Product product, final HttpSession session);
74 * Handler for amount from session
76 * @param product Product instance
77 * @param request Request instance
78 * @param session Session instance
79 * @return Amount as string
81 public String handleAmountFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session);
84 * Some "getter" for printable choosen (checkbox) from request or session
86 * @param product Product instance
87 * @param request Request instance
88 * @param session Session instance
89 * @return Amount as string
91 public String getPrintableChoosenFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session);
94 * Some "getter" for total price of position from request or session.
95 * Single price and amount is multiplyed.
97 * @param product Product instance
98 * @param request Request instance
99 * @param session Session instance
100 * @return Amount as string
102 public float getTotalPositionPriceFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session);
105 * Checks whether the given product is choosen, request overules session.
107 * @param product Product instance
108 * @param request Request instance
109 * @param session Session instance
110 * @return Whether the product is choosen
112 public boolean isProductChoosen (final Product product, final HttpServletRequest request, final HttpSession session);
115 * Calculates total price of all choosen products
117 * @param request Request instance
118 * @param session Session instance
119 * @return Total price of all choosen products
120 * @throws javax.servlet.ServletException If something unexpected happened
122 public float calculateTotalPrice (final HttpServletRequest request, final HttpSession session) throws ServletException;
125 * Calculates total amount of all choosen products
127 * @param request Request instance
128 * @param session Session instance
129 * @return Total amount of all choosen products
130 * @throws javax.servlet.ServletException If something unexpected happened
132 public int calculateTotalAmount (final HttpServletRequest request, final HttpSession session) throws ServletException;
135 * Some "getter" for HTML code 'checked="checked"' if the product is choosen
137 * @param product Product instance
138 * @param request Request instance
139 * @param session Session instance
140 * @return Whether the product is choosen
142 public String getCheckedHtmlFromProduct (final Product product, final HttpServletRequest request, final HttpSession session);
145 * Some "getter" for HTML code 'disabled="disabled"' for e.g. submit buttons
147 * @param request Request instance
148 * @param session Session instance
149 * @return Whether the product is choosen
150 * @throws javax.servlet.ServletException If something unexpected happened
152 public String getDisabledHtmlFromSession (final HttpServletRequest request, final HttpSession session) throws ServletException;
155 * Marks given product as ordered in session
157 * @param product Product to mark as ordered
158 * @param session Session instance
160 public void markProductAsOrdered(final Product product, final HttpSession session);
163 * Marks given product as choosen in session
165 * @param product Product to mark as ordered
166 * @param session Session instance
168 public void markProductAsChoosen(final Product product, final HttpSession session);
171 * Unmarks given product as ordered in session
173 * @param product Product to unmark as ordered
174 * @param session Session instance
176 public void unmarkProductAsOrdered(final Product product, final HttpSession session);
179 * Unmarks given product as choosen in session
181 * @param product Product to unmark as choosen
182 * @param session Session instance
184 public void unmarkProductAsChoosen(final Product product, final HttpSession session);
187 * Some getter for printable value from session or an empty string for null.
189 * @param session Session instance
190 * @param key Key to get
191 * @return Value from key, empty string for null
193 public Object getPrintableValeFromSession (final HttpSession session, final String key);
196 * Somewhat setter in session
198 * @param session Session instance
199 * @param key Session key to set
200 * @param value Value to set
202 public void setValueInSession (final HttpSession session, final String key, final Object value);
205 * Some "getter" for a an array of only available products
207 * @return Only available products
208 * @throws javax.servlet.ServletException If anything went wrong
210 public Iterator<Product> getAvailableProducts () throws ServletException;
213 * Some "getter" for a an array of all products
215 * @return All products
216 * @throws javax.servlet.ServletException If anything went wrong
218 public Iterator<Product> getAllProducts () throws ServletException;
221 * Some "getter" for a an array of all categories
223 * @return All categories
224 * @throws javax.servlet.ServletException If anything went wrong
226 public Iterator<Category> getCategories () throws ServletException;
229 * Checks if given Product instance is available and returns a printable
230 * (human-readable) string.
232 * @param product Product instance to check
233 * @return Human-readable version of product availability
235 public String getPrintableProduktAvailability (final Product product);
238 * Returns a printable (human-readable) string of product's category
240 * @param product Product instance to check
241 * @return Human-readable version of product availability
242 * @throws javax.servlet.ServletException If something unexpected happened
244 public String getPrintableProduktCategory (final Product product) throws ServletException;
247 * Marks all choosen products as ordered
249 * @param request Request instance
250 * @param session Session instance
251 * @throws javax.servlet.ServletException If something unexpected happened
253 public void markAllChoosenProductsAsOrdered (final HttpServletRequest request, final HttpSession session) throws ServletException;
256 * Adds given category data from request to database
258 * @param request Request instance
259 * @throws javax.servlet.ServletException If something unexpected happened
260 * @throws org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException If the given title is already used
262 public void doAdminAddCategory (final HttpServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException;
265 * Adds given product data from request to database
267 * @param request Request instance
268 * @throws javax.servlet.ServletException If something unexpected happened
269 * @throws org.mxchange.pizzaapplication.exceptions.ProductTitleAlreadyUsedException If the given product title is already used
271 public void doAdminAddProduct (final HttpServletRequest request) throws ServletException, ProductTitleAlreadyUsedException;
274 * Generates link HTML code for given category's parent id, if set. This
275 * link then points to products.jsp?category_id=x
277 * @param category Category instance
280 public String generateLinkForParent (final Category category);
283 * Handles admin product form requests
285 * @param request Request instance
286 * @param response Response instance
287 * @throws ServletException If something unexpected happened
289 public void doAdminHandleProductForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException;
292 * Handles admin category form requests
294 * @param request Request instance
295 * @param response Response instance
296 * @throws ServletException If something unexpected happened
298 public void doAdminHandleCategoryForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException;