]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Continued with project:
authorRoland Haeder <roland@mxchange.org>
Thu, 27 Aug 2015 21:52:56 +0000 (23:52 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 27 Aug 2015 21:52:56 +0000 (23:52 +0200)
- added method getProduct()
- added method getLast()
- added method getAll() (again?)
- Used BasketBean instead of Basket
- Yepp, JSPs don't support @Inject and @PostConstruct ... :-(
- added getLastNumRows() which deligates this call to jcore's method
- implemented MiniBasketTag (a bit broken)
- added missing language resourced
- updated jcore.jar
Signed-off-by:Roland Häder <roland@mxchange.org>

18 files changed:
lib/jcore.jar
src/java/org/mxchange/localization/bundle_de_DE.properties
src/java/org/mxchange/localization/bundle_en_US.properties
src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java
src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java
src/java/org/mxchange/pizzaapplication/basket/BaseBasket.java
src/java/org/mxchange/pizzaapplication/basket/Basket.java
src/java/org/mxchange/pizzaapplication/beans/PizzaBean.java
src/java/org/mxchange/pizzaapplication/beans/PizzaServiceBean.java
src/java/org/mxchange/pizzaapplication/beans/basket/BasketBean.java
src/java/org/mxchange/pizzaapplication/beans/basket/ItemBasketBean.java
src/java/org/mxchange/pizzaapplication/database/frontend/basket/BasketDatabaseFrontend.java
src/java/org/mxchange/pizzaapplication/database/frontend/basket/BasketFrontend.java
src/java/org/mxchange/pizzaapplication/database/frontend/product/PizzaProductDatabaseFrontend.java
src/java/org/mxchange/pizzaapplication/database/frontend/product/ProductFrontend.java
src/java/org/mxchange/pizzaapplication/filter/servlet/basket/BasketItemAddedFilter.java
src/java/org/mxchange/pizzaapplication/tags/basket/MiniBasketTag.java
web/form_handler/add_item.jsp

index 11b967e308d9a1e68b2d54167d9f1ae0f614b798..d787a20098c4086cdc60ddcf3a42bd11708845c0 100644 (file)
Binary files a/lib/jcore.jar and b/lib/jcore.jar differ
index 376c558726725062742c64a5c66c296add4a835a..35d75a9f06ae4c153dbdeec612003997163b5ecf 100644 (file)
@@ -17,3 +17,6 @@ BaseContact.gender.male.text=Herr
 BaseContact.gender.female.text=Frau
 BaseContact.gender.company.text=Firma
 MiniBasketTag.basket_is_empty=Der Warenkorb ist leer.
+MiniBasketTag.last_item=Zuletzt hinzugef&uuml;gt: {0}
+MiniBasketTag.additional_items=Es befinden sich noch {0} weitere Produkte im Warenkorb.
+MiniBasketTag.to_basket=Zum Warenkorb
index d61b69f41abfad86674ac45f433647aaf1bbfe6e..07e8210fff04912b6dfe91ee9511a9b9d69a5367 100644 (file)
@@ -17,3 +17,6 @@ BaseContact.gender.male.text=Mr.
 BaseContact.gender.female.text=Mrs.
 BaseContact.gender.company.text=Company
 MiniBasketTag.basket_is_empty=Der Warenkorb ist leer.
+MiniBasketTag.last_item=Zuletzt hinzugef&uuml;gt: {0}
+MiniBasketTag.additional_items=Es befinden sich noch {0} weitere Produkte im Warenkorb.
+MiniBasketTag.to_basket=Zum Warenkorb
index dcb6060fbf0a55a02c0263802172d38c32c8fcd7..8515db3f9044889c1211b5913697d3fadfdb998c 100644 (file)
@@ -30,6 +30,7 @@ import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
 import org.mxchange.pizzaapplication.category.Category;
 import org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException;
 import org.mxchange.pizzaapplication.exceptions.ProductTitleAlreadyUsedException;
+import org.mxchange.pizzaapplication.item.AddableBasketItem;
 import org.mxchange.pizzaapplication.product.Product;
 
 /**
@@ -341,4 +342,12 @@ public interface PizzaApplication extends Application {
         * @throws ServletException If something unexpected happened
         */
        public void doAdminHandleCategoryForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException;
+
+       /**
+        * Some "getter" for a Product instance from given item
+        * @param item Item instance
+        * @return A Product instance
+        * @throws ServletException If something unexpected happened
+        */
+       public Product getProduct (final AddableBasketItem item) throws ServletException;
 }
index b7f057c0c9e22d5a05c696ea079cf6428ae7add1..ff05279f08b30543367e76868062bb17e36e0a50 100644 (file)
@@ -38,6 +38,7 @@ import org.mxchange.pizzaapplication.database.frontend.product.PizzaProductDatab
 import org.mxchange.pizzaapplication.database.frontend.product.ProductFrontend;
 import org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException;
 import org.mxchange.pizzaapplication.exceptions.ProductTitleAlreadyUsedException;
+import org.mxchange.pizzaapplication.item.AddableBasketItem;
 import org.mxchange.pizzaapplication.product.Product;
 
 /**
@@ -1577,4 +1578,36 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
                // Return it
                return isUsed;
        }
+
+       @Override
+       public Product getProduct (final AddableBasketItem item) throws ServletException {
+               // Trace message
+               this.getLogger().trace("item=" + item + " - CALLED!");
+
+               // item should not be null
+               if (null == item) {
+                       // Abort here
+                       throw new NullPointerException("item is null");
+               } else if (null == this.productFrontend) {
+                       // Abort here
+                       throw new NullPointerException("productFrontend is null");
+               }
+
+               // Init product instance
+               Product product = null;
+
+               try {
+                       // Call frontend
+                       product = this.productFrontend.getProduct(item);
+               } catch (final SQLException | IOException | BadTokenException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
+                       // Continue to throw
+                       throw new ServletException(ex);
+               }
+
+               // Trace message
+               this.getLogger().trace("product=" + product + " - EXIT!");
+
+               // Return it
+               return product;
+       }
 }
index 3645d04cb1adbcdb53c039a4986cbe5b80d50669..58ff9cf657e19ff452e3c0ecfabed26d43f13db9 100644 (file)
@@ -21,6 +21,7 @@ import java.io.Serializable;
 import java.lang.reflect.InvocationTargetException;
 import java.sql.SQLException;
 import java.text.MessageFormat;
+import java.util.Map;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpSession;
 import org.mxchange.jcore.exceptions.BadTokenException;
@@ -163,4 +164,32 @@ public class BaseBasket<T extends AddableBasketItem> extends BasePizzaServiceSys
                // Return it
                return isAdded;
        }
+
+       @Override
+       public Map<Long, T> getAll () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+               // Trace message
+               this.getLogger().trace("CALLED!");
+
+               // Init map
+               @SuppressWarnings("unchecked")
+               Map<Long, T> map = (Map<Long, T>) ((BasketFrontend) this.getFrontend()).getAll();
+
+               // Trace message
+               this.getLogger().trace("map=" + map);
+
+               // Return it
+               return map;
+       }
+
+       @Override
+       public AddableBasketItem getLast () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+               // Deligate to frontend
+               return ((BasketFrontend) this.getFrontend()).getLast();
+       }
+
+       @Override
+       public int getLastNumRows () {
+               // Deligate to frontend
+               return this.getFrontend().getLastNumRows();
+       }
 }
index b583b5302521906f6125038473d7b717646c9d6e..462d46684d3a2446ef552c94fae4208e9c18be69 100644 (file)
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.io.Serializable;
 import java.lang.reflect.InvocationTargetException;
 import java.sql.SQLException;
+import java.util.Map;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpSession;
 import org.mxchange.jcore.FrameworkInterface;
@@ -107,4 +108,39 @@ public interface Basket<T extends AddableBasketItem> extends Serializable, Frame
         * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
         */
        public void init (final ServletContext context, final HttpSession session) throws UnsupportedDatabaseBackendException, SQLException, IOException, BadTokenException;
+
+       /**
+        * Some "getter" for all entries in this basket
+        *
+        * @return Map on all basket items
+        * @throws java.io.IOException If an IO error occurs
+        * @throws java.sql.SQLException If an SQL error occurs
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+        * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If a corrupted database file was found
+        * @throws java.lang.NoSuchMethodException If a method was not found
+        * @throws java.lang.IllegalAccessException If the invoked method is not public
+        * @throws java.lang.reflect.InvocationTargetException If anything else happened?
+        */
+       public Map<Long, T> getAll () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
+
+       /**
+        * Getter for last entry
+        *
+        * @return Last added item in basket
+        * @throws java.io.IOException If an IO error occurs
+        * @throws java.sql.SQLException If an SQL error occurs
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+        * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If a corrupted database file was found
+        * @throws java.lang.NoSuchMethodException If a method was not found
+        * @throws java.lang.IllegalAccessException If the invoked method is not public
+        * @throws java.lang.reflect.InvocationTargetException If anything else happened?
+        */
+       public AddableBasketItem getLast () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
+
+       /**
+        * Getter for last num rows
+        * 
+        * @return Last num rows
+        */
+       public int getLastNumRows ();
 }
index 539b0e7b46b9a8eb873b146a7e7162aada62ea03..84a356006a16f27326b16b445d0cded5756f7c64 100644 (file)
@@ -29,6 +29,7 @@ import org.mxchange.pizzaapplication.beans.basket.BasketBean;
 import org.mxchange.pizzaapplication.category.Category;
 import org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException;
 import org.mxchange.pizzaapplication.exceptions.ProductTitleAlreadyUsedException;
+import org.mxchange.pizzaapplication.item.AddableBasketItem;
 import org.mxchange.pizzaapplication.product.Product;
 
 /**
@@ -334,4 +335,12 @@ public interface PizzaBean extends Serializable {
         * @param application the application to set
         */
        public void setApplication (final ServletContext application);
+
+       /**
+        * Some "getter" for a product from given item
+        * @param item Item instance
+        * @return A Product instance
+        * @throws javax.servlet.ServletException If something bad happens
+        */
+       public Product getProduct (final AddableBasketItem item) throws ServletException;
 }
index fbbb338f96d49aa6a1ced7b45954ff105a76af50..d234d668cb88deca35af4ad54ad63e639e8449ea 100644 (file)
@@ -39,6 +39,7 @@ import org.mxchange.pizzaapplication.beans.basket.BasketBean;
 import org.mxchange.pizzaapplication.category.Category;
 import org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException;
 import org.mxchange.pizzaapplication.exceptions.ProductTitleAlreadyUsedException;
+import org.mxchange.pizzaapplication.item.AddableBasketItem;
 import org.mxchange.pizzaapplication.product.Product;
 
 /**
@@ -418,7 +419,7 @@ public class PizzaServiceBean implements PizzaBean {
        @Override
        public BasketBean getBasket () {
                // Trace message
-               this.getLogger().trace("basked=" + this.basket + " - EXIT!");
+               this.getLogger().trace("basket=" + this.basket + " - EXIT!");
 
                // Return it
                return this.basket;
@@ -430,7 +431,7 @@ public class PizzaServiceBean implements PizzaBean {
        @Override
        public void setBasket (final BasketBean basket) {
                // Trace message
-               this.getLogger().trace("basked=" + basket + " - CALLED!");
+               this.getLogger().trace("basket=" + basket + " - CALLED!");
 
                // Set it here
                this.basket = basket;
@@ -459,4 +460,10 @@ public class PizzaServiceBean implements PizzaBean {
                // Set it here
                this.application = application;
        }
+
+       @Override
+       public Product getProduct (final AddableBasketItem item) throws ServletException {
+               // Deligate to application
+               return this.app.getProduct(item);
+       }
 }
index c37e6322b0b01d7af0ff25757af196e169da5025..490740f71594ee18fa0cfdd4babe7d4fabf52ff3 100644 (file)
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.io.Serializable;
 import java.lang.reflect.InvocationTargetException;
 import java.sql.SQLException;
+import java.util.Map;
 import javax.faces.FacesException;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpSession;
@@ -135,4 +136,39 @@ public interface BasketBean extends Serializable {
         * @param session the session to set
         */
        public void setSession (final HttpSession session);
+
+       /**
+        * Some "getter" for all entries in this basket
+        *
+        * @return Map on all basket items
+        * @throws java.io.IOException If an IO error occurs
+        * @throws java.sql.SQLException If an SQL error occurs
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+        * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If a corrupted database file was found
+        * @throws java.lang.NoSuchMethodException If a method was not found
+        * @throws java.lang.IllegalAccessException If the invoked method is not public
+        * @throws java.lang.reflect.InvocationTargetException If anything else happened?
+        */
+       public Map<Long, AddableBasketItem> getAll () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
+
+       /**
+        * Getter for last entry
+        *
+        * @return Last added item in basket
+        * @throws java.io.IOException If an IO error occurs
+        * @throws java.sql.SQLException If an SQL error occurs
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+        * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If a corrupted database file was found
+        * @throws java.lang.NoSuchMethodException If a method was not found
+        * @throws java.lang.IllegalAccessException If the invoked method is not public
+        * @throws java.lang.reflect.InvocationTargetException If anything else happened?
+        */
+       public AddableBasketItem getLast () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
+
+       /**
+        * Getter for last num rows
+        * 
+        * @return Last num rows
+        */
+       public int getLastNumRows ();
 }
index 1a8f76638a35f892ae10461912bb8e8ac8a9afa6..ce19d15102e582a8b7fd3bf6f4a319a31d636257 100644 (file)
@@ -19,6 +19,7 @@ package org.mxchange.pizzaapplication.beans.basket;
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.sql.SQLException;
+import java.util.Map;
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.SessionScoped;
 import javax.faces.FacesException;
@@ -174,4 +175,22 @@ public class ItemBasketBean implements BasketBean {
        public void setSession (final HttpSession session) {
                this.session = session;
        }
+
+       @Override
+       public Map<Long, AddableBasketItem> getAll () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+               // Deligate to basket instance
+               return this.basket.getAll();
+       }
+
+       @Override
+       public AddableBasketItem getLast () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+               // Deligate to basket instance
+               return this.basket.getLast();
+       }
+
+       @Override
+       public int getLastNumRows () {
+               // Delegate to basket
+               return this.basket.getLastNumRows();
+       }
 }
index fb563d84721e0301e1995c57408464e8f436ccb9..28d4033bb0cd74907ee536c2999960914d73b010 100644 (file)
@@ -21,7 +21,9 @@ import java.lang.reflect.InvocationTargetException;
 import java.sql.SQLException;
 import java.text.MessageFormat;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.Map;
+import java.util.Set;
 import org.mxchange.jcore.criteria.logical.and.AndLogicalMatcher;
 import org.mxchange.jcore.criteria.searchable.SearchCriteria;
 import org.mxchange.jcore.criteria.searchable.SearchableCriteria;
@@ -409,4 +411,137 @@ public class BasketDatabaseFrontend extends BaseDatabaseFrontend implements Bask
                // Return it
                return result;
        }
+
+       @Override
+       public Map<Long, AddableBasketItem> getAll () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+               // Trace message
+               this.getLogger().trace("CALLED!");
+
+               // Session should be set here
+               if (this.getSessionId() == null) {
+                       // Abort here
+                       throw new NullPointerException("sessionId is null");
+               }
+
+               // Init seaerch instance
+               SearchableCriteria criteria = new SearchCriteria();
+
+               // Add only session id
+               criteria.addCriteria(BasketDatabaseConstants.COLUMN_SESSION_ID, this.getSessionId());
+
+               // Now run it on backend
+               Result<? extends Storeable> result = this.getBackend().doSelectByCriteria(criteria);
+
+               // Now convert it to a map
+               Set<? extends Storeable> set = result.resultSet();
+
+               // Debug message
+               this.getLogger().debug("set=" + set);
+
+               // Init map
+               Map<Long, AddableBasketItem> map = new LinkedHashMap<>(set.size());
+
+               // Add all entries
+               for (final Storeable storeable : set) {
+                       // Debug message
+                       this.getLogger().debug("storeable=" + storeable);
+
+                       // Check on AddableBasketItem
+                       if (!(storeable instanceof AddableBasketItem)) {
+                               // Not correct instance
+                               throw new IllegalStateException("storeable=" + storeable + " does not implement AddableBasketItem.");
+                       }
+
+                       // Get id
+                       Long id = ((AddableBasketItem) storeable).getItemId();
+
+                       // Debug message
+                       this.getLogger().debug("id=" + id);
+
+                       // Add it
+                       map.put(id, (AddableBasketItem) storeable);
+               }
+
+               // Trace message
+               this.getLogger().trace("map=" + map + " - EXIT!");
+
+               // Return it
+               return map;
+       }
+
+       @Override
+       public AddableBasketItem getLast () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+               // Trace message
+               this.getLogger().trace("CALLED!");
+
+               // Session should be set here
+               if (this.getSessionId() == null) {
+                       // Abort here
+                       throw new NullPointerException("sessionId is null");
+               }
+
+               // Init seaerch instance
+               SearchableCriteria criteria = new SearchCriteria();
+
+               // Add only session id
+               criteria.addCriteria(BasketDatabaseConstants.COLUMN_SESSION_ID, this.getSessionId());
+
+               // Get number of rows
+               int rows = this.getBackend().numRows(criteria);
+
+               // Debug message
+               this.getLogger().debug("rows=" + rows);
+
+               // Nothing found?
+               if (rows == 0) {
+                       // Debug message
+                       this.getLogger().debug("Nothing found, returning null ... - EXIT!");
+
+                       // Return null
+                       return null;
+               }
+
+               // Debug message
+               this.getLogger().debug("rows=" + rows);
+
+               // Set last num rows
+               this.setLastNumRows(rows);
+
+               // Now set this -1 as skip value and limit to 1
+               criteria.setSkip(rows);
+               criteria.setLimit(1);
+
+               // And run it ...
+               Result<? extends Storeable> result = this.getBackend().doSelectByCriteria(criteria);
+
+               // Debug message
+               this.getLogger().debug("result=" + result);
+
+               // Init instance
+               AddableBasketItem item;
+
+               // There should be something!
+               if (!result.hasNext()) {
+                       // Something isn't working here ...
+                       throw new IllegalStateException("result has zero entries, but rows=" + rows);
+               }
+
+               // Get next element
+               Storeable storeable = result.next();
+
+               // Is it still castable?
+               if (!(storeable instanceof AddableBasketItem)) {
+                       // Opps!
+                       throw new IllegalStateException("storeable=" + storeable + " does not implement AddableBasketItem.");
+               }
+
+               // Cast it
+               item = (AddableBasketItem) storeable;
+
+               // Trace message
+               this.getLogger().trace("item=" + item + " - EXIT!");
+
+               // Return it
+               return item;
+       }
 }
index 45d5326043f0781260d4925e1754c6f7ec896816..75391e81f6be84b4a9d3a1c90c33da0ec4c1cad4 100644 (file)
@@ -19,6 +19,7 @@ package org.mxchange.pizzaapplication.database.frontend.basket;
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.sql.SQLException;
+import java.util.Map;
 import org.mxchange.jcore.database.frontend.DatabaseFrontend;
 import org.mxchange.jcore.exceptions.BadTokenException;
 import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
@@ -87,4 +88,32 @@ public interface BasketFrontend extends DatabaseFrontend {
         * @throws java.lang.reflect.InvocationTargetException If anything else happened?
         */
        public boolean isItemAdded (final AddableBasketItem item, final String sessionId) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
+
+       /**
+        * Some "getter" for all entries in this basket
+        *
+        * @return Map on all basket items
+        * @throws java.io.IOException If an IO error occurs
+        * @throws java.sql.SQLException If an SQL error occurs
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+        * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If a corrupted database file was found
+        * @throws java.lang.NoSuchMethodException If a method was not found
+        * @throws java.lang.IllegalAccessException If the invoked method is not public
+        * @throws java.lang.reflect.InvocationTargetException If anything else happened?
+        */
+       public Map<Long, AddableBasketItem> getAll () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
+
+       /**
+        * Getter for last entry
+        *
+        * @return Last added item in basket
+        * @throws java.io.IOException If an IO error occurs
+        * @throws java.sql.SQLException If an SQL error occurs
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
+        * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If a corrupted database file was found
+        * @throws java.lang.NoSuchMethodException If a method was not found
+        * @throws java.lang.IllegalAccessException If the invoked method is not public
+        * @throws java.lang.reflect.InvocationTargetException If anything else happened?
+        */
+       public AddableBasketItem getLast () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;
 }
index 1c9008a9b36c6266dfdf61a38eef9eb3931a3b05..768757dd105293406deb6dabc57b578e36d8ae7c 100644 (file)
@@ -32,6 +32,7 @@ import org.mxchange.jcore.database.storage.Storeable;
 import org.mxchange.jcore.exceptions.BadTokenException;
 import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
 import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
+import org.mxchange.pizzaapplication.item.AddableBasketItem;
 import org.mxchange.pizzaapplication.product.Product;
 import org.mxchange.pizzaapplication.product.pizza.PizzaProduct;
 
@@ -44,7 +45,9 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement
 
        /**
         * Default constrcutor
-        * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the configured backend is not supported
+        *
+        * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException
+        * If the configured backend is not supported
         * @throws java.sql.SQLException If any SQL error occurs
         */
        public PizzaProductDatabaseFrontend () throws UnsupportedDatabaseBackendException, SQLException {
@@ -60,6 +63,7 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement
 
        /**
         * Adds product to database by given title, price and category id
+        *
         * @param title Product title
         * @param price Product price
         * @param category Product category id
@@ -70,7 +74,7 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement
        public void addProduct (final String title, final Float price, final Long category, final Boolean available) throws SQLException, IOException {
                // Trace message
                this.getLogger().trace(MessageFormat.format("title={0},price={1},category={2} - CALLED!", title, price, category)); //NOI18N
-               
+
                // Title should not be null
                if (null == title) {
                        // Abort here
@@ -85,30 +89,30 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement
                        // Abort here
                        throw new NullPointerException("available is null"); //NOI18N
                }
-               
+
                // Clear dataset from previous usage
                this.clearDataSet();
-               
+
                // Add title and parent
                this.addToDataSet(ProductFrontend.COLUMN_TITLE, title);
                this.addToDataSet(ProductFrontend.COLUMN_PRICE, price);
                this.addToDataSet(ProductFrontend.COLUMN_CATEGORY, category);
                this.addToDataSet(ProductFrontend.COLUMN_AVAILABLE, available);
-               
+
                // Handle this over to the backend
                // @todo Nothing is done yet!
                Result<? extends Storeable> result = this.doInsertDataSet();
-               
+
                // Debug message
                this.getLogger().debug(MessageFormat.format("result={0}", result)); //NOI18N
-               
+
                // Trace message
                this.getLogger().trace("EXIT!"); //NOI18N
        }
 
        /**
         * Shuts down the database layer
-        * 
+        *
         * @throws java.sql.SQLException If an SQL error occurs
         * @throws java.io.IOException If any IO error occurs
         */
@@ -158,11 +162,12 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement
         *
         * @return Iterator on all products
         * @throws java.io.IOException If any IO error occurs
-        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found in a file-based database backend's file ... ;-)
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token
+        * was found in a file-based database backend's file ... ;-)
         * @throws java.sql.SQLException If any SQL errors occur
         */
        @Override
-       @SuppressWarnings ("unchecked")
+       @SuppressWarnings("unchecked")
        public Iterator<Product> getAllProducts () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
                // Trace message
                this.getLogger().trace("CALLED!"); //NOI18N
@@ -187,7 +192,7 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement
        }
 
        @Override
-       @SuppressWarnings ("unchecked")
+       @SuppressWarnings("unchecked")
        public Iterator<Product> getAvailableProducts () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
                // Trace message
                this.getLogger().trace("CALLED!"); //NOI18N
@@ -197,7 +202,7 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement
 
                // Add criteria
                criteria.addCriteria(ProductFrontend.COLUMN_AVAILABLE, true);
-               
+
                // Run the query
                Result<? extends Storeable> result = this.getBackend().doSelectByCriteria(criteria);
 
@@ -278,43 +283,46 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement
         * @param title Product title
         * @return Whether the product title is already used
         * @throws java.io.IOException If any IO error occurs
-        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found in a file-based database backend's file ... ;-)
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token
+        * was found in a file-based database backend's file ... ;-)
         * @throws java.sql.SQLException If any SQL errors occur
         */
        @Override
        public boolean isProductTitleUsed (String title) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
                // Trace message
                this.getLogger().trace(MessageFormat.format("title={0} - CALLED!", title)); //NOI18N
-               
+
                // Get search criteria
                SearchableCriteria criteria = new SearchCriteria();
-               
+
                // Add criteria
                criteria.addCriteria(ProductFrontend.COLUMN_TITLE, title);
-               
+
                // Only one entry is find
                criteria.setLimit(1);
-               
+
                // Run it on backend
                Result<? extends Storeable> result = this.getBackend().doSelectByCriteria(criteria);
-               
+
                // Debug log
                this.getLogger().debug(MessageFormat.format("result({0}={1}", result, result.size())); //NOI18N
-               
+
                // Now check size of the result
                boolean isFound = (result.size() == 1);
-               
+
                // Trace message
                this.getLogger().trace(MessageFormat.format("isFound={0} - EXIT!", isFound)); //NOI18N
-               
+
                // Return it
                return isFound;
        }
 
        /**
-        * Converts the given map into a Storeable instance, depending on which class implements it. All
-        * keys are being interpreted as class fields/attributes and their respective setters are being searched for. As
-        * this method may fail to find one or access it, this method throws some exception.
+        * Converts the given map into a Storeable instance, depending on which
+        * class implements it. All keys are being interpreted as class
+        * fields/attributes and their respective setters are being searched for. As
+        * this method may fail to find one or access it, this method throws some
+        * exception.
         *
         * @param map Map instance to convert to Storeable
         * @return An instance of a Storeable implementation
@@ -360,4 +368,55 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement
                // Return it
                return instance;
        }
+
+       @Override
+       public Product getProduct (final AddableBasketItem item) throws SQLException, IOException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+               // Trace message
+               this.getLogger().trace("item=" + item + " - CALLED!");
+
+               // item should not be null
+               if (null == item) {
+                       // Abort here
+                       throw new NullPointerException("item is null");
+               }
+
+               // Get search criteria
+               SearchableCriteria criteria = new SearchCriteria();
+
+               // Add criteria
+               criteria.addCriteria(ProductFrontend.COLUMN_ITEM_ID, item.getItemId());
+
+               // Only one entry is find
+               criteria.setLimit(1);
+
+               // Run it on backend
+               Result<? extends Storeable> result = this.getBackend().doSelectByCriteria(criteria);
+
+               // Debug log
+               this.getLogger().debug(MessageFormat.format("result({0}={1}", result, result.size())); //NOI18N
+
+               // Init product instance
+               Product product = null;
+
+               // Is there one entry?
+               if (result.hasNext()) {
+                       // Get item
+                       Storeable storeable = result.next();
+
+                       // Is it Product?
+                       if (!(storeable instanceof Product)) {
+                               // Cannot cast!
+                               throw new IllegalStateException("storeable=" + storeable + " does not implement Product.");
+                       }
+
+                       // Cast it
+                       product = (Product) storeable;
+               }
+
+               // Trace message
+               this.getLogger().trace("product=" + product + " - EXIT!");
+
+               // Return it
+               return product;
+       }
 }
index 6cc261497d8b9854f96f5ab41116849a714eed20..6e71d77cb5bcec74b8f85e4bd34430710136e3ab 100644 (file)
@@ -23,6 +23,7 @@ import java.util.Iterator;
 import org.mxchange.jcore.database.frontend.DatabaseFrontend;
 import org.mxchange.jcore.exceptions.BadTokenException;
 import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
+import org.mxchange.pizzaapplication.item.AddableBasketItem;
 import org.mxchange.pizzaapplication.product.Product;
 
 /**
@@ -105,4 +106,19 @@ public interface ProductFrontend extends DatabaseFrontend {
         * @throws java.lang.reflect.InvocationTargetException Any other problems?
         */
        public boolean isProductTitleUsed (String title) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException;
+
+       /**
+        * Some "getter" for a Product instance from given item
+        *
+        * @param item Item instance
+        * @return  A Product instance
+        * @throws java.io.IOException If any IO error occurs
+        * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found in a file-based database backend's file ... ;-)
+        * @throws java.sql.SQLException If any SQL errors occur
+        * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged
+        * @throws java.lang.NoSuchMethodException If a method was not found
+        * @throws java.lang.IllegalAccessException If the method cannot be accessed
+        * @throws java.lang.reflect.InvocationTargetException Any other problems?
+        */
+       public Product getProduct (final AddableBasketItem item) throws SQLException, IOException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException;
 }
index 46ff6fa291cf9ff15c63ae320331923288e611ed..367a904bf3e7c102749c75472d6adf5f05a6c2f1 100644 (file)
@@ -29,7 +29,8 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 import org.mxchange.jcore.exceptions.BadTokenException;
 import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
-import org.mxchange.pizzaapplication.basket.Basket;
+import org.mxchange.pizzaapplication.beans.PizzaBean;
+import org.mxchange.pizzaapplication.beans.basket.BasketBean;
 import org.mxchange.pizzaapplication.filter.servlet.BaseServletFilter;
 import org.mxchange.pizzaapplication.item.AddableBasketItem;
 
@@ -83,7 +84,7 @@ public class BasketItemAddedFilter extends BaseServletFilter implements Filter {
                this.getLogger().debug(MessageFormat.format("item.id={0},item.itemId={1},item.itemType={2},item.amount={3}", item.getId(), item.getItemId(), item.getItemType(), item.getAmount())); //NOI18N
 
                // Init instance
-               Basket<AddableBasketItem> basket;
+               BasketBean basket;
                try {
                        // Get session instance
                        HttpSession session = ((HttpServletRequest) request).getSession();
@@ -97,8 +98,17 @@ public class BasketItemAddedFilter extends BaseServletFilter implements Filter {
                                throw new NullPointerException("session is null"); //NOI18N
                        }
 
+                       // Get man controller
+                       PizzaBean bean = (PizzaBean) session.getAttribute("controller"); //NOI18N
+
+                       // Debug message
+                       this.getLogger().debug("bean=" + bean);
+
                        // Get basket instance
-                       basket = (Basket<AddableBasketItem>) session.getAttribute("basket"); //NOI18N
+                       basket = bean.getBasket();
+
+                       // Debug message
+                       this.getLogger().debug("basket=" + basket);
 
                        // Is the item already added?
                        if (item.getItemId() == null) {
index b0d84b9e5d8c6c660fc50637790725dee4542c61..a2b9440b12199134ae3bb8052b0712779f687991 100644 (file)
@@ -19,13 +19,18 @@ package org.mxchange.pizzaapplication.tags.basket;
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.sql.SQLException;
+import java.text.MessageFormat;
+import javax.servlet.ServletException;
 import javax.servlet.jsp.JspException;
 import javax.servlet.jsp.tagext.BodyTagSupport;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.mxchange.jcore.exceptions.BadTokenException;
 import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
+import org.mxchange.pizzaapplication.beans.PizzaBean;
 import org.mxchange.pizzaapplication.beans.basket.BasketBean;
+import org.mxchange.pizzaapplication.item.AddableBasketItem;
+import org.mxchange.pizzaapplication.product.Product;
 
 /**
  * A basket tag that outputs a small basket and a link to the full basket website.
@@ -80,14 +85,57 @@ public class MiniBasketTag extends BodyTagSupport implements BasketTag {
                        // Some entries found?
                        if (this.getBasket().isEmpty()) {
                                // Empty basket
-                               out.append("<div class=\"mini_basket_info\">\n");
+                               out.append("<div class=\"mini_basket_box\">\n");
                                out.append(this.getBasket().getMessageStringFromKey("MiniBasketTag.basket_is_empty")).append("\n");
                                out.append("</div>\n");
                        } else {
-                               // Some times were found
-                               out.append("FOUND!");
+                               // Get all items
+                               AddableBasketItem item = this.getBasket().getLast();
+
+                               // item cannot be null here
+                               if (null == item) {
+                                       // Abort here
+                                       throw new NullPointerException("item is null");
+                               }
+
+                               // Get application bean from session
+                               PizzaBean bean = (PizzaBean) this.getBasket().getSession().getAttribute("controller");
+
+                               // Debug log
+                               this.LOG.debug("bean=" + bean);
+
+                               // Should not be null
+                               if (null == bean) {
+                                       // Abort here
+                                       throw new NullPointerException("bean is null");
+                               }
+
+                               // Get product instance
+                               Product product = bean.getProduct(item);
+
+                               // Debug message
+                               this.LOG.debug("product=" + product);
+
+                               // Get last num rows
+                               int lastNumRows = this.getBasket().getLastNumRows();
+
+                               // Debug message
+                               this.LOG.debug("lastNumRows=" + lastNumRows);
+
+                               // Output all
+                               out.append("<div class=\"mini_basket_box\">\n");
+                               out.append("  <div class=\"mini_basket_last\">\n");
+                               out.append("    ").append(MessageFormat.format(this.getBasket().getMessageStringFromKey("MiniBasketTag.last_item"), product.getTitle()));
+                               out.append("  </div>\n");
+                               out.append("  <div class=\"mini_basket_more\">\n");
+                               out.append("    ").append(MessageFormat.format(this.getBasket().getMessageStringFromKey("MiniBasketTag.additional_items"), (lastNumRows - 1)));
+                               out.append("  </div>\n");
+                               out.append("  <div class=\"mini_basket_link\">\n");
+                               out.append("    <a href=\"").append(this.getBasket().getApplication().getContextPath()).append("/basket.jsp\">").append(this.getBasket().getMessageStringFromKey("MiniBasketTag.to_basket")).append("</a>\n");
+                               out.append("  </div>\n");
+                               out.append("</div>\n");
                        }
-               } catch (final IOException | SQLException | BadTokenException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
+               } catch (final ServletException | IOException | SQLException | BadTokenException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
                        // Continue to throw
                        throw new JspException(ex);
                }
@@ -116,7 +164,7 @@ public class MiniBasketTag extends BodyTagSupport implements BasketTag {
        @Override
        public BasketBean getBasket () {
                // Trace message
-               this.LOG.trace("basket=" + this.basket + " - EXIT!");
+               //* NOISY-DEBUG: */ this.LOG.trace("basket=" + this.basket + " - EXIT!");
 
                // Return it
                return this.basket;
@@ -128,7 +176,7 @@ public class MiniBasketTag extends BodyTagSupport implements BasketTag {
        @Override
        public void setBasket (final BasketBean basket) {
                // Trace message
-               this.LOG.trace("basked=" + basket + " - CALLED!");
+               //* NOISY-DEBUG: */ this.LOG.trace("basked=" + basket + " - CALLED!");
 
                // Set it here
                this.basket = basket;
index aa07ebf68b51a284b8c02567d93040f43e63ca70..d5638079ca2cd838a98c437aadabca9df38cda5c 100644 (file)
 
 <jsp:useBean id="controller" scope="session" class="org.mxchange.pizzaapplication.beans.PizzaServiceBean" type="org.mxchange.pizzaapplication.beans.PizzaBean" />
 
+<jsp:setProperty name="controller" property="application" value="${pageContext.servletContext}" />
+<jsp:setProperty name="controller" property="basket" value="${basket}" />
+<%controller.init();%>
+
 <jsp:useBean id="item" scope="request" class="org.mxchange.pizzaapplication.item.basket.BasketItem" type="AddableBasketItem" />
 <jsp:setProperty name="item" property="*" />