]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceBean.java
Refacturing:
[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         public String getPrintableProduktAvailability (final Product product) {
100                 return this.app.getPrintableProduktAvailability(product);
101         }
102
103         @Override
104         public Iterator<Product> getAvailableProductsIterator () throws ServletException {
105                 try {
106                         return this.app.getAvailableProductsIterator();
107                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
108                         // Continue to throw
109                         throw new ServletException(ex);
110                 }
111         }
112
113         @Override
114         public Iterator<Product> getAllProductsIterator () throws ServletException {
115                 try {
116                         return this.app.getAllProductsIterator();
117                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
118                         // Continue to throw
119                         throw new ServletException(ex);
120                 }
121         }
122
123         @Override
124         public Deque<Product> getAvailableProducts () throws ServletException {
125                 try {
126                         return this.app.getAvailableProducts();
127                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
128                         // Continue to throw
129                         throw new ServletException(ex);
130                 }
131         }
132
133         @Override
134         public Deque<Product> getAllProducts () throws ServletException {
135                 try {
136                         return this.app.getAllProducts();
137                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
138                         // Continue to throw
139                         throw new ServletException(ex);
140                 }
141         }
142
143         @Override
144         public Iterator<Category> getAllCategoriesIterator () throws ServletException {
145                 try {
146                         return this.app.getAllCategoriesIterator();
147                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
148                         // Continue to throw
149                         throw new ServletException(ex);
150                 }
151         }
152
153         @Override
154         public Deque<Category> getAllCategories () throws ServletException {
155                 try {
156                         return this.app.getAllCategories();
157                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
158                         // Continue to throw
159                         throw new ServletException(ex);
160                 }
161         }
162
163         @Override
164         public void doAdminAddCategory (final ServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException {
165                 try {
166                         this.app.doAdminAddCategory(request);
167                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
168                         // Continue to throw
169                         throw new ServletException(ex);
170                 }
171         }
172
173         @Override
174         public void doAdminAddProduct (final ServletRequest request) throws ServletException, ProductTitleAlreadyUsedException {
175                 try {
176                         this.app.doAdminAddProduct(request);
177                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
178                         // Continue to throw
179                         throw new ServletException(ex);
180                 }
181         }
182
183         @Override
184         public String getPrintableProduktCategory (final Product product) throws ServletException {
185                 try {
186                         return this.app.getPrintableProductCategory(product);
187                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
188                         // Continue to throw
189                         throw new ServletException(ex);
190                 }
191         }
192
193         @Override
194         public void doAdminHandleProductForms () throws ServletException {
195                 try {
196                         this.app.doAdminHandleProductForms(this.getRequest(), this.getResponse());
197                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | ProductTitleAlreadyUsedException ex) {
198                         // Continue to throw
199                         throw new ServletException(ex);
200                 }
201         }
202
203         @Override
204         public void doAdminHandleCategoryForms () throws ServletException {
205                 try {
206                         this.app.doAdminHandleCategoryForms(this.getRequest(), this.getResponse());
207                 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | CategoryTitleAlreadyUsedException ex) {
208                         // Continue to throw
209                         throw new ServletException(ex);
210                 }
211         }
212
213         @Override
214         public Product getProduct (final AddableBasketItem item) throws ServletException {
215                 try {
216                         // Deligate to application
217                         return this.app.getProduct(item);
218                 } catch (IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
219                         // Continue to throw
220                         throw new ServletException(ex);
221                 }
222         }
223 }