From: Roland Haeder Date: Fri, 4 Sep 2015 21:38:18 +0000 (+0200) Subject: Moved stuff around + added dist.sh X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=bf1e54a2964e53d7454565b3687a78dd41f9cc6c;p=jproduct-core.git Moved stuff around + added dist.sh Signed-off-by:Roland Häder --- diff --git a/dist.sh b/dist.sh new file mode 100755 index 0000000..05a4fc4 --- /dev/null +++ b/dist.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +NAME="jshop-core" +LIST=`find ../*/lib/${NAME}.jar` +LIST="${LIST} `find ../*/*-ejb/lib/${NAME}.jar`" + +for entry in ${LIST}; +do + cp -v dist/${NAME}.jar ${entry} +done diff --git a/src/org/mxchange/jshop/BaseShopCore.java b/src/org/mxchange/jshop/BaseShopCore.java deleted file mode 100644 index 4c1acba..0000000 --- a/src/org/mxchange/jshop/BaseShopCore.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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.jshop; - -import org.mxchange.jcore.BaseFrameworkSystem; -import org.mxchange.jshop.model.product.Product; - -/** - * A general shop class - * - * @author Roland Haeder - */ -public class BaseShopCore extends BaseFrameworkSystem implements ShopInterface { - /** - * Item instance - */ - private Product product; - - /** - * @return the product - */ - @Override - public Product getProduct () { - return this.product; - } - - /** - * @param product the product to set - */ - @Override - public void setProduct (final Product product) { - this.product = product; - } -} diff --git a/src/org/mxchange/jshop/ShopInterface.java b/src/org/mxchange/jshop/ShopInterface.java deleted file mode 100644 index 9e3091c..0000000 --- a/src/org/mxchange/jshop/ShopInterface.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.jshop; - -import org.mxchange.jcore.FrameworkInterface; -import org.mxchange.jshop.model.product.Product; - -/** - * A general shop interface - * - * @author Roland Haeder - */ -public interface ShopInterface extends FrameworkInterface { - /** - * @return the product - */ - public Product getProduct (); - - /** - * @param product the product to set - */ - public void setProduct (final Product product); -} diff --git a/src/org/mxchange/jshop/exceptions/CategoryTitleAlreadyUsedException.java b/src/org/mxchange/jshop/exceptions/CategoryTitleAlreadyUsedException.java deleted file mode 100644 index d7d90dd..0000000 --- a/src/org/mxchange/jshop/exceptions/CategoryTitleAlreadyUsedException.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.jshop.exceptions; - -import java.text.MessageFormat; -import org.mxchange.jshop.model.category.Category; - -/** - * An exception thrown when the given title is already used - * - * @author Roland Haeder - */ -public class CategoryTitleAlreadyUsedException extends Exception { - /** - * Serial number - */ - private static final long serialVersionUID = 53751434673262L; - - /** - * Constructor with HttpServletRequest instance - * - * @param category Category instance - */ - public CategoryTitleAlreadyUsedException (final Category category) { - // Call super constructor - super(MessageFormat.format("Title {0} is already used.", category.getTitle())); //NOI18N - } -} diff --git a/src/org/mxchange/jshop/exceptions/ProductTitleAlreadyUsedException.java b/src/org/mxchange/jshop/exceptions/ProductTitleAlreadyUsedException.java deleted file mode 100644 index 18c3340..0000000 --- a/src/org/mxchange/jshop/exceptions/ProductTitleAlreadyUsedException.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.jshop.exceptions; - -import java.text.MessageFormat; -import org.mxchange.jshop.model.product.Product; - -/** - * An exception thrown when the given title is already used - * - * @author Roland Haeder - */ -public class ProductTitleAlreadyUsedException extends Exception { - /** - * Serial number - */ - private static final long serialVersionUID = 4252734834174L; - - /** - * Constructor with HttpServletRequest instance - * - * @param product Product instance - */ - public ProductTitleAlreadyUsedException (final Product product) { - // Call super constructor - super(MessageFormat.format("Title {0} is already used.", product.getTitle())); //NOI18N - } -} diff --git a/src/org/mxchange/jshop/model/basket/BaseBasket.java b/src/org/mxchange/jshop/model/basket/BaseBasket.java deleted file mode 100644 index 4fec090..0000000 --- a/src/org/mxchange/jshop/model/basket/BaseBasket.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * 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.jshop.model.basket; - -import java.io.IOException; -import java.io.Serializable; -import java.lang.reflect.InvocationTargetException; -import java.sql.SQLException; -import java.text.MessageFormat; -import java.util.Map; -import org.mxchange.jshop.BaseShopCore; -import org.mxchange.jshop.model.item.AddableBasketItem; - -/** - * A general basket class - * - * @author Roland Haeder - * @param Any instance that implements AddableBasketItem - */ -public class BaseBasket extends BaseShopCore implements Basket, Serializable { - /** - * Serial number - */ - private static final long serialVersionUID = 784396762230845717L; - - /** - * Protected constructor with session instance - * - * @throws java.sql.SQLException If an SQL error occurs - */ - protected BaseBasket () throws SQLException { - // Trace message - this.getLogger().trace("CALLED!"); //NOI18N - } - - @Override - public void init () throws SQLException { - // Trace message - this.getLogger().trace("CALLED!"); //NOI18N - - // Is the bundle initialized? - if (!BaseShopCore.isBundledInitialized()) { - // Temporary initialize default bundle - // TODO The enum Gender uses this - this.initBundle(); - } - } - - @Override - @SuppressWarnings ("unchecked") - public void addItem (final T item) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { - // Trace call - this.getLogger().trace(MessageFormat.format("item={0} - CALLED!", item)); //NOI18N - - // item must not be null - if (null == item) { - // Then abort here - throw new NullPointerException("item is null"); //NOI18N - } else if (this.isAdded(item)) { - // Already been added - throw new IllegalArgumentException("item has already been added. Did you miss to call isAdded()?"); //NOI18N - } - - // Add item to database - // TODO: ((BasketFrontend) this.getFrontend()).addItem(item, this.getSessionId()); - - // Trace call - this.getLogger().trace("EXIT!"); //NOI18N - } - - @Override - public boolean isEmpty () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { - // Deligate call to frontend - // TODO: return ((BasketFrontend) this.getFrontend()).isEmpty(); - throw new UnsupportedOperationException("Not yet implmeneted."); - } - - @Override - @SuppressWarnings("unchecked") - public Map getAll () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { - // Trace message - this.getLogger().trace("CALLED!"); //NOI18N - - // Init map - // TODO: Map map = ((BasketFrontend) this.getFrontend()).getAll(); - Map map = null; - - // Trace message - this.getLogger().trace("map=" + map); //NOI18N - - // Return it - return map; - } - - @Override - public AddableBasketItem getLast () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { - // Deligate to frontend - // TODO: return ((BasketFrontend) this.getFrontend()).getLast(); - throw new UnsupportedOperationException("Not yet implmeneted."); - } - - @Override - public int getLastNumRows () { - // Deligate to frontend - // TODO: return this.getFrontend().getLastNumRows(); - throw new UnsupportedOperationException("Not yet implmeneted."); - } - - @Override - public boolean isAdded (final T item) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { - // Trace call - this.getLogger().trace(MessageFormat.format("item={0} - CALLED!", item)); //NOI18N - - // item must not be null - if (null == item) { - // Then abort here - throw new NullPointerException("item is null"); //NOI18N - } - - // Call map's method - // TODO: boolean isAdded = ((BasketFrontend) this.getFrontend()).isAdded(item, this.getSessionId()); - boolean isAdded = true; - - // Trace message - this.getLogger().trace(MessageFormat.format("isAdded={0} - EXIT!", isAdded)); //NOI18N - - // Return it - return isAdded; - } -} diff --git a/src/org/mxchange/jshop/model/basket/Basket.java b/src/org/mxchange/jshop/model/basket/Basket.java deleted file mode 100644 index 97148b6..0000000 --- a/src/org/mxchange/jshop/model/basket/Basket.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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.jshop.model.basket; - -import java.io.IOException; -import java.io.Serializable; -import java.lang.reflect.InvocationTargetException; -import java.sql.SQLException; -import java.util.Map; -import org.mxchange.jshop.ShopInterface; -import org.mxchange.jshop.model.item.AddableBasketItem; - -/** - * An interface for baskets - * - * @author Roland Haeder - * @param Any addable basket items - */ -public interface Basket extends Serializable, ShopInterface { - - /** - * Adds given item instance to this basket - * @param item Item 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 - * @throws java.lang.IllegalAccessException If the invoked method is not public - * @throws java.lang.reflect.InvocationTargetException If anything else happened? - */ - public void addItem (final T item) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; - - /** - * Checks whether the given item as already been added. If the product's - * item id number was found in basket, the corresponding item instance will be set - * - * @param item Item instance to check - * @return Whether the given item has been found - * @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 - * @throws java.lang.IllegalAccessException If the invoked method is not public - * @throws java.lang.reflect.InvocationTargetException If anything else happened? - */ - public boolean isAdded (final T item) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; - - /** - * Checks if the basket is empty - * - * @return Whether the basket is empty - * @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 - * @throws java.lang.IllegalAccessException If the invoked method is not public - * @throws java.lang.reflect.InvocationTargetException If anything else happened? - */ - public boolean isEmpty () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; - - /** - * Initializes this instance with given ServletContext - * - * @throws java.sql.SQLException If an SQL error occurs - * @throws java.io.IOException If an IO error occurs - */ - public void init () throws SQLException, IOException; - - /** - * Some "getter" for all entries in this basket - * - * @return Map on all basket items - * @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 - * @throws java.lang.IllegalAccessException If the invoked method is not public - * @throws java.lang.reflect.InvocationTargetException If anything else happened? - */ - public Map getAll () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; - - /** - * Getter for last entry - * - * @return Last added item in basket - * @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 - * @throws java.lang.IllegalAccessException If the invoked method is not public - * @throws java.lang.reflect.InvocationTargetException If anything else happened? - */ - public AddableBasketItem getLast () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; - - /** - * Getter for last num rows - * - * @return Last num rows - */ - public int getLastNumRows (); -} diff --git a/src/org/mxchange/jshop/model/basket/item/ItemBasket.java b/src/org/mxchange/jshop/model/basket/item/ItemBasket.java deleted file mode 100644 index 1e3045f..0000000 --- a/src/org/mxchange/jshop/model/basket/item/ItemBasket.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.jshop.model.basket.item; - -import java.sql.SQLException; -import org.mxchange.jshop.model.basket.BaseBasket; -import org.mxchange.jshop.model.basket.Basket; -import org.mxchange.jshop.model.item.AddableBasketItem; - -/** - * A basket for orderable items - * - * @author Roland Haeder - */ -public class ItemBasket extends BaseBasket implements Basket { - /** - * Serial number - */ - private static final long serialVersionUID = 4384123923163957L; - - /** - * Default constructor to be able to throw exceptions from super constructor - * @throws java.sql.SQLException If an SQL error occurs - */ - public ItemBasket () throws SQLException { - // Call super constructor - super(); - } -} diff --git a/src/org/mxchange/jshop/model/category/BaseCategory.java b/src/org/mxchange/jshop/model/category/BaseCategory.java deleted file mode 100644 index 2a4264d..0000000 --- a/src/org/mxchange/jshop/model/category/BaseCategory.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * 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.jshop.model.category; - -import java.io.UnsupportedEncodingException; -import java.text.MessageFormat; -import java.util.Objects; -import org.mxchange.jshop.BaseShopCore; - -/** - * A general product category class - * - * @author Roland Haeder - */ -public class BaseCategory extends BaseShopCore implements Category { - - /** - * Id number of category - */ - private Long categoryId; - - /** - * Parent category categoryId - */ - private Long parentId; - - /** - * Title of category - */ - private String title; - - /** - * Constructor which accepts all database fields - * - * @param categoryId Id number of database record - * @param title Category title - * @param parentId Parent categoryId - */ - protected BaseCategory (final Long categoryId, final String title, final Long parentId) { - // Set all here - this.setCategoryId(categoryId); - this.setTitle(title); - this.setParentId(parentId); - } - - /** - * Default constructor - */ - protected BaseCategory () { - } - - /** - * Compares two categories with each other - * - * @param category Category comparator - * @return Comparison value - */ - @Override - public int compareTo (final Category category) { - // Trace message - this.getLogger().trace(MessageFormat.format("category={0} - CALLED!", category)); //NOI18N - - // category should not be null - if (null == category) { - throw new NullPointerException("category is null"); //NOI18N - } - - // Debug message - this.getLogger().debug(MessageFormat.format("this.id={0},category.id={1}", this.getCategoryId(), category.getCategoryId())); //NOI18N - - // Is the categoryId the same? - if (Objects.equals(this.getCategoryId(), category.getCategoryId())) { - // Same categoryId, means same category - return 0; - } else if (this.getCategoryId() > category.getCategoryId()) { - // This categoryId is larger than compared to - return -1; - } - - // The other categoryId is larger - return 1; - } - - /** - * Decodes the UTF8-encoded title - * - * @return Decoded title - */ - @Override - public final String getDecodedTitle () throws UnsupportedEncodingException { - // Get title - byte[] t = this.getTitle().getBytes(); - - // Decode it - return new String(t, "UTF-8"); //NOI18N - } - - /** - * Id number of category - * - * @return the categoryId - */ - @Override - public final Long getCategoryId () { - return this.categoryId; - } - - /** - * Id number of category - * - * @param categoryId the categoryId to set - */ - @Override - public final void setCategoryId (final Long categoryId) { - this.categoryId = categoryId; - } - - /** - * Parent category categoryId - * - * @return the parentId - */ - @Override - public final Long getParentId () { - return this.parentId; - } - - /** - * Parent category categoryId - * - * @param parentId the parentId to set - */ - @Override - public final void setParentId (final Long parentId) { - this.parentId = parentId; - } - - /** - * Title of category - * - * @return the title - */ - @Override - public final String getTitle () { - return this.title; - } - - /** - * Title of category - * - * @param title the title to set - */ - @Override - public final void setTitle (final String title) { - this.title = title; - } -} diff --git a/src/org/mxchange/jshop/model/category/Category.java b/src/org/mxchange/jshop/model/category/Category.java deleted file mode 100644 index d8ae5b0..0000000 --- a/src/org/mxchange/jshop/model/category/Category.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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.jshop.model.category; - -import java.io.UnsupportedEncodingException; -import org.mxchange.jshop.ShopInterface; - -/** - * An interface for categories - * - * @author Roland Haeder - */ -public interface Category extends ShopInterface, Comparable { - - /** - * Id number of category - * @return the id - */ - public Long getCategoryId (); - - /** - * Id number of category - * @param id the id to set - */ - public void setCategoryId (final Long id); - - /** - * Parent category id - * @return the parent - */ - public Long getParentId (); - - /** - * Parent category id - * @param parent the parent to set - */ - public void setParentId (final Long parent); - - /** - * Title of category - * @return the title - */ - public String getTitle (); - - /** - * Title of category - * @param title the title to set - */ - public void setTitle (final String title); - - /** - * Compare method - * @param category Category to compare to - * @return Comparison value - */ - @Override - public int compareTo (final Category category); - - /** - * Decodes the UTF8-encoded title - * - * @return Decoded title - * @throws java.io.UnsupportedEncodingException If the encoding UTF-8 is not supported - */ - public String getDecodedTitle () throws UnsupportedEncodingException ; -} diff --git a/src/org/mxchange/jshop/model/category/product/ProductCategory.java b/src/org/mxchange/jshop/model/category/product/ProductCategory.java deleted file mode 100644 index 7787b1f..0000000 --- a/src/org/mxchange/jshop/model/category/product/ProductCategory.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.jshop.model.category.product; - -import org.mxchange.jshop.model.category.BaseCategory; - -/** - * A product category - * @author Roland Haeder - */ -public class ProductCategory extends BaseCategory { - /** - * Constructor which accepts all database fields - * @param id Id number of database record - * @param title Category title - * @param parent Parent id - */ - public ProductCategory (final Long id, final String title, final Long parent) { - // Call parent constructor - super(id, title, parent); - } - - /** - * Default constructor - */ - public ProductCategory () { - } -} diff --git a/src/org/mxchange/jshop/model/customer/Customer.java b/src/org/mxchange/jshop/model/customer/Customer.java deleted file mode 100644 index 61fb863..0000000 --- a/src/org/mxchange/jshop/model/customer/Customer.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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.jshop.model.customer; - -import org.mxchange.jcore.model.contact.Contact; - -/** - * A customer interface - * - * @author Roland Haeder - */ -public interface Customer extends Contact { -} diff --git a/src/org/mxchange/jshop/model/customer/ShopCustomer.java b/src/org/mxchange/jshop/model/customer/ShopCustomer.java deleted file mode 100644 index 4fd24c0..0000000 --- a/src/org/mxchange/jshop/model/customer/ShopCustomer.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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.jshop.model.customer; - -import org.mxchange.jcore.model.contact.BaseContact; - -/** - * A shop customer class. - * - * @author Roland Haeder - */ -public class ShopCustomer extends BaseContact implements Customer { -} diff --git a/src/org/mxchange/jshop/model/item/AddableBasketItem.java b/src/org/mxchange/jshop/model/item/AddableBasketItem.java deleted file mode 100644 index 066a76c..0000000 --- a/src/org/mxchange/jshop/model/item/AddableBasketItem.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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.jshop.model.item; - -import org.mxchange.jshop.ShopInterface; - -/** - * An interface for addable basket items - * - * @author Roland Haeder - */ -public interface AddableBasketItem extends ShopInterface, Comparable { - - /** - * Item amount - * @return the amount - */ - public Long getAmount (); - - /** - * Item amount - * @param amount the amount to set - */ - public void setAmount (final Long amount); - - /** - * Entry id (from database backend) - * @return the id - */ - public Long getId (); - - /** - * Entry id (from database backend) - * @param id the id to set - */ - public void setId (final Long id); - - /** - * @return the id - */ - public Long getItemId (); - - /** - * @param id the id to set - */ - public void setItemId (final Long id); - - /** - * @return the type - */ - public String getItemType (); - - /** - * @param type the type to set - */ - public void setItemType (final String type); - - /** - * Calculates total price by multipying amount and single price - * - * @return Total price of this item - */ - public Float calculateTotalPrice (); - - /** - * Compare method - * @param item Item to compare to - * @return Comparison value - */ - @Override - public int compareTo (final AddableBasketItem item); -} diff --git a/src/org/mxchange/jshop/model/item/BaseItem.java b/src/org/mxchange/jshop/model/item/BaseItem.java deleted file mode 100644 index 53c9a53..0000000 --- a/src/org/mxchange/jshop/model/item/BaseItem.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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.jshop.model.item; - -import java.text.MessageFormat; -import java.util.Objects; -import org.mxchange.jshop.BaseShopCore; - -/** - * An item (addedable to a basket) could respresent a product or a discount - * coupon. This depends on the type of the item. - * - * @author Roland Haeder - */ -public class BaseItem extends BaseShopCore implements AddableBasketItem { - /** - * Entry id (from database backend) - */ - private Long id; - - /** - * Item amount - */ - private Long amount; - - /** - * Item id number - */ - private Long itemId; - - /** - * Item type - */ - private String itemType; - - @Override - public Float calculateTotalPrice () { - // product should be set - if (this.getProduct() == null) { - // Abort here - throw new NullPointerException("product is null"); //NOI18N - } - - // Calculate and return it - // TODO: If later other purchaseable items (other than products) are handled through this class, this needs expansion - return (this.getAmount() * this.getProduct().getPrice()); - } - - @Override - public int compareTo (final AddableBasketItem item) { - // Trace message - this.getLogger().trace(MessageFormat.format("item={0} - CALLED!", item)); //NOI18N - - // item should not be null - if (null == item) { - throw new NullPointerException("item is null"); //NOI18N - } - - // Debug message - this.getLogger().debug(MessageFormat.format("this.itemId={0},item.itemId={1}", this.getItemId(), item.getItemId())); //NOI18N - - // Is the id the same? - if (Objects.equals(this.getItemId(), item.getItemId())) { - // Same id, means same item - return 0; - } else if (this.getItemId() > item.getItemId()) { - // This id is larger than compared to - return -1; - } - - // The other id is larger - return 1; - } - - @Override - public final Long getAmount () { - return this.amount; - } - - @Override - public final void setAmount (final Long amount) { - this.amount = amount; - } - - @Override - public final Long getId () { - return this.id; - } - - @Override - public final void setId (final Long id) { - this.id = id; - } - - @Override - public final Long getItemId () { - return this.itemId; - } - - @Override - public final void setItemId( final Long itemId) { - this.itemId = itemId; - } - - @Override - public final String getItemType () { - return this.itemType; - } - - @Override - public final void setItemType (final String itemType) { - this.itemType = itemType; - } -} diff --git a/src/org/mxchange/jshop/model/item/basket/BasketItem.java b/src/org/mxchange/jshop/model/item/basket/BasketItem.java deleted file mode 100644 index 633a3ef..0000000 --- a/src/org/mxchange/jshop/model/item/basket/BasketItem.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.jshop.model.item.basket; - -import java.text.MessageFormat; -import org.mxchange.jshop.model.item.AddableBasketItem; -import org.mxchange.jshop.model.item.BaseItem; -import org.mxchange.jshop.model.product.Product; - -/** - * A general basket item - * - * @author Roland Haeder - */ -public class BasketItem extends BaseItem implements AddableBasketItem { - /** - * Default constructor - */ - public BasketItem () { - } - - /** - * Constructor for an item from given Product instance - * - * @param product Product instance - */ - public BasketItem (final Product product) { - // Call default constructor - this(); - - // Trace message - this.getLogger().debug(MessageFormat.format("product={0} - CALLED!", product)); //NOI18N - - // product must not be null - if (null == product) { - // Abort here - throw new NullPointerException("product is null"); //NOI18N - } - - // Copy all neccessary values - this.setItemId(product.getItemId()); - this.setItemType("Product"); //NOI18N - } -} diff --git a/src/org/mxchange/jshop/model/product/BaseProduct.java b/src/org/mxchange/jshop/model/product/BaseProduct.java deleted file mode 100644 index bb2cb40..0000000 --- a/src/org/mxchange/jshop/model/product/BaseProduct.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.mxchange.jshop.model.product; - -import java.text.MessageFormat; -import java.util.Objects; -import org.mxchange.jshop.BaseShopCore; - -/** - * - * @author Roland Haeder - */ -public class BaseProduct extends BaseShopCore implements Product { - /** - * Availability of product - */ - private Boolean available; - - /** - * Product category - */ - private Long categoryId; - - /** - * Id number of product item - */ - private Long itemId; - - /** - * Price of product - */ - private Float price; - - /** - * Title of product - */ - private String title; - - @Override - public int compareTo (final Product product) { - // Trace message - this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product)); //NOI18N - - // category should not be null - if (null == product) { - throw new NullPointerException("product is null"); //NOI18N - } - - // Debug message - this.getLogger().debug(MessageFormat.format("this.id={0},product.id={1}", this.getItemId(), product.getItemId())); //NOI18N - - // Is the id the same? - if (Objects.equals(this.getItemId(), product.getItemId())) { - // Same id, means same category - return 0; - } else if (this.getItemId() > product.getItemId()) { - // This id is larger than compared to - return 1; - } - - // The other id is larger - return -1; - } - - @Override - public final Boolean getAvailable () { - return this.available; - } - - @Override - public final void setAvailable (final Boolean available) { - this.available = available; - } - - @Override - public final Long getCategoryId () { - return this.categoryId; - } - - @Override - public final void setCategoryId (final Long categoryId) { - this.categoryId = categoryId; - } - - @Override - public final Long getItemId () { - return this.itemId; - } - - @Override - public final void setItemId (final Long itemId) { - this.itemId = itemId; - } - - @Override - public final Float getPrice () { - return this.price; - } - - @Override - public final void setPrice (final Float price) { - this.price = price; - } - - @Override - public final String getTitle () { - return this.title; - } - - @Override - public final void setTitle (final String title) { - this.title = title; - } -} diff --git a/src/org/mxchange/jshop/model/product/Product.java b/src/org/mxchange/jshop/model/product/Product.java deleted file mode 100644 index 75a0839..0000000 --- a/src/org/mxchange/jshop/model/product/Product.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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.jshop.model.product; - -import org.mxchange.jshop.ShopInterface; - -/** - * An interface for in database storable products - * - * @author Roland Haeder - */ -public interface Product extends ShopInterface, Comparable { - /** - * Getter for id number, suitable for form fields. - * - * @return Id number of product - */ - public Long getItemId (); - - /** - * Id number of product - * @param id the id number to set - */ - public void setItemId (final Long id); - - /** - * Getter for title. - * - * @return Title of product - */ - 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 id - * - * @return Product category id - */ - public Long getCategoryId (); - - /** - * Setter for product category - * - * @param categoryId Product category - */ - public void setCategoryId (final Long categoryId); - - /** - * 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 product Product to compare to - * @return Comparison value - */ - @Override - public int compareTo (final Product product); -} diff --git a/src/org/mxchange/jshop/model/product/generic/GenericProduct.java b/src/org/mxchange/jshop/model/product/generic/GenericProduct.java deleted file mode 100644 index cad00b8..0000000 --- a/src/org/mxchange/jshop/model/product/generic/GenericProduct.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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.jshop.model.product.generic; - -import java.text.MessageFormat; -import org.mxchange.jshop.model.product.BaseProduct; -import org.mxchange.jshop.model.product.Product; - -/** - * Generic product class - * - * @author Roland Haeder - */ -public class GenericProduct extends BaseProduct implements Product { - /** - * Default constructor - */ - public GenericProduct () { - } - - /** - * Constructor will all required data - * - * @param id Id number of product - * @param title Name of product - * @param price Price - * @param categoryId Category id - * @param available Availability (selectable by customer) - */ - public GenericProduct (final Long id, final String title, final Float price, final Long categoryId, final Boolean available) { - // Trace message - this.getLogger().trace(MessageFormat.format("id={0},title={1},price={2},categoryId={3},available={4} - CALLED!", id, title, price, categoryId, available)); //NOI18N - - // Set all here - this.setItemId(id); - this.setTitle(title); - this.setPrice(price); - this.setCategoryId(categoryId); - this.setAvailable(available); - } -} diff --git a/src/org/mxchange/jshopcore/BaseShopCore.java b/src/org/mxchange/jshopcore/BaseShopCore.java new file mode 100644 index 0000000..fe407a6 --- /dev/null +++ b/src/org/mxchange/jshopcore/BaseShopCore.java @@ -0,0 +1,48 @@ +/* + * 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.jshopcore; + +import org.mxchange.jcore.BaseFrameworkSystem; +import org.mxchange.jshopcore.model.product.Product; + +/** + * A general shop class + * + * @author Roland Haeder + */ +public class BaseShopCore extends BaseFrameworkSystem implements ShopInterface { + /** + * Item instance + */ + private Product product; + + /** + * @return the product + */ + @Override + public Product getProduct () { + return this.product; + } + + /** + * @param product the product to set + */ + @Override + public void setProduct (final Product product) { + this.product = product; + } +} diff --git a/src/org/mxchange/jshopcore/ShopInterface.java b/src/org/mxchange/jshopcore/ShopInterface.java new file mode 100644 index 0000000..d2813e5 --- /dev/null +++ b/src/org/mxchange/jshopcore/ShopInterface.java @@ -0,0 +1,37 @@ +/* + * 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.jshopcore; + +import org.mxchange.jcore.FrameworkInterface; +import org.mxchange.jshopcore.model.product.Product; + +/** + * A general shop interface + * + * @author Roland Haeder + */ +public interface ShopInterface extends FrameworkInterface { + /** + * @return the product + */ + public Product getProduct (); + + /** + * @param product the product to set + */ + public void setProduct (final Product product); +} diff --git a/src/org/mxchange/jshopcore/exceptions/CategoryTitleAlreadyUsedException.java b/src/org/mxchange/jshopcore/exceptions/CategoryTitleAlreadyUsedException.java new file mode 100644 index 0000000..ae81b3c --- /dev/null +++ b/src/org/mxchange/jshopcore/exceptions/CategoryTitleAlreadyUsedException.java @@ -0,0 +1,42 @@ +/* + * 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.jshopcore.exceptions; + +import java.text.MessageFormat; +import org.mxchange.jshopcore.model.category.Category; + +/** + * An exception thrown when the given title is already used + * + * @author Roland Haeder + */ +public class CategoryTitleAlreadyUsedException extends Exception { + /** + * Serial number + */ + private static final long serialVersionUID = 53751434673262L; + + /** + * Constructor with HttpServletRequest instance + * + * @param category Category instance + */ + public CategoryTitleAlreadyUsedException (final Category category) { + // Call super constructor + super(MessageFormat.format("Title {0} is already used.", category.getTitle())); //NOI18N + } +} diff --git a/src/org/mxchange/jshopcore/exceptions/ProductTitleAlreadyUsedException.java b/src/org/mxchange/jshopcore/exceptions/ProductTitleAlreadyUsedException.java new file mode 100644 index 0000000..1206661 --- /dev/null +++ b/src/org/mxchange/jshopcore/exceptions/ProductTitleAlreadyUsedException.java @@ -0,0 +1,42 @@ +/* + * 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.jshopcore.exceptions; + +import java.text.MessageFormat; +import org.mxchange.jshopcore.model.product.Product; + +/** + * An exception thrown when the given title is already used + * + * @author Roland Haeder + */ +public class ProductTitleAlreadyUsedException extends Exception { + /** + * Serial number + */ + private static final long serialVersionUID = 4252734834174L; + + /** + * Constructor with HttpServletRequest instance + * + * @param product Product instance + */ + public ProductTitleAlreadyUsedException (final Product product) { + // Call super constructor + super(MessageFormat.format("Title {0} is already used.", product.getTitle())); //NOI18N + } +} diff --git a/src/org/mxchange/jshopcore/model/basket/BaseBasket.java b/src/org/mxchange/jshopcore/model/basket/BaseBasket.java new file mode 100644 index 0000000..9c2b1ae --- /dev/null +++ b/src/org/mxchange/jshopcore/model/basket/BaseBasket.java @@ -0,0 +1,144 @@ +/* + * 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.jshopcore.model.basket; + +import java.io.IOException; +import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; +import java.sql.SQLException; +import java.text.MessageFormat; +import java.util.Map; +import org.mxchange.jshopcore.BaseShopCore; +import org.mxchange.jshopcore.model.item.AddableBasketItem; + +/** + * A general basket class + * + * @author Roland Haeder + * @param Any instance that implements AddableBasketItem + */ +public class BaseBasket extends BaseShopCore implements Basket, Serializable { + /** + * Serial number + */ + private static final long serialVersionUID = 784396762230845717L; + + /** + * Protected constructor with session instance + * + * @throws java.sql.SQLException If an SQL error occurs + */ + protected BaseBasket () throws SQLException { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + } + + @Override + public void init () throws SQLException { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + + // Is the bundle initialized? + if (!BaseShopCore.isBundledInitialized()) { + // Temporary initialize default bundle + // TODO The enum Gender uses this + this.initBundle(); + } + } + + @Override + @SuppressWarnings ("unchecked") + public void addItem (final T item) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + // Trace call + this.getLogger().trace(MessageFormat.format("item={0} - CALLED!", item)); //NOI18N + + // item must not be null + if (null == item) { + // Then abort here + throw new NullPointerException("item is null"); //NOI18N + } else if (this.isAdded(item)) { + // Already been added + throw new IllegalArgumentException("item has already been added. Did you miss to call isAdded()?"); //NOI18N + } + + // Add item to database + // TODO: ((BasketFrontend) this.getFrontend()).addItem(item, this.getSessionId()); + + // Trace call + this.getLogger().trace("EXIT!"); //NOI18N + } + + @Override + public boolean isEmpty () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + // Deligate call to frontend + // TODO: return ((BasketFrontend) this.getFrontend()).isEmpty(); + throw new UnsupportedOperationException("Not yet implmeneted."); + } + + @Override + @SuppressWarnings("unchecked") + public Map getAll () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N + + // Init map + // TODO: Map map = ((BasketFrontend) this.getFrontend()).getAll(); + Map map = null; + + // Trace message + this.getLogger().trace("map=" + map); //NOI18N + + // Return it + return map; + } + + @Override + public AddableBasketItem getLast () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + // Deligate to frontend + // TODO: return ((BasketFrontend) this.getFrontend()).getLast(); + throw new UnsupportedOperationException("Not yet implmeneted."); + } + + @Override + public int getLastNumRows () { + // Deligate to frontend + // TODO: return this.getFrontend().getLastNumRows(); + throw new UnsupportedOperationException("Not yet implmeneted."); + } + + @Override + public boolean isAdded (final T item) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + // Trace call + this.getLogger().trace(MessageFormat.format("item={0} - CALLED!", item)); //NOI18N + + // item must not be null + if (null == item) { + // Then abort here + throw new NullPointerException("item is null"); //NOI18N + } + + // Call map's method + // TODO: boolean isAdded = ((BasketFrontend) this.getFrontend()).isAdded(item, this.getSessionId()); + boolean isAdded = true; + + // Trace message + this.getLogger().trace(MessageFormat.format("isAdded={0} - EXIT!", isAdded)); //NOI18N + + // Return it + return isAdded; + } +} diff --git a/src/org/mxchange/jshopcore/model/basket/Basket.java b/src/org/mxchange/jshopcore/model/basket/Basket.java new file mode 100644 index 0000000..97423d7 --- /dev/null +++ b/src/org/mxchange/jshopcore/model/basket/Basket.java @@ -0,0 +1,110 @@ +/* + * 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.jshopcore.model.basket; + +import java.io.IOException; +import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; +import java.sql.SQLException; +import java.util.Map; +import org.mxchange.jshopcore.ShopInterface; +import org.mxchange.jshopcore.model.item.AddableBasketItem; + +/** + * An interface for baskets + * + * @author Roland Haeder + * @param Any addable basket items + */ +public interface Basket extends Serializable, ShopInterface { + + /** + * Adds given item instance to this basket + * @param item Item 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 + * @throws java.lang.IllegalAccessException If the invoked method is not public + * @throws java.lang.reflect.InvocationTargetException If anything else happened? + */ + public void addItem (final T item) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; + + /** + * Checks whether the given item as already been added. If the product's + * item id number was found in basket, the corresponding item instance will be set + * + * @param item Item instance to check + * @return Whether the given item has been found + * @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 + * @throws java.lang.IllegalAccessException If the invoked method is not public + * @throws java.lang.reflect.InvocationTargetException If anything else happened? + */ + public boolean isAdded (final T item) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; + + /** + * Checks if the basket is empty + * + * @return Whether the basket is empty + * @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 + * @throws java.lang.IllegalAccessException If the invoked method is not public + * @throws java.lang.reflect.InvocationTargetException If anything else happened? + */ + public boolean isEmpty () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; + + /** + * Initializes this instance with given ServletContext + * + * @throws java.sql.SQLException If an SQL error occurs + * @throws java.io.IOException If an IO error occurs + */ + public void init () throws SQLException, IOException; + + /** + * Some "getter" for all entries in this basket + * + * @return Map on all basket items + * @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 + * @throws java.lang.IllegalAccessException If the invoked method is not public + * @throws java.lang.reflect.InvocationTargetException If anything else happened? + */ + public Map getAll () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; + + /** + * Getter for last entry + * + * @return Last added item in basket + * @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 + * @throws java.lang.IllegalAccessException If the invoked method is not public + * @throws java.lang.reflect.InvocationTargetException If anything else happened? + */ + public AddableBasketItem getLast () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException; + + /** + * Getter for last num rows + * + * @return Last num rows + */ + public int getLastNumRows (); +} diff --git a/src/org/mxchange/jshopcore/model/basket/item/ItemBasket.java b/src/org/mxchange/jshopcore/model/basket/item/ItemBasket.java new file mode 100644 index 0000000..b7dda1f --- /dev/null +++ b/src/org/mxchange/jshopcore/model/basket/item/ItemBasket.java @@ -0,0 +1,43 @@ +/* + * 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.jshopcore.model.basket.item; + +import java.sql.SQLException; +import org.mxchange.jshopcore.model.basket.BaseBasket; +import org.mxchange.jshopcore.model.basket.Basket; +import org.mxchange.jshopcore.model.item.AddableBasketItem; + +/** + * A basket for orderable items + * + * @author Roland Haeder + */ +public class ItemBasket extends BaseBasket implements Basket { + /** + * Serial number + */ + private static final long serialVersionUID = 4384123923163957L; + + /** + * Default constructor to be able to throw exceptions from super constructor + * @throws java.sql.SQLException If an SQL error occurs + */ + public ItemBasket () throws SQLException { + // Call super constructor + super(); + } +} diff --git a/src/org/mxchange/jshopcore/model/category/BaseCategory.java b/src/org/mxchange/jshopcore/model/category/BaseCategory.java new file mode 100644 index 0000000..493da9b --- /dev/null +++ b/src/org/mxchange/jshopcore/model/category/BaseCategory.java @@ -0,0 +1,171 @@ +/* + * 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.jshopcore.model.category; + +import java.io.UnsupportedEncodingException; +import java.text.MessageFormat; +import java.util.Objects; +import org.mxchange.jshopcore.BaseShopCore; + +/** + * A general product category class + * + * @author Roland Haeder + */ +public class BaseCategory extends BaseShopCore implements Category { + + /** + * Id number of category + */ + private Long categoryId; + + /** + * Parent category categoryId + */ + private Long parentId; + + /** + * Title of category + */ + private String title; + + /** + * Constructor which accepts all database fields + * + * @param categoryId Id number of database record + * @param title Category title + * @param parentId Parent categoryId + */ + protected BaseCategory (final Long categoryId, final String title, final Long parentId) { + // Set all here + this.setCategoryId(categoryId); + this.setTitle(title); + this.setParentId(parentId); + } + + /** + * Default constructor + */ + protected BaseCategory () { + } + + /** + * Compares two categories with each other + * + * @param category Category comparator + * @return Comparison value + */ + @Override + public int compareTo (final Category category) { + // Trace message + this.getLogger().trace(MessageFormat.format("category={0} - CALLED!", category)); //NOI18N + + // category should not be null + if (null == category) { + throw new NullPointerException("category is null"); //NOI18N + } + + // Debug message + this.getLogger().debug(MessageFormat.format("this.id={0},category.id={1}", this.getCategoryId(), category.getCategoryId())); //NOI18N + + // Is the categoryId the same? + if (Objects.equals(this.getCategoryId(), category.getCategoryId())) { + // Same categoryId, means same category + return 0; + } else if (this.getCategoryId() > category.getCategoryId()) { + // This categoryId is larger than compared to + return -1; + } + + // The other categoryId is larger + return 1; + } + + /** + * Decodes the UTF8-encoded title + * + * @return Decoded title + */ + @Override + public final String getDecodedTitle () throws UnsupportedEncodingException { + // Get title + byte[] t = this.getTitle().getBytes(); + + // Decode it + return new String(t, "UTF-8"); //NOI18N + } + + /** + * Id number of category + * + * @return the categoryId + */ + @Override + public final Long getCategoryId () { + return this.categoryId; + } + + /** + * Id number of category + * + * @param categoryId the categoryId to set + */ + @Override + public final void setCategoryId (final Long categoryId) { + this.categoryId = categoryId; + } + + /** + * Parent category categoryId + * + * @return the parentId + */ + @Override + public final Long getParentId () { + return this.parentId; + } + + /** + * Parent category categoryId + * + * @param parentId the parentId to set + */ + @Override + public final void setParentId (final Long parentId) { + this.parentId = parentId; + } + + /** + * Title of category + * + * @return the title + */ + @Override + public final String getTitle () { + return this.title; + } + + /** + * Title of category + * + * @param title the title to set + */ + @Override + public final void setTitle (final String title) { + this.title = title; + } +} diff --git a/src/org/mxchange/jshopcore/model/category/Category.java b/src/org/mxchange/jshopcore/model/category/Category.java new file mode 100644 index 0000000..a32f8bd --- /dev/null +++ b/src/org/mxchange/jshopcore/model/category/Category.java @@ -0,0 +1,80 @@ +/* + * 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.jshopcore.model.category; + +import java.io.UnsupportedEncodingException; +import org.mxchange.jshopcore.ShopInterface; + +/** + * An interface for categories + * + * @author Roland Haeder + */ +public interface Category extends ShopInterface, Comparable { + + /** + * Id number of category + * @return the id + */ + public Long getCategoryId (); + + /** + * Id number of category + * @param id the id to set + */ + public void setCategoryId (final Long id); + + /** + * Parent category id + * @return the parent + */ + public Long getParentId (); + + /** + * Parent category id + * @param parent the parent to set + */ + public void setParentId (final Long parent); + + /** + * Title of category + * @return the title + */ + public String getTitle (); + + /** + * Title of category + * @param title the title to set + */ + public void setTitle (final String title); + + /** + * Compare method + * @param category Category to compare to + * @return Comparison value + */ + @Override + public int compareTo (final Category category); + + /** + * Decodes the UTF8-encoded title + * + * @return Decoded title + * @throws java.io.UnsupportedEncodingException If the encoding UTF-8 is not supported + */ + public String getDecodedTitle () throws UnsupportedEncodingException ; +} diff --git a/src/org/mxchange/jshopcore/model/category/product/ProductCategory.java b/src/org/mxchange/jshopcore/model/category/product/ProductCategory.java new file mode 100644 index 0000000..86b531f --- /dev/null +++ b/src/org/mxchange/jshopcore/model/category/product/ProductCategory.java @@ -0,0 +1,42 @@ +/* + * 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.jshopcore.model.category.product; + +import org.mxchange.jshopcore.model.category.BaseCategory; + +/** + * A product category + * @author Roland Haeder + */ +public class ProductCategory extends BaseCategory { + /** + * Constructor which accepts all database fields + * @param id Id number of database record + * @param title Category title + * @param parent Parent id + */ + public ProductCategory (final Long id, final String title, final Long parent) { + // Call parent constructor + super(id, title, parent); + } + + /** + * Default constructor + */ + public ProductCategory () { + } +} diff --git a/src/org/mxchange/jshopcore/model/customer/Customer.java b/src/org/mxchange/jshopcore/model/customer/Customer.java new file mode 100644 index 0000000..4524d65 --- /dev/null +++ b/src/org/mxchange/jshopcore/model/customer/Customer.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.jshopcore.model.customer; + +import org.mxchange.jcore.model.contact.Contact; + +/** + * A customer interface + * + * @author Roland Haeder + */ +public interface Customer extends Contact { +} diff --git a/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java b/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java new file mode 100644 index 0000000..d0c3e57 --- /dev/null +++ b/src/org/mxchange/jshopcore/model/customer/ShopCustomer.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.jshopcore.model.customer; + +import org.mxchange.jcore.model.contact.BaseContact; + +/** + * A shop customer class. + * + * @author Roland Haeder + */ +public class ShopCustomer extends BaseContact implements Customer { +} diff --git a/src/org/mxchange/jshopcore/model/item/AddableBasketItem.java b/src/org/mxchange/jshopcore/model/item/AddableBasketItem.java new file mode 100644 index 0000000..8ca2c40 --- /dev/null +++ b/src/org/mxchange/jshopcore/model/item/AddableBasketItem.java @@ -0,0 +1,86 @@ +/* + * 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.jshopcore.model.item; + +import org.mxchange.jshopcore.ShopInterface; + +/** + * An interface for addable basket items + * + * @author Roland Haeder + */ +public interface AddableBasketItem extends ShopInterface, Comparable { + + /** + * Item amount + * @return the amount + */ + public Long getAmount (); + + /** + * Item amount + * @param amount the amount to set + */ + public void setAmount (final Long amount); + + /** + * Entry id (from database backend) + * @return the id + */ + public Long getId (); + + /** + * Entry id (from database backend) + * @param id the id to set + */ + public void setId (final Long id); + + /** + * @return the id + */ + public Long getItemId (); + + /** + * @param id the id to set + */ + public void setItemId (final Long id); + + /** + * @return the type + */ + public String getItemType (); + + /** + * @param type the type to set + */ + public void setItemType (final String type); + + /** + * Calculates total price by multipying amount and single price + * + * @return Total price of this item + */ + public Float calculateTotalPrice (); + + /** + * Compare method + * @param item Item to compare to + * @return Comparison value + */ + @Override + public int compareTo (final AddableBasketItem item); +} diff --git a/src/org/mxchange/jshopcore/model/item/BaseItem.java b/src/org/mxchange/jshopcore/model/item/BaseItem.java new file mode 100644 index 0000000..25c758d --- /dev/null +++ b/src/org/mxchange/jshopcore/model/item/BaseItem.java @@ -0,0 +1,128 @@ +/* + * 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.jshopcore.model.item; + +import java.text.MessageFormat; +import java.util.Objects; +import org.mxchange.jshopcore.BaseShopCore; + +/** + * An item (addedable to a basket) could respresent a product or a discount + * coupon. This depends on the type of the item. + * + * @author Roland Haeder + */ +public class BaseItem extends BaseShopCore implements AddableBasketItem { + /** + * Entry id (from database backend) + */ + private Long id; + + /** + * Item amount + */ + private Long amount; + + /** + * Item id number + */ + private Long itemId; + + /** + * Item type + */ + private String itemType; + + @Override + public Float calculateTotalPrice () { + // product should be set + if (this.getProduct() == null) { + // Abort here + throw new NullPointerException("product is null"); //NOI18N + } + + // Calculate and return it + // TODO: If later other purchaseable items (other than products) are handled through this class, this needs expansion + return (this.getAmount() * this.getProduct().getPrice()); + } + + @Override + public int compareTo (final AddableBasketItem item) { + // Trace message + this.getLogger().trace(MessageFormat.format("item={0} - CALLED!", item)); //NOI18N + + // item should not be null + if (null == item) { + throw new NullPointerException("item is null"); //NOI18N + } + + // Debug message + this.getLogger().debug(MessageFormat.format("this.itemId={0},item.itemId={1}", this.getItemId(), item.getItemId())); //NOI18N + + // Is the id the same? + if (Objects.equals(this.getItemId(), item.getItemId())) { + // Same id, means same item + return 0; + } else if (this.getItemId() > item.getItemId()) { + // This id is larger than compared to + return -1; + } + + // The other id is larger + return 1; + } + + @Override + public final Long getAmount () { + return this.amount; + } + + @Override + public final void setAmount (final Long amount) { + this.amount = amount; + } + + @Override + public final Long getId () { + return this.id; + } + + @Override + public final void setId (final Long id) { + this.id = id; + } + + @Override + public final Long getItemId () { + return this.itemId; + } + + @Override + public final void setItemId( final Long itemId) { + this.itemId = itemId; + } + + @Override + public final String getItemType () { + return this.itemType; + } + + @Override + public final void setItemType (final String itemType) { + this.itemType = itemType; + } +} diff --git a/src/org/mxchange/jshopcore/model/item/basket/BasketItem.java b/src/org/mxchange/jshopcore/model/item/basket/BasketItem.java new file mode 100644 index 0000000..2807023 --- /dev/null +++ b/src/org/mxchange/jshopcore/model/item/basket/BasketItem.java @@ -0,0 +1,58 @@ +/* + * 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.jshopcore.model.item.basket; + +import java.text.MessageFormat; +import org.mxchange.jshopcore.model.item.AddableBasketItem; +import org.mxchange.jshopcore.model.item.BaseItem; +import org.mxchange.jshopcore.model.product.Product; + +/** + * A general basket item + * + * @author Roland Haeder + */ +public class BasketItem extends BaseItem implements AddableBasketItem { + /** + * Default constructor + */ + public BasketItem () { + } + + /** + * Constructor for an item from given Product instance + * + * @param product Product instance + */ + public BasketItem (final Product product) { + // Call default constructor + this(); + + // Trace message + this.getLogger().debug(MessageFormat.format("product={0} - CALLED!", product)); //NOI18N + + // product must not be null + if (null == product) { + // Abort here + throw new NullPointerException("product is null"); //NOI18N + } + + // Copy all neccessary values + this.setItemId(product.getItemId()); + this.setItemType("Product"); //NOI18N + } +} diff --git a/src/org/mxchange/jshopcore/model/product/BaseProduct.java b/src/org/mxchange/jshopcore/model/product/BaseProduct.java new file mode 100644 index 0000000..5faa9bf --- /dev/null +++ b/src/org/mxchange/jshopcore/model/product/BaseProduct.java @@ -0,0 +1,117 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.mxchange.jshopcore.model.product; + +import java.text.MessageFormat; +import java.util.Objects; +import org.mxchange.jshopcore.BaseShopCore; + +/** + * + * @author Roland Haeder + */ +public class BaseProduct extends BaseShopCore implements Product { + /** + * Availability of product + */ + private Boolean available; + + /** + * Product category + */ + private Long categoryId; + + /** + * Id number of product item + */ + private Long itemId; + + /** + * Price of product + */ + private Float price; + + /** + * Title of product + */ + private String title; + + @Override + public int compareTo (final Product product) { + // Trace message + this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product)); //NOI18N + + // category should not be null + if (null == product) { + throw new NullPointerException("product is null"); //NOI18N + } + + // Debug message + this.getLogger().debug(MessageFormat.format("this.id={0},product.id={1}", this.getItemId(), product.getItemId())); //NOI18N + + // Is the id the same? + if (Objects.equals(this.getItemId(), product.getItemId())) { + // Same id, means same category + return 0; + } else if (this.getItemId() > product.getItemId()) { + // This id is larger than compared to + return 1; + } + + // The other id is larger + return -1; + } + + @Override + public final Boolean getAvailable () { + return this.available; + } + + @Override + public final void setAvailable (final Boolean available) { + this.available = available; + } + + @Override + public final Long getCategoryId () { + return this.categoryId; + } + + @Override + public final void setCategoryId (final Long categoryId) { + this.categoryId = categoryId; + } + + @Override + public final Long getItemId () { + return this.itemId; + } + + @Override + public final void setItemId (final Long itemId) { + this.itemId = itemId; + } + + @Override + public final Float getPrice () { + return this.price; + } + + @Override + public final void setPrice (final Float price) { + this.price = price; + } + + @Override + public final String getTitle () { + return this.title; + } + + @Override + public final void setTitle (final String title) { + this.title = title; + } +} diff --git a/src/org/mxchange/jshopcore/model/product/Product.java b/src/org/mxchange/jshopcore/model/product/Product.java new file mode 100644 index 0000000..d0e46fb --- /dev/null +++ b/src/org/mxchange/jshopcore/model/product/Product.java @@ -0,0 +1,101 @@ +/* + * 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.jshopcore.model.product; + +import org.mxchange.jshopcore.ShopInterface; + +/** + * An interface for in database storable products + * + * @author Roland Haeder + */ +public interface Product extends ShopInterface, Comparable { + /** + * Getter for id number, suitable for form fields. + * + * @return Id number of product + */ + public Long getItemId (); + + /** + * Id number of product + * @param id the id number to set + */ + public void setItemId (final Long id); + + /** + * Getter for title. + * + * @return Title of product + */ + 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 id + * + * @return Product category id + */ + public Long getCategoryId (); + + /** + * Setter for product category + * + * @param categoryId Product category + */ + public void setCategoryId (final Long categoryId); + + /** + * 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 product Product to compare to + * @return Comparison value + */ + @Override + public int compareTo (final Product product); +} diff --git a/src/org/mxchange/jshopcore/model/product/generic/GenericProduct.java b/src/org/mxchange/jshopcore/model/product/generic/GenericProduct.java new file mode 100644 index 0000000..7fe9de6 --- /dev/null +++ b/src/org/mxchange/jshopcore/model/product/generic/GenericProduct.java @@ -0,0 +1,55 @@ +/* + * 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.jshopcore.model.product.generic; + +import java.text.MessageFormat; +import org.mxchange.jshopcore.model.product.BaseProduct; +import org.mxchange.jshopcore.model.product.Product; + +/** + * Generic product class + * + * @author Roland Haeder + */ +public class GenericProduct extends BaseProduct implements Product { + /** + * Default constructor + */ + public GenericProduct () { + } + + /** + * Constructor will all required data + * + * @param id Id number of product + * @param title Name of product + * @param price Price + * @param categoryId Category id + * @param available Availability (selectable by customer) + */ + public GenericProduct (final Long id, final String title, final Float price, final Long categoryId, final Boolean available) { + // Trace message + this.getLogger().trace(MessageFormat.format("id={0},title={1},price={2},categoryId={3},available={4} - CALLED!", id, title, price, categoryId, available)); //NOI18N + + // Set all here + this.setItemId(id); + this.setTitle(title); + this.setPrice(price); + this.setCategoryId(categoryId); + this.setAvailable(available); + } +}