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