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);
100 public String getPrintableProduktAvailability (final Product product) {
101 return this.app.getPrintableProduktAvailability(product);
105 public Iterator<Product> getAvailableProductsIterator () throws ServletException {
107 return this.app.getAvailableProductsIterator();
108 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
110 throw new ServletException(ex);
115 public Iterator<Product> getAllProductsIterator () throws ServletException {
117 return this.app.getAllProductsIterator();
118 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
120 throw new ServletException(ex);
125 public Deque<Product> getAvailableProducts () throws ServletException {
127 return this.app.getAvailableProducts();
128 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
130 throw new ServletException(ex);
135 public Deque<Product> getAllProducts () throws ServletException {
137 return this.app.getAllProducts();
138 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
140 throw new ServletException(ex);
145 public Iterator<Category> getAllCategoriesIterator () throws ServletException {
147 return this.app.getAllCategoriesIterator();
148 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
150 throw new ServletException(ex);
155 public Deque<Category> getAllCategories () throws ServletException {
157 return this.app.getAllCategories();
158 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
160 throw new ServletException(ex);
165 public void doAdminAddCategory (final ServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException {
167 this.app.doAdminAddCategory(request);
168 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
170 throw new ServletException(ex);
175 public void doAdminAddProduct (final ServletRequest request) throws ServletException, ProductTitleAlreadyUsedException {
177 this.app.doAdminAddProduct(request);
178 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
180 throw new ServletException(ex);
186 public String getPrintableProduktCategory (final Product product) throws ServletException {
188 return this.app.getPrintableProductCategory(product);
189 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
191 throw new ServletException(ex);
196 public void doAdminHandleProductForms () throws ServletException {
198 this.app.doAdminHandleProductForms(this.getRequest(), this.getResponse());
199 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | ProductTitleAlreadyUsedException ex) {
201 throw new ServletException(ex);
206 public void doAdminHandleCategoryForms () throws ServletException {
208 this.app.doAdminHandleCategoryForms(this.getRequest(), this.getResponse());
209 } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | CategoryTitleAlreadyUsedException ex) {
211 throw new ServletException(ex);
216 public Product getProduct (final AddableBasketItem item) throws ServletException {
218 // Deligate to application
219 return this.app.getProduct(item);
220 } catch (IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
222 throw new ServletException(ex);
228 public String generateLinkForParent (final Category category) {
230 return this.app.generateLinkForParent(category);