]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Continued with project:
authorRoland Haeder <roland@mxchange.org>
Fri, 14 Aug 2015 11:22:29 +0000 (13:22 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 14 Aug 2015 11:28:29 +0000 (13:28 +0200)
- 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 <roland@mxchange.org>

src/java/log4j2.xml
src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java
src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java
src/java/org/mxchange/pizzaapplication/database/frontend/category/PizzaCategoryDatabaseFrontend.java
web/admin/category.jsp
web/form_handler/admin/do_category.jsp
web/static/admin/parent_category_selection_box.jsp [new file with mode: 0644]

index d54528779709c848cfc5cbb23b88c670af70e7dd..8860f19ebe29c068e05b6e609157193486556ba0 100644 (file)
@@ -23,6 +23,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
        </Appenders>
        <Loggers>
                <Root level="trace">
+                       <AppenderRef ref="STDERR" level="WARNING"/>
                        <AppenderRef ref="STDOUT" level="TRACE"/>
                </Root>
        </Loggers>
index d9c953c58fa03e01bc4e0b6fd0bded628f313551..be6e2a64530ce01fa8af49bbabe82709ba988889 100644 (file)
@@ -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);
 }
index b8926b114bd186ee9044918da1e941a6db346cd8..c82f914b1cdff3ada5fb6efcdfdd1fbe9cc27ce9 100644 (file)
@@ -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";
+       }
 }
index 72b84ce860a63b19000b9870dac5c62f3b7968d7..74b7a802fc8ed48995919682db9f72988d11ca45 100644 (file)
@@ -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
index 516fceca7ec20e5506e40dae2d81b0cb61c4a9f0..febeb8b0359c307d1d383f0bcaffb9142e677b94 100644 (file)
                                                                </div>
 
                                                                <div class="table_right">
-                                                                       <select name="<%=PizzaCategoryDatabaseConstants.COLUMN_PARENT%>" size="1">
-                                                                               <option value="">Ist oberste Kategorie</option>
-                                                                       </select>
+                                                                       <jsp:include flush="true" page="/static/admin/parent_category_selection_box.jsp" />
                                                                </div>
 
                                                                <div class="clear"></div>
index d917e2a93f019f1218776d19288d777ef6a6fe0b..ddd04d64f8e23596b04007340ebb401f78e8e785 100644 (file)
@@ -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
                // 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 (file)
index 0000000..936fe66
--- /dev/null
@@ -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"%>
+
+<select name="<%=PizzaCategoryDatabaseConstants.COLUMN_PARENT%>" size="1">
+       <option value="">Ist oberste Kategorie</option>
+</select>