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