2 * Copyright (C) 2016 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (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 Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.pizzaapplication.beans.product;
19 import java.util.List;
20 import javax.enterprise.context.RequestScoped;
21 import javax.faces.view.facelets.FaceletException;
22 import javax.inject.Inject;
23 import javax.inject.Named;
24 import javax.naming.Context;
25 import javax.naming.InitialContext;
26 import javax.naming.NamingException;
27 import org.mxchange.jshopcore.exceptions.CannotAddProductException;
28 import org.mxchange.jshopcore.exceptions.ProductTitleAlreadyUsedException;
29 import org.mxchange.jshopcore.model.category.Category;
30 import org.mxchange.jshopcore.model.product.AdminProductSessionBeanRemote;
31 import org.mxchange.jshopcore.model.product.GenericProduct;
32 import org.mxchange.jshopcore.model.product.Product;
33 import org.mxchange.pizzaapplication.beans.shop.PizzaShopWebApplicationController;
36 * Main application class
38 * @author Roland Haeder<roland@mxchange.org>
40 @Named ("adminProductController")
42 public class PizzaAdminProductWebRequestBean implements PizzaAdminProductWebRequestController {
47 private static final long serialVersionUID = 5_819_375_183_472_871L;
49 /////////////////////// Properties /////////////////////
53 private Boolean productAvailability;
58 private Category productCategory;
61 * Property productPrice
63 private Float productPrice;
66 * Remote bean for products
68 private AdminProductSessionBeanRemote productRemoteBean;
71 * Property productTitle
73 private String productTitle;
75 ////////////////////// Bean injections ///////////////////////
81 private PizzaShopWebApplicationController shopController;
86 public PizzaAdminProductWebRequestBean () {
89 // Get initial context
90 Context context = new InitialContext();
92 // Try to lookup the bean
93 this.productRemoteBean = (AdminProductSessionBeanRemote) context.lookup("java:global/jshop-ejb/admin_product!org.mxchange.jshopcore.model.product.AdminProductSessionBeanRemote"); //NOI18N
94 } catch (final NamingException e) {
96 throw new FaceletException(e);
101 public void addProduct () throws FaceletException {
103 // Create product instance
104 Product product = new GenericProduct();
107 product.setProductAvailability(this.getProductAvailability());
108 product.setProductCategory(this.getProductCategory());
109 product.setProductPrice(this.getProductPrice());
110 product.setProductTitle(this.getProductTitle());
113 Product updatedProduct = this.productRemoteBean.doAdminAddProduct(product);
115 // Add to shop controller
116 this.shopController.addProduct(updatedProduct);
119 this.setProductAvailability(Boolean.FALSE);
120 this.setProductCategory(null);
121 this.setProductPrice(null);
122 this.setProductTitle(null);
123 } catch (final ProductTitleAlreadyUsedException | CannotAddProductException ex) {
125 throw new FaceletException(ex);
130 public List<Product> getAllProducts () throws FaceletException {
132 return this.productRemoteBean.getAllProducts();
136 public Boolean getProductAvailability () {
137 return this.productAvailability;
141 public void setProductAvailability (final Boolean productAvailability) {
142 this.productAvailability = productAvailability;
146 public Category getProductCategory () {
147 return this.productCategory;
151 public void setProductCategory (final Category productCategory) {
152 this.productCategory = productCategory;
156 public Float getProductPrice () {
157 return this.productPrice;
161 public void setProductPrice (final Float productPrice) {
162 this.productPrice = productPrice;
166 public String getProductTitle () {
167 return this.productTitle;
171 public void setProductTitle (final String productTitle) {
172 this.productTitle = productTitle;