From: Roland Haeder Date: Fri, 4 Sep 2015 13:12:54 +0000 (+0200) Subject: Updated jcore, jsfcore and jshop (out-dated) + rewrites towards EJB X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=490373411a08449174681369ee7dfe336cf763e0;p=pizzaservice-lib.git Updated jcore, jsfcore and jshop (out-dated) + rewrites towards EJB Signed-off-by:Roland Häder --- diff --git a/lib/jcore.jar b/lib/jcore.jar index 01a404f..a12ac5b 100644 Binary files a/lib/jcore.jar and b/lib/jcore.jar differ diff --git a/lib/jsfcore.jar b/lib/jsfcore.jar index 6a08207..e9671bc 100644 Binary files a/lib/jsfcore.jar and b/lib/jsfcore.jar differ diff --git a/lib/jshop.jar b/lib/jshop.jar index f1d74f0..0ba207f 100644 Binary files a/lib/jshop.jar and b/lib/jshop.jar differ diff --git a/nbproject/project.properties b/nbproject/project.properties index b860922..5946cd5 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -30,12 +30,12 @@ dist.jar=${dist.dir}/PizzaService-lib.jar dist.javadoc.dir=${dist.dir}/javadoc endorsed.classpath= excludes= -file.reference.cdi-api.jar=lib\\cdi-api.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.cdi-api.jar=lib/cdi-api.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 includes=** jar.compress=false javac.classpath=\ diff --git a/src/org/mxchange/pizzaapplication/application/PizzaApplication.java b/src/org/mxchange/pizzaapplication/application/PizzaApplication.java index f22e33d..c940165 100644 --- a/src/org/mxchange/pizzaapplication/application/PizzaApplication.java +++ b/src/org/mxchange/pizzaapplication/application/PizzaApplication.java @@ -21,9 +21,6 @@ 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; @@ -84,13 +81,12 @@ public interface PizzaApplication extends Application { /** * 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 UnsupportedDatabaseBackendException, SQLException, IOException, BadTokenException; /** * Some "getter" for a an array of only available products @@ -176,7 +172,7 @@ public interface PizzaApplication extends Application { /** * Adds given category data from request to database * - * @param request Request instance + * @param category Category to be added * @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 @@ -186,12 +182,12 @@ public interface PizzaApplication extends Application { * @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, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException; /** * Adds given product data from request to database * - * @param request Request instance + * @param product Product instance to add * @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 @@ -201,13 +197,11 @@ public interface PizzaApplication extends Application { * @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, BadTokenException, SQLException, CorruptedDatabaseFileException, 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 @@ -216,14 +210,14 @@ public interface PizzaApplication extends Application { * @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, BadTokenException, SQLException, CorruptedDatabaseFileException, 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 @@ -232,8 +226,10 @@ public interface PizzaApplication extends Application { * @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 Old lost code */ - public void doAdminHandleCategoryForms (final ServletRequest request, final ServletResponse response) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException; + @Deprecated + public void doAdminHandleCategoryForms () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException; /** * Some "getter" for a Product instance from given item diff --git a/src/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java b/src/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java index c9f0ee2..25fc401 100644 --- a/src/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java +++ b/src/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java @@ -22,11 +22,6 @@ 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; @@ -84,15 +79,9 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } @Override - public void init (final ServletContext context) throws UnsupportedDatabaseBackendException, SQLException { + public void init () throws UnsupportedDatabaseBackendException, 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()) { @@ -101,9 +90,6 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P this.initBundle(); } - // Initialize properties from context - this.initProperties(context); - // Init database frontends this.initDatabaseFrontends(); @@ -213,10 +199,10 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P /** * Checks whether given category title is already used * - * @param title Title of category to check + * @param category Category instance * @return Whether it has been found */ - private boolean isCategoryTitleUsed(final String title) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + private boolean isCategoryTitleUsed(final Category category) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // categoryFrontend must be set if (null == this.categoryFrontend) { // Abort here @@ -224,7 +210,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } // Delegate to frontend - return this.categoryFrontend.isCategoryTitleUsed(title); + return this.categoryFrontend.isCategoryTitleUsed(category.getTitle()); } /** @@ -244,26 +230,23 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } @Override - public void doAdminAddCategory (final ServletRequest request) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException { + public void doAdminAddCategory (final Category category) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, 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) { + 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 - // Init variables for casting - Integer id = 0; - // Check all fields if (null == title) { // "title" not set @@ -271,53 +254,44 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } 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); - } + } else if ((parentId == null) || (parentId == 0)) { + // "parent" is not set + throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", parentId)); } // Try to check if title is used already - if (this.isCategoryTitleUsed(title)) { + if (this.isCategoryTitleUsed(category)) { // Title already used - throw new CategoryTitleAlreadyUsedException(request); + throw new CategoryTitleAlreadyUsedException(category); } // The category is not found, so add it to database - this.categoryFrontend.addCategory(title, id); + this.categoryFrontend.addCategory(title, parentId); // Trace message this.getLogger().trace("EXIT!"); //NOI18N } @Override - public void doAdminAddProduct (final ServletRequest request) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, ProductTitleAlreadyUsedException { + public void doAdminAddProduct (final Product product) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, 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 @@ -328,46 +302,22 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } 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 } 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 } 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); } - // 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 @@ -442,18 +392,20 @@ 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, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // Trace message - this.getLogger().trace(MessageFormat.format("request={0} - CALLED!", request)); //NOI18N - - // Init title - String title = request.getParameter(ProductFrontend.COLUMN_TITLE); + this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product)); //NOI18N // request must not be null and "title" must be found and non-empty - if (null == request) { + if (null == product) { // Abort here throw new NullPointerException("request is null"); //NOI18N - } else if (null == title) { + } + + // Init title + String title = product.getTitle(); + + if (null == title) { // title is not set throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", ProductFrontend.COLUMN_TITLE)); //NOI18N } else if (title.isEmpty()) { @@ -472,137 +424,17 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } @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, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, ProductTitleAlreadyUsedException { + // Deprecated method called + throw new UnsupportedOperationException("Deprecated method has been 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 - } - - /** - * Checks if category's title is already used. - * - * @param request Request 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 ... ;-) - * @throws java.sql.SQLException If any SQL error occurs - * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged - * @throws java.lang.NoSuchMethodException If a method was not found - * @throws java.lang.IllegalAccessException If the method cannot be accessed - * @throws java.lang.reflect.InvocationTargetException Any other problems? - */ - private boolean isCategoryTitleUsed (final ServletRequest request) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { - // Trace message - this.getLogger().trace(MessageFormat.format("request={0} - CALLED!", request)); //NOI18N - - // Init title - String title = request.getParameter(CategoryFrontend.COLUMN_TITLE); - - // request must not be null and "title" must be found and non-empty - if (null == request) { - // Abort here - throw new NullPointerException("request is null"); //NOI18N - } else if (null == title) { - // title is not set - throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", CategoryFrontend.COLUMN_TITLE)); //NOI18N - } else if (title.isEmpty()) { - // Is left empty - throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", CategoryFrontend.COLUMN_TITLE)); //NOI18N - } - - // Default is not used - boolean isUsed = this.isCategoryTitleUsed(title); - - // Trace message - this.getLogger().trace(MessageFormat.format("isUsed={0} - EXIT!", isUsed)); //NOI18N - - // Return it - return isUsed; + @Deprecated + public void doAdminHandleCategoryForms () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException { + // Deprecated method called + throw new UnsupportedOperationException("Deprecated method has been called."); } @Override