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