]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java
a017e4de44bbcdfc7de3cef6c1c1b87d24ff743d
[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.jshop.category.Category;
31 import org.mxchange.jshop.exceptions.CategoryTitleAlreadyUsedException;
32 import org.mxchange.jshop.exceptions.ProductTitleAlreadyUsedException;
33 import org.mxchange.jshop.item.AddableBasketItem;
34 import org.mxchange.jshop.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          * Some "getter" for total price of position from request or session.
92          * Single price and amount is multiplyed.
93          *
94          * @param product Product instance
95          * @param request Request instance
96          * @param session Session instance
97          * @return Amount as string
98          * @deprecated Old code
99          */
100         @Deprecated
101         public float getTotalPositionPriceFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session);
102
103         /**
104          * Initializes this instance with given ServletContext
105          *
106          * @param context Servlet context
107          * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the backend is unsupported
108          * @throws java.sql.SQLException If an SQL error occurs
109          * @throws java.io.IOException If an IO error occurs
110          * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
111          */
112         public void init (final ServletContext context) throws UnsupportedDatabaseBackendException, SQLException, IOException, BadTokenException;
113
114         /**
115          * Checks whether the given product is choosen, request overules session.
116          *
117          * @param product Product instance
118          * @param request Request instance
119          * @param session Session instance
120          * @return Whether the product is choosen
121          * @deprecated Old lost code
122          */
123         @Deprecated
124         public boolean isProductChoosen (final Product product, final HttpServletRequest request, final HttpSession session);
125
126         /**
127          * Some "getter" for HTML code 'checked="checked"' if the product is choosen
128          *
129          * @param product Product instance
130          * @param request Request instance
131          * @param session Session instance
132          * @return Whether the product is choosen
133          */
134         public String getCheckedHtmlFromProduct (final Product product, final HttpServletRequest request, final HttpSession session);
135
136         /**
137          * Some "getter" for HTML code 'disabled="disabled"' for e.g. submit buttons
138          *
139          * @param request Request instance
140          * @param session Session instance
141          * @return Whether the product is choosen
142          * @throws javax.servlet.ServletException If something unexpected happened
143          */
144         public String getDisabledHtmlFromSession (final HttpServletRequest request, final HttpSession session) throws ServletException;
145
146         /**
147          * Some getter for printable value from session or an empty string for null.
148          *
149          * @param session Session instance
150          * @param key Key to get
151          * @return Value from key, empty string for null
152          */
153         public Object getPrintableValeFromSession (final HttpSession session, final String key);
154
155         /**
156          * Somewhat setter in session
157          *
158          * @param session Session instance
159          * @param key Session key to set
160          * @param value Value to set
161          */
162         public void setValueInSession (final HttpSession session, final String key, final Object value);
163
164         /**
165          * Some "getter" for a an array of only available products
166          * 
167          * @return Only available products
168          * @throws javax.servlet.ServletException If anything went wrong
169          */
170         public Iterator<Product> getAvailableProducts () throws ServletException;
171
172         /**
173          * Some "getter" for a an array of all products
174          *
175          * @return All products
176          * @throws javax.servlet.ServletException If anything went wrong
177          */
178         public Iterator<Product> getAllProducts () throws ServletException;
179
180         /**
181          * Some "getter" for a an array of all categories
182          *
183          * @return All categories
184          * @throws javax.servlet.ServletException If anything went wrong
185          */
186         public Iterator<Category> getAllCategories () throws ServletException;
187
188         /**
189          * Checks if given Product instance is available and returns a printable
190          * (human-readable) string.
191          * 
192          * @param product Product instance to check
193          * @return Human-readable version of product availability
194          */
195         public String getPrintableProduktAvailability (final Product product);
196
197         /**
198          * Returns a printable (human-readable) string of product's category
199          * 
200          * @param product Product instance to check
201          * @return Human-readable version of product availability
202          * @throws javax.servlet.ServletException If something unexpected happened
203          */
204         public String getPrintableProduktCategory (final Product product) throws ServletException;
205
206         /**
207          * Adds given category data from request to database
208          *
209          * @param request Request instance
210          * @throws javax.servlet.ServletException If something unexpected happened
211          * @throws org.mxchange.jshop.exceptions.CategoryTitleAlreadyUsedException If the given title is already used
212          */
213         public void doAdminAddCategory (final HttpServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException;
214
215         /**
216          * Adds given product data from request to database
217          *
218          * @param request Request instance
219          * @throws javax.servlet.ServletException If something unexpected happened
220          * @throws org.mxchange.jshop.exceptions.ProductTitleAlreadyUsedException If the given product title is already used
221          */
222         public void doAdminAddProduct (final HttpServletRequest request) throws ServletException, ProductTitleAlreadyUsedException;
223
224         /**
225          * Generates link HTML code for given category's parent id, if set. This
226          * link then points to products.jsp?category_id=x
227          *
228          * @param category Category instance
229          * @return HTML code
230          */
231         public String generateLinkForParent (final Category category);
232
233         /**
234          * Handles admin product form requests
235          *
236          * @param request Request instance
237          * @param response Response instance
238          * @throws ServletException If something unexpected happened
239          */
240         public void doAdminHandleProductForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException;
241
242         /**
243          * Handles admin category form requests
244          * 
245          * @param request Request instance
246          * @param response Response instance
247          * @throws ServletException If something unexpected happened
248          */
249         public void doAdminHandleCategoryForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException;
250
251         /**
252          * Some "getter" for a Product instance from given item
253          * @param item Item instance
254          * @return A Product instance
255          * @throws ServletException If something unexpected happened
256          */
257         public Product getProduct (final AddableBasketItem item) throws ServletException;
258 }