]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceWebBean.java
Well, if that is EJB, it sucks somehow: Logging not allowed and a complexer class...
[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 = 58137539530279L;
47
48         /**
49          * Remote bean
50          */
51         //@EJB
52         private final ShopSessionBeanRemote shop;
53
54         /**
55          * Default constructor
56          * 
57          * @throws javax.naming.NamingException Something happened here?
58          */
59         public PizzaServiceWebBean () throws NamingException {
60                 // Get initial context
61                 InitialContext context = new InitialContext();
62
63                 // Try to lookup the bean
64                 this.shop = (ShopSessionBeanRemote) context.lookup("ejb/stateless-shop"); //NOI18N
65         }
66
67         @PostConstruct
68         public void init () throws RuntimeException {
69                 // Call super init first
70                 super.genericInit();
71         }
72
73         @Override
74         public Deque<Product> getAvailableProducts () throws FacesException {
75                 try {
76                         return this.getShop().getAvailableProducts();
77                 } catch (final RemoteException ex) {
78                         // Continue to throw
79                         throw new FacesException(ex);
80                 }
81         }
82
83         @Override
84         public Deque<Product> getAllProducts () throws FacesException {
85                 try {
86                         return this.getShop().getAllProducts();
87                 } catch (final RemoteException ex) {
88                         // Continue to throw
89                         throw new FacesException(ex);
90                 }
91         }
92
93         @Override
94         public Deque<Category> getAllCategories () throws FacesException {
95                 try {
96                         return this.getShop().getAllCategories();
97                 } catch (final RemoteException ex) {
98                         // Continue to throw
99                         throw new FacesException(ex);
100                 }
101         }
102
103         @Override
104         public void doAdminAddCategory (final Category category) throws FacesException {
105                 try {
106                         this.getShop().doAdminAddCategory(category);
107                 } catch (final IOException | CategoryTitleAlreadyUsedException ex) {
108                         // Continue to throw
109                         throw new FacesException(ex);
110                 }
111         }
112
113         @Override
114         public void doAdminAddProduct (final Product product) throws FacesException {
115                 try {
116                         this.getShop().doAdminAddProduct(product);
117                 } catch (final IOException | ProductTitleAlreadyUsedException ex) {
118                         // Continue to throw
119                         throw new FacesException(ex);
120                 }
121         }
122
123         /**
124          * Getter for shop remote bean
125          *
126          * @return Remote shop bean
127          */
128         private ShopSessionBeanRemote getShop () {
129                 return this.shop;
130         }
131 }