]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceWebBean.java
Removed thrown exceptions + added EJB call
[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 java.util.Iterator;
23 import javax.annotation.PostConstruct;
24 import javax.ejb.EJB;
25 import javax.enterprise.context.SessionScoped;
26 import javax.faces.FacesException;
27 import javax.inject.Named;
28 import javax.naming.InitialContext;
29 import javax.naming.NamingException;
30 import org.mxchange.jcoreee.beans.BaseFrameworkBean;
31 import org.mxchange.jshopcore.exceptions.CategoryTitleAlreadyUsedException;
32 import org.mxchange.jshopcore.exceptions.ProductTitleAlreadyUsedException;
33 import org.mxchange.jshopcore.model.category.Category;
34 import org.mxchange.jshopcore.model.product.Product;
35 import org.mxchange.jshopeelib.beans.remote.shop.ShopSessionBeanRemote;
36
37 /**
38  * Main application class
39  *
40  * @author Roland Haeder
41  */
42 @Named("controller")
43 @SessionScoped
44 public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBean {
45         /**
46          * Serial id
47          */
48         private static final long serialVersionUID = 58137539530279L;
49
50         /**
51          * Remote bean
52          */
53         @EJB
54         private final ShopSessionBeanRemote remote;
55
56         /**
57          * Initializer block
58          */
59         {
60                 // Get new application instance
61                 this.getLogger().debug("INITIALIZER!"); //NOI18N
62         }
63
64         /**
65          * Default constructor
66          * 
67          * @throws javax.naming.NamingException Something happened here?
68          */
69         public PizzaServiceWebBean () throws NamingException {
70                 this.getLogger().trace("CALLED!"); //NOI18N
71
72                 // Get initial context
73                 InitialContext context = new InitialContext();
74
75                 // Try to lookup the bean
76                 this.remote = (ShopSessionBeanRemote) context.lookup("ejb/stateless-shop"); //NOI18N
77         }
78
79         @Override
80         @PostConstruct
81         public void init () throws RuntimeException {
82                 // Call super init first
83                 super.genericInit();
84         }
85
86         @Override
87         public Iterator<Product> getAvailableProductsIterator () throws FacesException {
88                 try {
89                         return this.remote.getAvailableProductsIterator();
90                 } catch (final RemoteException ex) {
91                         // Continue to throw
92                         throw new FacesException(ex);
93                 }
94         }
95
96         @Override
97         public Iterator<Product> getAllProductsIterator () throws FacesException {
98                 try {
99                         return this.remote.getAllProductsIterator();
100                 } catch (final RemoteException ex) {
101                         // Continue to throw
102                         throw new FacesException(ex);
103                 }
104         }
105
106         @Override
107         public Deque<Product> getAvailableProducts () throws FacesException {
108                 try {
109                         return this.remote.getAvailableProducts();
110                 } catch (final RemoteException ex) {
111                         // Continue to throw
112                         throw new FacesException(ex);
113                 }
114         }
115
116         @Override
117         public Deque<Product> getAllProducts () throws FacesException {
118                 try {
119                         return this.remote.getAllProducts();
120                 } catch (final RemoteException ex) {
121                         // Continue to throw
122                         throw new FacesException(ex);
123                 }
124         }
125
126         @Override
127         public Iterator<Category> getAllCategoriesIterator () throws FacesException {
128                 try {
129                         return this.remote.getAllCategoriesIterator();
130                 } catch (final RemoteException ex) {
131                         // Continue to throw
132                         throw new FacesException(ex);
133                 }
134         }
135
136         @Override
137         public Deque<Category> getAllCategories () throws FacesException {
138                 try {
139                         return this.remote.getAllCategories();
140                 } catch (final RemoteException ex) {
141                         // Continue to throw
142                         throw new FacesException(ex);
143                 }
144         }
145
146         @Override
147         public void doAdminAddCategory (final Category category) throws FacesException {
148                 try {
149                         this.remote.doAdminAddCategory(category);
150                 } catch (final IOException | CategoryTitleAlreadyUsedException ex) {
151                         // Continue to throw
152                         throw new FacesException(ex);
153                 }
154         }
155
156         @Override
157         public void doAdminAddProduct (final Product product) throws FacesException {
158                 try {
159                         this.remote.doAdminAddProduct(product);
160                 } catch (final IOException | ProductTitleAlreadyUsedException ex) {
161                         // Continue to throw
162                         throw new FacesException(ex);
163                 }
164         }
165 }