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.jcoreee.beans.BaseFrameworkBean;
28 import org.mxchange.jshopcore.exceptions.CannotAddProductException;
29 import org.mxchange.jshopcore.exceptions.ProductTitleAlreadyUsedException;
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.controller.ShopWebController;
36 * Main application class
38 * @author Roland Haeder<roland@mxchange.org>
40 @Named ("admin_product")
42 public class AdminProductWebBean extends BaseFrameworkBean implements AdminProductWebController {
47 private static final long serialVersionUID = 5_819_375_183_472_871L;
50 * Remote bean for products
52 private final AdminProductSessionBeanRemote productBean;
54 ////////////////////// Bean injections ///////////////////////
59 private ShopWebController controller;
61 /////////////////////// Properties /////////////////////
65 private Boolean available;
85 public AdminProductWebBean () {
88 // Get initial context
89 Context context = new InitialContext();
91 // Try to lookup the bean
92 this.productBean = (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.setAvailable(this.getAvailable());
107 product.setId(this.getId());
108 product.setPrice(this.getPrice());
109 product.setTitle(this.getTitle());
112 this.productBean.doAdminAddProduct(product);
114 // Add to shop controller
115 this.controller.addProduct(product);
118 this.setAvailable(Boolean.FALSE);
122 } catch (final ProductTitleAlreadyUsedException | CannotAddProductException ex) {
124 throw new FaceletException(ex);
129 public List<Product> getAllProducts () throws FaceletException {
131 return this.productBean.getAllProducts();
135 public void setAvailable (final Boolean available) {
136 this.available = available;
140 public Long getId () {
145 public void setId (final Long id) {
150 public Float getPrice () {
155 public void setPrice (final Float price) {
160 public String getTitle () {
165 public void setTitle (final String title) {
170 public Boolean getAvailable () {
171 return this.available;