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.HttpSession;
23 import org.mxchange.jcore.application.Application;
24 import org.mxchange.pizzaapplication.category.Category;
25 import org.mxchange.pizzaapplication.product.Product;
29 * @author Roland Haeder
31 public interface PizzaApplication extends Application {
33 * HTTP parameter "amount"
35 public static final String HTTP_PARAM_AMOUNT = "amount"; //NOI18N
38 * HTTP parameter "choose"
40 public static final String HTTP_PARAM_CHOOSE = "choose"; //NOI18N
43 * Session key "ordered"
45 public static final String SESSION_ORDERED = "ordered"; //NOI18N
48 * Mask for all parameters
50 public static final String HTTP_PARAM_MASK = "%s[%s]"; //NOI18N
53 * Some "getter" for amount from session
55 * @param product Product instance
56 * @param session Session instance
57 * @return Amount as string
59 public String getAmountFromSession (final Product product, final HttpSession session);
62 * Some "getter" for choose from session
64 * @param product Product instance
65 * @param session Session instance
66 * @return Choose as string
68 public String getChooseFromSession (final Product product, final HttpSession session);
71 * Handler for amount from session
73 * @param product Product instance
74 * @param request Request instance
75 * @param session Session instance
76 * @return Amount as string
78 public String handleAmountFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session);
81 * Some "getter" for printable choosen (checkbox) from request or session
83 * @param product Product instance
84 * @param request Request instance
85 * @param session Session instance
86 * @return Amount as string
88 public String getPrintableChoosenFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session);
91 * Some "getter" for total price of position from request or session.
92 * Single price and amount is multiplyed.
94 * @param product Product instance
95 * @param request Request instance
96 * @param session Session instance
97 * @return Amount as string
99 public float getTotalPositionPriceFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session);
102 * Checks whether the given product is choosen, request overules session.
104 * @param product Product instance
105 * @param request Request instance
106 * @param session Session instance
107 * @return Whether the product is choosen
109 public boolean isProductChoosen (final Product product, final HttpServletRequest request, final HttpSession session);
112 * Calculates total price of all choosen products
114 * @param request Request instance
115 * @param session Session instance
116 * @return Total price of all choosen products
117 * @throws javax.servlet.ServletException If something unexpected happened
119 public float calculateTotalPrice (final HttpServletRequest request, final HttpSession session) throws ServletException;
122 * Calculates total amount of all choosen products
124 * @param request Request instance
125 * @param session Session instance
126 * @return Total amount of all choosen products
127 * @throws javax.servlet.ServletException If something unexpected happened
129 public int calculateTotalAmount (final HttpServletRequest request, final HttpSession session) throws ServletException;
132 * Some "getter" for HTML code 'checked="checked"' if the product is choosen
134 * @param product Product instance
135 * @param request Request instance
136 * @param session Session instance
137 * @return Whether the product is choosen
139 public String getCheckedHtmlFromProduct (final Product product, final HttpServletRequest request, final HttpSession session);
142 * Some "getter" for HTML code 'disabled="disabled"' for e.g. submit buttons
144 * @param request Request instance
145 * @param session Session instance
146 * @return Whether the product is choosen
147 * @throws javax.servlet.ServletException If something unexpected happened
149 public String getDisabledHtmlFromSession (final HttpServletRequest request, final HttpSession session) throws ServletException;
152 * Marks given product as ordered in session
154 * @param product Product to mark as ordered
155 * @param session Session instance
157 public void markProductAsOrdered(final Product product, final HttpSession session);
160 * Marks given product as choosen in session
162 * @param product Product to mark as ordered
163 * @param session Session instance
165 public void markProductAsChoosen(final Product product, final HttpSession session);
168 * Unmarks given product as ordered in session
170 * @param product Product to unmark as ordered
171 * @param session Session instance
173 public void unmarkProductAsOrdered(final Product product, final HttpSession session);
176 * Unmarks given product as choosen in session
178 * @param product Product to unmark as choosen
179 * @param session Session instance
181 public void unmarkProductAsChoosen(final Product product, final HttpSession session);
184 * Some getter for printable value from session or an empty string for null.
186 * @param session Session instance
187 * @param key Key to get
188 * @return Value from key, empty string for null
190 public Object getPrintableValeFromSession (final HttpSession session, final String key);
193 * Somewhat setter in session
195 * @param session Session instance
196 * @param key Session key to set
197 * @param value Value to set
199 public void setValueInSession (final HttpSession session, final String key, final Object value);
202 * Some "getter" for a an array of all products
204 * @return All products
205 * @throws javax.servlet.ServletException If anything went wrong
207 public Iterator<Product> getProducts () throws ServletException;
210 * Some "getter" for a an array of all categories
212 * @return All categories
213 * @throws javax.servlet.ServletException If anything went wrong
215 public Iterator<Category> getCategories () throws ServletException;
218 * Checks if given Product instance is available and returns a printable
219 * (human-readable) string.
221 * @param product Product instance to check
222 * @return Human-readable version of product availability
224 public String getPrintableProduktAvailability (final Product product);
227 * Marks all choosen products as ordered
229 * @param request Request instance
230 * @param session Session instance
231 * @throws javax.servlet.ServletException If something unexpected happened
233 public void markAllChoosenProductsAsOrdered (final HttpServletRequest request, final HttpSession session) throws ServletException;
236 * Adds given category data from request to database
238 * @param request Request instance
239 * @throws javax.servlet.ServletException If something unexpected happened
241 public void doAdminAddCategory (final HttpServletRequest request) throws ServletException;
244 * Adds given product data from request to database
246 * @param request Request instance
247 * @throws javax.servlet.ServletException If something unexpected happened
249 public void doAdminAddProduct (final HttpServletRequest request) throws ServletException;