2 * Copyright (C) 2015 Roland Haeder
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.
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.
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/>.
17 package org.mxchange.pizzaapplication.beans.controller;
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;
44 * Main application class
46 * @author Roland Haeder
50 public class PizzaServiceBean extends BaseFrameworkBean implements PizzaBean {
54 private static final long serialVersionUID = 58137539530279L;
59 private final PizzaApplication app;
65 // Get new application instance
66 this.getLogger().debug("INITIALIZER!"); //NOI18N
67 this.app = new PizzaServiceApplication();
73 public PizzaServiceBean () {
74 this.getLogger().trace("CALLED!"); //NOI18N
79 public void init () throws FacesException {
81 this.getLogger().trace(MessageFormat.format("application={0} - CALLED!", this.getApplication())); //NOI18N
84 if (this.getApplication() == null) {
86 throw new NullPointerException("application is null"); //NOI18N
91 this.app.init(this.getApplication());
92 } catch (final UnsupportedDatabaseBackendException | SQLException | IOException | BadTokenException ex) {
94 throw new FacesException(ex);
99 public String getPrintableProduktAvailability (final Product product) {
100 return this.app.getPrintableProduktAvailability(product);
104 public Iterator<Product> getAvailableProductsIterator () throws ServletException {
106 return this.app.getAvailableProductsIterator();
107 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
109 throw new ServletException(ex);
114 public Iterator<Product> getAllProductsIterator () throws ServletException {
116 return this.app.getAllProductsIterator();
117 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
119 throw new ServletException(ex);
124 public Deque<Product> getAvailableProducts () throws ServletException {
126 return this.app.getAvailableProducts();
127 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
129 throw new ServletException(ex);
134 public Deque<Product> getAllProducts () throws ServletException {
136 return this.app.getAllProducts();
137 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
139 throw new ServletException(ex);
144 public Iterator<Category> getAllCategoriesIterator () throws ServletException {
146 return this.app.getAllCategoriesIterator();
147 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
149 throw new ServletException(ex);
154 public Deque<Category> getAllCategories () throws ServletException {
156 return this.app.getAllCategories();
157 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
159 throw new ServletException(ex);
164 public void doAdminAddCategory (final ServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException {
166 this.app.doAdminAddCategory(request);
167 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
169 throw new ServletException(ex);
174 public void doAdminAddProduct (final ServletRequest request) throws ServletException, ProductTitleAlreadyUsedException {
176 this.app.doAdminAddProduct(request);
177 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
179 throw new ServletException(ex);
184 public String getPrintableProduktCategory (final Product product) throws ServletException {
186 return this.app.getPrintableProductCategory(product);
187 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
189 throw new ServletException(ex);
194 public void doAdminHandleProductForms () throws ServletException {
196 this.app.doAdminHandleProductForms(this.getRequest(), this.getResponse());
197 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | ProductTitleAlreadyUsedException ex) {
199 throw new ServletException(ex);
204 public void doAdminHandleCategoryForms () throws ServletException {
206 this.app.doAdminHandleCategoryForms(this.getRequest(), this.getResponse());
207 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | CategoryTitleAlreadyUsedException ex) {
209 throw new ServletException(ex);
214 public Product getProduct (final AddableBasketItem item) throws ServletException {
216 // Deligate to application
217 return this.app.getProduct(item);
218 } catch (IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
220 throw new ServletException(ex);