From: Roland Haeder Date: Fri, 4 Sep 2015 15:46:44 +0000 (+0200) Subject: More cleanups from TDGP towards EJB X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=256adc5dbf299402c428c8a4665702eb4cb50cd4;p=pizzaservice-war.git More cleanups from TDGP towards EJB Signed-off-by:Roland Häder --- diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml index 7c7566e6..ef45db9e 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -877,16 +877,8 @@ exists or setup the property manually. For example like this: - - - - - - - - - - + + @@ -1030,16 +1022,30 @@ exists or setup the property manually. For example like this: - + + + + + + + + - + + + + + + + + @@ -1452,9 +1458,7 @@ exists or setup the property manually. For example like this: CLEANUP SECTION --> - - - + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index d4e8376e..3c858bbd 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=dda72f05 +build.xml.data.CRC32=d470fc14 build.xml.script.CRC32=82213886 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=dda72f05 -nbproject/build-impl.xml.script.CRC32=06b680e3 +nbproject/build-impl.xml.data.CRC32=d470fc14 +nbproject/build-impl.xml.script.CRC32=617ba396 nbproject/build-impl.xml.stylesheet.CRC32=99ea4b56@1.68.1.1 diff --git a/nbproject/project.properties b/nbproject/project.properties index 5dd48b8a..d65221ed 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -29,7 +29,15 @@ endorsed.classpath=\ ${libs.javaee-endorsed-api-6.0.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.gf-client.jar=lib/gf-client.jar +file.reference.jcore.jar=lib/jcore.jar +file.reference.jsfcore.jar=lib/jsfcore.jar +file.reference.jshop.jar=lib/jshop.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 +file.reference.log4j-web-2.3.jar=lib/log4j-web-2.3.jar includes=** j2ee.compile.on.save=true j2ee.copy.static.files.on.save=true @@ -44,9 +52,16 @@ j2ee.platform.wsit.classpath= j2ee.server.type=gfv3ee6 jar.compress=false javac.classpath=\ - ${reference.jshop.jar}:\ + ${file.reference.jcore.jar}:\ + ${file.reference.jsfcore.jar}:\ + ${file.reference.jshop.jar}:\ ${file.reference.cdi-api.jar}:\ - ${file.reference.gf-client.jar} + ${file.reference.gf-client.jar}:\ + ${file.reference.commons-codec-1.10.jar}:\ + ${file.reference.commons-lang3-3.4.jar}:\ + ${file.reference.log4j-api-2.3.jar}:\ + ${file.reference.log4j-core-2.3.jar}:\ + ${file.reference.log4j-web-2.3.jar} # Space-separated list of extra javac options javac.compilerargs= javac.debug=true @@ -75,8 +90,6 @@ javadoc.windowtitle= lib.dir=${web.docbase.dir}/WEB-INF/lib persistence.xml.dir=${conf.dir} platform.active=default_platform -project.jshop=../../jshop -reference.jshop.jar=${project.jshop}/dist/jshop.jar resource.dir=setup run.test.classpath=\ ${javac.test.classpath}:\ diff --git a/nbproject/project.xml b/nbproject/project.xml index 954eb020..b8af222c 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -7,15 +7,43 @@ 1.6.5 - ${reference.jshop.jar} + ${file.reference.cdi-api.jar} WEB-INF/lib - ${file.reference.cdi-api.jar} + ${file.reference.gf-client.jar} WEB-INF/lib - ${file.reference.gf-client.jar} + ${file.reference.commons-codec-1.10.jar} + WEB-INF/lib + + + ${file.reference.commons-lang3-3.4.jar} + WEB-INF/lib + + + ${file.reference.jcore.jar} + WEB-INF/lib + + + ${file.reference.jsfcore.jar} + WEB-INF/lib + + + ${file.reference.jshop.jar} + WEB-INF/lib + + + ${file.reference.log4j-api-2.3.jar} + WEB-INF/lib + + + ${file.reference.log4j-core-2.3.jar} + WEB-INF/lib + + + ${file.reference.log4j-web-2.3.jar} WEB-INF/lib @@ -30,15 +58,6 @@ .\lib\nblibraries.properties - - - jshop - jar - - jar - clean - jar - - + diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java index f22e33d9..0b2f79ef 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java @@ -21,13 +21,7 @@ import java.lang.reflect.InvocationTargetException; import java.sql.SQLException; import java.util.Deque; import java.util.Iterator; -import javax.servlet.ServletContext; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; import org.mxchange.jcore.application.Application; -import org.mxchange.jcore.exceptions.BadTokenException; -import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException; -import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException; import org.mxchange.jshop.category.Category; import org.mxchange.jshop.exceptions.CategoryTitleAlreadyUsedException; import org.mxchange.jshop.exceptions.ProductTitleAlreadyUsedException; @@ -48,10 +42,8 @@ public interface PizzaApplication extends Application { * @throws java.lang.NoSuchMethodException If a method was not found * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly * @throws java.lang.reflect.InvocationTargetException If something else happens? - * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found - * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged */ - public Deque getAvailableProducts () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; + public Deque getAvailableProducts () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; /** * Some "getter" for a linked list of all products @@ -62,10 +54,8 @@ public interface PizzaApplication extends Application { * @throws java.lang.NoSuchMethodException If a method was not found * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly * @throws java.lang.reflect.InvocationTargetException If something else happens? - * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found - * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged */ - public Deque getAllProducts () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; + public Deque getAllProducts () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; /** * Some "getter" for a linked list of all categories @@ -76,21 +66,16 @@ public interface PizzaApplication extends Application { * @throws java.lang.NoSuchMethodException If a method was not found * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly * @throws java.lang.reflect.InvocationTargetException If something else happens? - * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found - * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged */ - public Deque getAllCategories () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; + public Deque getAllCategories () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; /** * Initializes this instance with given ServletContext * - * @param context Servlet context - * @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) throws UnsupportedDatabaseBackendException, SQLException, IOException, BadTokenException; + public void init () throws SQLException, IOException; /** * Some "getter" for a an array of only available products @@ -101,10 +86,8 @@ public interface PizzaApplication extends Application { * @throws java.lang.NoSuchMethodException If a method was not found * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly * @throws java.lang.reflect.InvocationTargetException If something else happens? - * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found - * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged */ - public Iterator getAvailableProductsIterator () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; + public Iterator getAvailableProductsIterator () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; /** * Some "getter" for a an array of all products @@ -115,10 +98,8 @@ public interface PizzaApplication extends Application { * @throws java.lang.NoSuchMethodException If a method was not found * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly * @throws java.lang.reflect.InvocationTargetException If something else happens? - * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found - * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged */ - public Iterator getAllProductsIterator () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; + public Iterator getAllProductsIterator () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; /** * Some "getter" for a an array of all categories @@ -129,10 +110,8 @@ public interface PizzaApplication extends Application { * @throws java.lang.NoSuchMethodException If a method was not found * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly * @throws java.lang.reflect.InvocationTargetException If something else happens? - * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found - * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged */ - public Iterator getAllCategoriesIterator () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; + public Iterator getAllCategoriesIterator () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; /** * Generates a link for category's parent category. If none is given, the method will return only a small @@ -166,74 +145,64 @@ public interface PizzaApplication extends Application { * @throws java.lang.NoSuchMethodException If a method was not found * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly * @throws java.lang.reflect.InvocationTargetException If something else happens? - * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found - * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged * @deprecated Old lost code */ @Deprecated - public String getPrintableProductCategory (final Product product) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; + public String getPrintableProductCategory (final Product product) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; /** * Adds given category data from request to database * - * @param request Request instance + * @param category Category instance * @throws org.mxchange.jshop.exceptions.CategoryTitleAlreadyUsedException The category's title is already used * @throws java.io.IOException If an IO error occurs * @throws java.sql.SQLException If an SQL error occurs * @throws java.lang.NoSuchMethodException If a method was not found * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly * @throws java.lang.reflect.InvocationTargetException If something else happens? - * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found - * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged */ - public void doAdminAddCategory (final ServletRequest request) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException; + public void doAdminAddCategory (final Category category) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException; /** * Adds given product data from request to database * - * @param request Request instance + * @param product Product instance * @throws java.io.IOException If an IO error occurs * @throws java.sql.SQLException If an SQL error occurs * @throws java.lang.NoSuchMethodException If a method was not found * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly * @throws java.lang.reflect.InvocationTargetException If something else happens? - * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found - * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged * @throws org.mxchange.jshop.exceptions.ProductTitleAlreadyUsedException If the product's title is already used */ - public void doAdminAddProduct (final ServletRequest request) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, ProductTitleAlreadyUsedException; + public void doAdminAddProduct (final Product product) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, ProductTitleAlreadyUsedException; /** * Handles admin product form requests * - * @param request Request instance - * @param response Response instance * @throws java.io.IOException If an IO error occurs * @throws java.sql.SQLException If an SQL error occurs * @throws java.lang.NoSuchMethodException If a method was not found * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly * @throws java.lang.reflect.InvocationTargetException If something else happens? - * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found - * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged * @throws org.mxchange.jshop.exceptions.ProductTitleAlreadyUsedException If the product's title is already used + * @deprecated Old lost code */ - public void doAdminHandleProductForms (final ServletRequest request, final ServletResponse response) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, ProductTitleAlreadyUsedException; + @Deprecated + public void doAdminHandleProductForms () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, ProductTitleAlreadyUsedException; /** * Handles admin category form requests * - * @param request Request instance - * @param response Response instance * @throws java.io.IOException If an IO error occurs * @throws java.sql.SQLException If an SQL error occurs * @throws java.lang.NoSuchMethodException If a method was not found * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly * @throws java.lang.reflect.InvocationTargetException If something else happens? - * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found - * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged * @throws org.mxchange.jshop.exceptions.CategoryTitleAlreadyUsedException The category's title is already used + * @deprecated */ - public void doAdminHandleCategoryForms (final ServletRequest request, final ServletResponse response) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException; + @Deprecated + public void doAdminHandleCategoryForms () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException; /** * Some "getter" for a Product instance from given item @@ -245,8 +214,6 @@ public interface PizzaApplication extends Application { * @throws java.lang.NoSuchMethodException If a method was not found * @throws java.lang.IllegalAccessException If the method cannot be accessed publicly * @throws java.lang.reflect.InvocationTargetException If something else happens? - * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found - * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged */ - public Product getProduct (final AddableBasketItem item) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; + public Product getProduct (final AddableBasketItem item) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; } diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java index c9f0ee24..cd83bce7 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java @@ -22,19 +22,7 @@ import java.sql.SQLException; import java.text.MessageFormat; import java.util.Deque; import java.util.Iterator; -import javax.servlet.ServletContext; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.mxchange.jcore.exceptions.BadTokenException; -import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException; -import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException; import org.mxchange.jshop.category.Category; -import org.mxchange.jshop.database.frontend.category.CategoryDatabaseFrontend; -import org.mxchange.jshop.database.frontend.category.CategoryFrontend; -import org.mxchange.jshop.database.frontend.product.ProductDatabaseFrontend; -import org.mxchange.jshop.database.frontend.product.ProductFrontend; import org.mxchange.jshop.exceptions.CategoryTitleAlreadyUsedException; import org.mxchange.jshop.exceptions.ProductTitleAlreadyUsedException; import org.mxchange.jshop.item.AddableBasketItem; @@ -47,16 +35,6 @@ import org.mxchange.pizzaapplication.BasePizzaServiceSystem; * @author Roland Haeder */ public class PizzaServiceApplication extends BasePizzaServiceSystem implements PizzaApplication { - /** - * Database frontend for products - */ - private ProductFrontend productFrontend; - - /** - * Database frontend for categories - */ - private CategoryFrontend categoryFrontend; - /** * Default constructor */ @@ -66,47 +44,35 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } @Override - public Deque getAllCategories () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + public Deque getAllCategories () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { // Deligate to frontend return this.categoryFrontend.getAllCategories(); } @Override - public Deque getAllProducts () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + public Deque getAllProducts () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { // Deligate to frontend return this.productFrontend.getAllProducts(); } @Override - public Deque getAvailableProducts () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + public Deque getAvailableProducts () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { // Deligate to frontend return this.productFrontend.getAllAvailableProducts(); } @Override - public void init (final ServletContext context) throws UnsupportedDatabaseBackendException, SQLException { + public void init () throws SQLException { // Trace message - this.getLogger().trace(MessageFormat.format("context={0} - CALLED!", context)); //NOI18N - - // context should not be null - if (null == context) { - // Abort here - throw new NullPointerException("context is null"); //NOI18N - } + this.getLogger().trace("CALLED!"); //NOI18N // Is the bundle initialized? - if (!this.isBundledInitialized()) { + if (!isBundledInitialized()) { // Temporary initialize default bundle // TODO The enum Gender uses this this.initBundle(); } - // Initialize properties from context - this.initProperties(context); - - // Init database frontends - this.initDatabaseFrontends(); - // Trace message this.getLogger().trace("EXIT!"); //NOI18N } @@ -150,12 +116,9 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P @Override @SuppressWarnings ("unchecked") - public Iterator getAvailableProductsIterator () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { - // categoryFrontend must be set - if (null == this.productFrontend) { - // Abort here - throw new NullPointerException("productFrontend is null"); //NOI18N - } + public Iterator getAvailableProductsIterator () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N // Ask frontend for a list of products return (Iterator) this.productFrontend.getAvailableProductsIterator(); @@ -163,100 +126,52 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P @Override @SuppressWarnings ("unchecked") - public Iterator getAllProductsIterator () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + public Iterator getAllProductsIterator () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { // Trace message this.getLogger().trace("CALLED!"); //NOI18N - // categoryFrontend must be set - if (null == this.productFrontend) { - // Abort here - throw new NullPointerException("productFrontend is null"); //NOI18N - } - // Ask frontend for a list of products return (Iterator) this.productFrontend.getAllProductsIterator(); } @Override @SuppressWarnings ("unchecked") - public Iterator getAllCategoriesIterator () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + public Iterator getAllCategoriesIterator () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { // Trace message this.getLogger().trace("CALLED!"); //NOI18N - // categoryFrontend must be set - if (null == this.categoryFrontend) { - // Abort here - throw new NullPointerException("categoryFrontend is null"); //NOI18N - } - // Ask frontend for a list of categories return (Iterator) this.categoryFrontend.getAllCategoriesIterator(); } - /** - * Initializes database frontends. - */ - private void initDatabaseFrontends () throws UnsupportedDatabaseBackendException, SQLException { - // Trace message - this.getLogger().trace("CALLED!"); //NOI18N - - // Product frontend - this.productFrontend = new ProductDatabaseFrontend(); - - // Category frontend - this.categoryFrontend = new CategoryDatabaseFrontend(); - - // Trace message - this.getLogger().trace("EXIT!"); //NOI18N - } - /** * Checks whether given category title is already used * * @param title Title of category to check * @return Whether it has been found */ - private boolean isCategoryTitleUsed(final String title) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { - // categoryFrontend must be set - if (null == this.categoryFrontend) { - // Abort here - throw new NullPointerException("categoryFrontend is null"); //NOI18N - } + private boolean isCategoryTitleUsed(final String title) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + // Trace message + this.getLogger().trace("title=" + title + " - CALLED!"); //NOI18N // Delegate to frontend return this.categoryFrontend.isCategoryTitleUsed(title); } - /** - * Checks if given product title is already used - * @param title Product title to check - * @return Whether the product title has already been used - */ - private boolean isProductTitleUsed (final String title) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { - // categoryFrontend must be set - if (null == this.productFrontend) { - // Abort here - throw new NullPointerException("productFrontend is null"); //NOI18N - } - - // Delegate to frontend - return this.productFrontend.isProductTitleUsed(title); - } - @Override - public void doAdminAddCategory (final ServletRequest request) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException { + public void doAdminAddCategory (final Category category) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException { // Trace message - this.getLogger().trace(MessageFormat.format("request={0} - CALLED!", request)); //NOI18N + this.getLogger().trace(MessageFormat.format("category={0} - CALLED!", category)); //NOI18N - // request must not be null - if (null == request) { + // category must not be null + if (null == category) { // Is null - throw new NullPointerException("request is null"); //NOI18N + throw new NullPointerException("category is null"); //NOI18N } // Get all fields - String title = request.getParameter(CategoryFrontend.COLUMN_TITLE); - String parentId = request.getParameter(CategoryFrontend.COLUMN_PARENT); + String title = category.getTitle(); + Long parentId = category.getParentId(); // Debug message this.getLogger().debug(MessageFormat.format("title={0},parentId={1}", title, parentId)); //NOI18N @@ -267,24 +182,19 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Check all fields if (null == title) { // "title" not set - throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", CategoryFrontend.COLUMN_TITLE)); //NOI18N + throw new IllegalArgumentException("title is not set."); //NOI18N } else if (title.isEmpty()) { // Is left empty - throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", CategoryFrontend.COLUMN_TITLE)); //NOI18N - } else if ((parentId != null) && (!parentId.isEmpty())) { - // "parent" is set, so check it - try { - id = Integer.parseInt(parentId); - } catch (final NumberFormatException e) { - // Not valid number - throw new IllegalArgumentException(e); - } + throw new IllegalArgumentException("title is empty."); //NOI18N + } else if ((parentId == null) || (parentId == 0)) { + // Is left empty + throw new IllegalArgumentException("parentId is empty."); //NOI18N } // Try to check if title is used already if (this.isCategoryTitleUsed(title)) { // Title already used - throw new CategoryTitleAlreadyUsedException(request); + throw new CategoryTitleAlreadyUsedException(category); } // The category is not found, so add it to database @@ -295,79 +205,51 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } @Override - public void doAdminAddProduct (final ServletRequest request) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, ProductTitleAlreadyUsedException { + public void doAdminAddProduct (final Product product) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, ProductTitleAlreadyUsedException { // Trace message - this.getLogger().trace(MessageFormat.format("request={0} - CALLED!", request)); //NOI18N + this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product)); //NOI18N - // request must not be null - if (null == request) { + // product must not be null + if (null == product) { // Is null - throw new NullPointerException("request is null"); //NOI18N + throw new NullPointerException("product is null"); //NOI18N } // Get title, price and category id - String title = request.getParameter(ProductFrontend.COLUMN_TITLE); - String price = request.getParameter(ProductFrontend.COLUMN_PRICE); - String categoryId = request.getParameter(ProductFrontend.COLUMN_CATEGORY); - String available = request.getParameter(ProductFrontend.COLUMN_AVAILABLE); + String title = product.getTitle(); + Float price = product.getPrice(); + Long categoryId = product.getCategoryId(); + Boolean available = product.getAvailable(); // Debug message this.getLogger().debug(MessageFormat.format("title={0},price={1},categoryId={2},available={3}", title, price, categoryId, available)); //NOI18N - // Variables for converting - Long id = null; - Float p = null; - // Check all fields if (null == title) { // "title" not set - throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", ProductFrontend.COLUMN_TITLE)); //NOI18N + throw new IllegalArgumentException("product title is not set"); //NOI18N } else if (title.isEmpty()) { // Is left empty - throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", ProductFrontend.COLUMN_TITLE)); //NOI18N + throw new IllegalArgumentException("product title is empty"); //NOI18N } else if (null == price) { // "price" not set - throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", ProductFrontend.COLUMN_PRICE)); //NOI18N - } else if (price.isEmpty()) { - // Is left empty - throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", ProductFrontend.COLUMN_PRICE)); //NOI18N + throw new IllegalArgumentException("product price is not set."); //NOI18N } else if (null == categoryId) { // "title" not set - throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", ProductFrontend.COLUMN_CATEGORY)); //NOI18N - } else if (categoryId.isEmpty()) { - // Is left empty - throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", ProductFrontend.COLUMN_CATEGORY)); //NOI18N + throw new IllegalArgumentException("product category id is not set."); //NOI18N } else if (null == available) { // "title" not set - throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", ProductFrontend.COLUMN_AVAILABLE)); //NOI18N - } else if (available.isEmpty()) { - // Is left empty - throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", ProductFrontend.COLUMN_AVAILABLE)); //NOI18N - } else if ((!"true".equals(available)) && (!"false".equals(available))) { //NOI18N - // Invalid value - throw new IllegalArgumentException(MessageFormat.format("{0} is invalid: {1}", ProductFrontend.COLUMN_AVAILABLE, available)); //NOI18N - } - - // Parse numbers - try { - id = Long.parseLong(categoryId); - p = Float.parseFloat(price); - } catch (final NumberFormatException e) { - // Not valid number - throw new IllegalArgumentException(e); + throw new IllegalArgumentException("product availability not set."); //NOI18N } - // Parse boolean - Boolean a = Boolean.parseBoolean(available); - // Try to check if title is used already - if (this.isProductTitleUsed(title)) { + if (this.isProductTitleUsed(product)) { // Title already used - throw new ProductTitleAlreadyUsedException(request); + throw new ProductTitleAlreadyUsedException(product); } // The product is not found, so add it to database - this.productFrontend.addProduct(title, p, id, a); + this.productFrontend.addProduct(title, price, categoryId, available); // Trace message this.getLogger().trace("EXIT!"); //NOI18N @@ -400,7 +282,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P @Override @Deprecated - public String getPrintableProductCategory (final Product product) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + public String getPrintableProductCategory (final Product product) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { // Trace message this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product)); //NOI18N @@ -432,7 +314,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P /** * Checks if product's title is already used. * - * @param request Request instance + * @param product Product instance * @return Whether the product title is already used * @throws java.io.IOException If any IO error occurs * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found in a file-based database backend's file ... ;-) @@ -442,131 +324,54 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P * @throws java.lang.IllegalAccessException If the method cannot be accessed * @throws java.lang.reflect.InvocationTargetException Any other problems? */ - private boolean isProductTitleUsed (final ServletRequest request) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + private boolean isProductTitleUsed (final Product product) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // Trace message - this.getLogger().trace(MessageFormat.format("request={0} - CALLED!", request)); //NOI18N + this.getLogger().trace(MessageFormat.format("category={0} - CALLED!", product)); //NOI18N // Init title - String title = request.getParameter(ProductFrontend.COLUMN_TITLE); + String title = product.getTitle(); - // request must not be null and "title" must be found and non-empty - if (null == request) { + // category must not be null and "title" must be found and non-empty + if (null == product) { // Abort here - throw new NullPointerException("request is null"); //NOI18N + throw new NullPointerException("category is null"); //NOI18N } else if (null == title) { // title is not set - throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", ProductFrontend.COLUMN_TITLE)); //NOI18N + throw new IllegalArgumentException("product title is not set"); //NOI18N } else if (title.isEmpty()) { // Is left empty - throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", ProductFrontend.COLUMN_TITLE)); //NOI18N + throw new IllegalArgumentException("product title is empty"); //NOI18N } // Default is not used - boolean isUsed = this.isProductTitleUsed(title); + // TODO Call backend + throw new UnsupportedOperationException("not finished yet."); // Trace message - this.getLogger().trace(MessageFormat.format("isUsed={0} - EXIT!", isUsed)); //NOI18N + //this.getLogger().trace(MessageFormat.format("isUsed={0} - EXIT!", isUsed)); //NOI18N // Return it - return isUsed; + //return isUsed; } @Override - public void doAdminHandleProductForms (final ServletRequest request, final ServletResponse response) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, ProductTitleAlreadyUsedException { - // Trace message - this.getLogger().trace(MessageFormat.format("request={0},response={1} - CALLED!", request, response)); //NOI18N - - // request and response must both be set - if (null == request) { - // request is null - throw new NullPointerException("request is null"); //NOI18N - } else if (null == response) { - // response is null - throw new NullPointerException("response is null"); //NOI18N - } - - // Is it post? - if ("POST".equals(((HttpServletRequest) request).getMethod())) { //NOI18N - // Is "add/edit/delete" set? - if (request.getParameter("add") != null) { //NOI18N - // Is it already added? - if (this.isProductTitleUsed(request)) { - // Debug message - this.getLogger().debug("Already used, redirecting ..."); //NOI18N - - // Already added, so redirect here, else a ServletException will be thrown - ((HttpServletResponse) response).sendRedirect(String.format("%s/admin/product.jsp?already=1", ((HttpServletRequest) request).getContextPath())); //NOI18N - } else { - // Add new product - this.doAdminAddProduct(request); - - // Redirect to proper URL - ((HttpServletResponse) response).sendRedirect(String.format("%s/admin/product.jsp?added=1", ((HttpServletRequest) request).getContextPath())); //NOI18N - } - } else if (request.getParameter("edit") != null) { //NOI18N - // TODO - } else if (request.getParameter("delete") != null) { //NOI18N - // TODO - } - - // Request not handled - throw new IllegalArgumentException("request not handled."); //NOI18N - } - - // Trace message - this.getLogger().trace("EXIT!"); //NOI18N + @Deprecated + public void doAdminHandleProductForms () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, ProductTitleAlreadyUsedException { + // Deprecated method called + throw new UnsupportedOperationException("Deprecated method called."); } @Override - public void doAdminHandleCategoryForms (final ServletRequest request, final ServletResponse response) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException { - // Trace message - this.getLogger().trace(MessageFormat.format("request={0},response={1} - CALLED!", request, response)); //NOI18N - - // request and response must both be set - if (null == request) { - // request is null - throw new NullPointerException("request is null"); //NOI18N - } else if (null == response) { - // response is null - throw new NullPointerException("response is null"); //NOI18N - } - - // Is it post? - if ("POST".equals(((HttpServletRequest) request).getMethod())) { //NOI18N - // Is "add/edit/delete" set? - if (request.getParameter("add") != null) { //NOI18N - // Is the category title already used? - if (this.isCategoryTitleUsed(request)) { - // Debug message - this.getLogger().debug("Already used, redirecting ..."); //NOI18N - - // Already added, so redirect here, else a ServletException will be thrown - ((HttpServletResponse) response).sendRedirect(String.format("%s/admin/category.jsp?already=1", ((HttpServletRequest) request).getContextPath())); //NOI18N - } else { - // Add new category - this.doAdminAddCategory(request); - - // Redirect to proper URL - ((HttpServletResponse) response).sendRedirect(String.format("%s/admin/category.jsp?added=1", ((HttpServletRequest) request).getContextPath())); //NOI18N - } - } else if (request.getParameter("edit") != null) { //NOI18N - // TODO - } else if (request.getParameter("delete") != null) { //NOI18N - // TODO - } - - // Request not handled - throw new IllegalArgumentException("request not handled."); //NOI18N - } - - // Trace message - this.getLogger().trace("EXIT!"); //NOI18N + @Deprecated + public void doAdminHandleCategoryForms () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException { + // Deprecated method called + throw new UnsupportedOperationException("Deprecated method called."); } /** * Checks if category's title is already used. * - * @param request Request instance + * @param category Category instance * @return Whether the product title is already used * @throws java.io.IOException If any IO error occurs * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found in a file-based database backend's file ... ;-) @@ -576,23 +381,23 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P * @throws java.lang.IllegalAccessException If the method cannot be accessed * @throws java.lang.reflect.InvocationTargetException Any other problems? */ - private boolean isCategoryTitleUsed (final ServletRequest request) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + private boolean isCategoryTitleUsed (final Category category) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // Trace message - this.getLogger().trace(MessageFormat.format("request={0} - CALLED!", request)); //NOI18N + this.getLogger().trace(MessageFormat.format("category={0} - CALLED!", category)); //NOI18N // Init title - String title = request.getParameter(CategoryFrontend.COLUMN_TITLE); + String title = category.getTitle(); - // request must not be null and "title" must be found and non-empty - if (null == request) { + // category must not be null and "title" must be found and non-empty + if (null == category) { // Abort here - throw new NullPointerException("request is null"); //NOI18N + throw new NullPointerException("category is null"); //NOI18N } else if (null == title) { // title is not set - throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", CategoryFrontend.COLUMN_TITLE)); //NOI18N + throw new IllegalArgumentException("category title is not set."); //NOI18N } else if (title.isEmpty()) { // Is left empty - throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", CategoryFrontend.COLUMN_TITLE)); //NOI18N + throw new IllegalArgumentException("category title is empty."); //NOI18N } // Default is not used @@ -606,7 +411,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } @Override - public Product getProduct (final AddableBasketItem item) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + public Product getProduct (final AddableBasketItem item) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { // Trace message this.getLogger().trace(MessageFormat.format("item={0} - CALLED!", item)); //NOI18N @@ -614,9 +419,6 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P if (null == item) { // Abort here throw new NullPointerException("item is null"); //NOI18N - } else if (null == this.productFrontend) { - // Abort here - throw new NullPointerException("productFrontend is null"); //NOI18N } // Init product instance diff --git a/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaBean.java b/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaBean.java index ff23c127..8ad0547f 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaBean.java @@ -16,12 +16,10 @@ */ package org.mxchange.pizzaapplication.beans.controller; +import java.rmi.RemoteException; import java.util.Deque; import java.util.Iterator; import javax.faces.FacesException; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.http.HttpSession; import org.mxchange.jshop.beans.FrameworkBean; import org.mxchange.jshop.category.Category; import org.mxchange.jshop.exceptions.CategoryTitleAlreadyUsedException; @@ -45,49 +43,49 @@ public interface PizzaBean extends FrameworkBean { * Some "getter" for an iterator of only available products * * @return Only available products - * @throws javax.servlet.ServletException If anything went wrong + * @throws java.rmi.RemoteException If anything went wrong */ - public Iterator getAvailableProductsIterator () throws ServletException; + public Iterator getAvailableProductsIterator () throws RemoteException; /** * Some "getter" for an iterator of all products * * @return All products - * @throws javax.servlet.ServletException If anything went wrong + * @throws java.rmi.RemoteException If anything went wrong */ - public Iterator getAllProductsIterator () throws ServletException; + public Iterator getAllProductsIterator () throws RemoteException; /** * Some "getter" for an iterator of all categories * * @return All categories - * @throws javax.servlet.ServletException If anything went wrong + * @throws java.rmi.RemoteException If anything went wrong */ - public Iterator getAllCategoriesIterator () throws ServletException; + public Iterator getAllCategoriesIterator () throws RemoteException; /** * Some "getter" for a linked list of only available products * * @return Only available products - * @throws javax.servlet.ServletException If anything went wrong + * @throws java.rmi.RemoteException If anything went wrong */ - public Deque getAvailableProducts () throws ServletException; + public Deque getAvailableProducts () throws RemoteException; /** * Some "getter" for a linked list of all products * * @return All products - * @throws javax.servlet.ServletException If anything went wrong + * @throws java.rmi.RemoteException If anything went wrong */ - public Deque getAllProducts () throws ServletException; + public Deque getAllProducts () throws RemoteException; /** * Some "getter" for a linked list of all categories * * @return All categories - * @throws javax.servlet.ServletException If anything went wrong + * @throws java.rmi.RemoteException If anything went wrong */ - public Deque getAllCategories () throws ServletException; + public Deque getAllCategories () throws RemoteException; /** * Generates a link for category's parent category. If none is given, the method will return only a small @@ -116,49 +114,53 @@ public interface PizzaBean extends FrameworkBean { * * @param product Product instance to check * @return Human-readable version of product availability - * @throws javax.servlet.ServletException If something unexpected happened + * @throws java.rmi.RemoteException If something unexpected happened * @deprecated Old lost code */ @Deprecated - public String getPrintableProduktCategory (final Product product) throws ServletException; + public String getPrintableProduktCategory (final Product product) throws RemoteException; /** * Adds given category data from request to database * - * @param request Request instance - * @throws javax.servlet.ServletException If something unexpected happened + * @param category Category instance + * @throws java.rmi.RemoteException If something unexpected happened * @throws org.mxchange.jshop.exceptions.CategoryTitleAlreadyUsedException If the given title is already used */ - public void doAdminAddCategory (final ServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException; + public void doAdminAddCategory (final Category category) throws RemoteException, CategoryTitleAlreadyUsedException; /** * Adds given product data from request to database * - * @param request Request instance - * @throws javax.servlet.ServletException If something unexpected happened + * @param product Product instance + * @throws java.rmi.RemoteException If something unexpected happened * @throws org.mxchange.jshop.exceptions.ProductTitleAlreadyUsedException If the given product title is already used */ - public void doAdminAddProduct (final ServletRequest request) throws ServletException, ProductTitleAlreadyUsedException; + public void doAdminAddProduct (final Product product) throws RemoteException, ProductTitleAlreadyUsedException; /** * Handles admin product form requests * - * @throws ServletException If something unexpected happened + * @throws RemoteException If something unexpected happened + * @deprecated Old lost code */ - public void doAdminHandleProductForms () throws ServletException; + @Deprecated + public void doAdminHandleProductForms () throws RemoteException; /** * Handles admin category form requests * - * @throws ServletException If something unexpected happened + * @throws RemoteException If something unexpected happened + * @deprecated Old lost code */ - public void doAdminHandleCategoryForms () throws ServletException; + @Deprecated + public void doAdminHandleCategoryForms () throws RemoteException; /** * Some "getter" for a product from given item * @param item Item instance * @return A Product instance - * @throws javax.servlet.ServletException If something bad happens + * @throws java.rmi.RemoteException If something bad happens */ - public Product getProduct (final AddableBasketItem item) throws ServletException; + public Product getProduct (final AddableBasketItem item) throws RemoteException; } diff --git a/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceBean.java b/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceBean.java index 76cedd68..66cfb17e 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/controller/PizzaServiceBean.java @@ -18,6 +18,7 @@ package org.mxchange.pizzaapplication.beans.controller; import java.io.IOException; import java.lang.reflect.InvocationTargetException; +import java.rmi.RemoteException; import java.sql.SQLException; import java.text.MessageFormat; import java.util.Deque; @@ -26,11 +27,6 @@ import javax.annotation.PostConstruct; import javax.enterprise.context.SessionScoped; import javax.faces.FacesException; import javax.inject.Named; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import org.mxchange.jcore.exceptions.BadTokenException; -import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException; -import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException; import org.mxchange.jshop.beans.BaseFrameworkBean; import org.mxchange.jshop.category.Category; import org.mxchange.jshop.exceptions.CategoryTitleAlreadyUsedException; @@ -88,8 +84,8 @@ public class PizzaServiceBean extends BaseFrameworkBean implements PizzaBean { try { // Call init method - this.app.init(this.getApplication()); - } catch (final UnsupportedDatabaseBackendException | SQLException | IOException | BadTokenException ex) { + this.app.init(); + } catch (final SQLException | IOException ex) { // Continue to throw throw new FacesException(ex); } @@ -102,124 +98,118 @@ public class PizzaServiceBean extends BaseFrameworkBean implements PizzaBean { } @Override - public Iterator getAvailableProductsIterator () throws ServletException { + public Iterator getAvailableProductsIterator () throws RemoteException { try { return this.app.getAvailableProductsIterator(); - } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { + } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { // Continue to throw - throw new ServletException(ex); + throw new RemoteException("getAvailableProductsIterator() failed", ex); } } @Override - public Iterator getAllProductsIterator () throws ServletException { + public Iterator getAllProductsIterator () throws RemoteException { try { return this.app.getAllProductsIterator(); - } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { + } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { // Continue to throw - throw new ServletException(ex); + throw new RemoteException("getAllProductsIterator() failed.", ex); } } @Override - public Deque getAvailableProducts () throws ServletException { + public Deque getAvailableProducts () throws RemoteException { try { return this.app.getAvailableProducts(); - } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { + } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { // Continue to throw - throw new ServletException(ex); + throw new RemoteException("getAvailableProducts() failed.", ex); } } @Override - public Deque getAllProducts () throws ServletException { + public Deque getAllProducts () throws RemoteException { try { return this.app.getAllProducts(); - } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { + } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { // Continue to throw - throw new ServletException(ex); + throw new RemoteException("getAllProducts() failed", ex); } } @Override - public Iterator getAllCategoriesIterator () throws ServletException { + public Iterator getAllCategoriesIterator () throws RemoteException { try { return this.app.getAllCategoriesIterator(); - } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { + } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { // Continue to throw - throw new ServletException(ex); + throw new RemoteException("getAllCategoriesIterator() failed.", ex); } } @Override - public Deque getAllCategories () throws ServletException { + public Deque getAllCategories () throws RemoteException { try { return this.app.getAllCategories(); - } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { + } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { // Continue to throw - throw new ServletException(ex); + throw new RemoteException("getAllCategories() failed.", ex); } } @Override - public void doAdminAddCategory (final ServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException { + public void doAdminAddCategory (final Category category) throws RemoteException, CategoryTitleAlreadyUsedException { try { - this.app.doAdminAddCategory(request); - } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { + this.app.doAdminAddCategory(category); + } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { // Continue to throw - throw new ServletException(ex); + throw new RemoteException("doAdminAddCategory() failed.", ex); } } @Override - public void doAdminAddProduct (final ServletRequest request) throws ServletException, ProductTitleAlreadyUsedException { + public void doAdminAddProduct (final Product product) throws RemoteException, ProductTitleAlreadyUsedException { try { - this.app.doAdminAddProduct(request); - } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { + this.app.doAdminAddProduct(product); + } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { // Continue to throw - throw new ServletException(ex); + throw new RemoteException("doAdminAddProduct() failed.", ex); } } @Override @Deprecated - public String getPrintableProduktCategory (final Product product) throws ServletException { + public String getPrintableProduktCategory (final Product product) throws RemoteException { try { return this.app.getPrintableProductCategory(product); - } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { + } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { // Continue to throw - throw new ServletException(ex); + throw new RemoteException("getPrintableProduktCategory() failed.", ex); } } @Override - public void doAdminHandleProductForms () throws ServletException { - try { - this.app.doAdminHandleProductForms(this.getRequest(), this.getResponse()); - } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | ProductTitleAlreadyUsedException ex) { - // Continue to throw - throw new ServletException(ex); - } + @Deprecated + public void doAdminHandleProductForms () throws RemoteException { + // Deprecated method called + throw new UnsupportedOperationException("Deprecated method called"); } @Override - public void doAdminHandleCategoryForms () throws ServletException { - try { - this.app.doAdminHandleCategoryForms(this.getRequest(), this.getResponse()); - } catch (final IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | CategoryTitleAlreadyUsedException ex) { - // Continue to throw - throw new ServletException(ex); - } + @Deprecated + public void doAdminHandleCategoryForms () throws RemoteException { + // Deprecated method called + throw new UnsupportedOperationException("Deprecated method called"); } @Override - public Product getProduct (final AddableBasketItem item) throws ServletException { + public Product getProduct (final AddableBasketItem item) throws RemoteException { try { // Deligate to application return this.app.getProduct(item); - } catch (IOException | BadTokenException | SQLException | CorruptedDatabaseFileException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { + } catch (IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { // Continue to throw - throw new ServletException(ex); + throw new RemoteException("getProductI() failed.", ex); } } diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerBean.java b/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerBean.java index ffe424ab..4dbdd44c 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerBean.java @@ -16,12 +16,8 @@ */ package org.mxchange.pizzaapplication.beans.customer; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.util.Iterator; -import java.util.Map; import org.mxchange.jcore.client.Client; -import org.mxchange.jcore.contact.Gender; +import org.mxchange.jcore.contact.gender.Gender; import org.mxchange.jshop.beans.FrameworkBean; /** @@ -30,16 +26,6 @@ import org.mxchange.jshop.beans.FrameworkBean; * @author Roland Haeder */ public interface CustomerBean extends FrameworkBean { - /** - * Returns an iterator of all values from this object - * - * @return An iterator - * @throws java.lang.NoSuchMethodException If the invoked method was not found - * @throws java.lang.IllegalAccessException If the method cannot be accessed - * @throws java.lang.reflect.InvocationTargetException Any other problems? - */ - public Iterator> iterator ()throws NoSuchMethodException, IllegalAccessException, InvocationTargetException; - /** * Some "getter" for translated gender of the contact * @@ -270,30 +256,4 @@ public interface CustomerBean extends FrameworkBean { * @param client Client instance to call back */ public void show (final Client client); - - /** - * Some "getter for a value from given column name. This name will be - * translated into a method name and then this method is called. - * - * @param columnName Column name - * @return Value from field - * @throws IllegalArgumentException Some implementations may throw this - * @throws java.lang.NoSuchMethodException If the invoked method was not found - * @throws java.lang.IllegalAccessException If the method cannot be accessed - * @throws java.lang.reflect.InvocationTargetException Any other problems? - */ - public Object getValueFromColumn (final String columnName) throws IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; - - /** - * Some "setter" for a value from given column name. You may wish to overwrite this method in your - * own class. - * - * @param columnName Column name - * @param value Value to set in object's field - * @throws IllegalArgumentException Some implementations may throw this - * @throws java.lang.NoSuchMethodException If the invoked method was not found - * @throws java.lang.IllegalAccessException If the method cannot be accessed - * @throws java.lang.reflect.InvocationTargetException Any other problems? - */ - public void setValueFromColumn (final String columnName, final Object value) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException; } diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaServiceCustomerBean.java b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaServiceCustomerBean.java index 370539a1..b57ce0e0 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaServiceCustomerBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaServiceCustomerBean.java @@ -24,7 +24,7 @@ import javax.enterprise.context.SessionScoped; import javax.inject.Named; import org.mxchange.jcore.client.Client; import org.mxchange.jcore.contact.Contact; -import org.mxchange.jcore.contact.Gender; +import org.mxchange.jcore.contact.gender.Gender; import org.mxchange.jshop.beans.BaseFrameworkBean; import org.mxchange.pizzaapplication.customer.PizzaServiceCustomer; @@ -254,29 +254,11 @@ public class PizzaServiceCustomerBean extends BaseFrameworkBean implements Custo throw new UnsupportedOperationException("Not supported yet."); //NOI18N } - @Override - public Iterator> iterator () throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { - // Deligate to "hidden" object - return this.getContact().iterator(); - } - @Override public void show (final Client client) { throw new UnsupportedOperationException("Not supported yet."); //NOI18N } - @Override - public Object getValueFromColumn (final String columnName) throws IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { - // Deligate to "hidden" object - return this.getContact().getValueFromColumn(columnName); - } - - @Override - public void setValueFromColumn (final String columnName, final Object value) throws IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { - // Deligate to "hidden" object - this.getContact().setValueFromColumn(columnName, value); - } - /** * Setter for Contact instance * @param contact Contact instance to set diff --git a/src/java/org/mxchange/pizzaapplication/beans/enums/DataBean.java b/src/java/org/mxchange/pizzaapplication/beans/enums/DataBean.java deleted file mode 100644 index 6a7d4000..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/enums/DataBean.java +++ /dev/null @@ -1,41 +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.enums; - -import java.util.List; -import org.mxchange.jcore.contact.Gender; -import org.mxchange.jshop.beans.FrameworkBean; - -/** - * An interface for data beans - * - * @author Roland Haeder - */ -public interface DataBean extends FrameworkBean { - /** - * Getter for all genders as array - * - * @return All genders as array - */ - public Gender[] getGenders (); - /** - * Getter for only selectable genders as array, UNKNOWN is not selectable - * - * @return All genders as array - */ - public List getSelectableGenders (); -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/enums/DataWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/enums/DataWebBean.java new file mode 100644 index 00000000..fa210d00 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/enums/DataWebBean.java @@ -0,0 +1,41 @@ +/* + * 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.enums; + +import java.util.List; +import org.mxchange.jcore.contact.gender.Gender; +import org.mxchange.jshop.beans.FrameworkBean; + +/** + * An interface for data beans + * + * @author Roland Haeder + */ +public interface DataWebBean extends FrameworkBean { + /** + * Getter for all genders as array + * + * @return All genders as array + */ + public Gender[] getGenders (); + /** + * Getter for only selectable genders as array, UNKNOWN is not selectable + * + * @return All genders as array + */ + public List getSelectableGenders (); +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/enums/PizzaServiceDataBean.java b/src/java/org/mxchange/pizzaapplication/beans/enums/PizzaServiceDataBean.java deleted file mode 100644 index 152f60bd..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/enums/PizzaServiceDataBean.java +++ /dev/null @@ -1,86 +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.enums; - -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Named; -import org.mxchange.jcore.contact.Gender; -import org.mxchange.jshop.beans.BaseFrameworkBean; - -/** - * A customer bean which hides the customer instance - * - * @author Roland Haeder - */ -@Named ("data") -@ApplicationScoped -public class PizzaServiceDataBean extends BaseFrameworkBean implements DataBean { - - /** - * Serial number - */ - private static final long serialVersionUID = 835482364189L; - - @Override - public Gender[] getGenders () { - // Trace message - this.getLogger().trace(MessageFormat.format("Genders={0} - EXIT!", Arrays.toString(Gender.values()))); - - // Return it - return Gender.values(); - } - - @Override - public List getSelectableGenders () { - // Trace message - this.getLogger().trace("CALLED!"); //NOI18N - - // Init array - List genders = new ArrayList<>(this.getGenders().length - 1); - - // Debug message - this.getLogger().debug(MessageFormat.format("genders.size()={0}", genders.size())); - - // Return it - for (final Gender gender : Gender.values()) { - // Debug message - this.getLogger().debug(MessageFormat.format("gender={0}", gender)); - - // Is it unknown? - if (!gender.equals(Gender.UNKNOWN)) { - // Debug message - this.getLogger().debug(MessageFormat.format("gender={0} - adding ...", gender)); - - // Not, then add it - boolean added = genders.add(gender); - - // Debug message - this.getLogger().debug(MessageFormat.format("added={0}", added)); - } - } - - // Trace message - this.getLogger().trace(MessageFormat.format("genders={0} - EXIT!", genders)); //NOI18N - - // Return it - return genders; - } -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/enums/PizzaServiceDataWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/enums/PizzaServiceDataWebBean.java new file mode 100644 index 00000000..3d32fc9c --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/enums/PizzaServiceDataWebBean.java @@ -0,0 +1,86 @@ +/* + * 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.enums; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Named; +import org.mxchange.jcore.contact.gender.Gender; +import org.mxchange.jshop.beans.BaseFrameworkBean; + +/** + * A customer bean which hides the customer instance + * + * @author Roland Haeder + */ +@Named ("data") +@ApplicationScoped +public class PizzaServiceDataWebBean extends BaseFrameworkBean implements DataWebBean { + + /** + * Serial number + */ + private static final long serialVersionUID = 835482364189L; + + @Override + public Gender[] getGenders () { + // Trace message + this.getLogger().trace(MessageFormat.format("Genders={0} - EXIT!", Arrays.toString(Gender.values()))); + + // Return it + return Gender.values(); + } + + @Override + public List getSelectableGenders () { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + + // Init array + List genders = new ArrayList<>(this.getGenders().length - 1); + + // Debug message + this.getLogger().debug(MessageFormat.format("genders.size()={0}", genders.size())); + + // Return it + for (final Gender gender : Gender.values()) { + // Debug message + this.getLogger().debug(MessageFormat.format("gender={0}", gender)); + + // Is it unknown? + if (!gender.equals(Gender.UNKNOWN)) { + // Debug message + this.getLogger().debug(MessageFormat.format("gender={0} - adding ...", gender)); + + // Not, then add it + boolean added = genders.add(gender); + + // Debug message + this.getLogger().debug(MessageFormat.format("added={0}", added)); + } + } + + // Trace message + this.getLogger().trace(MessageFormat.format("genders={0} - EXIT!", genders)); //NOI18N + + // Return it + return genders; + } +}