*/
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
/**
* 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 shop;
+ 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
* @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.shop = (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 RuntimeException {
// Call super init first
}
@Override
- public Iterator<Product> getAvailableProductsIterator () throws FacesException {
- try {
- return this.getShop().getAvailableProductsIterator();
- } catch (final RemoteException ex) {
- // Continue to throw
- throw new FacesException(ex);
- }
- }
-
- @Override
- public Iterator<Product> getAllProductsIterator () throws FacesException {
+ public Queue<Product> getAvailableProducts () throws FacesException {
try {
- return this.getShop().getAllProductsIterator();
+ return this.getProduct().getAvailableProducts();
} catch (final RemoteException ex) {
// Continue to throw
throw new FacesException(ex);
}
@Override
- public Deque<Product> getAvailableProducts () throws FacesException {
+ public Queue<Category> getAllCategories () throws FacesException {
try {
- return this.getShop().getAvailableProducts();
- } catch (final RemoteException ex) {
- // Continue to throw
- throw new FacesException(ex);
- }
- }
-
- @Override
- public Deque<Product> getAllProducts () throws FacesException {
- try {
- return this.getShop().getAllProducts();
- } catch (final RemoteException ex) {
- // Continue to throw
- throw new FacesException(ex);
- }
- }
+ // Fake zero category
+ Category c = new ProductCategory(0L, "Ist oberste Kategorie", 0L);
- @Override
- public Iterator<Category> getAllCategoriesIterator () throws FacesException {
- try {
- return this.getShop().getAllCategoriesIterator();
- } catch (final RemoteException ex) {
- // Continue to throw
- throw new FacesException(ex);
- }
- }
+ // Get List back
+ Deque<Category> deque = this.getCategory().getAllCategories();
- @Override
- public Deque<Category> getAllCategories () throws FacesException {
- try {
- return this.getShop().getAllCategories();
- } catch (final RemoteException ex) {
- // Continue to throw
- throw new FacesException(ex);
- }
- }
+ // Add fake category
+ deque.addFirst(c);
- @Override
- public void doAdminAddCategory (final Category category) throws FacesException {
- try {
- this.getShop().doAdminAddCategory(category);
- } catch (final IOException | CategoryTitleAlreadyUsedException ex) {
+ // Return it
+ return deque;
+ } catch (final SQLException ex) {
// Continue to throw
throw new FacesException(ex);
}
}
- @Override
- public void doAdminAddProduct (final Product product) throws FacesException {
- try {
- this.getShop().doAdminAddProduct(product);
- } catch (final IOException | ProductTitleAlreadyUsedException ex) {
- // Continue to throw
- throw new FacesException(ex);
- }
+ /**
+ * Getter for shop remote bean
+ *
+ * @return Remote shop bean
+ */
+ private CategorySessionBeanRemote getCategory () {
+ return this.category;
}
/**
*
* @return Remote shop bean
*/
- private ShopSessionBeanRemote getShop () {
- return this.shop;
+ private ProductSessionBeanRemote getProduct () {
+ return this.product;
}
}