import java.util.Deque;
import java.util.Iterator;
import org.mxchange.jshop.category.Category;
-import org.mxchange.jshop.database.frontend.category.CategoryDatabaseFrontend;
-import org.mxchange.jshop.database.frontend.category.CategoryFrontend;
-import org.mxchange.jshop.database.frontend.product.ProductDatabaseFrontend;
-import org.mxchange.jshop.database.frontend.product.ProductFrontend;
import org.mxchange.jshop.exceptions.CategoryTitleAlreadyUsedException;
import org.mxchange.jshop.exceptions.ProductTitleAlreadyUsedException;
import org.mxchange.jshop.item.AddableBasketItem;
* @author Roland Haeder
*/
public class PizzaServiceApplication extends BasePizzaServiceSystem implements PizzaApplication {
- /**
- * Database frontend for products
- */
- private ProductFrontend productFrontend;
-
- /**
- * Database frontend for categories
- */
- private CategoryFrontend categoryFrontend;
-
/**
* Default constructor
*/
this.getLogger().trace("CALLED!"); //NOI18N
// Is the bundle initialized?
- if (!this.isBundledInitialized()) {
+ if (!isBundledInitialized()) {
// Temporary initialize default bundle
// TODO The enum Gender uses this
this.initBundle();
}
- // Init database frontends
- this.initDatabaseFrontends();
-
// Trace message
this.getLogger().trace("EXIT!"); //NOI18N
}
@Override
@SuppressWarnings ("unchecked")
public Iterator<Product> getAvailableProductsIterator () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- // categoryFrontend must be set
- if (null == this.productFrontend) {
- // Abort here
- throw new NullPointerException("productFrontend is null"); //NOI18N
- }
+ // Trace message
+ this.getLogger().trace("CALLED!"); //NOI18N
// Ask frontend for a list of products
return (Iterator<Product>) this.productFrontend.getAvailableProductsIterator();
// Trace message
this.getLogger().trace("CALLED!"); //NOI18N
- // categoryFrontend must be set
- if (null == this.productFrontend) {
- // Abort here
- throw new NullPointerException("productFrontend is null"); //NOI18N
- }
-
// Ask frontend for a list of products
return (Iterator<Product>) this.productFrontend.getAllProductsIterator();
}
// Trace message
this.getLogger().trace("CALLED!"); //NOI18N
- // categoryFrontend must be set
- if (null == this.categoryFrontend) {
- // Abort here
- throw new NullPointerException("categoryFrontend is null"); //NOI18N
- }
-
// Ask frontend for a list of categories
return (Iterator<Category>) this.categoryFrontend.getAllCategoriesIterator();
}
- /**
- * Initializes database frontends.
- */
- private void initDatabaseFrontends () throws SQLException {
- // Trace message
- this.getLogger().trace("CALLED!"); //NOI18N
-
- // Product frontend
- this.productFrontend = new ProductDatabaseFrontend();
-
- // Category frontend
- this.categoryFrontend = new CategoryDatabaseFrontend();
-
- // Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
- }
-
/**
* Checks whether given category title is already used
*
* @return Whether it has been found
*/
private boolean isCategoryTitleUsed(final Category category) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
- // categoryFrontend must be set
- if (null == this.categoryFrontend) {
- // Abort here
- throw new NullPointerException("categoryFrontend is null"); //NOI18N
- }
+ // Trace message
+ this.getLogger().trace("CALLED!"); //NOI18N
// Delegate to frontend
return this.categoryFrontend.isCategoryTitleUsed(category.getTitle());
* @return Whether the product title has already been used
*/
private boolean isProductTitleUsed (final String title) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
- // categoryFrontend must be set
- if (null == this.productFrontend) {
- // Abort here
- throw new NullPointerException("productFrontend is null"); //NOI18N
- }
+ // Trace message
+ this.getLogger().trace("CALLED!"); //NOI18N
// Delegate to frontend
return this.productFrontend.isProductTitleUsed(title);
// Check all fields
if (null == title) {
// "title" not set
- throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", CategoryFrontend.COLUMN_TITLE)); //NOI18N
+ throw new IllegalArgumentException("category title is not set."); //NOI18N
} else if (title.isEmpty()) {
// Is left empty
- throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", CategoryFrontend.COLUMN_TITLE)); //NOI18N
+ throw new IllegalArgumentException("category title is empty."); //NOI18N
} else if ((parentId == null) || (parentId == 0)) {
// "parent" is not set
- throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", parentId));
+ throw new IllegalArgumentException(MessageFormat.format("category id is not valid: {0}", parentId));
}
// Try to check if title is used already
}
// Get title, price and category id
- String title = product.getTitle();
- Float price = product.getPrice();
- Long categoryId = product.getCategoryId();
+ String title = product.getTitle();
+ Float price = product.getPrice();
+ Long categoryId = product.getCategoryId();
Boolean available = product.getAvailable();
// Debug message
// Check all fields
if (null == title) {
// "title" not set
- throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", ProductFrontend.COLUMN_TITLE)); //NOI18N
+ throw new IllegalArgumentException("product title is not set."); //NOI18N
} else if (title.isEmpty()) {
// Is left empty
- throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", ProductFrontend.COLUMN_TITLE)); //NOI18N
+ throw new IllegalArgumentException("product title is empty."); //NOI18N
} else if (null == price) {
// "price" not set
- throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", ProductFrontend.COLUMN_PRICE)); //NOI18N
+ throw new IllegalArgumentException("product price is not set."); //NOI18N
} else if (null == categoryId) {
- // "title" not set
- throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", ProductFrontend.COLUMN_CATEGORY)); //NOI18N
+ // "categoryId" not set
+ throw new IllegalArgumentException("product category id is not set."); //NOI18N
} else if (null == available) {
- // "title" not set
- throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", ProductFrontend.COLUMN_AVAILABLE)); //NOI18N
+ // "available" not set
+ throw new IllegalArgumentException("product availability is not set."); //NOI18N
}
// Try to check if title is used already
if (null == title) {
// title is not set
- throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", ProductFrontend.COLUMN_TITLE)); //NOI18N
+ throw new IllegalArgumentException("product title is not set."); //NOI18N
} else if (title.isEmpty()) {
// Is left empty
- throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", ProductFrontend.COLUMN_TITLE)); //NOI18N
+ throw new IllegalArgumentException("product title is empty."); //NOI18N
}
// Default is not used
if (null == item) {
// Abort here
throw new NullPointerException("item is null"); //NOI18N
- } else if (null == this.productFrontend) {
- // Abort here
- throw new NullPointerException("productFrontend is null"); //NOI18N
}
// Init product instance