From: Roland Haeder Date: Thu, 27 Aug 2015 13:33:11 +0000 (+0200) Subject: Added a lot new stuff: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=15d48155271344364b297d71ce1413fff97b1c53;p=pizzaservice-war.git Added a lot new stuff: - New beans added that should get rid of scriptlets (Java code within view) - New JARs added - jcore updated Signed-off-by:Roland Häder --- diff --git a/lib/cdi-api.jar b/lib/cdi-api.jar new file mode 100644 index 00000000..1fa239e3 Binary files /dev/null and b/lib/cdi-api.jar differ diff --git a/lib/commons-lang3-3.4.jar b/lib/commons-lang3-3.4.jar new file mode 100644 index 00000000..8ec91d45 Binary files /dev/null and b/lib/commons-lang3-3.4.jar differ diff --git a/lib/jcore.jar b/lib/jcore.jar index d75f9b63..68d45378 100644 Binary files a/lib/jcore.jar and b/lib/jcore.jar differ diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml index 6c45f222..31465cbd 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -1029,6 +1029,8 @@ exists or setup the property manually. For example like this: + + @@ -1040,6 +1042,8 @@ exists or setup the property manually. For example like this: + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index 6c0603df..88d3fe8f 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=1c5f2332 +build.xml.data.CRC32=45780b08 build.xml.script.CRC32=a6f5a733 build.xml.stylesheet.CRC32=651128d4@1.68.1.1 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=1c5f2332 -nbproject/build-impl.xml.script.CRC32=7b6df8a6 +nbproject/build-impl.xml.data.CRC32=45780b08 +nbproject/build-impl.xml.script.CRC32=0bccd313 nbproject/build-impl.xml.stylesheet.CRC32=99ea4b56@1.68.1.1 diff --git a/nbproject/project.properties b/nbproject/project.properties index 491a7d92..9d9683c2 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -28,7 +28,9 @@ dist.javadoc.dir=${dist.dir}/javadoc dist.war=${dist.dir}/${war.name} endorsed.classpath= excludes= +file.reference.cdi-api.jar=lib\\cdi-api.jar file.reference.commons-codec-1.10.jar=lib/commons-codec-1.10.jar +file.reference.commons-lang3-3.4.jar=lib\\commons-lang3-3.4.jar file.reference.jsfcore.jar=lib/jsfcore.jar file.reference.log4j-api-2.3.jar=lib/log4j-api-2.3.jar file.reference.log4j-core-2.3.jar=lib/log4j-core-2.3.jar @@ -54,9 +56,11 @@ javac.classpath=\ ${file.reference.commons-codec-1.10.jar}:\ ${libs.MySQLDriver.classpath}:\ ${file.reference.log4j-web-2.3.jar}:\ - ${file.reference.jsfcore.jar} + ${file.reference.jsfcore.jar}:\ + ${file.reference.cdi-api.jar}:\ + ${file.reference.commons-lang3-3.4.jar} # Space-separated list of extra javac options -javac.compilerargs=-Xlint:unchecked +javac.compilerargs=-Xlint:unchecked -Xlint:deprecation javac.debug=true javac.deprecation=true javac.processorpath=\ diff --git a/nbproject/project.xml b/nbproject/project.xml index 83f48326..a0911229 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -34,6 +34,14 @@ ${file.reference.jsfcore.jar} WEB-INF/lib + + ${file.reference.cdi-api.jar} + WEB-INF/lib + + + ${file.reference.commons-lang3-3.4.jar} + WEB-INF/lib + diff --git a/src/java/org/mxchange/localization/bundle_de_DE.properties b/src/java/org/mxchange/localization/bundle_de_DE.properties index f7de0503..376c5587 100644 --- a/src/java/org/mxchange/localization/bundle_de_DE.properties +++ b/src/java/org/mxchange/localization/bundle_de_DE.properties @@ -16,3 +16,4 @@ BaseContact.gender.unknown.text=Unbekannt BaseContact.gender.male.text=Herr BaseContact.gender.female.text=Frau BaseContact.gender.company.text=Firma +MiniBasketTag.basket_is_empty=Der Warenkorb ist leer. diff --git a/src/java/org/mxchange/localization/bundle_en_US.properties b/src/java/org/mxchange/localization/bundle_en_US.properties index 0813997e..d61b69f4 100644 --- a/src/java/org/mxchange/localization/bundle_en_US.properties +++ b/src/java/org/mxchange/localization/bundle_en_US.properties @@ -16,3 +16,4 @@ BaseContact.gender.unknown.text=Unknown BaseContact.gender.male.text=Mr. BaseContact.gender.female.text=Mrs. BaseContact.gender.company.text=Company +MiniBasketTag.basket_is_empty=Der Warenkorb ist leer. diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java index 88886d5d..38d7dd4f 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java @@ -70,7 +70,9 @@ public interface PizzaApplication extends Application { * @param product Product instance * @param session Session instance * @return Amount as string + * @deprecated Old code */ + @Deprecated public String getAmountFromSession (final Product product, final HttpSession session); /** @@ -79,7 +81,9 @@ public interface PizzaApplication extends Application { * @param product Product instance * @param session Session instance * @return Choose as string + * @deprecated Old code */ + @Deprecated public String getChooseFromSession (final Product product, final HttpSession session); /** @@ -89,7 +93,9 @@ public interface PizzaApplication extends Application { * @param request Request instance * @param session Session instance * @return Amount as string + * @deprecated Old code */ + @Deprecated public String handleAmountFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session); /** @@ -99,7 +105,9 @@ public interface PizzaApplication extends Application { * @param request Request instance * @param session Session instance * @return Amount as string + * @deprecated Old code */ + @Deprecated public String getPrintableChoosenFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session); /** @@ -131,7 +139,9 @@ public interface PizzaApplication extends Application { * @param request Request instance * @param session Session instance * @return Whether the product is choosen + * @deprecated Old lost code */ + @Deprecated public boolean isProductChoosen (final Product product, final HttpServletRequest request, final HttpSession session); /** @@ -179,7 +189,9 @@ public interface PizzaApplication extends Application { * * @param product Product to mark as ordered * @param session Session instance + * @deprecated Old code */ + @Deprecated public void markProductAsOrdered(final Product product, final HttpSession session); /** @@ -187,7 +199,9 @@ public interface PizzaApplication extends Application { * * @param product Product to mark as ordered * @param session Session instance + * @deprecated Old code */ + @Deprecated public void markProductAsChoosen(final Product product, final HttpSession session); /** @@ -195,7 +209,9 @@ public interface PizzaApplication extends Application { * * @param product Product to unmark as ordered * @param session Session instance + * @deprecated Old code */ + @Deprecated public void unmarkProductAsOrdered(final Product product, final HttpSession session); /** @@ -203,7 +219,9 @@ public interface PizzaApplication extends Application { * * @param product Product to unmark as choosen * @param session Session instance + * @deprecated Old code */ + @Deprecated public void unmarkProductAsChoosen(final Product product, final HttpSession session); /** @@ -272,7 +290,9 @@ public interface PizzaApplication extends Application { * @param request Request instance * @param session Session instance * @throws javax.servlet.ServletException If something unexpected happened + * @deprecated Old code */ + @Deprecated public void markAllChoosenProductsAsOrdered (final HttpServletRequest request, final HttpSession session) throws ServletException; /** diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java index 2507b024..fa19b61b 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java @@ -18,25 +18,20 @@ package org.mxchange.pizzaapplication.application; import java.io.IOException; import java.io.UnsupportedEncodingException; -import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.sql.SQLException; import java.text.MessageFormat; import java.util.Iterator; -import java.util.Map; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -import org.mxchange.jcore.contact.Gender; import org.mxchange.jcore.exceptions.BadTokenException; import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException; import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException; import org.mxchange.pizzaapplication.BasePizzaServiceSystem; import org.mxchange.pizzaapplication.category.Category; -import org.mxchange.pizzaapplication.customer.Customer; -import org.mxchange.pizzaapplication.customer.PizzaServiceCustomer; import org.mxchange.pizzaapplication.database.category.PizzaCategoryDatabaseConstants; import org.mxchange.pizzaapplication.database.frontend.category.CategoryFrontend; import org.mxchange.pizzaapplication.database.frontend.category.PizzaCategoryDatabaseFrontend; @@ -53,11 +48,6 @@ import org.mxchange.pizzaapplication.product.Product; * @author Roland Haeder */ public class PizzaServiceApplication extends BasePizzaServiceSystem implements PizzaApplication { - /** - * Main title - */ - public static final String MAIN_TITLE = "Pizza-Service"; - /** * Frontend for products */ @@ -68,87 +58,32 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P */ private CategoryFrontend categoryFrontend; - /** - * Some singleton getter for this instance. If the instance is not set in - * given application, it will be created. - * - * @param context Servlet context - * @return This instance - * @throws javax.servlet.ServletException If object is not set correctly - */ - public static final PizzaApplication getInstance (final ServletContext context) throws ServletException { - // Check application instance - if (null == context) { - // Not set - throw new NullPointerException("application is null"); //NOI18N - } - - // Init instance - PizzaApplication instance = null; - - // Get instance from servlet application (aka. "application scope") - Object object = context.getAttribute("app"); //NOI18N - - // Is it set? - if (object instanceof PizzaApplication) { - // Instance is set, so casting should work - instance = (PizzaApplication) object; - - // Debug message - instance.getLogger().debug(MessageFormat.format("Using existing instance {0} ...", object)); //NOI18N - } else if (object instanceof Object) { - // Not correct instance - throw new ServletException("app is not set correctly"); //NOI18N - } else { - try { - // "service" is null, so initialize it - instance = new PizzaServiceApplication(); - instance.init(context); - - // Debug message - instance.getLogger().debug(MessageFormat.format("Created new instance {0} ...", object)); //NOI18N - } catch (final UnsupportedDatabaseBackendException | SQLException | IOException | BadTokenException ex) { - throw new ServletException(ex); - } - - // And set it here - context.setAttribute("app", instance); //NOI18N - } - + @Override + public void init (final ServletContext context) throws UnsupportedDatabaseBackendException, SQLException { // Trace message - instance.getLogger().trace(MessageFormat.format("instance={0} - EXIT!", instance)); //NOI18N + this.getLogger().trace(MessageFormat.format("context={0} - CALLED!", context)); //NOI18N - // Return it - return instance; - } - - /** - * For debugging purpose - * - * @param args Arguments - */ - public static void main (String[] args) { - // Get instance and start it - new PizzaServiceApplication().start(); - } - - @Override - public void init (final ServletContext context) throws UnsupportedDatabaseBackendException, SQLException, IOException, BadTokenException { - // Temporary initialize default bundle - // @TODO The JSF may have better internatialization support - this.initBundle(); + // Is the bundle initialized? + if (!this.isBundledInitialized()) { + // Temporary initialize default bundle + // @TODO The enum Gender uses this + this.initBundle(); + } - // Initialize properties from config + // Initialize properties from context this.initProperties(context); // Init database frontends this.initDatabaseFrontends(); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** * Default constructor */ - private PizzaServiceApplication () { + public PizzaServiceApplication () { } /** @@ -274,6 +209,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P * @return Amount as string */ @Override + @Deprecated public String getAmountFromSession (final Product product, final HttpSession session) { // Trace message this.getLogger().trace(MessageFormat.format("product={0},session={1} - CALLED!", product, session)); //NOI18N @@ -355,6 +291,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P * @return Choose as string */ @Override + @Deprecated public String getChooseFromSession (final Product product, final HttpSession session) { // Trace message this.getLogger().trace(MessageFormat.format("product={0},session={1} - CALLED!", product, session)); //NOI18N @@ -437,6 +374,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P * @return Amount as string */ @Override + @Deprecated public String getPrintableChoosenFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session) { // Trace message this.getLogger().trace(MessageFormat.format("product={0},request={1},session={2} - CALLED!", product, request, session)); //NOI18N @@ -677,6 +615,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P * @return Amount as string */ @Override + @Deprecated public String handleAmountFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session) { // Trace message this.getLogger().trace(MessageFormat.format("product={0},request={1},session={2} - CALLED!", product, request, session)); //NOI18N @@ -744,6 +683,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P * @return Whether the product is choosen */ @Override + @Deprecated public boolean isProductChoosen (final Product product, final HttpServletRequest request, final HttpSession session) { // Trace message this.getLogger().trace(MessageFormat.format("product={0},request={1},session={2} - CALLED!", product, request, session)); //NOI18N @@ -794,6 +734,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P * @param session Session instance */ @Override + @Deprecated public void markAllChoosenProductsAsOrdered (final HttpServletRequest request, final HttpSession session) throws ServletException { // Trace message this.getLogger().trace(MessageFormat.format("request={0},session={1} - CALLED!", request, session)); //NOI18N @@ -827,6 +768,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P * @param session Session instance */ @Override + @Deprecated public void markProductAsChoosen (final Product product, final HttpSession session) { // Trace message this.getLogger().trace(MessageFormat.format("product={0},session={1} - CALLED!", product, session)); //NOI18N @@ -855,6 +797,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P * @param session Session instance */ @Override + @Deprecated public void markProductAsOrdered (final Product product, final HttpSession session) { // Trace message this.getLogger().trace(MessageFormat.format("product={0},session={1} - CALLED!", product, session)); //NOI18N @@ -904,6 +847,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P * @param session Session instance */ @Override + @Deprecated public void unmarkProductAsChoosen (final Product product, final HttpSession session) { // Trace message this.getLogger().trace(MessageFormat.format("product={0},session={1} - CALLED!", product, session)); //NOI18N @@ -932,6 +876,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P * @param session Session instance */ @Override + @Deprecated public void unmarkProductAsOrdered (final Product product, final HttpSession session) { // Trace message this.getLogger().trace(MessageFormat.format("product={0},session={1} - CALLED!", product, session)); //NOI18N @@ -1091,11 +1036,17 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P * Initializes database frontends. */ private void initDatabaseFrontends () throws UnsupportedDatabaseBackendException, SQLException { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + // Product frontend this.productFrontend = new PizzaProductDatabaseFrontend(); // Category frontend this.categoryFrontend = new PizzaCategoryDatabaseFrontend(); + + // Trace message + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -1157,74 +1108,6 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Trace message this.getLogger().trace("EXIT!"); //NOI18N } - - /** - * Application starter - */ - private void start() { - // Init bundle - this.initBundle(); - - try { - // Init properties - this.initProperties(); - - // And frontends - this.initDatabaseFrontends(); - } catch (final IOException | UnsupportedDatabaseBackendException | SQLException ex) { - // Abort here - this.abortProgramWithException(ex); - } - - // Init instance - Iterator iterator = null; - - try { - // Get iterator - iterator = this.getAvailableProducts(); - } catch (final ServletException ex) { - this.abortProgramWithException(ex); - } - - // "Walk" over all products - while ((iterator instanceof Iterator) && (iterator.hasNext())) { - // Get next product - Product product = iterator.next(); - - // Output data - this.getLogger().debug(MessageFormat.format("Product {0}, {1}: {2}", product.getItemId(), product.getTitle(), product.getPrice())); //NOI18N - } - - // Generate fake Customer instance - Customer customer = new PizzaServiceCustomer(); - - /* - * Need a least a gender ... :( See, that is why I don't like default - * constructors, you can easily miss something important and bam! You - * get an NPE. The fix here is, to have construtors (or factories) which - * requires all required instances that needs to be set to get a - * consitent object back. - */ - - // Gender is MALE now - customer.setGender(Gender.MALE); - - // Init iterator - Iterator> it = null; - - try { - // Get iterator on all its fields - it = customer.iterator(); - } catch (final NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { - this.abortProgramWithException(ex); - } - - // Output it - while ((it instanceof Iterator) && (it.hasNext())) { - Map.Entry entry = it.next(); - this.getLogger().debug(MessageFormat.format("entry {0}={1}", entry.getKey(), entry.getValue())); //NOI18N - } - } /** * Adds given category data from request to database diff --git a/src/java/org/mxchange/pizzaapplication/basket/BaseBasket.java b/src/java/org/mxchange/pizzaapplication/basket/BaseBasket.java index 819b853d..85daa560 100644 --- a/src/java/org/mxchange/pizzaapplication/basket/BaseBasket.java +++ b/src/java/org/mxchange/pizzaapplication/basket/BaseBasket.java @@ -22,10 +22,12 @@ import java.io.Serializable; import java.lang.reflect.InvocationTargetException; import java.sql.SQLException; import java.text.MessageFormat; -import org.mxchange.jcore.BaseFrameworkSystem; +import javax.servlet.ServletContext; +import javax.servlet.http.HttpSession; import org.mxchange.jcore.exceptions.BadTokenException; import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException; import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException; +import org.mxchange.pizzaapplication.BasePizzaServiceSystem; import org.mxchange.pizzaapplication.database.frontend.basket.BasketDatabaseFrontend; import org.mxchange.pizzaapplication.database.frontend.basket.BasketFrontend; import org.mxchange.pizzaapplication.item.AddableBasketItem; @@ -37,30 +39,36 @@ import org.mxchange.pizzaapplication.product.Product; * @author Roland Haeder * @param Any instance that implements AddableBasketItem */ -public class BaseBasket extends BaseFrameworkSystem implements Basket, Serializable { +public class BaseBasket extends BasePizzaServiceSystem implements Basket, Serializable { /** * Serial number */ private static final long serialVersionUID = 784396762230845717L; - /** - * Session id assigned with this basket, or any other unique identifier - */ - private String sessionId; - - /** - * Protected constructor with session instance - * - * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If an unsupported backend has been configured - * @throws java.sql.SQLException If an SQL error occurs - */ - protected BaseBasket () throws UnsupportedDatabaseBackendException, SQLException { + @Override + public void init (final ServletContext context, final HttpSession session) throws UnsupportedDatabaseBackendException, SQLException { // Trace message - this.getLogger().trace("CALLED!"); //NOI18N + this.getLogger().trace(MessageFormat.format("context={0} - CALLED!", context)); //NOI18N + + // Is the bundle initialized? + if (!this.isBundledInitialized()) { + // Temporary initialize default bundle + // @TODO The enum Gender uses this + this.initBundle(); + } + + // Initialize properties from context + this.initProperties(context); // Create frontend instance BasketFrontend frontend = new BasketDatabaseFrontend(); + // Set session id here + this.setSessionId(session.getId()); + + // Set it in frontend, too + frontend.setSessionId(session.getId()); + // Debug message this.getLogger().debug(MessageFormat.format("frontend={0} being set ...", frontend)); //NOI18N @@ -68,6 +76,17 @@ public class BaseBasket extends BaseFrameworkSystem this.setFrontend(frontend); } + /** + * Protected constructor with session instance + * + * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If an unsupported backend has been configured + * @throws java.sql.SQLException If an SQL error occurs + */ + protected BaseBasket () throws UnsupportedDatabaseBackendException, SQLException { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + } + @Override public void addItem (final T item) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { // Trace call @@ -119,6 +138,12 @@ public class BaseBasket extends BaseFrameworkSystem return item; } + @Override + public boolean isEmpty () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + // Deligate call to frontend + return ((BasketFrontend) this.getFrontend()).isEmpty(); + } + @Override public boolean isItemAdded (final T item) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { // Trace call @@ -140,24 +165,6 @@ public class BaseBasket extends BaseFrameworkSystem return isAdded; } - /** - * Setter for session id - * - * @param sessionId Session id - */ - protected final void setSessionId (final String sessionId) { - this.sessionId = sessionId; - } - - /** - * Getter for session id - * - * @return Session id - */ - protected final String getSessionId () { - return this.sessionId; - } - /** * Called when fields are set on deserialization * diff --git a/src/java/org/mxchange/pizzaapplication/basket/Basket.java b/src/java/org/mxchange/pizzaapplication/basket/Basket.java index 5f63d07e..b583b530 100644 --- a/src/java/org/mxchange/pizzaapplication/basket/Basket.java +++ b/src/java/org/mxchange/pizzaapplication/basket/Basket.java @@ -17,11 +17,15 @@ package org.mxchange.pizzaapplication.basket; import java.io.IOException; +import java.io.Serializable; import java.lang.reflect.InvocationTargetException; import java.sql.SQLException; +import javax.servlet.ServletContext; +import javax.servlet.http.HttpSession; import org.mxchange.jcore.FrameworkInterface; 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; @@ -31,7 +35,7 @@ import org.mxchange.pizzaapplication.product.Product; * @author Roland Haeder * @param Any addable basket items */ -public interface Basket extends FrameworkInterface { +public interface Basket extends Serializable, FrameworkInterface { /** * Adds given item instance to this basket @@ -46,6 +50,20 @@ public interface Basket extends FrameworkInterface */ public void addItem (final T item) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; + /** + * Checks if the basket is empty + * + * @return Whether the basket is empty + * @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 boolean isEmpty () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; + /** * Checks whether the given item as already been added. Mostly * implementations may check the id number as this is mostly believed being @@ -77,4 +95,16 @@ public interface Basket extends FrameworkInterface * @throws java.lang.reflect.InvocationTargetException If anything else happened? */ public AddableBasketItem getItem (final Product product) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; + + /** + * Initializes this instance with given ServletContext + * + * @param context Servlet context + * @param session Session instance + * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the backend is unsupported + * @throws java.sql.SQLException If an SQL error occurs + * @throws java.io.IOException If an IO error occurs + * @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; } diff --git a/src/java/org/mxchange/pizzaapplication/basket/item/ItemBasket.java b/src/java/org/mxchange/pizzaapplication/basket/item/ItemBasket.java index e69bc5e4..ae34890f 100644 --- a/src/java/org/mxchange/pizzaapplication/basket/item/ItemBasket.java +++ b/src/java/org/mxchange/pizzaapplication/basket/item/ItemBasket.java @@ -17,9 +17,6 @@ package org.mxchange.pizzaapplication.basket.item; import java.sql.SQLException; -import java.text.MessageFormat; -import javax.servlet.http.HttpSession; -import org.mxchange.jcore.BaseFrameworkSystem; import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException; import org.mxchange.pizzaapplication.basket.BaseBasket; import org.mxchange.pizzaapplication.basket.Basket; @@ -29,65 +26,21 @@ import org.mxchange.pizzaapplication.item.AddableBasketItem; * A basket for orderable items * * @author Roland Haeder - * @param Any instance that implements AddableBasketItem */ -public class ItemBasket extends BaseBasket implements Basket { +public class ItemBasket extends BaseBasket implements Basket { /** * Serial number */ private static final long serialVersionUID = 4384123923163957L; - /** - * Creates a singleton instance from given session's id - * - * @param session An instance of a HttpSession class - * @return A session-id based singleton instance of this basket - * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If an unsupported backend was configured - * @throws java.sql.SQLException If an SQL error occurs - */ - @SuppressWarnings ("unchecked") - public final static Basket getInstance (final HttpSession session) throws UnsupportedDatabaseBackendException, SQLException { - // Trace message - BaseFrameworkSystem.getInstance().getLogger().trace(MessageFormat.format("session={0} - CALLED!", session)); //NOI18N - - // Get instance - Basket basket = (Basket) session.getAttribute("basket"); //NOI18N - - // Debug message - BaseFrameworkSystem.getInstance().getLogger().debug(MessageFormat.format("basket={0}", basket)); - - // Is the basket already created? - if (!(basket instanceof Basket)) { - // Not yet, so create it - basket = new ItemBasket<>(session); - - // Add it in session - session.setAttribute("basket", basket); //NOI18N - } - - // Return it casted - return basket; - } - /** * Default constructor to be able to throw exceptions from super constructor - * - * @param session HttpSession instance + * @param context Context instance + * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the backend is unsupported + * @throws java.sql.SQLException If an SQL error occurs */ - private ItemBasket (final HttpSession session) throws UnsupportedDatabaseBackendException, SQLException { + public ItemBasket () throws UnsupportedDatabaseBackendException, SQLException { // Call super constructor super(); - - // Trace message - this.getLogger().trace(MessageFormat.format("session={0} - CALLED!", session)); //NOI18N - - // Session must be set - if (null == session) { - // Session is null - throw new NullPointerException("session is null"); - } - - // Set session id here - this.setSessionId(session.getId()); } } diff --git a/src/java/org/mxchange/pizzaapplication/beans/CustomerBean.java b/src/java/org/mxchange/pizzaapplication/beans/CustomerBean.java deleted file mode 100644 index 4826a9b3..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/CustomerBean.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.pizzaapplication.beans; - -import org.mxchange.pizzaapplication.customer.Customer; - -/** - * An interface for customer beans - * - * @author Roland Haeder - */ -public interface CustomerBean extends Customer { -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/PizzaBean.java b/src/java/org/mxchange/pizzaapplication/beans/PizzaBean.java new file mode 100644 index 00000000..00188ca3 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/PizzaBean.java @@ -0,0 +1,307 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans; + +import java.io.Serializable; +import java.util.Iterator; +import javax.faces.FacesException; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import org.mxchange.pizzaapplication.category.Category; +import org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException; +import org.mxchange.pizzaapplication.exceptions.ProductTitleAlreadyUsedException; +import org.mxchange.pizzaapplication.product.Product; + +/** + * + * @author Roland Haeder + */ +public interface PizzaBean extends Serializable { + /** + * Some "getter" for amount from session + * + * @param product Product instance + * @param session Session instance + * @return Amount as string + * @deprecated Old code + */ + @Deprecated + public String getAmountFromSession (final Product product, final HttpSession session); + + /** + * Some "getter" for choose from session + * + * @param product Product instance + * @param session Session instance + * @return Choose as string + * @deprecated Old code + */ + @Deprecated + public String getChooseFromSession (final Product product, final HttpSession session); + + /** + * Handler for amount from session + * + * @param product Product instance + * @param request Request instance + * @param session Session instance + * @return Amount as string + * @deprecated Old code + */ + @Deprecated + public String handleAmountFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session); + + /** + * Some "getter" for printable choosen (checkbox) from request or session + * + * @param product Product instance + * @param request Request instance + * @param session Session instance + * @return Amount as string + * @deprecated Old code + */ + @Deprecated + public String getPrintableChoosenFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session); + + /** + * Some "getter" for total price of position from request or session. + * Single price and amount is multiplyed. + * + * @param product Product instance + * @param request Request instance + * @param session Session instance + * @return Amount as string + */ + public float getTotalPositionPriceFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session); + + /** + * Initializes this instance + * + * @throws FacesException If something was wrong + */ + public void init () throws FacesException; + + /** + * Checks whether the given product is choosen, request overules session. + * + * @param product Product instance + * @param request Request instance + * @param session Session instance + * @return Whether the product is choosen + * @deprecated Old lost code + */ + @Deprecated + public boolean isProductChoosen (final Product product, final HttpServletRequest request, final HttpSession session); + + /** + * Calculates total price of all choosen products + * + * @param request Request instance + * @param session Session instance + * @return Total price of all choosen products + * @throws javax.servlet.ServletException If something unexpected happened + */ + public float calculateTotalPrice (final HttpServletRequest request, final HttpSession session) throws ServletException; + + /** + * Calculates total amount of all choosen products + * + * @param request Request instance + * @param session Session instance + * @return Total amount of all choosen products + * @throws javax.servlet.ServletException If something unexpected happened + */ + public int calculateTotalAmount (final HttpServletRequest request, final HttpSession session) throws ServletException; + + /** + * Some "getter" for HTML code 'checked="checked"' if the product is choosen + * + * @param product Product instance + * @param request Request instance + * @param session Session instance + * @return Whether the product is choosen + */ + public String getCheckedHtmlFromProduct (final Product product, final HttpServletRequest request, final HttpSession session); + + /** + * Some "getter" for HTML code 'disabled="disabled"' for e.g. submit buttons + * + * @param request Request instance + * @param session Session instance + * @return Whether the product is choosen + * @throws javax.servlet.ServletException If something unexpected happened + */ + public String getDisabledHtmlFromSession (final HttpServletRequest request, final HttpSession session) throws ServletException; + + /** + * Marks given product as ordered in session + * + * @param product Product to mark as ordered + * @param session Session instance + * @deprecated Old code + */ + @Deprecated + public void markProductAsOrdered(final Product product, final HttpSession session); + + /** + * Marks given product as choosen in session + * + * @param product Product to mark as ordered + * @param session Session instance + * @deprecated Old code + */ + @Deprecated + public void markProductAsChoosen(final Product product, final HttpSession session); + + /** + * Unmarks given product as ordered in session + * + * @param product Product to unmark as ordered + * @param session Session instance + * @deprecated Old code + */ + @Deprecated + public void unmarkProductAsOrdered(final Product product, final HttpSession session); + + /** + * Unmarks given product as choosen in session + * + * @param product Product to unmark as choosen + * @param session Session instance + * @deprecated Old code + */ + @Deprecated + public void unmarkProductAsChoosen(final Product product, final HttpSession session); + + /** + * Some getter for printable value from session or an empty string for null. + * + * @param session Session instance + * @param key Key to get + * @return Value from key, empty string for null + */ + public Object getPrintableValeFromSession (final HttpSession session, final String key); + + /** + * Somewhat setter in session + * + * @param session Session instance + * @param key Session key to set + * @param value Value to set + */ + public void setValueInSession (final HttpSession session, final String key, final Object value); + + /** + * Some "getter" for a an array of only available products + * + * @return Only available products + * @throws javax.servlet.ServletException If anything went wrong + */ + public Iterator getAvailableProducts () throws ServletException; + + /** + * Some "getter" for a an array of all products + * + * @return All products + * @throws javax.servlet.ServletException If anything went wrong + */ + public Iterator getAllProducts () throws ServletException; + + /** + * Some "getter" for a an array of all categories + * + * @return All categories + * @throws javax.servlet.ServletException If anything went wrong + */ + public Iterator getCategories () throws ServletException; + + /** + * Checks if given Product instance is available and returns a printable + * (human-readable) string. + * + * @param product Product instance to check + * @return Human-readable version of product availability + */ + public String getPrintableProduktAvailability (final Product product); + + /** + * Returns a printable (human-readable) string of product's category + * + * @param product Product instance to check + * @return Human-readable version of product availability + * @throws javax.servlet.ServletException If something unexpected happened + */ + public String getPrintableProduktCategory (final Product product) throws ServletException; + + /** + * Marks all choosen products as ordered + * + * @param request Request instance + * @param session Session instance + * @throws javax.servlet.ServletException If something unexpected happened + * @deprecated Old code + */ + @Deprecated + public void markAllChoosenProductsAsOrdered (final HttpServletRequest request, final HttpSession session) throws ServletException; + + /** + * Adds given category data from request to database + * + * @param request Request instance + * @throws javax.servlet.ServletException If something unexpected happened + * @throws org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException If the given title is already used + */ + public void doAdminAddCategory (final HttpServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException; + + /** + * Adds given product data from request to database + * + * @param request Request instance + * @throws javax.servlet.ServletException If something unexpected happened + * @throws org.mxchange.pizzaapplication.exceptions.ProductTitleAlreadyUsedException If the given product title is already used + */ + public void doAdminAddProduct (final HttpServletRequest request) throws ServletException, ProductTitleAlreadyUsedException; + + /** + * Generates link HTML code for given category's parent id, if set. This + * link then points to products.jsp?category_id=x + * + * @param category Category instance + * @return HTML code + */ + public String generateLinkForParent (final Category category); + + /** + * Handles admin product form requests + * + * @param request Request instance + * @param response Response instance + * @throws ServletException If something unexpected happened + */ + public void doAdminHandleProductForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException; + + /** + * Handles admin category form requests + * + * @param request Request instance + * @param response Response instance + * @throws ServletException If something unexpected happened + */ + public void doAdminHandleCategoryForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException; +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/PizzaServiceBean.java b/src/java/org/mxchange/pizzaapplication/beans/PizzaServiceBean.java new file mode 100644 index 00000000..7248b7d7 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/PizzaServiceBean.java @@ -0,0 +1,384 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans; + +import java.io.IOException; +import java.sql.SQLException; +import java.util.Iterator; +import javax.annotation.PostConstruct; +import javax.enterprise.context.SessionScoped; +import javax.faces.FacesException; +import javax.inject.Inject; +import javax.inject.Named; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import org.mxchange.jcore.exceptions.BadTokenException; +import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException; +import org.mxchange.pizzaapplication.application.PizzaApplication; +import org.mxchange.pizzaapplication.application.PizzaServiceApplication; +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.product.Product; + +/** + * Main application class + * + * @author Roland Haeder + */ +@Named("service") +@SessionScoped +public class PizzaServiceBean implements PizzaBean { + /** + * Serial id + */ + private static final long serialVersionUID = 58137539530279L; + + /** + * Servlet context + */ + @Inject + private ServletContext application; + + /** + * Basket instance + */ + @Inject + private BasketBean basket; + + /** + * Pizza application + */ + private final PizzaApplication app; + + /** + * Initializer block + */ + { + // Get new application instance + this.app = new PizzaServiceApplication(); + } + + @Override + @PostConstruct + public void init () throws FacesException { + try { + // Call init method + this.app.init(this.application); + } catch (final UnsupportedDatabaseBackendException | SQLException | IOException | BadTokenException ex) { + // Continue to throw + throw new FacesException(ex); + } + } + + /** + * Default constructor + */ + public PizzaServiceBean () { + } + + /** + * Calculates total amount of all choosen products + * + * @param request Request instance + * @param session Session instance + * @return Total amount of all choosen products + */ + @Override + public int calculateTotalAmount (final HttpServletRequest request, final HttpSession session) throws ServletException { + return this.app.calculateTotalAmount(request, session); + } + + /** + * Calculates total price of all choosen products + * + * @param request Request instance + * @param session Session instance + * @return Total price of all choosen products + */ + @Override + public float calculateTotalPrice (final HttpServletRequest request, final HttpSession session) throws ServletException { + return this.app.calculateTotalPrice(request, session); + } + + /** + * Some "getter" for amount from session + * + * @param product Product instance + * @param session Session instance + * @return Amount as string + */ + @Override + @Deprecated + public String getAmountFromSession (final Product product, final HttpSession session) { + return this.app.getAmountFromSession(product, session); + } + + /** + * Some "getter" for HTML code 'checked="checked"' if the product is choosen + * + * @param product Product instance + * @param request Request instance + * @param session Session instance + * @return Whether the product is choosen + */ + @Override + public String getCheckedHtmlFromProduct (final Product product, final HttpServletRequest request, final HttpSession session) { + return this.app.getCheckedHtmlFromProduct(product, request, session); + } + + /** + * Some "getter" for choose from session + * + * @param product Product instance + * @param session Session instance + * @return Choose as string + */ + @Override + @Deprecated + public String getChooseFromSession (final Product product, final HttpSession session) { + return this.app.getChooseFromSession(product, session); + } + + /** + * Some "getter" for HTML code 'disabled="disabled"' for e.g. submit buttons + * + * @param request Request instance + * @param session Session instance + * @return Whether the product is choosen + */ + @Override + public String getDisabledHtmlFromSession (final HttpServletRequest request, final HttpSession session) throws ServletException { + return this.app.getDisabledHtmlFromSession(request, session); + } + + /** + * Some "getter" for choosen (checkbox) from session + * + * @param product Product instance + * @param request Request instance + * @param session Session instance + * @return Amount as string + */ + @Override + @Deprecated + public String getPrintableChoosenFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session) { + return this.app.getPrintableChoosenFromRequestSession(product, request, session); + } + + /** + * Checks if given Product instance is available and returns a printable + * (human-readable) string. + * + * @param product Product instance to check + * @return Human-readable version of product availability + */ + @Override + public String getPrintableProduktAvailability (final Product product) { + return this.app.getPrintableProduktAvailability(product); + } + + /** + * Some getter for printable value from session or an empty string for null. + * + * @param session Session instance + * @param key Key to get + * @return Value from key, empty string for null + */ + @Override + public Object getPrintableValeFromSession (final HttpSession session, final String key) { + return this.app.getPrintableValeFromSession(session, key); + } + + /** + * Some "getter" for a an array of only available products + * + * @return All products + */ + @Override + public Iterator getAvailableProducts () throws ServletException { + return this.app.getAvailableProducts(); + } + + /** + * Some "getter" for a an array of all products + * + * @return All products + */ + @Override + public Iterator getAllProducts () throws ServletException { + return this.app.getAllProducts(); + } + + /** + * Some "getter" for a an array of all categories + * + * @return All categories + */ + @Override + public Iterator getCategories () throws ServletException { + return this.app.getCategories(); + } + + /** + * Some "getter" for total price of position from request or session. + * Single price and amount is multiplyed. + * + * @param product Product instance + * @param request Request instance + * @param session Session instance + * @return Amount as string + */ + @Override + public float getTotalPositionPriceFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session) { + return this.app.getTotalPositionPriceFromRequestSession(product, request, session); + } + + /** + * Handler for amount from request or session + * + * @param product Product instance + * @param request Request instance + * @param session Session instance + * @return Amount as string + */ + @Override + @Deprecated + public String handleAmountFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session) { + return this.app.handleAmountFromRequestSession(product, request, session); + } + + /** + * Checks whether the given product is choosen, request overules session. + * + * @param product Product instance + * @param request Request instance + * @param session Session instance + * @return Whether the product is choosen + */ + @Override + @Deprecated + public boolean isProductChoosen (final Product product, final HttpServletRequest request, final HttpSession session) { + return this.app.isProductChoosen(product, request, session); + } + + /** + * Marks all choosen products as ordered + * + * @param request Request instance + * @param session Session instance + */ + @Override + @Deprecated + public void markAllChoosenProductsAsOrdered (final HttpServletRequest request, final HttpSession session) throws ServletException { + this.app.markAllChoosenProductsAsOrdered(request, session); + } + + /** + * Marks given product as choosen in session + * + * @param product Product to mark as ordered + * @param session Session instance + */ + @Override + @Deprecated + public void markProductAsChoosen (final Product product, final HttpSession session) { + this.app.markProductAsChoosen(product, session); + } + + /** + * Marks given product as ordered in session + * + * @param product Product to mark as ordered + * @param session Session instance + */ + @Override + @Deprecated + public void markProductAsOrdered (final Product product, final HttpSession session) { + this.app.markProductAsOrdered(product, session); + } + + /** + * Somewhat setter in session + * + * @param session Session instance + * @param key Session key to set + * @param value Value to set + */ + @Override + public void setValueInSession (final HttpSession session, final String key, final Object value) { + this.app.setValueInSession(session, key, value); + } + + /** + * Unmarks given product as choosen in session + * + * @param product Product to unmark as choosen + * @param session Session instance + */ + @Override + @Deprecated + public void unmarkProductAsChoosen (final Product product, final HttpSession session) { + this.app.unmarkProductAsChoosen(product, session); + } + + /** + * Unmarks given product as ordered in session + * + * @param product Product to unmark as ordered + * @param session Session instance + */ + @Override + @Deprecated + public void unmarkProductAsOrdered (final Product product, final HttpSession session) { + this.app.unmarkProductAsOrdered(product, session); + } + + @Override + public void doAdminAddCategory (final HttpServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException { + this.app.doAdminAddCategory(request); + } + + @Override + public void doAdminAddProduct (final HttpServletRequest request) throws ServletException, ProductTitleAlreadyUsedException { + this.app.doAdminAddProduct(request); + } + + @Override + public String generateLinkForParent (final Category category) { + return this.app.generateLinkForParent(category); + } + + @Override + public String getPrintableProduktCategory (final Product product) throws ServletException { + return this.app.getPrintableProduktCategory(product); + } + + @Override + public void doAdminHandleProductForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException { + this.app.doAdminHandleProductForms(request, response); + } + + @Override + public void doAdminHandleCategoryForms (final HttpServletRequest request, final HttpServletResponse response) throws ServletException { + this.app.doAdminHandleCategoryForms(request, response); + } +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/basket/BasketBean.java b/src/java/org/mxchange/pizzaapplication/beans/basket/BasketBean.java new file mode 100644 index 00000000..22d12224 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/basket/BasketBean.java @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.basket; + +import java.io.IOException; +import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; +import java.sql.SQLException; +import javax.faces.FacesException; +import org.mxchange.jcore.exceptions.BadTokenException; +import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException; +import org.mxchange.pizzaapplication.item.AddableBasketItem; +import org.mxchange.pizzaapplication.product.Product; + +/** + * An interface for a basket bean + * + * @author Roland Haeder + */ +public interface BasketBean extends Serializable { + /** + * Initializes this instance + * + * @throws FacesException If something was wrong + */ + public void init () throws FacesException; + + /** + * Adds given item instance to this basket + * @param item Item instance to add + * @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 void addItem (final AddableBasketItem item) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; + + /** + * Checks if the basket is empty + * + * @return Whether the basket is empty + * @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 boolean isEmpty () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; + + /** + * Checks whether the given item as already been added. Mostly + * implementations may check the id number as this is mostly believed being + * unique. + * + * @param item Item instance to check + * @return Whether the given item has been found + * @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 boolean isItemAdded (final AddableBasketItem item) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; + + /** + * Returns an item for given product instance or null if not found. + * + * @param product Product instance + * @return Item instance or null + * @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 getItem (final Product product) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; + + /** + * Getter for human-readable string from given key + * + * @param key Key to return + * @return Human-readable message + */ + public String getMessageStringFromKey (final String key); +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/basket/ItemBasketBean.java b/src/java/org/mxchange/pizzaapplication/beans/basket/ItemBasketBean.java new file mode 100644 index 00000000..27a074ba --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/basket/ItemBasketBean.java @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.basket; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.sql.SQLException; +import javax.annotation.PostConstruct; +import javax.enterprise.context.Dependent; +import javax.faces.FacesException; +import javax.faces.view.facelets.FaceletException; +import javax.inject.Inject; +import javax.inject.Named; +import javax.servlet.ServletContext; +import javax.servlet.http.HttpSession; +import org.mxchange.jcore.exceptions.BadTokenException; +import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException; +import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException; +import org.mxchange.pizzaapplication.basket.Basket; +import org.mxchange.pizzaapplication.basket.item.ItemBasket; +import org.mxchange.pizzaapplication.item.AddableBasketItem; +import org.mxchange.pizzaapplication.product.Product; + +/** + * A basket for orderable items + * + * @author Roland Haeder + */ +@Named("basket") +@Dependent +public class ItemBasketBean implements BasketBean { + /** + * Serial number + */ + private static final long serialVersionUID = 4384123923163957L; + + /** + * Servlet context + */ + @Inject + private ServletContext application; + + /** + * Session + */ + @Inject + private HttpSession session; + + /** + * Instance of wrapped basket + */ + private final Basket basket; + + /** + * Default constructor to be able to throw exceptions from super constructor + * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the backend is unsupported + * @throws java.sql.SQLException If an SQL error occurs + */ + public ItemBasketBean () throws UnsupportedDatabaseBackendException, SQLException { + // Get new application instance + this.basket = new ItemBasket(); + } + + @Override + public void addItem (final AddableBasketItem item) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + this.basket.addItem(item); + } + + @Override + public AddableBasketItem getItem (final Product product) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + return this.basket.getItem(product); + } + + @Override + public String getMessageStringFromKey (final String key) { + return this.basket.getMessageStringFromKey(key); + } + + @Override + @PostConstruct + public void init () throws FacesException { + try { + // Init instance + this.basket.init(this.application, this.session); + } catch (final UnsupportedDatabaseBackendException | IOException | SQLException | BadTokenException ex) { + // Continue to throw + throw new FaceletException(ex); + } + } + + @Override + public boolean isEmpty () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + return this.basket.isEmpty(); + } + + @Override + public boolean isItemAdded (final AddableBasketItem item) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + return this.basket.isItemAdded(item); + } +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerBean.java b/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerBean.java new file mode 100644 index 00000000..12fc8fb6 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerBean.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.customer; + +import org.mxchange.pizzaapplication.customer.Customer; + +/** + * An interface for customer beans + * + * @author Roland Haeder + */ +public interface CustomerBean extends Customer { +} diff --git a/src/java/org/mxchange/pizzaapplication/customer/bean/PizzaServiceCustomerBean.java b/src/java/org/mxchange/pizzaapplication/customer/bean/PizzaServiceCustomerBean.java index ee40002b..d2fb8d70 100644 --- a/src/java/org/mxchange/pizzaapplication/customer/bean/PizzaServiceCustomerBean.java +++ b/src/java/org/mxchange/pizzaapplication/customer/bean/PizzaServiceCustomerBean.java @@ -24,7 +24,7 @@ import org.mxchange.jcore.client.Client; import org.mxchange.jcore.contact.Contact; import org.mxchange.jcore.contact.Gender; import org.mxchange.pizzaapplication.BasePizzaServiceSystem; -import org.mxchange.pizzaapplication.beans.CustomerBean; +import org.mxchange.pizzaapplication.beans.customer.CustomerBean; import org.mxchange.pizzaapplication.customer.PizzaServiceCustomer; /** diff --git a/src/java/org/mxchange/pizzaapplication/database/frontend/basket/BasketDatabaseFrontend.java b/src/java/org/mxchange/pizzaapplication/database/frontend/basket/BasketDatabaseFrontend.java index 1d03b562..fb563d84 100644 --- a/src/java/org/mxchange/pizzaapplication/database/frontend/basket/BasketDatabaseFrontend.java +++ b/src/java/org/mxchange/pizzaapplication/database/frontend/basket/BasketDatabaseFrontend.java @@ -199,6 +199,37 @@ public class BasketDatabaseFrontend extends BaseDatabaseFrontend implements Bask throw new UnsupportedOperationException(MessageFormat.format("Not supported yet: rowIndex={0}", rowIndex)); } + @Override + public boolean isEmpty () 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 search instance + SearchableCriteria criteria = new SearchCriteria(); + + // Add session id and product id and limit to 1 + criteria.addCriteria(BasketDatabaseConstants.COLUMN_SESSION_ID, this.getSessionId()); + criteria.setLimit(1); + + // Get result back + Result result = this.getBackend().doSelectByCriteria(criteria); + + // Is it empty? + boolean isEmpty = (!result.hasNext()); + + // Trace message + this.getLogger().trace(MessageFormat.format("isEmpty={0} - EXIT!", isEmpty)); + + // Return it + return isEmpty; + } + @Override public boolean isItemAdded (final AddableBasketItem item, final String sessionId) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { // Trace message diff --git a/src/java/org/mxchange/pizzaapplication/database/frontend/basket/BasketFrontend.java b/src/java/org/mxchange/pizzaapplication/database/frontend/basket/BasketFrontend.java index 323fae0a..45d53260 100644 --- a/src/java/org/mxchange/pizzaapplication/database/frontend/basket/BasketFrontend.java +++ b/src/java/org/mxchange/pizzaapplication/database/frontend/basket/BasketFrontend.java @@ -58,6 +58,20 @@ public interface BasketFrontend extends DatabaseFrontend { */ public AddableBasketItem getItem (final Product product, final String sessionId) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; + /** + * Checks if the basket is empty + * + * @return Whether the basket is empty + * @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 boolean isEmpty () throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; + /** * Checks if given item instance is found in basket by its id number. * diff --git a/src/java/org/mxchange/pizzaapplication/filter/servlet/basket/BasketItemAddedFilter.java b/src/java/org/mxchange/pizzaapplication/filter/servlet/basket/BasketItemAddedFilter.java index 3cfa682a..46ff6fa2 100644 --- a/src/java/org/mxchange/pizzaapplication/filter/servlet/basket/BasketItemAddedFilter.java +++ b/src/java/org/mxchange/pizzaapplication/filter/servlet/basket/BasketItemAddedFilter.java @@ -29,9 +29,7 @@ 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.jcore.exceptions.UnsupportedDatabaseBackendException; import org.mxchange.pizzaapplication.basket.Basket; -import org.mxchange.pizzaapplication.basket.item.ItemBasket; import org.mxchange.pizzaapplication.filter.servlet.BaseServletFilter; import org.mxchange.pizzaapplication.item.AddableBasketItem; @@ -43,6 +41,7 @@ import org.mxchange.pizzaapplication.item.AddableBasketItem; public class BasketItemAddedFilter extends BaseServletFilter implements Filter { @Override + @SuppressWarnings ("unchecked") public void doFilter (final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { // Trace message this.getLogger().trace(MessageFormat.format("request={0},response={1},chain={2} - CALLED!", request, response, chain)); //NOI18N @@ -81,7 +80,7 @@ public class BasketItemAddedFilter extends BaseServletFilter implements Filter { AddableBasketItem item = (AddableBasketItem) object; // Debug message - 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())); + 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 basket; @@ -99,7 +98,7 @@ public class BasketItemAddedFilter extends BaseServletFilter implements Filter { } // Get basket instance - basket = ItemBasket.getInstance(session); + basket = (Basket) session.getAttribute("basket"); //NOI18N // Is the item already added? if (item.getItemId() == null) { @@ -121,7 +120,7 @@ public class BasketItemAddedFilter extends BaseServletFilter implements Filter { // Register item with it basket.addItem(item); - } catch (final UnsupportedDatabaseBackendException | SQLException | BadTokenException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { + } catch (final SQLException | BadTokenException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { // Continue to throw throw new ServletException(ex); } diff --git a/src/java/org/mxchange/pizzaapplication/item/AddableBasketItem.java b/src/java/org/mxchange/pizzaapplication/item/AddableBasketItem.java index 12e3346b..a14b710a 100644 --- a/src/java/org/mxchange/pizzaapplication/item/AddableBasketItem.java +++ b/src/java/org/mxchange/pizzaapplication/item/AddableBasketItem.java @@ -69,18 +69,6 @@ public interface AddableBasketItem extends Storeable, Comparable. + */ +package org.mxchange.pizzaapplication.tags.basket; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.sql.SQLException; +import javax.enterprise.context.SessionScoped; +import javax.inject.Inject; +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.tagext.BodyTagSupport; +import org.mxchange.jcore.exceptions.BadTokenException; +import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException; +import org.mxchange.pizzaapplication.beans.basket.BasketBean; + +/** + * A basket tag that outputs a small basket and a link to the full basket website. + * + * @author Roland Haeder + */ +@SessionScoped +public class MiniBasketTag extends BodyTagSupport { + /** + * Basket instance + */ + @Inject + private BasketBean basket; + + /** + * Outputs a div container with last added item + a link to the basket + * web page. + * + * @return No need to process the body + * @throws JspException If anything happens + */ + @Override + public int doStartTag () throws JspException { + // Init output + StringBuilder out = new StringBuilder("
\n"); + + // basket should not be null + if (this.basket == null) { + // Not set + throw new NullPointerException("basket instance is null"); + } + + try { + // Some entries found? + if (this.basket.isEmpty()) { + // Empty basket + out.append("
\n"); + out.append(this.basket.getMessageStringFromKey("MiniBasketTag.basket_is_empty")).append("\n"); + out.append("
\n"); + } else { + // Some times were found + out.append("FOUND!"); + } + } catch (final IOException | SQLException | BadTokenException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { + // Continue to throw + throw new JspException(ex); + } + + // Finish output + out.append("
\n"); + + try { + // Get output instance and write it + pageContext.getOut().print(out.toString()); + } catch (final IOException ex) { + // Continue to throw + throw new JspException(ex); + } + + // Don't process any body + return SKIP_BODY; + } +} diff --git a/web/WEB-INF/tlds/basket.tld b/web/WEB-INF/tlds/basket.tld new file mode 100644 index 00000000..6eed62f3 --- /dev/null +++ b/web/WEB-INF/tlds/basket.tld @@ -0,0 +1,13 @@ + + + 1.0 + 1.2 + basket + http://mxchange.org/pizza-service/tags/basket + + + mini_basket + A mini basket showing latest added item and a link to the full basket web page + org.mxchange.pizzaapplication.tags.basket.MiniBasketTag + + diff --git a/web/admin/category.jsp b/web/admin/category.jsp index e8769598..3f9c0369 100644 --- a/web/admin/category.jsp +++ b/web/admin/category.jsp @@ -8,13 +8,13 @@ <%--<%@page errorPage="errorHandler.jsp" %>--%> <%@page import="org.mxchange.pizzaapplication.category.Category"%> <%@page import="org.mxchange.pizzaapplication.database.category.PizzaCategoryDatabaseConstants"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaServiceBean"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaBean"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <% // Init application instance - PizzaApplication app = PizzaServiceApplication.getInstance(application); + PizzaBean app = PizzaServiceBean.getInstance(application); %> @@ -22,13 +22,13 @@ - <%=PizzaServiceApplication.MAIN_TITLE%> - Kategorien + Pizza-Service - Kategorien diff --git a/web/admin/index.jsp b/web/admin/index.jsp index 933a0310..778b6b21 100644 --- a/web/admin/index.jsp +++ b/web/admin/index.jsp @@ -7,27 +7,27 @@ <%--<%@page errorPage="errorHandler.jsp" %>--%> <%@page import="java.util.Map"%> <%@page import="java.util.Iterator"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaServiceBean"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaBean"%> <%@page import="org.mxchange.pizzaapplication.product.Product"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <% // Init application instance - PizzaApplication app = PizzaServiceApplication.getInstance(application); + PizzaBean app = PizzaServiceBean.getInstance(application); %> - <%=PizzaServiceApplication.MAIN_TITLE%> - Administration + Pizza-Service - Administration diff --git a/web/admin/product.jsp b/web/admin/product.jsp index 85006fcb..cac2d9d9 100644 --- a/web/admin/product.jsp +++ b/web/admin/product.jsp @@ -11,26 +11,26 @@ <%@page import="java.util.Map"%> <%@page import="org.mxchange.jcore.contact.Gender"%> <%@page import="org.mxchange.pizzaapplication.product.Product"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaBean"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaServiceBean"%> <%@page import="org.mxchange.pizzaapplication.database.product.PizzaProductDatabaseConstants"%> <% // Init application instance - PizzaApplication app = PizzaServiceApplication.getInstance(application); + PizzaBean app = PizzaServiceBean.getInstance(application); %> - <%=PizzaServiceApplication.MAIN_TITLE%> - Produkte + Pizza-Service - Produkte diff --git a/web/bye.jsp b/web/bye.jsp index c9bbd00b..bb87fe23 100644 --- a/web/bye.jsp +++ b/web/bye.jsp @@ -5,20 +5,20 @@ --%> <%--<%@page errorPage="errorHandler.jsp" %>--%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaServiceBean"%> - <%=PizzaServiceApplication.MAIN_TITLE%> - Sitzung beenden + Pizza-Service - Sitzung beenden diff --git a/web/customer/login.jsp b/web/customer/login.jsp index 48bcd462..576f73f7 100644 --- a/web/customer/login.jsp +++ b/web/customer/login.jsp @@ -6,20 +6,20 @@ <%--<%@page errorPage="errorHandler.jsp" %>--%> <%@page contentType="text/html" pageEncoding="UTF-8"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaServiceBean"%> - <%=PizzaServiceApplication.MAIN_TITLE%> - Einloggen + Pizza-Service - Einloggen diff --git a/web/customer/lost_passwd.jsp b/web/customer/lost_passwd.jsp index b242e882..62cdae6b 100644 --- a/web/customer/lost_passwd.jsp +++ b/web/customer/lost_passwd.jsp @@ -6,20 +6,20 @@ <%--<%@page errorPage="errorHandler.jsp" %>--%> <%@page contentType="text/html" pageEncoding="UTF-8"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaServiceBean"%> - <%=PizzaServiceApplication.MAIN_TITLE%> - Passwort vergessen + Pizza-Service - Passwort vergessen diff --git a/web/customer/register.jsp b/web/customer/register.jsp index c3f999e3..1c7088ec 100644 --- a/web/customer/register.jsp +++ b/web/customer/register.jsp @@ -8,20 +8,20 @@ <%--<%@page errorPage="errorHandler.jsp" %>--%> <%@page contentType="text/html" pageEncoding="UTF-8"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaServiceBean"%> - <%=PizzaServiceApplication.MAIN_TITLE%> - Neukunde + Pizza-Service - Neukunde @@ -29,7 +29,7 @@
-

Anmelden zum <%=PizzaServiceApplication.MAIN_TITLE%>:

+

Anmelden zum Pizza-Service:

diff --git a/web/errorHandler.jsp b/web/errorHandler.jsp index 9f7dbdbf..059399fd 100644 --- a/web/errorHandler.jsp +++ b/web/errorHandler.jsp @@ -4,8 +4,8 @@ Author : Roland Haeder --%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaBean"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaServiceBean"%> <%@page import="java.io.PrintWriter"%> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> @@ -16,13 +16,13 @@ - <%=PizzaServiceApplication.MAIN_TITLE%> - Fehler + Pizza-Service - Fehler diff --git a/web/form_handler/add_item.jsp b/web/form_handler/add_item.jsp index b3d8ca83..4a9fb126 100644 --- a/web/form_handler/add_item.jsp +++ b/web/form_handler/add_item.jsp @@ -6,8 +6,8 @@ <%--<%@page errorPage="errorHandler.jsp" %>--%> <%@page contentType="text/html" pageEncoding="UTF-8"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaBean"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaServiceBean"%> <%@page import="org.mxchange.pizzaapplication.item.AddableBasketItem"%> @@ -15,7 +15,7 @@ <% // Init application instance - PizzaApplication app = PizzaServiceApplication.getInstance(application); + PizzaBean app = PizzaServiceBean.getInstance(application); // Get amount from item Long amount = item.getAmount(); @@ -38,12 +38,12 @@ - <%=PizzaServiceApplication.MAIN_TITLE%> - Form-Handler + Pizza-Service - Form-Handler
-

<%=PizzaServiceApplication.MAIN_TITLE%> - Form-Handler

+

Pizza-Service - Form-Handler

diff --git a/web/form_handler/admin/do_category.jsp b/web/form_handler/admin/do_category.jsp index 8c54f096..ca3fa531 100644 --- a/web/form_handler/admin/do_category.jsp +++ b/web/form_handler/admin/do_category.jsp @@ -6,15 +6,15 @@ <%--<%@page errorPage="errorHandler.jsp" %>--%> <%@page contentType="text/html" pageEncoding="UTF-8"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaServiceBean"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaBean"%> <%@page import="org.mxchange.pizzaapplication.beans.CustomerBean" %> <%@page import="org.mxchange.pizzaapplication.product.Product"%> <%@page import="org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException"%> <% // Init application instance - PizzaApplication app = PizzaServiceApplication.getInstance(application); + PizzaBean app = PizzaServiceBean.getInstance(application); // Handle forms app.doAdminHandleCategoryForms(request, response); @@ -25,12 +25,12 @@ - <%=PizzaServiceApplication.MAIN_TITLE%> - Form-Handler + Pizza-Service - Form-Handler
-

<%=PizzaServiceApplication.MAIN_TITLE%> - Form-Handler

+

Pizza-Service - Form-Handler

diff --git a/web/form_handler/admin/do_product.jsp b/web/form_handler/admin/do_product.jsp index 4631e09f..f806c874 100644 --- a/web/form_handler/admin/do_product.jsp +++ b/web/form_handler/admin/do_product.jsp @@ -6,14 +6,14 @@ <%--<%@page errorPage="errorHandler.jsp" %>--%> <%@page contentType="text/html" pageEncoding="UTF-8"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaServiceBean"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaBean"%> <%@page import="org.mxchange.pizzaapplication.beans.CustomerBean" %> <%@page import="org.mxchange.pizzaapplication.product.Product"%> <% // Init application instance - PizzaApplication app = PizzaServiceApplication.getInstance(application); + PizzaBean app = PizzaServiceBean.getInstance(application); // Handle forms app.doAdminHandleProductForms(request, response); @@ -24,12 +24,12 @@ - <%=PizzaServiceApplication.MAIN_TITLE%> - Form-Handler + Pizza-Service - Form-Handler
-

<%=PizzaServiceApplication.MAIN_TITLE%> - Form-Handler

+

Pizza-Service - Form-Handler

diff --git a/web/form_handler/do_order.jsp b/web/form_handler/do_order.jsp index 1b54e633..a6006607 100644 --- a/web/form_handler/do_order.jsp +++ b/web/form_handler/do_order.jsp @@ -6,14 +6,14 @@ <%--<%@page errorPage="errorHandler.jsp" %>--%> <%@page contentType="text/html" pageEncoding="UTF-8"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaServiceBean"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaBean"%> <%@page import="org.mxchange.pizzaapplication.beans.CustomerBean" %> <%@page import="org.mxchange.pizzaapplication.product.Product"%> <% // Init application instance - PizzaApplication app = PizzaServiceApplication.getInstance(application); + PizzaBean app = PizzaServiceBean.getInstance(application); // Is it post? if ("POST".equals(request.getMethod())) { //NOI18N @@ -38,12 +38,12 @@ - <%=PizzaServiceApplication.MAIN_TITLE%> - Form-Handler + Pizza-Service - Form-Handler
-

<%=PizzaServiceApplication.MAIN_TITLE%> - Form-Handler

+

Pizza-Service - Form-Handler

diff --git a/web/form_handler/do_preview.jsp b/web/form_handler/do_preview.jsp index 14657f69..f4b7f13d 100644 --- a/web/form_handler/do_preview.jsp +++ b/web/form_handler/do_preview.jsp @@ -9,14 +9,14 @@ <%@page import="java.util.Map"%> <%@page import="org.mxchange.jcore.contact.Gender"%> <%@page import="org.mxchange.pizzaapplication.product.Product"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaBean"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaServiceBean"%> <%@page import="org.mxchange.pizzaapplication.beans.CustomerBean" %> <%@page contentType="text/html" pageEncoding="UTF-8"%> <% // Init application instance - PizzaApplication app = PizzaServiceApplication.getInstance(application); + PizzaBean app = PizzaServiceBean.getInstance(application); // Is it post? if ("POST".equals(request.getMethod())) { //NOI18N @@ -56,12 +56,12 @@ - <%=PizzaServiceApplication.MAIN_TITLE%> - Form-Handler + Pizza-Service - Form-Handler
-

<%=PizzaServiceApplication.MAIN_TITLE%> - Form-Handler

+

Pizza-Service - Form-Handler

diff --git a/web/imprint.jsp b/web/imprint.jsp index 8a5e7ed4..cd0acdb2 100644 --- a/web/imprint.jsp +++ b/web/imprint.jsp @@ -5,20 +5,20 @@ --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaServiceBean"%> - <%=PizzaServiceApplication.MAIN_TITLE%> - Impressum + Pizza-Service - Impressum diff --git a/web/index.jsp b/web/index.jsp index a0757c00..f3c27c5a 100644 --- a/web/index.jsp +++ b/web/index.jsp @@ -4,35 +4,33 @@ Author : Roland Haeder --%> +<%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%> <%--<%@page errorPage="errorHandler.jsp" %>--%> <%@page import="java.util.Map"%> <%@page import="java.util.Iterator"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaBean"%> <%@page import="org.mxchange.pizzaapplication.product.Product"%> <%@page import="org.mxchange.pizzaapplication.basket.Basket"%> -<%@page import="org.mxchange.pizzaapplication.basket.item.ItemBasket"%> <%@page import="org.mxchange.pizzaapplication.item.basket.BasketItem"%> <%@page import="org.mxchange.pizzaapplication.item.AddableBasketItem"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +<%@taglib prefix="basket" uri="http://mxchange.org/pizza-service/tags/basket" %> + + -<% - // Init application instance - PizzaApplication app = PizzaServiceApplication.getInstance(application); -%> - <%=PizzaServiceApplication.MAIN_TITLE%> - Willkommen + Pizza-Service - Willkommen @@ -44,6 +42,8 @@
+ +
@@ -63,7 +63,7 @@ <% // Get Iterator - Iterator iterator = app.getAvailableProducts(); + Iterator iterator = service.getAvailableProducts(); // "Walk" through all products and unmark them as ordered while (iterator.hasNext()) { @@ -73,9 +73,6 @@ // Debug message product.getLogger().debug("product.itemId=" + product.getItemId()); - // Get basket instance - Basket basket = ItemBasket.getInstance(session); - // Create an item instance form this product AddableBasketItem item = basket.getItem(product); @@ -110,7 +107,7 @@ } // Unmark as ordered - app.unmarkProductAsOrdered(product, session); + service.unmarkProductAsOrdered(product, session); %>
diff --git a/web/index.xhtml b/web/index.xhtml deleted file mode 100644 index ae4a587f..00000000 --- a/web/index.xhtml +++ /dev/null @@ -1,98 +0,0 @@ - - - - - - - - Willkommen - - - - - - -
-
-

Folgendes kann bestellt werden:

-
- -
- - Bestellen? - Anzahl: - Produkt: - Einzelpreis: - - - <% - // Get app instance - PizzaApplication app = PizzaServiceApplication.getInstance(application); - - // Get Iterator - Iterator iterator = app.getAvailableProducts(); - - // "Walk" through all products and unmark them as ordered - while (iterator.hasNext()) { - // Get product instance - Product product = iterator.next(); - - // Get basket instance - Basket basket = ItemBasket.getInstance(session); - - // Create an item instance form this product - AddableBasketItem item = basket.getItem(product); - - // Has it been already added to the basket? - if (item != null) { - // Some nice output ... - %> - - Warenkorb - <%=item.getAmount()%> - <%=product.getTitle()%> - <%=product.getPrice()%> - - <% - // Then skip this item - continue; - } - - // Unmark as ordered - app.unmarkProductAsOrdered(product, session); - %> - - - - - - - - - - - - - <%=product.getTitle()%> - - - <%=product.getPrice()%> - - - - <% - } - %> -
-
- - - -
- diff --git a/web/privacy.jsp b/web/privacy.jsp index 9ed1ddff..00c02e3a 100644 --- a/web/privacy.jsp +++ b/web/privacy.jsp @@ -6,20 +6,20 @@ <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@page contentType="text/html" pageEncoding="UTF-8"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaServiceBean"%> - <%=PizzaServiceApplication.MAIN_TITLE%> - Datenschutzbestimmungen + Pizza-Service - Datenschutzbestimmungen diff --git a/web/static/admin/admin_category_selection_box.jsp b/web/static/admin/admin_category_selection_box.jsp index 39cbeab1..908bc072 100644 --- a/web/static/admin/admin_category_selection_box.jsp +++ b/web/static/admin/admin_category_selection_box.jsp @@ -6,16 +6,12 @@ <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@page import="org.mxchange.pizzaapplication.database.category.PizzaCategoryDatabaseConstants"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%> - -<% - // Init application instance - PizzaApplication app = PizzaServiceApplication.getInstance(application); -%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaServiceBean"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaBean"%> + diff --git a/web/static/admin/admin_parent_category_selection_box.jsp b/web/static/admin/admin_parent_category_selection_box.jsp index 2004c883..877396a6 100644 --- a/web/static/admin/admin_parent_category_selection_box.jsp +++ b/web/static/admin/admin_parent_category_selection_box.jsp @@ -6,17 +6,13 @@ <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@page import="org.mxchange.pizzaapplication.database.category.PizzaCategoryDatabaseConstants"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%> - -<% - // Init application instance - PizzaApplication app = PizzaServiceApplication.getInstance(application); -%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaServiceBean"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaBean"%> + diff --git a/web/static/gender_selection_box.jsp b/web/static/gender_selection_box.jsp index dfd0a2f9..615ef9e9 100644 --- a/web/static/gender_selection_box.jsp +++ b/web/static/gender_selection_box.jsp @@ -4,18 +4,14 @@ Author : Roland Haeder --%> <%@page import="org.mxchange.jcore.contact.Gender"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%> -<%@page import="org.mxchange.pizzaapplication.beans.CustomerBean" %> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaServiceBean"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaBean"%> +<%@page import="org.mxchange.pizzaapplication.beans.customer.CustomerBean" %> + -<% - // Init application instance - PizzaApplication app = PizzaServiceApplication.getInstance(application); -%> - -> <% // "Walk" through all genders and output them for (final Gender gender : Gender.values()) { diff --git a/web/terms.jsp b/web/terms.jsp index 506e7f89..bbd11465 100644 --- a/web/terms.jsp +++ b/web/terms.jsp @@ -6,20 +6,20 @@ <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@page contentType="text/html" pageEncoding="UTF-8"%> -<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> +<%@page import="org.mxchange.pizzaapplication.beans.PizzaServiceBean"%> - <%=PizzaServiceApplication.MAIN_TITLE%> - Allgemeine Geschäftsbedingungen + Pizza-Service - Allgemeine Geschäftsbedingungen