X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjava%2Forg%2Fmxchange%2Fpizzaapplication%2Fbeans%2Fcontroller%2FPizzaServiceWebBean.java;h=c184dbcf4fb2d503cb2c5f78f887c24eb9606299;hb=fd5a4cc816eb64e69093320ae114cfce3629e3a7;hp=06465f622e15bcc63537bc4afa02e1b9b63bb763;hpb=6b990c93ddd91ec8bfdd03283e6af111595c9ed4;p=pizzaservice-war.git diff --git a/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceWebBean.java index 06465f62..c184dbcf 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceWebBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceWebBean.java @@ -16,24 +16,22 @@ */ package org.mxchange.pizzaapplication.beans.controller; -import java.io.IOException; import java.rmi.RemoteException; import java.sql.SQLException; import java.util.Deque; -import java.util.Iterator; +import java.util.Queue; import javax.annotation.PostConstruct; -import javax.ejb.EJB; import javax.enterprise.context.SessionScoped; import javax.faces.FacesException; import javax.inject.Named; import javax.naming.InitialContext; import javax.naming.NamingException; import org.mxchange.jcoreee.beans.BaseFrameworkBean; -import org.mxchange.jshopcore.exceptions.CategoryTitleAlreadyUsedException; -import org.mxchange.jshopcore.exceptions.ProductTitleAlreadyUsedException; import org.mxchange.jshopcore.model.category.Category; +import org.mxchange.jshopcore.model.category.CategorySessionBeanRemote; +import org.mxchange.jshopcore.model.category.ProductCategory; import org.mxchange.jshopcore.model.product.Product; -import org.mxchange.jshopeelib.beans.remote.shop.ShopSessionBeanRemote; +import org.mxchange.jshopcore.model.product.ProductSessionBeanRemote; /** * Main application class @@ -46,21 +44,17 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe /** * Serial id */ - private static final long serialVersionUID = 58137539530279L; + private static final long serialVersionUID = 58_137_539_530_279L; /** - * Remote bean + * Remote bean for categories */ - @EJB - private final ShopSessionBeanRemote remote; + private final CategorySessionBeanRemote category; /** - * Initializer block + * Remote bean for products */ - { - // Get new application instance - this.getLogger().debug("INITIALIZER!"); //NOI18N - } + private final ProductSessionBeanRemote product; /** * Default constructor @@ -68,102 +62,67 @@ public class PizzaServiceWebBean extends BaseFrameworkBean implements PizzaWebBe * @throws javax.naming.NamingException Something happened here? */ public PizzaServiceWebBean () throws NamingException { - this.getLogger().trace("CALLED!"); //NOI18N - // Get initial context InitialContext context = new InitialContext(); // Try to lookup the bean - this.remote = (ShopSessionBeanRemote) context.lookup("ejb/stateless-shop"); //NOI18N + this.category = (CategorySessionBeanRemote) context.lookup("ejb/stateless-category"); //NOI18N + + // Try to lookup the bean + this.product = (ProductSessionBeanRemote) context.lookup("ejb/stateless-product"); //NOI18N } - @Override @PostConstruct - public void init () throws FacesException { - // Trace message - this.getLogger().trace("CALLED!"); //NOI18N - - // Super call - super.init(); + public void init () throws RuntimeException { + // Call super init first + super.genericInit(); } @Override - public Iterator getAvailableProductsIterator () throws RemoteException { + public Queue getAvailableProducts () throws FacesException { try { - return this.remote.getAvailableProductsIterator(); - } catch (final IOException | SQLException ex) { + return this.getProduct().getAvailableProducts(); + } catch (final RemoteException ex) { // Continue to throw - throw new RemoteException("getAvailableProductsIterator() failed", ex); + throw new FacesException(ex); } } @Override - public Iterator getAllProductsIterator () throws RemoteException { + public Queue getAllCategories () throws FacesException { try { - return this.remote.getAllProductsIterator(); - } catch (final IOException | SQLException ex) { - // Continue to throw - throw new RemoteException("getAllProductsIterator() failed.", ex); - } - } + // Fake zero category + Category c = new ProductCategory(0L, "Ist oberste Kategorie", 0L); - @Override - public Deque getAvailableProducts () throws RemoteException { - try { - return this.remote.getAvailableProducts(); - } catch (final IOException | SQLException ex) { - // Continue to throw - throw new RemoteException("getAvailableProducts() failed.", ex); - } - } + // Get List back + Deque deque = this.getCategory().getAllCategories(); - @Override - public Deque getAllProducts () throws RemoteException { - try { - return this.remote.getAllProducts(); - } catch (final IOException | SQLException ex) { - // Continue to throw - throw new RemoteException("getAllProducts() failed", ex); - } - } + // Add fake category + deque.addFirst(c); - @Override - public Iterator getAllCategoriesIterator () throws RemoteException { - try { - return this.remote.getAllCategoriesIterator(); - } catch (final IOException | SQLException ex) { - // Continue to throw - throw new RemoteException("getAllCategoriesIterator() failed.", ex); - } - } - - @Override - public Deque getAllCategories () throws RemoteException { - try { - return this.remote.getAllCategories(); - } catch (final IOException | SQLException ex) { + // Return it + return deque; + } catch (final SQLException ex) { // Continue to throw - throw new RemoteException("getAllCategories() failed.", ex); + throw new FacesException(ex); } } - @Override - public void doAdminAddCategory (final Category category) throws RemoteException { - try { - this.remote.doAdminAddCategory(category); - } catch (final IOException | SQLException | CategoryTitleAlreadyUsedException ex) { - // Continue to throw - throw new RemoteException("doAdminAddCategory() failed.", ex); - } + /** + * Getter for shop remote bean + * + * @return Remote shop bean + */ + private CategorySessionBeanRemote getCategory () { + return this.category; } - @Override - public void doAdminAddProduct (final Product product) throws RemoteException { - try { - this.remote.doAdminAddProduct(product); - } catch (final IOException | SQLException | ProductTitleAlreadyUsedException ex) { - // Continue to throw - throw new RemoteException("doAdminAddProduct() failed.", ex); - } + /** + * Getter for shop remote bean + * + * @return Remote shop bean + */ + private ProductSessionBeanRemote getProduct () { + return this.product; } }