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.sql.SQLException;
21 import java.text.MessageFormat;
22 import java.util.Deque;
23 import java.util.Iterator;
24 import javax.annotation.PostConstruct;
25 import javax.enterprise.context.SessionScoped;
26 import javax.faces.FacesException;
27 import javax.inject.Named;
28 import javax.servlet.ServletException;
29 import javax.servlet.ServletRequest;
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;
43 * Main application class
45 * @author Roland Haeder
49 public class PizzaServiceBean extends BaseFrameworkBean implements PizzaBean {
53 private static final long serialVersionUID = 58137539530279L;
58 private final PizzaApplication app;
64 // Get new application instance
65 this.getLogger().debug("INITIALIZER!"); //NOI18N
66 this.app = new PizzaServiceApplication();
72 public PizzaServiceBean () {
73 this.getLogger().trace("CALLED!"); //NOI18N
78 public void init () throws FacesException {
80 this.getLogger().trace(MessageFormat.format("application={0} - CALLED!", this.getApplication())); //NOI18N
83 if (this.getApplication() == null) {
85 throw new NullPointerException("application is null"); //NOI18N
90 this.app.init(this.getApplication());
91 } catch (final UnsupportedDatabaseBackendException | SQLException | IOException | BadTokenException ex) {
93 throw new FacesException(ex);
98 public String getPrintableProduktAvailability (final Product product) {
99 return this.app.getPrintableProduktAvailability(product);
103 public Iterator<Product> getAvailableProductsIterator () throws ServletException {
104 return this.app.getAvailableProductsIterator();
108 public Iterator<Product> getAllProductsIterator () throws ServletException {
109 return this.app.getAllProductsIterator();
113 public Deque<Product> getAvailableProducts () throws ServletException {
114 return this.app.getAvailableProducts();
118 public Deque<Product> getAllProducts () throws ServletException {
119 return this.app.getAllProducts();
123 public Iterator<Category> getAllCategoriesIterator () throws ServletException {
124 return this.app.getAllCategoriesIterator();
128 public Deque<Category> getAllCategories () throws ServletException {
129 return this.app.getAllCategories();
133 public void setValueInSession (final HttpSession session, final String key, final Object value) {
134 this.app.setValueInSession(session, key, value);
138 public void doAdminAddCategory (final ServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException {
139 this.app.doAdminAddCategory(request);
143 public void doAdminAddProduct (final ServletRequest request) throws ServletException, ProductTitleAlreadyUsedException {
144 this.app.doAdminAddProduct(request);
148 public String generateLinkForParent (final Category category) {
149 return this.app.generateLinkForParent(category);
153 public String getPrintableProduktCategory (final Product product) throws ServletException {
154 return this.app.getPrintableProduktCategory(product);
158 public void doAdminHandleProductForms () throws ServletException {
159 this.app.doAdminHandleProductForms(this.getRequest(), this.getResponse());
163 public void doAdminHandleCategoryForms () throws ServletException {
164 this.app.doAdminHandleCategoryForms(this.getRequest(), this.getResponse());
168 public Product getProduct (final AddableBasketItem item) throws ServletException {
169 // Deligate to application
170 return this.app.getProduct(item);