]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceBean.java
Added old method back + marked some others as deprecated
[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.lang.reflect.InvocationTargetException;
21 import java.sql.SQLException;
22 import java.text.MessageFormat;
23 import java.util.Deque;
24 import java.util.Iterator;
25 import javax.annotation.PostConstruct;
26 import javax.enterprise.context.SessionScoped;
27 import javax.faces.FacesException;
28 import javax.inject.Named;
29 import javax.servlet.ServletException;
30 import javax.servlet.ServletRequest;
31 import org.mxchange.jcore.exceptions.BadTokenException;
32 import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
33 import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
34 import org.mxchange.jshop.beans.BaseFrameworkBean;
35 import org.mxchange.jshop.category.Category;
36 import org.mxchange.jshop.exceptions.CategoryTitleAlreadyUsedException;
37 import org.mxchange.jshop.exceptions.ProductTitleAlreadyUsedException;
38 import org.mxchange.jshop.item.AddableBasketItem;
39 import org.mxchange.jshop.product.Product;
40 import org.mxchange.pizzaapplication.application.PizzaApplication;
41 import org.mxchange.pizzaapplication.application.PizzaServiceApplication;
42
43 /**
44  * Main application class
45  *
46  * @author Roland Haeder
47  */
48 @Named("controller")
49 @SessionScoped
50 public class PizzaServiceBean extends BaseFrameworkBean implements PizzaBean {
51         /**
52          * Serial id
53          */
54         private static final long serialVersionUID = 58137539530279L;
55
56         /**
57          * Pizza application
58          */
59         private final PizzaApplication app;
60
61         /**
62          * Initializer block
63          */
64         {
65                 // Get new application instance
66                 this.getLogger().debug("INITIALIZER!"); //NOI18N
67                 this.app = new PizzaServiceApplication();
68         }
69
70         /**
71          * Default constructor
72          */
73         public PizzaServiceBean () {
74                 this.getLogger().trace("CALLED!"); //NOI18N
75         }
76
77         @Override
78         @PostConstruct
79         public void init () throws FacesException {
80                 // Trace message
81                 this.getLogger().trace(MessageFormat.format("application={0} - CALLED!", this.getApplication())); //NOI18N
82
83                 // Must not be null
84                 if (this.getApplication() == null) {
85                         // Abort here
86                         throw new NullPointerException("application is null"); //NOI18N
87                 }
88
89                 try {
90                         // Call init method
91                         this.app.init(this.getApplication());
92                 } catch (final UnsupportedDatabaseBackendException | SQLException | IOException | BadTokenException ex) {
93                         // Continue to throw
94                         throw new FacesException(ex);
95                 }
96         }
97
98         @Override
99         @Deprecated
100         public String getPrintableProduktAvailability (final Product product) {
101                 return this.app.getPrintableProduktAvailability(product);
102         }
103
104         @Override
105         public Iterator<Product> getAvailableProductsIterator () throws ServletException {
106                 try {
107                         return this.app.getAvailableProductsIterator();
108                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
109                         // Continue to throw
110                         throw new ServletException(ex);
111                 }
112         }
113
114         @Override
115         public Iterator<Product> getAllProductsIterator () throws ServletException {
116                 try {
117                         return this.app.getAllProductsIterator();
118                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
119                         // Continue to throw
120                         throw new ServletException(ex);
121                 }
122         }
123
124         @Override
125         public Deque<Product> getAvailableProducts () throws ServletException {
126                 try {
127                         return this.app.getAvailableProducts();
128                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
129                         // Continue to throw
130                         throw new ServletException(ex);
131                 }
132         }
133
134         @Override
135         public Deque<Product> getAllProducts () throws ServletException {
136                 try {
137                         return this.app.getAllProducts();
138                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
139                         // Continue to throw
140                         throw new ServletException(ex);
141                 }
142         }
143
144         @Override
145         public Iterator<Category> getAllCategoriesIterator () throws ServletException {
146                 try {
147                         return this.app.getAllCategoriesIterator();
148                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
149                         // Continue to throw
150                         throw new ServletException(ex);
151                 }
152         }
153
154         @Override
155         public Deque<Category> getAllCategories () throws ServletException {
156                 try {
157                         return this.app.getAllCategories();
158                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
159                         // Continue to throw
160                         throw new ServletException(ex);
161                 }
162         }
163
164         @Override
165         public void doAdminAddCategory (final ServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException {
166                 try {
167                         this.app.doAdminAddCategory(request);
168                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
169                         // Continue to throw
170                         throw new ServletException(ex);
171                 }
172         }
173
174         @Override
175         public void doAdminAddProduct (final ServletRequest request) throws ServletException, ProductTitleAlreadyUsedException {
176                 try {
177                         this.app.doAdminAddProduct(request);
178                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
179                         // Continue to throw
180                         throw new ServletException(ex);
181                 }
182         }
183
184         @Override
185         @Deprecated
186         public String getPrintableProduktCategory (final Product product) throws ServletException {
187                 try {
188                         return this.app.getPrintableProductCategory(product);
189                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
190                         // Continue to throw
191                         throw new ServletException(ex);
192                 }
193         }
194
195         @Override
196         public void doAdminHandleProductForms () throws ServletException {
197                 try {
198                         this.app.doAdminHandleProductForms(this.getRequest(), this.getResponse());
199                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | ProductTitleAlreadyUsedException ex) {
200                         // Continue to throw
201                         throw new ServletException(ex);
202                 }
203         }
204
205         @Override
206         public void doAdminHandleCategoryForms () throws ServletException {
207                 try {
208                         this.app.doAdminHandleCategoryForms(this.getRequest(), this.getResponse());
209                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | CategoryTitleAlreadyUsedException ex) {
210                         // Continue to throw
211                         throw new ServletException(ex);
212                 }
213         }
214
215         @Override
216         public Product getProduct (final AddableBasketItem item) throws ServletException {
217                 try {
218                         // Deligate to application
219                         return this.app.getProduct(item);
220                 } catch (IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
221                         // Continue to throw
222                         throw new ServletException(ex);
223                 }
224         }
225
226         @Override
227         @Deprecated
228         public String generateLinkForParent (final Category category) {
229                 // Deligate to app
230                 return this.app.generateLinkForParent(category);
231         }
232 }