]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Continued with project:
authorRoland Haeder <roland@mxchange.org>
Fri, 14 Aug 2015 13:39:12 +0000 (15:39 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 14 Aug 2015 13:39:12 +0000 (15:39 +0200)
- added install.sql
- Renamed method getProducts() to getAvailableProducts()
- Added method getAllProducts()
- Renamed parseLineToCategory() and parseLineToProduct() to parseLine()
- All products are now comparable + compareTo() implemented in BaseProduct
- Added column "id" for product database
- Implemented getPrintableProduktAvailability() very rudely
- Ids must be parsed as Long, not Integer, as the BASE64-encoded database backend does parse it so
- Added "available" to HTML form and all relevant methods
- Added method decodedTitle() to have a UTF8-decoded title
- Constructor PizzaProduct (id, title, price) is now deprecated
- Some other cleanups
Signed-off-by:Roland Häder <roland@mxchange.org>

15 files changed:
install/install.sql [new file with mode: 0644]
src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java
src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java
src/java/org/mxchange/pizzaapplication/category/BaseCategory.java
src/java/org/mxchange/pizzaapplication/database/frontend/category/PizzaCategoryDatabaseFrontend.java
src/java/org/mxchange/pizzaapplication/database/frontend/product/PizzaProductDatabaseFrontend.java
src/java/org/mxchange/pizzaapplication/database/frontend/product/ProductFrontend.java
src/java/org/mxchange/pizzaapplication/database/product/PizzaProductDatabaseConstants.java
src/java/org/mxchange/pizzaapplication/product/PizzaProduct.java
src/java/org/mxchange/pizzaapplication/product/Product.java
web/admin/product.jsp
web/finished.jsp
web/form_handler/do_preview.jsp
web/index.jsp
web/preview.jsp

diff --git a/install/install.sql b/install/install.sql
new file mode 100644 (file)
index 0000000..04fb29b
--- /dev/null
@@ -0,0 +1,68 @@
+SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
+SET time_zone = "+00:00";
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!40101 SET NAMES utf8 */;
+
+
+DROP TABLE IF EXISTS `category`;
+CREATE TABLE IF NOT EXISTS `category` (
+`id` bigint(20) unsigned NOT NULL COMMENT 'Primary key',
+  `title` varchar(255) NOT NULL COMMENT 'Category title',
+  `parent` bigint(20) unsigned DEFAULT NULL COMMENT 'Parent category'
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COMMENT='Categories' AUTO_INCREMENT=3 ;
+
+DROP TABLE IF EXISTS `contacts`;
+CREATE TABLE IF NOT EXISTS `contacts` (
+`id` bigint(20) unsigned NOT NULL COMMENT 'Primary key',
+  `own_contact` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Whether own contact',
+  `gender` varchar(10) NOT NULL DEFAULT 'UNKNOWN' COMMENT 'Gender',
+  `surname` varchar(100) NOT NULL COMMENT 'Surname',
+  `family_name` varchar(100) NOT NULL COMMENT 'Family name',
+  `company_name` varchar(255) DEFAULT NULL COMMENT 'Company name',
+  `street` varchar(255) DEFAULT NULL COMMENT 'Street name',
+  `house_number` smallint(5) unsigned DEFAULT NULL COMMENT 'House number',
+  `city` varchar(100) DEFAULT NULL COMMENT 'City name',
+  `zip_code` smallint(5) unsigned DEFAULT NULL COMMENT 'ZIP code',
+  `country_code` char(2) DEFAULT NULL COMMENT 'Country code',
+  `phone_number` varchar(100) DEFAULT NULL COMMENT 'Phone number',
+  `cellphone_number` varchar(100) DEFAULT NULL COMMENT 'Cellphone number',
+  `fax_number` varchar(100) DEFAULT NULL COMMENT 'Fax number',
+  `email_address` varchar(100) DEFAULT NULL COMMENT 'Email addres',
+  `birthday` date DEFAULT NULL COMMENT 'Birth day',
+  `comment` tinytext NOT NULL COMMENT 'Comment',
+  `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Entry created',
+  `updated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Contacts data' AUTO_INCREMENT=1 ;
+
+DROP TABLE IF EXISTS `products`;
+CREATE TABLE IF NOT EXISTS `products` (
+`id` bigint(20) unsigned NOT NULL COMMENT 'Primary key',
+  `category` bigint(20) unsigned DEFAULT NULL COMMENT 'Category id',
+  `title` varchar(255) NOT NULL COMMENT 'Title of product',
+  `price` decimal(20,2) unsigned NOT NULL COMMENT 'Product price',
+  `available` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Whether product is available'
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COMMENT='Products' AUTO_INCREMENT=2 ;
+
+
+ALTER TABLE `category`
+ ADD PRIMARY KEY (`id`), ADD KEY `parent` (`parent`);
+
+ALTER TABLE `contacts`
+ ADD PRIMARY KEY (`id`);
+
+ALTER TABLE `products`
+ ADD PRIMARY KEY (`id`), ADD KEY `category` (`category`);
+
+
+ALTER TABLE `category`
+MODIFY `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key',AUTO_INCREMENT=3;
+ALTER TABLE `contacts`
+MODIFY `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key';
+ALTER TABLE `products`
+MODIFY `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key',AUTO_INCREMENT=2;
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
index eac4882f9ed8172f2a51f813b9d3e24bced2e60d..dc0140bb8408606ba7a0536c5dcd936b594215cb 100644 (file)
@@ -201,12 +201,20 @@ public interface PizzaApplication extends Application {
        public void setValueInSession (final HttpSession session, final String key, final Object value);
 
        /**
-        * Some "getter" for a an array of all products
+        * Some "getter" for a an array of only available products
         * 
+        * @return Only available products
+        * @throws javax.servlet.ServletException If anything went wrong
+        */
+       public Iterator<Product> getAvailableProducts () throws ServletException;
+
+       /**
+        * Some "getter" for a an array of all products
+        *
         * @return All products
         * @throws javax.servlet.ServletException If anything went wrong
         */
-       public Iterator<Product> getProducts () throws ServletException;
+       public Iterator<Product> getAllProducts () throws ServletException;
 
        /**
         * Some "getter" for a an array of all categories
index 914711b9353034399e312567c52b3e40b7ca233b..e32f4556cf24de8150ddc769b7067b7d04aa3c81 100644 (file)
@@ -168,7 +168,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
 
                // Init/declare total price and iterator
                int totalAmount = 0;
-               Iterator<Product> iterator = this.getProducts();
+               Iterator<Product> iterator = this.getAvailableProducts();
 
                // "Walk" over all products
                while (iterator.hasNext()) {
@@ -222,7 +222,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
                float totalPrice = 0.00f;
 
                // Get iterator
-               Iterator<Product> iterator = this.getProducts();
+               Iterator<Product> iterator = this.getAvailableProducts();
 
                // "Walk" over all products
                while (iterator.hasNext()) {
@@ -481,7 +481,23 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
         */
        @Override
        public String getPrintableProduktAvailability (final Product product) {
-               throw new UnsupportedOperationException(MessageFormat.format("Not supported yet: product={0}", product)); //NOI18N
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product));
+
+               // Is it null?
+               if (product == null) {
+                       // Should not be null
+                       throw new NullPointerException("product is null");
+               }
+
+               // Get availability
+               if (product.getAvailable() == true) {
+                       // Is available
+                       return "Ja";
+               } else {
+                       // Not, not for public
+                       return "Nein";
+               }
        }
 
        /**
@@ -518,16 +534,31 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
                return this.convertNullToEmpty(value);
        }
 
+       /**
+        * Some "getter" for a an array of only available products
+        *
+        * @return All products
+        */
+       @Override
+       public Iterator<Product> getAvailableProducts () throws ServletException {
+               try {
+                       // Ask frontend for a list of products
+                       return this.productFrontend.getAvailableProducts();
+               } catch (final IOException | BadTokenException | SQLException ex) {
+                       throw new ServletException(ex);
+               }
+       }
+
        /**
         * Some "getter" for a an array of all products
         *
         * @return All products
         */
        @Override
-       public Iterator<Product> getProducts () throws ServletException {
+       public Iterator<Product> getAllProducts () throws ServletException {
                try {
                        // Ask frontend for a list of products
-                       return this.productFrontend.getProducts();
+                       return this.productFrontend.getAllProducts();
                } catch (final IOException | BadTokenException | SQLException ex) {
                        throw new ServletException(ex);
                }
@@ -756,7 +787,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
                this.getLogger().trace(MessageFormat.format("request={0},session={1} - CALLED!", request, session)); //NOI18N
 
                // Init iterator
-               Iterator<Product> iterator = this.getProducts();
+               Iterator<Product> iterator = this.getAvailableProducts();
 
                // "Walk" over all products
                while (iterator.hasNext()) {
@@ -1135,7 +1166,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
 
                try {
                        // Get iterator
-                       iterator = this.getProducts();
+                       iterator = this.getAvailableProducts();
                } catch (final ServletException ex) {
                        this.abortProgramWithException(ex);
                }
@@ -1259,8 +1290,11 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
                String title = request.getParameter(PizzaProductDatabaseConstants.COLUMN_TITLE);
                String price = request.getParameter(PizzaProductDatabaseConstants.COLUMN_PRICE);
                String category = request.getParameter(PizzaProductDatabaseConstants.COLUMN_CATEGORY);
-               Integer id = null;
+               String available = request.getParameter(PizzaProductDatabaseConstants.COLUMN_AVAILABLE);
+
+               Long id = null;
                Float p = null;
+               Boolean a = null;
 
                // Check all fields
                if (title == null) {
@@ -1281,17 +1315,29 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
                } else if (category.isEmpty()) {
                        // Is left empty
                        throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", PizzaProductDatabaseConstants.COLUMN_CATEGORY));
-               } else {
-                       // "parent" is set, so check it
-                       try {
-                               id = Integer.parseInt(category);
-                               p = Float.parseFloat(price);
-                       } catch (final NumberFormatException e) {
-                               // Not valid number
-                               throw new IllegalArgumentException(e);
-                       }
+               } else if (available == null) {
+                       // "title" not set
+                       throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", PizzaProductDatabaseConstants.COLUMN_AVAILABLE));
+               } else if (available.isEmpty()) {
+                       // Is left empty
+                       throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", PizzaProductDatabaseConstants.COLUMN_AVAILABLE));
+               } else if ((!"true".equals(available)) && (!"false".equals(available))) {
+                       // Invalid value
+                       throw new IllegalArgumentException(MessageFormat.format("{0} is invalid: {1}", PizzaProductDatabaseConstants.COLUMN_AVAILABLE, available));
                }
 
+               // Parse numbers
+               try {
+                       id = Long.parseLong(category);
+                       p = Float.parseFloat(price);
+               } catch (final NumberFormatException e) {
+                       // Not valid number
+                       throw new IllegalArgumentException(e);
+               }
+
+               // Parse boolean
+               a = Boolean.parseBoolean(available);
+
                // Test on product title
                try {
                        // Try to check if title is used already
@@ -1305,7 +1351,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
 
                try {
                        // The product is not found, so add it to database
-                       this.productFrontend.addProduct(title, p, id);
+                       this.productFrontend.addProduct(title, p, id, a);
                } catch (final SQLException ex) {
                        // Continue to throw it
                        throw new ServletException(ex);
index 5043b940f370b77e8b6976c9d2ed53ba2b1f919d..04b78b71b026c3428a8bc51bdffbbe011f045158 100644 (file)
@@ -87,6 +87,20 @@ public class BaseCategory extends BaseFrameworkSystem implements Category {
                return 1;
        }
 
+       /**
+        * Decodes the UTF8-encoded title
+        *
+        * @return Decoded title
+        */
+       @Override
+       public final String decodedTitle () throws UnsupportedEncodingException {
+               // Get title
+               byte[] t = this.getTitle().getBytes();
+               
+               // Decode it
+               return new String(t, "UTF-8");
+       }
+
        /**
         * Id number of category
         * @return the id
@@ -140,18 +154,4 @@ public class BaseCategory extends BaseFrameworkSystem implements Category {
        public final void setTitle (final String title) {
                this.title = title;
        }
-
-       /**
-        * Decodes the UTF8-encoded title
-        *
-        * @return Decoded title
-        */
-       @Override
-       public final String decodedTitle () throws UnsupportedEncodingException {
-               // Get title
-               byte[] t = this.getTitle().getBytes();
-
-               // Decode it
-               return new String(t, "UTF-8");
-       }
 }
index d491d03102baf3b5049bd5460cb22159e23acdf8..e9e76f4c4d3293640e2c1d57278103e1d9f65e0c 100644 (file)
@@ -257,7 +257,7 @@ public class PizzaCategoryDatabaseFrontend extends BaseDatabaseFrontend implemen
                this.getLogger().trace(MessageFormat.format("line={0} - CALLED!", line)); //NOI18N
 
                // Call inner method
-               Category category = this.parseLineToCategory(line);
+               Category category = this.parseLine(line);
 
                // Debug message
                this.getLogger().trace(MessageFormat.format("category={0} - EXIT!", category)); //NOI18N
@@ -272,7 +272,7 @@ public class PizzaCategoryDatabaseFrontend extends BaseDatabaseFrontend implemen
         * @param line Raw, decoded line from a file-based backend
         * @return A Category instance from given line
         */
-       private Category parseLineToCategory (final String line) {
+       private Category parseLine (final String line) {
                throw new UnsupportedOperationException(MessageFormat.format("Not supported yet: line={0}", line)); //NOI18N
        }
 }
index 633e44a491f7fccc8e09f0a4e9cee3ef45002f11..321e3097eb931cf5ec008373621757a8deaa8480 100644 (file)
@@ -30,6 +30,7 @@ import org.mxchange.jcore.database.storage.Storeable;
 import org.mxchange.jcore.exceptions.BadTokenException;
 import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
 import org.mxchange.pizzaapplication.database.product.PizzaProductDatabaseConstants;
+import org.mxchange.pizzaapplication.product.PizzaProduct;
 import org.mxchange.pizzaapplication.product.Product;
 
 /**
@@ -104,7 +105,7 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement
 
        @Override
        @SuppressWarnings ("unchecked")
-       public Iterator<Product> getProducts () throws IOException, BadTokenException, SQLException {
+       public Iterator<Product> getAvailableProducts () throws IOException, BadTokenException, SQLException {
                // Trace message
                this.getLogger().trace("CALLED!"); //NOI18N
 
@@ -130,6 +131,39 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement
                return (Iterator<Product>) iterator;
        }
 
+       /**
+        * An iterator on all products
+        *
+        * @return Iterator on all products
+        * @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 errors occur
+        */
+       @Override
+       @SuppressWarnings ("unchecked")
+       public Iterator<Product> getAllProducts () throws IOException, BadTokenException, SQLException {
+               // Trace message
+               this.getLogger().trace("CALLED!"); //NOI18N
+
+               // Instance search criteria
+               SearchableCritera critera = new SearchCriteria();
+
+               // Run the query
+               Result<? extends Storeable> result = this.getBackend().doSelectByCriteria(critera);
+
+               // Debug message
+               this.getLogger().debug(MessageFormat.format("result={0}", result)); //NOI18N
+
+               // Get iterator
+               Iterator<?> iterator = result.iterator();
+
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("iterator={0} - EXIT!", iterator)); //NOI18N
+
+               // Get iterator and return it
+               return (Iterator<Product>) iterator;
+       }
+
        /**
         * Gets a Result back from given ResultSet instance
         *
@@ -150,8 +184,18 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement
 
                // "Walk" through all entries
                while (resultSet.next()) {
-                       // Unwrap whole object
-                       Product product = resultSet.unwrap(Product.class);
+                       // Get id, title and parent id
+                       Long id = resultSet.getLong(PizzaProductDatabaseConstants.COLUMN_ID);
+                       String title = resultSet.getString(PizzaProductDatabaseConstants.COLUMN_TITLE);
+                       Float price = resultSet.getFloat(PizzaProductDatabaseConstants.COLUMN_PRICE);
+                       Long category = resultSet.getLong(PizzaProductDatabaseConstants.COLUMN_CATEGORY);
+                       Boolean available = resultSet.getBoolean(PizzaProductDatabaseConstants.COLUMN_AVAILABLE);
+
+                       // Debug message
+                       this.getLogger().debug(MessageFormat.format("id={0},title={1},category={2},available={3}", id, title, category, available));
+
+                       // Instance new object
+                       Product product = new PizzaProduct(id, title, price, category, available);
 
                        // Debug log
                        this.getLogger().debug(MessageFormat.format("product={0}", product));
@@ -219,7 +263,7 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement
                this.getLogger().trace(MessageFormat.format("line={0} - CALLED!", line)); //NOI18N
 
                // Call inner method
-               Product product = this.parseLineToProduct(line);
+               Product product = this.parseLine(line);
 
                // Debug message
                this.getLogger().trace(MessageFormat.format("product={0} - EXIT!", product)); //NOI18N
@@ -234,7 +278,7 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement
         * @param line
         * @return A Product instance from given line
         */
-       private Product parseLineToProduct (final String line) {
+       private Product parseLine (final String line) {
                throw new UnsupportedOperationException(MessageFormat.format("Not supported yet: line={0}", line)); //NOI18N
        }
 
@@ -243,10 +287,11 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement
         * @param title Product title
         * @param price Product price
         * @param category Product category id
+        * @param available Availability of product (selectable by customer)
         * @throws java.sql.SQLException If any SQL errors occur
         */
        @Override
-       public void addProduct (final String title, final Float price, final Integer category) throws SQLException {
+       public void addProduct (final String title, final Float price, final Long category, final Boolean available) throws SQLException {
                // Trace message
                this.getLogger().trace(MessageFormat.format("title={0},price={1},category={2} - CALLED!", title, price, category));
 
@@ -260,6 +305,9 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement
                } else if (category == null) {
                        // Abort here
                        throw new NullPointerException("category is null");
+               } else if (available == null) {
+                       // Abort here
+                       throw new NullPointerException("available is null");
                }
 
                // Clear dataset from previous usage
@@ -269,6 +317,7 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement
                this.addToDataSet(PizzaProductDatabaseConstants.COLUMN_TITLE, title);
                this.addToDataSet(PizzaProductDatabaseConstants.COLUMN_PRICE, price);
                this.addToDataSet(PizzaProductDatabaseConstants.COLUMN_CATEGORY, category);
+               this.addToDataSet(PizzaProductDatabaseConstants.COLUMN_AVAILABLE, available);
 
                // Handle this over to the backend
                Result<? extends Storeable> result = this.doInsertDataSet();
index 4363aac3fa1b0224bf3e24cc9564c4630e095de9..4455fd543308f1ee787ff0dea3be75e6506cf876 100644 (file)
@@ -35,9 +35,10 @@ public interface ProductFrontend extends DatabaseFrontend {
         * @param title Product title
         * @param price Product price
         * @param category Product category id
+        * @param available Availability of product (selectable by customer)
         * @throws java.sql.SQLException If any SQL errors occur
         */
-       public void addProduct (final String title, final Float price, final Integer category) throws SQLException;
+       public void addProduct (final String title, final Float price, final Long category, final Boolean available) throws SQLException;
 
        /**
         * An iterator on all products
@@ -47,7 +48,17 @@ public interface ProductFrontend extends DatabaseFrontend {
         * @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 errors occur
         */
-       public Iterator<Product> getProducts () throws IOException, BadTokenException, SQLException;
+       public Iterator<Product> getAllProducts () throws IOException, BadTokenException, SQLException;
+
+       /**
+        * An iterator on all products
+        *
+        * @return Iterator on all products
+        * @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 errors occur
+        */
+       public Iterator<Product> getAvailableProducts () throws IOException, BadTokenException, SQLException;
 
        /**
         * Checks wether the given product title is already used.
index 8d3646f784cfb30d57dbfb14b7c92543ca5fc2ed..4d698b11ee2790f7677c59e65f3566bf6d7a9505 100644 (file)
@@ -32,6 +32,11 @@ public final class PizzaProductDatabaseConstants {
         */
        public static final String COLUMN_CATEGORY = "category";
 
+       /**
+        * Column name for "id"
+        */
+       public static final String COLUMN_ID = "id";
+
        /**
         * Column name for "price"
         */
index 751aaea8a0c32f443aac99e19b56b2dc0cdfa683..23f37575b520849eb9c004c0a6c6894f5d5cbe03 100644 (file)
@@ -16,7 +16,8 @@
  */
 package org.mxchange.pizzaapplication.product;
 
-import org.mxchange.pizzaapplication.category.Category;
+import java.text.MessageFormat;
+import java.util.Objects;
 import org.mxchange.jcore.BaseFrameworkSystem;
 
 /**
@@ -25,10 +26,15 @@ import org.mxchange.jcore.BaseFrameworkSystem;
  * @author Roland Haeder
  */
 public class PizzaProduct extends BaseFrameworkSystem implements Product {
+       /**
+        * Availability of product
+        */
+       private Boolean available;
+
        /**
         * Product category
         */
-       private Category category;
+       private Long category;
 
        /**
         * Id number of product
@@ -45,26 +51,67 @@ public class PizzaProduct extends BaseFrameworkSystem implements Product {
         */
        private String title;
 
+
        /**
         * Constructor for products with a name and a price.
         * 
         * @param id Id number of product
         * @param title Name of product
         * @param price Price
+        * @deprecated Please use constructor with category and available
         */
+       @Deprecated
        public PizzaProduct (final Long id, final String title, final float price) {
                this.setId(id);
                this.setTitle(title);
                this.setPrice(price);
        }
 
+       /**
+        * Constructor will all required data
+        *
+        * @param id Id number of product
+        * @param title Name of product
+        * @param price Price
+        * @param category Category id
+        * @param available Availability (selectable by customer)
+        */
+       public PizzaProduct (final Long id, final String title, final Float price, final Long category, final Boolean available) {
+               // Set all here
+               this.setId(id);
+               this.setTitle(title);
+               this.setPrice(price);
+               this.setCategory(category);
+               this.setAvailable(available);
+       }
+
+       /**
+        * Getter for product availability
+        *
+        * @return Product availability
+        */
+       @Override
+       public final Boolean getAvailable () {
+               return this.available;
+       }
+
+       /**
+        * Setter for product availability
+        *
+        * @param available Product availability
+        */
+       @Override
+       public final void setAvailable (final Boolean available) {
+               this.available = available;
+       }
+
        /**
         * Getter for product category
         *
         * @return Product category
         */
        @Override
-       public final Category getCategory () {
+       public final Long getCategory () {
                return this.category;
        }
 
@@ -74,7 +121,7 @@ public class PizzaProduct extends BaseFrameworkSystem implements Product {
         * @param category Product category
         */
        @Override
-       public final void setCategory (final Category category) {
+       public final void setCategory (final Long category) {
                this.category = category;
        }
 
@@ -131,4 +178,36 @@ public class PizzaProduct extends BaseFrameworkSystem implements Product {
        public final void setTitle (final String title) {
                this.title = title;
        }
+
+       /**
+        * Compares two categories with each other
+        *
+        * @param product Product comparator
+        * @return Comparison value
+        */
+       @Override
+       public int compareTo (final Product product) {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product));
+               
+               // category should not be null
+               if (product == null) {
+                       throw new NullPointerException("product is null");
+               }
+
+               // Debug message
+               this.getLogger().debug(MessageFormat.format("this.id={0},product.id={1}", this.getId(), product.getId()));
+
+               // Is the id the same?
+               if (Objects.equals(this.getId(), product.getId())) {
+                       // Same id, means same category
+                       return 0;
+               } else if (this.getId() > product.getId()) {
+                       // This id is larger than compared to
+                       return -1;
+               }
+
+               // The other id is larger
+               return 1;
+       }
 }
index 6157ad6edbf2b43f225fe003a51641fc0d03f8f1..2e17f8c8a04a9a051977e4c03c6f909e7c4e00d3 100644 (file)
  */
 package org.mxchange.pizzaapplication.product;
 
-import org.mxchange.pizzaapplication.category.Category;
 import org.mxchange.jcore.database.storage.Storeable;
 
 /**
+ * An interface for in database storeable products
  *
  * @author Roland Haeder
  */
-public interface Product extends Storeable {
+public interface Product extends Storeable, Comparable<Product> {
        /**
         * Getter for id number, suitable for form fields.
         * 
@@ -68,12 +68,33 @@ public interface Product extends Storeable {
         *
         * @return Product category
         */
-       public Category getCategory ();
+       public Long getCategory ();
 
        /**
         * Setter for product category
         *
         * @param category Product category
         */
-       public void setCategory (final Category category);
+       public void setCategory (final Long category);
+
+       /**
+        * Getter for product availability
+        *
+        * @return Product availability
+        */
+       public Boolean getAvailable ();
+
+       /**
+        * Setter for product availability
+        *
+        * @param available Product availability
+        */
+       public void setAvailable (final Boolean available);
+
+       /**
+        * Compare method
+        * @param category Category to compare to
+        */
+       @Override
+       public int compareTo (final Product category);
 }
index 4fa59cbcd85e5344402e9ad3c50bd39754044990..9f827724d42d5344db85f5d6b5c98ef409098026 100644 (file)
        <head>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                <link rel="stylesheet" href="<%=request.getContextPath()%>/style.css" type="text/css"/>
-               <title><%=PizzaServiceApplication.MAIN_TITLE%> - Bestellung anzeigen</title>
+               <title><%=PizzaServiceApplication.MAIN_TITLE%> - Produkte</title>
        </head>
 
        <body>
                <div id="title">
-                       <h1><%=PizzaServiceApplication.MAIN_TITLE%> - Bestellung anzeigen</h1>
+                       <h1><%=PizzaServiceApplication.MAIN_TITLE%> - Produkte</h1>
                </div>
 
                <jsp:include page="/static/admin/menu.jsp" flush="true" />
@@ -46,7 +46,7 @@
                                                <thead class="table_header">
                                                        <tr>
                                                                <th class="table_header_column">
-                                                                       Produktname: (Schlüssel)
+                                                                       Produktnummer:
                                                                </th>
                                                                <th class="table_header_column">
                                                                        Produktbezeichnung:
@@ -61,7 +61,7 @@
                                                </thead>
 
                                                <tbody class="table_body">
-                                                       <c:forEach var="product" items="<%=app.getProducts()%>">
+                                                       <c:forEach var="product" items="<%=app.getAllProducts()%>">
                                                        <tr>
                                                                <td>
                                                                        ${product.getId()}
 
                                                                <div class="clear"></div>
                                                        </div>
+
+                                                       <div class="data_row">
+                                                               <div class="table_left">
+                                                                       Verfügbar?
+                                                               </div>
+
+                                                               <div class="table_right">
+                                                                       <select name="available" size="1">
+                                                                               <option value="true">Ja</option>
+                                                                               <option value="false">Nein</option>
+                                                                       </select>
+                                                               </div>
+
+                                                               <div class="clear"></div>
+                                                       </div>
                                                </fieldset>
 
                                                <div class="table_footer">
index 3a2430b4cd1b4d50b81f5d58bb2e60e9b87faf2d..4f574d8b2b4502c9ca000a4697a4e2968fa17b1c 100644 (file)
@@ -66,7 +66,7 @@
                                        <tbody class="table_body">
                                                <%
                                                // Get Iterator
-                                               Iterator<Product> iterator = app.getProducts();
+                                               Iterator<Product> iterator = app.getAvailableProducts();
 
                                                // "Walk" through all products and unmark them as ordered
                                                while (iterator.hasNext()) {
index a1b20cb0e258cc11bea9a036796c5a9abc34cd4e..51e5b0cff6f7b47aa6b3637e2cb2e0338d910783 100644 (file)
@@ -21,7 +21,7 @@
        // Is it post?
        if ("POST".equals(request.getMethod())) { //NOI18N
                // Get Iterator
-               Iterator<Product> iterator = app.getProducts();
+               Iterator<Product> iterator = app.getAvailableProducts();
 
                // "Walk" through all products and unmark them as ordered
                while (iterator.hasNext()) {
index 7dd9458f998549606c69ffb01a75005f82c47518..31610d6b9dcd9f1e70227dc4d116b9d0a06a3f79 100644 (file)
@@ -59,7 +59,7 @@
                                        <tbody class="table_body">
                                                <%
                                                // Get Iterator
-                                               Iterator<Product> iterator = app.getProducts();
+                                               Iterator<Product> iterator = app.getAvailableProducts();
 
                                                // "Walk" through all products and unmark them as ordered
                                                while (iterator.hasNext()) {
index fb93d38627b62e12ed7fc6e189a390bf836c5c4c..ca5a32d7d14f14e58407a0d07829778c30c89dcf 100644 (file)
@@ -66,7 +66,7 @@
                                        <tbody class="table_body">
                                                <%
                                                // Get Iterator
-                                               Iterator<Product> iterator = app.getProducts();
+                                               Iterator<Product> iterator = app.getAvailableProducts();
 
                                                // "Walk" through all products and unmark them as ordered
                                                while (iterator.hasNext()) {