]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceBean.java
Removed already no longer used methods and cleared some which you should really not...
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / beans / controller / PizzaServiceBean.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.beans.controller;
18
19 import java.io.IOException;
20 import java.sql.SQLException;
21 import java.text.MessageFormat;
22 import java.util.Iterator;
23 import javax.annotation.PostConstruct;
24 import javax.enterprise.context.SessionScoped;
25 import javax.faces.FacesException;
26 import javax.inject.Named;
27 import javax.servlet.ServletException;
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpServletResponse;
30 import javax.servlet.http.HttpSession;
31 import org.mxchange.jcore.exceptions.BadTokenException;
32 import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
33 import org.mxchange.jshop.beans.BaseFrameworkBean;
34 import org.mxchange.jshop.category.Category;
35 import org.mxchange.jshop.exceptions.CategoryTitleAlreadyUsedException;
36 import org.mxchange.jshop.exceptions.ProductTitleAlreadyUsedException;
37 import org.mxchange.jshop.item.AddableBasketItem;
38 import org.mxchange.jshop.product.Product;
39 import org.mxchange.pizzaapplication.application.PizzaApplication;
40 import org.mxchange.pizzaapplication.application.PizzaServiceApplication;
41
42 /**
43  * Main application class
44  *
45  * @author Roland Haeder
46  */
47 @Named("controller")
48 @SessionScoped
49 public class PizzaServiceBean extends BaseFrameworkBean implements PizzaBean {
50         /**
51          * Serial id
52          */
53         private static final long serialVersionUID = 58137539530279L;
54
55         /**
56          * Pizza application
57          */
58         private final PizzaApplication app;
59
60         /**
61          * Initializer block
62          */
63         {
64                 // Get new application instance
65                 this.getLogger().debug("INITIALIZER!"); //NOI18N
66                 this.app = new PizzaServiceApplication();
67         }
68
69         /**
70          * Default constructor
71          */
72         public PizzaServiceBean () {
73                 this.getLogger().trace("CALLED!"); //NOI18N
74         }
75
76         @Override
77         @PostConstruct
78         public void init () throws FacesException {
79                 // Trace message
80                 this.getLogger().trace(MessageFormat.format("application={0},basket={1} - CALLED!", this.getApplication(), this.getBasket())); //NOI18N
81
82                 // Must not be null
83                 if (this.getApplication() == null) {
84                         // Abort here
85                         throw new NullPointerException("application is null"); //NOI18N
86                 }
87
88                 try {
89                         // Call init method
90                         this.app.init(this.getApplication());
91                 } catch (final UnsupportedDatabaseBackendException | SQLException | IOException | BadTokenException ex) {
92                         // Continue to throw
93                         throw new FacesException(ex);
94                 }
95         }
96
97         /**
98          * Calculates total amount of all choosen products
99          *
100          * @param request Request instance
101          * @param session Session instance
102          * @return Total amount of all choosen products
103          * @deprecated Old lost code
104          */
105         @Override
106         @Deprecated
107         public int calculateTotalAmount (final HttpServletRequest request, final HttpSession session) throws ServletException {
108                 return this.app.calculateTotalAmount(request, session);
109         }
110
111         /**
112          * Calculates total price of all choosen products
113          *
114          * @param request Request instance
115          * @param session Session instance
116          * @return Total price of all choosen products
117          */
118         @Override
119         public float calculateTotalPrice (final HttpServletRequest request, final HttpSession session) throws ServletException {
120                 return this.app.calculateTotalPrice(request, session);
121         }
122
123         /**
124          * Some "getter" for amount from session
125          *
126          * @param product Product instance
127          * @param session Session instance
128          * @return Amount as string
129          */
130         @Override
131         @Deprecated
132         public String getAmountFromSession (final Product product, final HttpSession session) {
133                 return this.app.getAmountFromSession(product, session);
134         }
135
136         /**
137          * Some "getter" for HTML code 'checked="checked"' if the product is choosen
138          * 
139          * @param product Product instance
140          * @param request Request instance
141          * @param session Session instance
142          * @return Whether the product is choosen
143          */
144         @Override
145         public String getCheckedHtmlFromProduct (final Product product, final HttpServletRequest request, final HttpSession session) {
146                 return this.app.getCheckedHtmlFromProduct(product, request, session);
147         }
148
149         /**
150          * Some "getter" for choose from session
151          * 
152          * @param product Product instance
153          * @param session Session instance
154          * @return Choose as string
155          */
156         @Override
157         @Deprecated
158         public String getChooseFromSession (final Product product, final HttpSession session) {
159                 return this.app.getChooseFromSession(product, session);
160         }
161
162         /**
163          * Some "getter" for HTML code 'disabled="disabled"' for e.g. submit buttons
164          *
165          * @param request Request instance
166          * @param session Session instance
167          * @return Whether the product is choosen
168          */
169         @Override
170         public String getDisabledHtmlFromSession (final HttpServletRequest request, final HttpSession session) throws ServletException {
171                 return this.app.getDisabledHtmlFromSession(request, session);
172         }
173
174         /**
175          * Checks if given Product instance is available and returns a printable
176          * (human-readable) string.
177          * 
178          * @param product Product instance to check
179          * @return Human-readable version of product availability
180          */
181         @Override
182         public String getPrintableProduktAvailability (final Product product) {
183                 return this.app.getPrintableProduktAvailability(product);
184         }
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         @Override
194         public Object getPrintableValeFromSession (final HttpSession session, final String key) {
195                 return this.app.getPrintableValeFromSession(session, key);
196         }
197
198         /**
199          * Some "getter" for a an array of only available products
200          *
201          * @return All products
202          */
203         @Override
204         public Iterator<Product> getAvailableProducts () throws ServletException {
205                 return this.app.getAvailableProducts();
206         }
207
208         /**
209          * Some "getter" for a an array of all products
210          *
211          * @return All products
212          */
213         @Override
214         public Iterator<Product> getAllProducts () throws ServletException {
215                 return this.app.getAllProducts();
216         }
217
218         /**
219          * Some "getter" for a an array of all categories
220          *
221          * @return All categories
222          */
223         @Override
224         public Iterator<Category> getAllCategories () throws ServletException {
225                 return this.app.getAllCategories();
226         }
227
228         /**
229          * Some "getter" for total price of position from request or session.
230          * Single price and amount is multiplyed.
231          *
232          * @param product Product instance
233          * @param request Request instance
234          * @param session Session instance
235          * @return Amount as string
236          */
237         @Override
238         @Deprecated
239         public float getTotalPositionPriceFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session) {
240                 return this.app.getTotalPositionPriceFromRequestSession(product, request, session);
241         }
242
243         /**
244          * Checks whether the given product is choosen, request overules session.
245          *
246          * @param product Product instance
247          * @param request Request instance
248          * @param session Session instance
249          * @return Whether the product is choosen
250          */
251         @Override
252         @Deprecated
253         public boolean isProductChoosen (final Product product, final HttpServletRequest request, final HttpSession session) {
254                 return this.app.isProductChoosen(product, request, session);
255         }
256
257         /**
258          * Somewhat setter in session
259          *
260          * @param session Session instance
261          * @param key Session key to set
262          * @param value Value to set
263          */
264         @Override
265         public void setValueInSession (final HttpSession session, final String key, final Object value) {
266                 this.app.setValueInSession(session, key, value);
267         }
268
269         @Override
270         public void doAdminAddCategory (final HttpServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException {
271                 this.app.doAdminAddCategory(request);
272         }
273
274         @Override
275         public void doAdminAddProduct (final HttpServletRequest request) throws ServletException, ProductTitleAlreadyUsedException {
276                 this.app.doAdminAddProduct(request);
277         }
278
279         @Override
280         public String generateLinkForParent (final Category category) {
281                 return this.app.generateLinkForParent(category);
282         }
283
284         @Override
285         public String getPrintableProduktCategory (final Product product) throws ServletException {
286                 return this.app.getPrintableProduktCategory(product);
287         }
288
289         @Override
290         public void doAdminHandleProductForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException {
291                 this.app.doAdminHandleProductForms(request, response);
292         }
293
294         @Override
295         public void doAdminHandleCategoryForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException {
296                 this.app.doAdminHandleCategoryForms(request, response);
297         }
298
299         @Override
300         public Product getProduct (final AddableBasketItem item) throws ServletException {
301                 // Deligate to application
302                 return this.app.getProduct(item);
303         }
304 }