]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceWebBean.java
Continued:
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / beans / controller / PizzaServiceWebBean.java
1 /*
2  * Copyright (C) 2015 Roland Haeder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.pizzaapplication.beans.controller;
18
19 import java.io.IOException;
20 import java.rmi.RemoteException;
21 import java.util.Deque;
22 import javax.annotation.PostConstruct;
23 import javax.enterprise.context.SessionScoped;
24 import javax.faces.FacesException;
25 import javax.inject.Named;
26 import javax.naming.InitialContext;
27 import javax.naming.NamingException;
28 import org.mxchange.jcoreee.beans.BaseFrameworkBean;
29 import org.mxchange.jshopcore.exceptions.CategoryTitleAlreadyUsedException;
30 import org.mxchange.jshopcore.exceptions.ProductTitleAlreadyUsedException;
31 import org.mxchange.jshopcore.model.category.Category;
32 import org.mxchange.jshopcore.model.product.Product;
33 import org.mxchange.jshopeelib.beans.remote.shop.ShopSessionBeanRemote;
34
35 /**
36  * Main application class
37  *
38  * @author Roland Haeder
39  */
40 @Named("controller")
41 @SessionScoped
42 public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBean {
43         /**
44          * Serial id
45          */
46         private static final long serialVersionUID = 58_137_539_530_279L;
47
48         /**
49          * Remote bean
50          */
51         private final ShopSessionBeanRemote shop;
52
53         /**
54          * Default constructor
55          * 
56          * @throws javax.naming.NamingException Something happened here?
57          */
58         public PizzaServiceWebBean () throws NamingException {
59                 // Get initial context
60                 InitialContext context = new InitialContext();
61
62                 // Try to lookup the bean
63                 this.shop = (ShopSessionBeanRemote) context.lookup("ejb/stateless-shop"); //NOI18N
64         }
65
66         @PostConstruct
67         public void init () throws RuntimeException {
68                 // Call super init first
69                 super.genericInit();
70         }
71
72         @Override
73         public Deque<Product> getAvailableProducts () throws FacesException {
74                 try {
75                         return this.getShop().getAvailableProducts();
76                 } catch (final RemoteException ex) {
77                         // Continue to throw
78                         throw new FacesException(ex);
79                 }
80         }
81
82         @Override
83         public Deque<Product> getAllProducts () throws FacesException {
84                 try {
85                         return this.getShop().getAllProducts();
86                 } catch (final RemoteException ex) {
87                         // Continue to throw
88                         throw new FacesException(ex);
89                 }
90         }
91
92         @Override
93         public Deque<Category> getAllCategories () throws FacesException {
94                 try {
95                         return this.getShop().getAllCategories();
96                 } catch (final RemoteException ex) {
97                         // Continue to throw
98                         throw new FacesException(ex);
99                 }
100         }
101
102         @Override
103         public void doAdminAddCategory (final Category category) throws FacesException {
104                 try {
105                         this.getShop().doAdminAddCategory(category);
106                 } catch (final IOException | CategoryTitleAlreadyUsedException ex) {
107                         // Continue to throw
108                         throw new FacesException(ex);
109                 }
110         }
111
112         @Override
113         public void doAdminAddProduct (final Product product) throws FacesException {
114                 try {
115                         this.getShop().doAdminAddProduct(product);
116                 } catch (final IOException | ProductTitleAlreadyUsedException ex) {
117                         // Continue to throw
118                         throw new FacesException(ex);
119                 }
120         }
121
122         /**
123          * Getter for shop remote bean
124          *
125          * @return Remote shop bean
126          */
127         private ShopSessionBeanRemote getShop () {
128                 return this.shop;
129         }
130 }