From 3378a51117b7345528f3433dc7bcb25b5d10d6ba Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 13 Aug 2015 09:37:43 +0200 Subject: [PATCH] =?utf8?q?Continued=20with=20project:=20-=20Added=20menu?= =?utf8?q?=20item=20(and=20JSP)=20for=20categories=20-=20Renamed=20JSP=20t?= =?utf8?q?o=20get=20rid=20of=20plural=20-=20Started=20with=20refactoring?= =?utf8?q?=20of=20application,=20the=20whole=20product=20(and=20now=20cate?= =?utf8?q?gory)=20list=20would=20be=20kept=20in=20RAM=20which=20is=20far?= =?utf8?q?=20to=20much=20wasting=20-=20Got=20rid=20of=20getUnmarkedProduct?= =?utf8?q?s(),=20better=20use=20generic=20getProducts()=20Signed-off-by:Ro?= =?utf8?q?land=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../application/PizzaApplication.java | 16 +- .../application/PizzaServiceApplication.java | 219 ++++++------------ .../pizzaapplication/category/Category.java | 27 +++ .../product/PizzaProduct.java | 56 +++-- .../pizzaapplication/product/Product.java | 39 +++- web/admin/category.jsp | 141 +++++++++++ web/admin/{products.jsp => product.jsp} | 30 +-- web/index.jsp | 8 +- web/preview.jsp | 4 +- web/static/admin/menu.jsp | 3 +- 10 files changed, 339 insertions(+), 204 deletions(-) create mode 100644 src/java/org/mxchange/pizzaapplication/category/Category.java create mode 100644 web/admin/category.jsp rename web/admin/{products.jsp => product.jsp} (78%) diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java index 3c31ab08..3e2a6a39 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java @@ -19,6 +19,7 @@ package org.mxchange.pizzaapplication.application; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.mxchange.jcore.application.Application; +import org.mxchange.pizzaapplication.category.Category; import org.mxchange.pizzaapplication.product.Product; /** @@ -193,19 +194,18 @@ public interface PizzaApplication extends Application { public void setValueInSession (final HttpSession session, final String key, final Object value); /** - * Some "getter" for a an array of unmarked products + * Some "getter" for a an array of all products * - * @param session HttpSession instance - * @return Unmarked products + * @return All products */ - public Product[] getUnmarkedProducts (final HttpSession session); + public Iterable getProducts (); /** - * Some "getter" for a an array of all products - * - * @return Unmarked products + * Some "getter" for a an array of all categories + * + * @return All categories */ - public Product[] getProducts (); + public Iterable getCategories (); /** * Checks if given Product instance is available and returns a printable diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java index 8a8adac8..5b8c210f 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java @@ -23,8 +23,6 @@ import java.sql.SQLException; import java.text.MessageFormat; import java.util.Iterator; import java.util.Map; -import java.util.SortedMap; -import java.util.TreeMap; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -33,6 +31,7 @@ import org.mxchange.jcore.contact.Gender; import org.mxchange.jcore.exceptions.BadTokenException; import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException; import org.mxchange.pizzaapplication.BasePizzaServiceSystem; +import org.mxchange.pizzaapplication.category.Category; import org.mxchange.pizzaapplication.customer.Customer; import org.mxchange.pizzaapplication.customer.PizzaServiceCustomer; import org.mxchange.pizzaapplication.database.frontend.product.PizzaProductDatabaseFrontend; @@ -49,6 +48,11 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P */ public static final String MAIN_TITLE = "Pizza-Service"; + /** + * Frontend for products + */ + private ProductFrontend productFrontend; + /** * Some singleton getter for this instance. If the instance is not set in * given application, it will be created. @@ -106,28 +110,12 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P new PizzaServiceApplication().start(); } - /** - * Product list - */ - private final SortedMap products; - - /** - * Private constructor - */ - private PizzaServiceApplication () { - // Init products instance - this.products = new TreeMap<>(); - } - /** * Constructor with servet configuration * * @param context Servlet context */ private PizzaServiceApplication (final ServletContext context) throws UnsupportedDatabaseBackendException, SQLException, IOException, BadTokenException { - // Call other constructor first - this(); - // Temporary initialize default bundle // @TODO The JSF may have better internatialization support this.initBundle(); @@ -135,8 +123,14 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Initialize properties from config this.initProperties(context); - // Load available products - this.fillProductsList(); + // Init database frontends + this.initDatabaseFrontends(); + } + + /** + * Default constructor + */ + private PizzaServiceApplication () { } /** @@ -168,7 +162,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Is this choosen? if (this.isProductChoosen(product, request, session)) { // Then add ordered amount - this.getLogger().debug(MessageFormat.format("Counting {0} ...", product.getName())); //NOI18N + this.getLogger().debug(MessageFormat.format("Counting {0} ...", product.getId())); //NOI18N // Getting amount String amount = this.getAmountFromSession(product, session); @@ -177,7 +171,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P this.getLogger().debug(MessageFormat.format("amount={0}", amount)); //NOI18N totalAmount += Integer.valueOf(amount); } - this.getLogger().debug(MessageFormat.format("product={0},totalAmount={1}", product.getName(), totalAmount)); //NOI18N + this.getLogger().debug(MessageFormat.format("product={0},totalAmount={1}", product.getId(), totalAmount)); //NOI18N } // Trace message @@ -216,10 +210,10 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Is this choosen? if (this.isProductChoosen(product, request, session)) { // Then add product's total price - this.getLogger().debug(MessageFormat.format("Calling getTotalPositionPriceFromRequestSession({0},request,session) ...", product.getName())); //NOI18N + this.getLogger().debug(MessageFormat.format("Calling getTotalPositionPriceFromRequestSession({0},request,session) ...", product.getId())); //NOI18N totalPrice += this.getTotalPositionPriceFromRequestSession(product, request, session); } - this.getLogger().debug(MessageFormat.format("product={0},totalPrice={1}", product.getName(), totalPrice)); //NOI18N + this.getLogger().debug(MessageFormat.format("product={0},totalPrice={1}", product.getId(), totalPrice)); //NOI18N } // Trace message @@ -352,7 +346,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Is the object null? if (object == null) { // Not found - this.getLogger().debug(MessageFormat.format("Returning empty string for product={0} ...", product.getName())); //NOI18N + this.getLogger().debug(MessageFormat.format("Returning empty string for product={0} ...", product.getId())); //NOI18N return ""; //NOI18N } @@ -426,9 +420,9 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } // Get element - this.getLogger().debug(MessageFormat.format("Calling handleChooseFromRequestSession({0},{1},{2}) ...", product.getName(), request, session)); //NOI18N + this.getLogger().debug(MessageFormat.format("Calling handleChooseFromRequestSession({0},{1},{2}) ...", product.getId(), request, session)); //NOI18N String choosen = this.handleChooseFromRequestSession(product, request, session); - this.getLogger().debug(MessageFormat.format("product={0},choosen={1}", product.getName(), choosen)); //NOI18N + this.getLogger().debug(MessageFormat.format("product={0},choosen={1}", product.getId(), choosen)); //NOI18N // Must not be null assert(choosen instanceof String): "choosen is null"; //NOI18N @@ -441,7 +435,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Get amount String amount = this.handleAmountFromRequestSession(product, request, session); - this.getLogger().debug(MessageFormat.format("product={0},amount={1}", product.getName(), amount)); //NOI18N + this.getLogger().debug(MessageFormat.format("product={0},amount={1}", product.getId(), amount)); //NOI18N // Must not be null assert(amount instanceof String): "amount is null"; //NOI18N @@ -505,11 +499,21 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P /** * Some "getter" for a an array of all products * - * @return Unmarked products + * @return All products */ @Override - public Product[] getProducts () { - return this.products.values().toArray(new Product[this.products.size()]); + public Iterable getProducts () { + throw new UnsupportedOperationException("Needs refacturing ..."); + } + + /** + * Some "getter" for a an array of all categories + * + * @return All categories + */ + @Override + public Iterable getCategories () { + throw new UnsupportedOperationException("Needs refacturing ..."); } /** @@ -539,9 +543,9 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } // Get choosen - this.getLogger().debug(MessageFormat.format("Calling handleChooseFromRequestSession({0},{1},{2}) ...", product.getName(), request, session)); //NOI18N + this.getLogger().debug(MessageFormat.format("Calling handleChooseFromRequestSession({0},{1},{2}) ...", product.getId(), request, session)); //NOI18N String choosen = this.handleChooseFromRequestSession(product, request, session); - this.getLogger().debug(MessageFormat.format("product={0},choosen={1}", product.getName(), choosen)); //NOI18N + this.getLogger().debug(MessageFormat.format("product={0},choosen={1}", product.getId(), choosen)); //NOI18N // Must not be null assert(choosen instanceof String): "choosen is null"; //NOI18N @@ -549,13 +553,13 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Is it set? if (choosen.isEmpty()) { // Is empty - this.getLogger().debug(MessageFormat.format("product={0},choosen={1} - returning zero ...", product.getName(), choosen)); //NOI18N + this.getLogger().debug(MessageFormat.format("product={0},choosen={1} - returning zero ...", product.getId(), choosen)); //NOI18N return 0.00f; } // Get amount String amount = this.handleAmountFromRequestSession(product, request, session); - this.getLogger().debug(MessageFormat.format("product={0},amount={1}", product.getName(), amount)); //NOI18N + this.getLogger().debug(MessageFormat.format("product={0},amount={1}", product.getId(), amount)); //NOI18N // Must not be null assert(amount instanceof String): "amount is null"; //NOI18N @@ -563,7 +567,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Is it empty? if (amount.isEmpty() || "0".equals(amount)) { //NOI18N // Is empty - this.getLogger().debug(MessageFormat.format("product={0},amount={1} - returning zero ...", product.getName(), amount)); //NOI18N + this.getLogger().debug(MessageFormat.format("product={0},amount={1} - returning zero ...", product.getId(), amount)); //NOI18N return 0.00f; } @@ -583,32 +587,12 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P float price = (product.getPrice() * value); // Trace message - this.getLogger().trace(MessageFormat.format("product={0},price={1} - EXIT!", product.getName(), price)); //NOI18N + this.getLogger().trace(MessageFormat.format("product={0},price={1} - EXIT!", product.getId(), price)); //NOI18N // Then multiply it with price return price; } - /** - * Gets an array of products from product iterator and unmarks them as ordered - * - * @param session HttpSession instance - * @return Unmarked products - */ - @Override - public Product[] getUnmarkedProducts (final HttpSession session) { - // Init array - Product[] array = this.getProducts(); - - // Unmark are all as ordered - for (final Product product : array) { - this.unmarkProductAsOrdered(product, session); - } - - // Return finished array - return array; - } - /** * Handler for amount from request or session * @@ -644,12 +628,12 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } else if (this.handleChooseFromRequestSession(product, request, session).isEmpty()) { // Not choosen this.clearSessionAttribute(product, session, HTTP_PARAM_AMOUNT); - this.getLogger().debug(MessageFormat.format("Unsetting for product={0} in session, returning zero ...", product.getName())); //NOI18N + this.getLogger().debug(MessageFormat.format("Unsetting for product={0} in session, returning zero ...", product.getId())); //NOI18N return "0"; //NOI18N } // Get attribute from request - object = request.getParameter(String.format(HTTP_PARAM_MASK, HTTP_PARAM_AMOUNT, product.getName())); + object = request.getParameter(String.format(HTTP_PARAM_MASK, HTTP_PARAM_AMOUNT, product.getId())); // Is it set? if (object instanceof String) { @@ -702,9 +686,9 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } // Get choosen - this.getLogger().debug(MessageFormat.format("Calling handleChooseFromRequestSession({0},{1},{2}) ...", product.getName(), request, session)); //NOI18N + this.getLogger().debug(MessageFormat.format("Calling handleChooseFromRequestSession({0},{1},{2}) ...", product.getId(), request, session)); //NOI18N String choosen = this.handleChooseFromRequestSession(product, request, session); - this.getLogger().debug(MessageFormat.format("product={0},choosen={1}", product.getName(), choosen)); //NOI18N + this.getLogger().debug(MessageFormat.format("product={0},choosen={1}", product.getId(), choosen)); //NOI18N // Must not be null assert(choosen instanceof String): "choosen is null"; //NOI18N @@ -749,7 +733,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } // Mark it as ordered by setting flag - this.getLogger().debug(MessageFormat.format("Marking product={0} as choosen.", product.getName())); //NOI18N + this.getLogger().debug(MessageFormat.format("Marking product={0} as choosen.", product.getId())); //NOI18N this.setValueInSession(product, session, HTTP_PARAM_CHOOSE, "1"); //NOI18N // Trace message @@ -777,7 +761,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } // Mark it as ordered by setting flag - this.getLogger().debug(MessageFormat.format("Marking product={0} as ordered.", product.getName())); //NOI18N + this.getLogger().debug(MessageFormat.format("Marking product={0} as ordered.", product.getId())); //NOI18N this.setValueInSession(product, session, SESSION_ORDERED, "true"); //NOI18N // Trace message @@ -826,7 +810,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } // Mark it as ordered by setting flag - this.getLogger().debug(MessageFormat.format("Unmarking product={0} as choosen.", product.getName())); //NOI18N + this.getLogger().debug(MessageFormat.format("Unmarking product={0} as choosen.", product.getId())); //NOI18N this.clearSessionAttribute(product, session, HTTP_PARAM_CHOOSE); // Trace message @@ -854,41 +838,13 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } // Mark it as ordered by setting flag - this.getLogger().debug(MessageFormat.format("Unmarking product={0} as ordered.", product.getName())); //NOI18N + this.getLogger().debug(MessageFormat.format("Unmarking product={0} as ordered.", product.getId())); //NOI18N this.clearSessionAttribute(product, session, SESSION_ORDERED); // Trace message this.getLogger().trace("EXIT!"); //NOI18N } - /** - * Adds given product to list or throws an exception if name is already found - * - * @param product Product instance to add - */ - private void addProduct (final Product product) { - // Trace message - this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product)); //NOI18N - - // Get all data from it - String name = product.getName(); - - // Is the name already used? - if (this.isProductNameUsed(name)) { - // Something went wrong - throw new IllegalArgumentException(MessageFormat.format("product {0} is already used.", name)); //NOI18N - } - - // Debug message - this.getLogger().debug(MessageFormat.format("Adding product={0} ...", product)); //NOI18N - - // Add it - this.products.put(product.getName(), product); - - // Trace message - this.getLogger().trace("EXIT!"); //NOI18N - } - /** * Clears given parameter for product in session * @@ -901,40 +857,13 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P this.getLogger().trace(MessageFormat.format("produce={0},parameter={1},session={2} - CALLED!", product, parameter, session)); //NOI18N // Clear in session - this.getLogger().debug(MessageFormat.format("Clearing product={0},parameter={1} ...", product.getName(), parameter)); //NOI18N + this.getLogger().debug(MessageFormat.format("Clearing product={0},parameter={1} ...", product.getId(), parameter)); //NOI18N this.setValueInSession(product, session, parameter, null); // Trace message this.getLogger().trace("EXIT!"); //NOI18N } - /** - * Fills products list - * @todo Very hard-coded stuff ... - */ - private void fillProductsList () throws UnsupportedDatabaseBackendException, SQLException, IOException, BadTokenException { - // Trace message - this.getLogger().trace("CALLED!"); //NOI18N - - // Get a product frontend - ProductFrontend frontend = new PizzaProductDatabaseFrontend(); - - // Get iterator - Iterator iterator = frontend.getProducts(); - - // Get all products - while (iterator.hasNext()) { - // Get it - Product product = iterator.next(); - - // Add it - this.addProduct(product); - } - - // Trace message - this.getLogger().trace("EXIT!"); //NOI18N - } - /** * Some getter for value from session * @@ -948,9 +877,9 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P this.getLogger().trace(MessageFormat.format("product={0},session={1},attribute={2} - CALLED!", product, session, attribute)); //NOI18N // Init variable - Object value = this.getValueFromSession(session, String.format(HTTP_PARAM_MASK, attribute, product.getName())); + Object value = this.getValueFromSession(session, String.format(HTTP_PARAM_MASK, attribute, product.getId())); - this.getLogger().debug(MessageFormat.format("product={0},attribute={1},value={2}", product.getName(), attribute, value)); //NOI18N + this.getLogger().debug(MessageFormat.format("product={0},attribute={1},value={2}", product.getId(), attribute, value)); //NOI18N // Trace message this.getLogger().trace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N @@ -1015,26 +944,26 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Check request method if (!"POST".equals(request.getMethod())) { //NOI18N // Not POST, so get from session - this.getLogger().trace(MessageFormat.format("Calling this.getChooseFromSession({0},{1}) ... - EXIT!", product.getName(), session)); + this.getLogger().trace(MessageFormat.format("Calling this.getChooseFromSession({0},{1}) ... - EXIT!", product.getId(), session)); return this.getChooseFromSession(product, session); } else if (this.isProductOrdered(product, session)) { // Product is ordered - this.getLogger().trace(MessageFormat.format("Calling this.getChooseFromSession({0},{1}) ... - EXIT!", product.getName(), session)); + this.getLogger().trace(MessageFormat.format("Calling this.getChooseFromSession({0},{1}) ... - EXIT!", product.getId(), session)); return this.getChooseFromSession(product, session); } else if (!this.getChooseFromSession(product, session).isEmpty()) { // Found in session - this.getLogger().trace(MessageFormat.format("Calling this.getChooseFromSession({0},{1}) ... - EXIT!", product.getName(), session)); + this.getLogger().trace(MessageFormat.format("Calling this.getChooseFromSession({0},{1}) ... - EXIT!", product.getId(), session)); return this.getChooseFromSession(product, session); } // Get reqzest element - object = request.getParameter(String.format(HTTP_PARAM_MASK, HTTP_PARAM_CHOOSE, product.getName())); - this.getLogger().debug(MessageFormat.format("product={0},object={1}", product.getName(), object)); //NOI18N + object = request.getParameter(String.format(HTTP_PARAM_MASK, HTTP_PARAM_CHOOSE, product.getId())); + this.getLogger().debug(MessageFormat.format("product={0},object={1}", product.getId(), object)); //NOI18N // Is it null? if (object == null) { // Unset session - this.getLogger().debug(MessageFormat.format("Unsetting session for product={0} ...", product.getName())); //NOI18N + this.getLogger().debug(MessageFormat.format("Unsetting session for product={0} ...", product.getId())); //NOI18N this.clearSessionAttribute(product, session, HTTP_PARAM_CHOOSE); this.clearSessionAttribute(product, session, HTTP_PARAM_AMOUNT); @@ -1046,29 +975,22 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P this.setValueInSession(product, session, HTTP_PARAM_CHOOSE, object); // Cast to string and return it - this.getLogger().debug(MessageFormat.format("product={0} - Returning {1} ...", product.getName(), object)); //NOI18N + this.getLogger().debug(MessageFormat.format("product={0} - Returning {1} ...", product.getId(), object)); //NOI18N return (String) object; } /** - * Checks whether given product is already used - * - * @param name Name of product - * @return Whether the given product's name is already used + * Initializes database frontends. */ - private boolean isProductNameUsed(final String name) { - // Trace message - this.getLogger().trace(MessageFormat.format("name={0} - CALLED!", name)); //NOI18N - - // Is it found? - return this.products.containsKey(name); + private void initDatabaseFrontends () throws UnsupportedDatabaseBackendException, SQLException { + this.productFrontend = new PizzaProductDatabaseFrontend(); } /** * Checks if the product ordered? * - * @param product - * @param session + * @param product Product instance + * @param session HttpSession instance * @return */ private boolean isProductOrdered(final Product product, final HttpSession session) { @@ -1077,7 +999,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Get session Object isOrdered = this.getValueFromSession(product, session, SESSION_ORDERED); - this.getLogger().debug(MessageFormat.format("product={0},isOrdered={1}", product.getName(), isOrdered)); //NOI18N + this.getLogger().debug(MessageFormat.format("product={0},isOrdered={1}", product.getId(), isOrdered)); //NOI18N // Return result return ("true".equals(isOrdered)); //NOI18N @@ -1096,8 +1018,8 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P this.getLogger().trace(MessageFormat.format("product={0},session={1},keyPart={2},value={3} - CALLED!", product, session, keyPart, value)); //NOI18N // Set it synced - this.getLogger().debug(MessageFormat.format("Setting value={0} for product={1},keyPart={2}", value, product.getName(), keyPart)); //NOI18N - this.setValueInSession(session, String.format(HTTP_PARAM_MASK, keyPart, product.getName()), value); + this.getLogger().debug(MessageFormat.format("Setting value={0} for product={1},keyPart={2}", value, product.getId(), keyPart)); //NOI18N + this.setValueInSession(session, String.format(HTTP_PARAM_MASK, keyPart, product.getId()), value); // Trace message this.getLogger().trace("EXIT!"); //NOI18N @@ -1113,10 +1035,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P try { // Init properties this.initProperties(); - - // Fill products list - this.fillProductsList(); - } catch (final IOException | UnsupportedDatabaseBackendException | SQLException | BadTokenException ex) { + } catch (final IOException ex) { // Abort here this.abortProgramWithException(ex); } @@ -1124,7 +1043,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // "Walk" over all products for (final Product product : this.getProducts()) { // Output data - this.getLogger().debug(MessageFormat.format("Product {0}, {1}: {2}", product.getName(), product.getTitle(), product.getPrice())); //NOI18N + this.getLogger().debug(MessageFormat.format("Product {0}, {1}: {2}", product.getId(), product.getTitle(), product.getPrice())); //NOI18N } // Generate fake Customer instance diff --git a/src/java/org/mxchange/pizzaapplication/category/Category.java b/src/java/org/mxchange/pizzaapplication/category/Category.java new file mode 100644 index 00000000..c1b0fdf7 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/category/Category.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.category; + +import org.mxchange.jcore.FrameworkInterface; + +/** + * An interface for categories + * + * @author Roland Haeder + */ +public interface Category extends FrameworkInterface { +} diff --git a/src/java/org/mxchange/pizzaapplication/product/PizzaProduct.java b/src/java/org/mxchange/pizzaapplication/product/PizzaProduct.java index 1f626b97..751aaea8 100644 --- a/src/java/org/mxchange/pizzaapplication/product/PizzaProduct.java +++ b/src/java/org/mxchange/pizzaapplication/product/PizzaProduct.java @@ -16,17 +16,24 @@ */ package org.mxchange.pizzaapplication.product; +import org.mxchange.pizzaapplication.category.Category; import org.mxchange.jcore.BaseFrameworkSystem; /** + * Product class for pizza application * * @author Roland Haeder */ public class PizzaProduct extends BaseFrameworkSystem implements Product { /** - * Name of product + * Product category */ - private String name; + private Category category; + + /** + * Id number of product + */ + private Long id; /** * Price of product @@ -41,31 +48,52 @@ public class PizzaProduct extends BaseFrameworkSystem implements Product { /** * Constructor for products with a name and a price. * - * @param name Name of product + * @param id Id number of product * @param title Name of product * @param price Price */ - public PizzaProduct (final String name, final String title, final float price) { - this.setName(name); + public PizzaProduct (final Long id, final String title, final float price) { + this.setId(id); this.setTitle(title); this.setPrice(price); } + /** + * Getter for product category + * + * @return Product category + */ + @Override + public final Category getCategory () { + return this.category; + } + + /** + * Setter for product category + * + * @param category Product category + */ + @Override + public final void setCategory (final Category category) { + this.category = category; + } + /** * Name of product * @return the name */ @Override - public final String getName () { - return this.name; + public final Long getId () { + return this.id; } /** - * Name of product - * @param name the name to set + * Id number of product + * @param id the id number to set */ - protected final void setName (final String name) { - this.name = name; + @Override + public final void setId (final Long id) { + this.id = id; } /** @@ -81,7 +109,8 @@ public class PizzaProduct extends BaseFrameworkSystem implements Product { * Price of product * @param price the price to set */ - protected final void setPrice (final float price) { + @Override + public final void setPrice (final float price) { this.price = price; } @@ -98,7 +127,8 @@ public class PizzaProduct extends BaseFrameworkSystem implements Product { * Title of product * @param title the title to set */ - protected final void setTitle (final String title) { + @Override + public final void setTitle (final String title) { this.title = title; } } diff --git a/src/java/org/mxchange/pizzaapplication/product/Product.java b/src/java/org/mxchange/pizzaapplication/product/Product.java index bdeea227..6157ad6e 100644 --- a/src/java/org/mxchange/pizzaapplication/product/Product.java +++ b/src/java/org/mxchange/pizzaapplication/product/Product.java @@ -16,6 +16,7 @@ */ package org.mxchange.pizzaapplication.product; +import org.mxchange.pizzaapplication.category.Category; import org.mxchange.jcore.database.storage.Storeable; /** @@ -24,11 +25,17 @@ import org.mxchange.jcore.database.storage.Storeable; */ public interface Product extends Storeable { /** - * Getter for name, suitable for form fields. + * Getter for id number, suitable for form fields. * - * @return Name of product + * @return Id number of product */ - public String getName (); + public Long getId (); + + /** + * Id number of product + * @param id the id number to set + */ + public void setId (final Long id); /** * Getter for title. @@ -37,10 +44,36 @@ public interface Product extends Storeable { */ public String getTitle (); + /** + * Title of product + * @param title the title to set + */ + public void setTitle (final String title); + /** * Getter for raw price. * * @return Single price of product */ public float getPrice (); + + /** + * Price of product + * @param price the price to set + */ + public void setPrice (final float price); + + /** + * Getter for product category + * + * @return Product category + */ + public Category getCategory (); + + /** + * Setter for product category + * + * @param category Product category + */ + public void setCategory (final Category category); } diff --git a/web/admin/category.jsp b/web/admin/category.jsp new file mode 100644 index 00000000..1dc87c57 --- /dev/null +++ b/web/admin/category.jsp @@ -0,0 +1,141 @@ +<%-- + Document : category + Created on : 05.08.2015, 10:51:14 + Author : Roland Haeder +--%> + +<%--<%@page errorPage="errorHandler.jsp" %>--%> +<%@page import="org.mxchange.pizzaapplication.category.Category"%> +<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> +<%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + +<% + // Init application instance + PizzaApplication app = PizzaServiceApplication.getInstance(application); +%> + + + + + + + <%=PizzaServiceApplication.MAIN_TITLE%> - Kategorien + + + +
+

<%=PizzaServiceApplication.MAIN_TITLE%> - Kategorien

+
+ + + +
+
+

Kategorien administrieren:

+
+ +
+
+
+ + + + + + + + + + + <% + // "Walk" through all products and unmark them as ordered + for (final Category category : app.getCategories()) { + %> + + + + + + <% + } + %> + + + + + +
+ Produktname: (Schlüssel) + + Produktbezeichnung: + + Einzelpreis: +
+ <%=category.getId()%> + + <%=category.getTitle()%> + + <%=category.getPrice()%> +
+
+
+ +
+
+
+
+ Neue Kategorie hinzufügen: +
+ +
+ Bitte alle Felder ausfüllen: + +
+
+ Produktbezeichnung: +
(z.B. Pizza Italia)
+
+ +
+ +
+ +
+
+ +
+
+ Einzelpreis: +
(z.B. 50.0)
+
+ +
+ +
+ +
+
+
+ + +
+
+
+
+ Hinweise zum Hinzufügen von Kategorien +
    +
  • +
+
+
+
+ + diff --git a/web/admin/products.jsp b/web/admin/product.jsp similarity index 78% rename from web/admin/products.jsp rename to web/admin/product.jsp index 0999f8ec..1efbefef 100644 --- a/web/admin/products.jsp +++ b/web/admin/product.jsp @@ -11,12 +11,8 @@ <%@page import="org.mxchange.pizzaapplication.product.Product"%> <%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%> <%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%> -<%@page import="org.mxchange.pizzaapplication.beans.CustomerBean" %> <%@page contentType="text/html" pageEncoding="UTF-8"%> - - - <% // Init application instance PizzaApplication app = PizzaServiceApplication.getInstance(application); @@ -43,7 +39,7 @@
-
+ @@ -65,11 +61,11 @@ <% // "Walk" through all products and unmark them as ordered - for (final Product product : app.getUnmarkedProducts(session)) { + for (final Product product : app.getProducts()) { %> - <% // "Walk" through all products and unmark them as ordered - for (final Product product : app.getUnmarkedProducts(session)) { + for (final Product product : app.getProducts()) { + // Unmark as ordered + app.unmarkProductAsOrdered(product, session); %> <% // "Walk" through all products and unmark them as ordered - for (final Product product : app.getUnmarkedProducts(session)) { + for (final Product product : app.getProducts()) { + // Unmark it as ordered + app.unmarkProductAsOrdered(product, session); %>
- <%=product.getName()%> + <%=product.getId()%> <%=product.getTitle()%> @@ -86,7 +82,7 @@ %>
- /> + /> - + <%=product.getTitle()%> diff --git a/web/preview.jsp b/web/preview.jsp index 13233c49..dd300782 100644 --- a/web/preview.jsp +++ b/web/preview.jsp @@ -66,7 +66,9 @@
diff --git a/web/static/admin/menu.jsp b/web/static/admin/menu.jsp index 8b331153..627ffde6 100644 --- a/web/static/admin/menu.jsp +++ b/web/static/admin/menu.jsp @@ -7,7 +7,8 @@