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