From: Roland Haeder Date: Fri, 14 Aug 2015 11:22:29 +0000 (+0200) Subject: Continued with project: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e94dc1b532d626b460881f246b1889925888cca3;p=pizzaservice-war.git Continued with project: - Added parent_category_selection_box.jsp which holds the selection box for parent categories - Added method generateLinkForParent() - Fixed wrong use of COLUMN_PARENT for title - Catched newly thrown CategoryTitleAlreadyUsedException Signed-off-by:Roland Häder --- diff --git a/src/java/log4j2.xml b/src/java/log4j2.xml index d5452877..8860f19e 100644 --- a/src/java/log4j2.xml +++ b/src/java/log4j2.xml @@ -23,6 +23,7 @@ along with this program. If not, see . + diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java index d9c953c5..be6e2a64 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java @@ -16,6 +16,7 @@ */ package org.mxchange.pizzaapplication.application; +import org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException; import java.util.Iterator; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -237,8 +238,9 @@ public interface PizzaApplication extends Application { * * @param request Request instance * @throws javax.servlet.ServletException If something unexpected happened + * @throws org.mxchange.pizzaapplication.application.CategoryTitleAlreadyUsedException If the given title is already used */ - public void doAdminAddCategory (final HttpServletRequest request) throws ServletException; + public void doAdminAddCategory (final HttpServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException; /** * Adds given product data from request to database @@ -247,4 +249,13 @@ public interface PizzaApplication extends Application { * @throws javax.servlet.ServletException If something unexpected happened */ public void doAdminAddProduct (final HttpServletRequest request) throws ServletException; + + /** + * Generates link HTML code for given category's parent id, if set. This + * link then points to products.jsp?category_id=x + * + * @param category Category instance + * @return HTML code + */ + public String generateLinkForParent (final Category category); } diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java index b8926b11..c82f914b 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java @@ -16,6 +16,7 @@ */ package org.mxchange.pizzaapplication.application; +import org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException; import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -1172,7 +1173,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P * @param request Request instance */ @Override - public void doAdminAddCategory (final HttpServletRequest request) throws ServletException { + public void doAdminAddCategory (final HttpServletRequest request) throws ServletException, CategoryTitleAlreadyUsedException { // Trace message this.getLogger().trace(MessageFormat.format("request={0} - CALLED!", request)); //NOI18N @@ -1202,7 +1203,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Try to check if title is used already if (this.isCategoryUsed(request.getParameter(PizzaCategoryDatabaseConstants.COLUMN_TITLE))) { // Title already used - throw new IllegalArgumentException(MessageFormat.format("Title {0} is already used.", request.getParameter(PizzaCategoryDatabaseConstants.COLUMN_TITLE))); + throw new CategoryTitleAlreadyUsedException(request); } } catch (final IOException | SQLException | BadTokenException ex) { throw new ServletException(ex); @@ -1245,4 +1246,35 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Trace message this.getLogger().trace("EXIT!"); //NOI18N } + + /** + * Generates link HTML code for given category's parent id, if set. This + * link then points to products.jsp?category_id=x + * + * @param category Category instance + * @return HTML code + */ + @Override + public String generateLinkForParent (final Category category) { + // Trace message + this.getLogger().trace(MessageFormat.format("category={0} - CALLED!", category)); + + // category must not be null + if (category == null) { + // Is null + throw new NullPointerException("category is null"); + } + + // Get parent id + Integer parent = category.getParent(); + + // Is the id set? + if (parent > 0) { + // Product HTML code for link + throw new UnsupportedOperationException(MessageFormat.format("parent={0} - Unfinished!", parent)); + } + + // No parent set + return "Keine"; + } } diff --git a/src/java/org/mxchange/pizzaapplication/database/frontend/category/PizzaCategoryDatabaseFrontend.java b/src/java/org/mxchange/pizzaapplication/database/frontend/category/PizzaCategoryDatabaseFrontend.java index 72b84ce8..74b7a802 100644 --- a/src/java/org/mxchange/pizzaapplication/database/frontend/category/PizzaCategoryDatabaseFrontend.java +++ b/src/java/org/mxchange/pizzaapplication/database/frontend/category/PizzaCategoryDatabaseFrontend.java @@ -185,7 +185,7 @@ public class PizzaCategoryDatabaseFrontend extends BaseDatabaseFrontend implemen while (resultSet.next()) { // Get id, title and parent id Integer id = resultSet.getInt(PizzaCategoryDatabaseConstants.COLUMN_ID); - String title = resultSet.getString(PizzaCategoryDatabaseConstants.COLUMN_PARENT); + String title = resultSet.getString(PizzaCategoryDatabaseConstants.COLUMN_TITLE); Integer parent = resultSet.getInt(PizzaCategoryDatabaseConstants.COLUMN_PARENT); // Debug message diff --git a/web/admin/category.jsp b/web/admin/category.jsp index 516fceca..febeb8b0 100644 --- a/web/admin/category.jsp +++ b/web/admin/category.jsp @@ -111,9 +111,7 @@
- +
diff --git a/web/form_handler/admin/do_category.jsp b/web/form_handler/admin/do_category.jsp index d917e2a9..ddd04d64 100644 --- a/web/form_handler/admin/do_category.jsp +++ b/web/form_handler/admin/do_category.jsp @@ -10,6 +10,7 @@ <%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%> <%@page import="org.mxchange.pizzaapplication.beans.CustomerBean" %> <%@page import="org.mxchange.pizzaapplication.product.Product"%> +<%@page import="org.mxchange.pizzaapplication.exceptions.CategoryTitleAlreadyUsedException"%> <% // Init application instance @@ -20,7 +21,12 @@ // Is "add/edit/delete" set? if (request.getParameter("add") != null) { //NOI18N // Add new category - app.doAdminAddCategory(request); + try { + app.doAdminAddCategory(request); + } catch (final CategoryTitleAlreadyUsedException e) { + // Already used! + response.sendRedirect(request.getContextPath() + "/admin/category.jsp?already=1"); //NOI18N + } } else if (request.getParameter("edit") != null) { //NOI18N // @TODO } else if (request.getParameter("delete") != null) { //NOI18N diff --git a/web/static/admin/parent_category_selection_box.jsp b/web/static/admin/parent_category_selection_box.jsp new file mode 100644 index 00000000..936fe664 --- /dev/null +++ b/web/static/admin/parent_category_selection_box.jsp @@ -0,0 +1,11 @@ +<%-- + Document : parent_category_selection_box + Created on : 14.08.2015, 12:51:05 + Author : Roland Haeder +--%> + +<%@page import="org.mxchange.pizzaapplication.database.category.PizzaCategoryDatabaseConstants"%> + +