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.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.ShopWebController;
36 * Main application class
38 * @author Roland Haeder<roland@mxchange.org>
40 @Named ("admin_product")
42 public class AdminProductWebBean implements AdminProductWebController {
47 private static final long serialVersionUID = 5_819_375_183_472_871L;
50 * Remote bean for products
52 private final AdminProductSessionBeanRemote productRemoteBean;
54 ////////////////////// Bean injections ///////////////////////
59 private ShopWebController shopController;
61 /////////////////////// Properties /////////////////////
65 private Boolean productAvailability;
70 private Category productCategory;
73 * Property productPrice
75 private Float productPrice;
78 * Property productTitle
80 private String productTitle;
85 public AdminProductWebBean () {
88 // Get initial context
89 Context context = new InitialContext();
91 // Try to lookup the bean
92 this.productRemoteBean = (AdminProductSessionBeanRemote) context.lookup("ejb/stateless-admin-product"); //NOI18N
93 } catch (final NamingException e) {
95 throw new FaceletException(e);
100 public void addProduct () throws FaceletException {
102 // Create product instance
103 Product product = new GenericProduct();
106 product.setProductAvailability(this.getProductAvailability());
107 product.setProductCategory(this.getProductCategory());
108 product.setProductPrice(this.getProductPrice());
109 product.setProductTitle(this.getProductTitle());
112 Product updatedProduct = this.productRemoteBean.doAdminAddProduct(product);
114 // Add to shop controller
115 this.shopController.addProduct(updatedProduct);
118 this.setProductAvailability(Boolean.FALSE);
119 this.setProductCategory(null);
120 this.setProductPrice(null);
121 this.setProductTitle(null);
122 } catch (final ProductTitleAlreadyUsedException | CannotAddProductException ex) {
124 throw new FaceletException(ex);
129 public List<Product> getAllProducts () throws FaceletException {
131 return this.productRemoteBean.getAllProducts();
135 public void setProductAvailability (final Boolean productAvailability) {
136 this.productAvailability = productAvailability;
140 public Category getProductCategory () {
141 return productCategory;
145 public void setProductCategory (final Category productCategory) {
146 this.productCategory = productCategory;
150 public Float getProductPrice () {
151 return this.productPrice;
155 public void setProductPrice (final Float productPrice) {
156 this.productPrice = productPrice;
160 public String getProductTitle () {
161 return this.productTitle;
165 public void setProductTitle (final String productTitle) {
166 this.productTitle = productTitle;
170 public Boolean getProductAvailability () {
171 return this.productAvailability;