]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java
Maybe an idea to get rid of the scriptlet in index.jsp? A bean for basket items?
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / application / PizzaApplication.java
1 /*
2  * Copyright (C) 2015 Roland Haeder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.pizzaapplication.application;
18
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.item.AddableBasketItem;
34 import org.mxchange.pizzaapplication.product.Product;
35
36 /**
37  *
38  * @author Roland Haeder
39  */
40 public interface PizzaApplication extends Application {
41         /**
42          * HTTP parameter "amount"
43          */
44         public static final String HTTP_PARAM_AMOUNT = "amount"; //NOI18N
45
46         /**
47          * HTTP parameter "item_id"
48          */
49         public static final String HTTP_PARAM_ITEM_ID = "itemId"; //NOI18N
50
51         /**
52          * HTTP parameter "type"
53          */
54         public static final String HTTP_PARAM_ITEM_TYPE = "itemType"; //NOI18N
55
56         /**
57          * Session key "ordered"
58          */
59         public static final String SESSION_ORDERED = "ordered"; //NOI18N
60
61         /**
62          * Mask for all parameters
63          * @deprecated Please refacture!
64          */
65         @Deprecated
66         static final String HTTP_PARAM_MASK = "%s[%s]"; //NOI18N
67
68         /**
69          * Some "getter" for amount from session
70          *
71          * @param product Product instance
72          * @param session Session instance
73          * @return Amount as string
74          * @deprecated Old code
75          */
76         @Deprecated
77         public String getAmountFromSession (final Product product, final HttpSession session);
78
79         /**
80          * Some "getter" for choose from session
81          *
82          * @param product Product instance
83          * @param session Session instance
84          * @return Choose as string
85          * @deprecated Old code
86          */
87         @Deprecated
88         public String getChooseFromSession (final Product product, final HttpSession session);
89
90         /**
91          * Handler for amount from session
92          *
93          * @param product Product instance
94          * @param request Request instance
95          * @param session Session instance
96          * @return Amount as string
97          * @deprecated Old code
98          */
99         @Deprecated
100         public String handleAmountFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session);
101
102         /**
103          * Some "getter" for printable choosen (checkbox) from request or session
104          *
105          * @param product Product instance
106          * @param request Request instance
107          * @param session Session instance
108          * @return Amount as string
109          * @deprecated Old code
110          */
111         @Deprecated
112         public String getPrintableChoosenFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session);
113
114         /**
115          * Some "getter" for total price of position from request or session.
116          * Single price and amount is multiplyed.
117          *
118          * @param product Product instance
119          * @param request Request instance
120          * @param session Session instance
121          * @return Amount as string
122          * @deprecated Old code
123          */
124         @Deprecated
125         public float getTotalPositionPriceFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session);
126
127         /**
128          * Initializes this instance with given ServletContext
129          *
130          * @param context Servlet context
131          * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the backend is unsupported
132          * @throws java.sql.SQLException If an SQL error occurs
133          * @throws java.io.IOException If an IO error occurs
134          * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
135          */
136         public void init (final ServletContext context) throws UnsupportedDatabaseBackendException, SQLException, IOException, BadTokenException;
137
138         /**
139          * Checks whether the given product is choosen, request overules session.
140          *
141          * @param product Product instance
142          * @param request Request instance
143          * @param session Session instance
144          * @return Whether the product is choosen
145          * @deprecated Old lost code
146          */
147         @Deprecated
148         public boolean isProductChoosen (final Product product, final HttpServletRequest request, final HttpSession session);
149
150         /**
151          * Calculates total price of all choosen products
152          *
153          * @param request Request instance
154          * @param session Session instance
155          * @return Total price of all choosen products
156          * @throws javax.servlet.ServletException If something unexpected happened
157          */
158         public float calculateTotalPrice (final HttpServletRequest request, final HttpSession session) throws ServletException;
159
160         /**
161          * Calculates total amount of all choosen products
162          *
163          * @param request Request instance
164          * @param session Session instance
165          * @return Total amount of all choosen products
166          * @throws javax.servlet.ServletException If something unexpected happened
167          */
168         public int calculateTotalAmount (final HttpServletRequest request, final HttpSession session) throws ServletException;
169
170         /**
171          * Some "getter" for HTML code 'checked="checked"' if the product is choosen
172          *
173          * @param product Product instance
174          * @param request Request instance
175          * @param session Session instance
176          * @return Whether the product is choosen
177          */
178         public String getCheckedHtmlFromProduct (final Product product, final HttpServletRequest request, final HttpSession session);
179
180         /**
181          * Some "getter" for HTML code 'disabled="disabled"' for e.g. submit buttons
182          *
183          * @param request Request instance
184          * @param session Session instance
185          * @return Whether the product is choosen
186          * @throws javax.servlet.ServletException If something unexpected happened
187          */
188         public String getDisabledHtmlFromSession (final HttpServletRequest request, final HttpSession session) throws ServletException;
189
190         /**
191          * Marks given product as ordered in session
192          *
193          * @param product Product to mark as ordered
194          * @param session Session instance
195          * @deprecated Old code
196          */
197         @Deprecated
198         public void markProductAsOrdered(final Product product, final HttpSession session);
199
200         /**
201          * Marks given product as choosen in session
202          *
203          * @param product Product to mark as ordered
204          * @param session Session instance
205          * @deprecated Old code
206          */
207         @Deprecated
208         public void markProductAsChoosen(final Product product, final HttpSession session);
209
210         /**
211          * Unmarks given product as ordered in session
212          *
213          * @param product Product to unmark as ordered
214          * @param session Session instance
215          * @deprecated Old code
216          */
217         @Deprecated
218         public void unmarkProductAsOrdered(final Product product, final HttpSession session);
219
220         /**
221          * Unmarks given product as choosen in session
222          *
223          * @param product Product to unmark as choosen
224          * @param session Session instance
225          * @deprecated Old code
226          */
227         @Deprecated
228         public void unmarkProductAsChoosen(final Product product, final HttpSession session);
229
230         /**
231          * Some getter for printable value from session or an empty string for null.
232          *
233          * @param session Session instance
234          * @param key Key to get
235          * @return Value from key, empty string for null
236          */
237         public Object getPrintableValeFromSession (final HttpSession session, final String key);
238
239         /**
240          * Somewhat setter in session
241          *
242          * @param session Session instance
243          * @param key Session key to set
244          * @param value Value to set
245          */
246         public void setValueInSession (final HttpSession session, final String key, final Object value);
247
248         /**
249          * Some "getter" for a an array of only available products
250          * 
251          * @return Only available products
252          * @throws javax.servlet.ServletException If anything went wrong
253          */
254         public Iterator<Product> getAvailableProducts () throws ServletException;
255
256         /**
257          * Some "getter" for a an array of all products
258          *
259          * @return All products
260          * @throws javax.servlet.ServletException If anything went wrong
261          */
262         public Iterator<Product> getAllProducts () throws ServletException;
263
264         /**
265          * Some "getter" for a an array of all categories
266          *
267          * @return All categories
268          * @throws javax.servlet.ServletException If anything went wrong
269          */
270         public Iterator<Category> getAllCategories () throws ServletException;
271
272         /**
273          * Checks if given Product instance is available and returns a printable
274          * (human-readable) string.
275          * 
276          * @param product Product instance to check
277          * @return Human-readable version of product availability
278          */
279         public String getPrintableProduktAvailability (final Product product);
280
281         /**
282          * Returns a printable (human-readable) string of product's category
283          * 
284          * @param product Product instance to check
285          * @return Human-readable version of product availability
286          * @throws javax.servlet.ServletException If something unexpected happened
287          */
288         public String getPrintableProduktCategory (final Product product) throws ServletException;
289
290         /**
291          * Marks all choosen products as ordered
292          *
293          * @param request Request instance
294          * @param session Session instance
295          * @throws javax.servlet.ServletException If something unexpected happened
296          * @deprecated Old code
297          */
298         @Deprecated
299         public void markAllChoosenProductsAsOrdered (final HttpServletRequest request, final HttpSession session) throws ServletException;
300
301         /**
302          * Adds given category data from request to database
303          *
304          * @param request Request instance
305          * @throws javax.servlet.ServletException If something unexpected happened
306          * @throws org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException If the given title is already used
307          */
308         public void doAdminAddCategory (final HttpServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException;
309
310         /**
311          * Adds given product data from request to database
312          *
313          * @param request Request instance
314          * @throws javax.servlet.ServletException If something unexpected happened
315          * @throws org.mxchange.pizzaapplication.exceptions.ProductTitleAlreadyUsedException If the given product title is already used
316          */
317         public void doAdminAddProduct (final HttpServletRequest request) throws ServletException, ProductTitleAlreadyUsedException;
318
319         /**
320          * Generates link HTML code for given category's parent id, if set. This
321          * link then points to products.jsp?category_id=x
322          *
323          * @param category Category instance
324          * @return HTML code
325          */
326         public String generateLinkForParent (final Category category);
327
328         /**
329          * Handles admin product form requests
330          *
331          * @param request Request instance
332          * @param response Response instance
333          * @throws ServletException If something unexpected happened
334          */
335         public void doAdminHandleProductForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException;
336
337         /**
338          * Handles admin category form requests
339          * 
340          * @param request Request instance
341          * @param response Response instance
342          * @throws ServletException If something unexpected happened
343          */
344         public void doAdminHandleCategoryForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException;
345
346         /**
347          * Some "getter" for a Product instance from given item
348          * @param item Item instance
349          * @return A Product instance
350          * @throws ServletException If something unexpected happened
351          */
352         public Product getProduct (final AddableBasketItem item) throws ServletException;
353 }