import java.sql.SQLException;
import java.util.Deque;
import java.util.Iterator;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
import org.mxchange.jcore.application.Application;
import org.mxchange.jcore.exceptions.BadTokenException;
import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
/**
* Initializes this instance with given ServletContext
*
- * @param context Servlet context
* @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the backend is unsupported
* @throws java.sql.SQLException If an SQL error occurs
* @throws java.io.IOException If an IO error occurs
* @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
*/
- public void init (final ServletContext context) throws UnsupportedDatabaseBackendException, SQLException, IOException, BadTokenException;
+ public void init () throws UnsupportedDatabaseBackendException, SQLException, IOException, BadTokenException;
/**
* Some "getter" for a an array of only available products
/**
* Adds given category data from request to database
*
- * @param request Request instance
+ * @param category Category to be added
* @throws org.mxchange.jshop.exceptions.CategoryTitleAlreadyUsedException The category's title is already used
* @throws java.io.IOException If an IO error occurs
* @throws java.sql.SQLException If an SQL error occurs
* @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
* @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged
*/
- public void doAdminAddCategory (final ServletRequest request) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException;
+ public void doAdminAddCategory (final Category category) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException;
/**
* Adds given product data from request to database
*
- * @param request Request instance
+ * @param product Product 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 org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged
* @throws org.mxchange.jshop.exceptions.ProductTitleAlreadyUsedException If the product's title is already used
*/
- public void doAdminAddProduct (final ServletRequest request) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, ProductTitleAlreadyUsedException;
+ public void doAdminAddProduct (final Product product) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, ProductTitleAlreadyUsedException;
/**
* Handles admin product form requests
*
- * @param request Request instance
- * @param response Response instance
* @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 org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
* @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged
* @throws org.mxchange.jshop.exceptions.ProductTitleAlreadyUsedException If the product's title is already used
+ * @deprecated Old lost code
*/
- public void doAdminHandleProductForms (final ServletRequest request, final ServletResponse response) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, ProductTitleAlreadyUsedException;
+ @Deprecated
+ public void doAdminHandleProductForms () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, ProductTitleAlreadyUsedException;
/**
* Handles admin category form requests
*
- * @param request Request instance
- * @param response Response instance
* @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 org.mxchange.jcore.exceptions.BadTokenException If a bad token was found
* @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged
* @throws org.mxchange.jshop.exceptions.CategoryTitleAlreadyUsedException The category's title is already used
+ * @deprecated Old lost code
*/
- public void doAdminHandleCategoryForms (final ServletRequest request, final ServletResponse response) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException;
+ @Deprecated
+ public void doAdminHandleCategoryForms () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException;
/**
* Some "getter" for a Product instance from given item
import java.text.MessageFormat;
import java.util.Deque;
import java.util.Iterator;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
import org.mxchange.jcore.exceptions.BadTokenException;
import org.mxchange.jcore.exceptions.CorruptedDatabaseFileException;
import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
}
@Override
- public void init (final ServletContext context) throws UnsupportedDatabaseBackendException, SQLException {
+ public void init () throws UnsupportedDatabaseBackendException, SQLException {
// Trace message
- this.getLogger().trace(MessageFormat.format("context={0} - CALLED!", context)); //NOI18N
-
- // context should not be null
- if (null == context) {
- // Abort here
- throw new NullPointerException("context is null"); //NOI18N
- }
+ this.getLogger().trace("CALLED!"); //NOI18N
// Is the bundle initialized?
if (!this.isBundledInitialized()) {
this.initBundle();
}
- // Initialize properties from context
- this.initProperties(context);
-
// Init database frontends
this.initDatabaseFrontends();
/**
* Checks whether given category title is already used
*
- * @param title Title of category to check
+ * @param category Category instance
* @return Whether it has been found
*/
- private boolean isCategoryTitleUsed(final String title) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ private boolean isCategoryTitleUsed(final Category category) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// categoryFrontend must be set
if (null == this.categoryFrontend) {
// Abort here
}
// Delegate to frontend
- return this.categoryFrontend.isCategoryTitleUsed(title);
+ return this.categoryFrontend.isCategoryTitleUsed(category.getTitle());
}
/**
}
@Override
- public void doAdminAddCategory (final ServletRequest request) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException {
+ public void doAdminAddCategory (final Category category) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException {
// Trace message
- this.getLogger().trace(MessageFormat.format("request={0} - CALLED!", request)); //NOI18N
+ this.getLogger().trace(MessageFormat.format("category={0} - CALLED!", category)); //NOI18N
// request must not be null
- if (null == request) {
+ if (null == category) {
// Is null
- throw new NullPointerException("request is null"); //NOI18N
+ throw new NullPointerException("category is null"); //NOI18N
}
// Get all fields
- String title = request.getParameter(CategoryFrontend.COLUMN_TITLE);
- String parentId = request.getParameter(CategoryFrontend.COLUMN_PARENT);
+ String title = category.getTitle();
+ Long parentId = category.getParentId();
// Debug message
this.getLogger().debug(MessageFormat.format("title={0},parentId={1}", title, parentId)); //NOI18N
- // Init variables for casting
- Integer id = 0;
-
// Check all fields
if (null == title) {
// "title" not set
} else if (title.isEmpty()) {
// Is left empty
throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", CategoryFrontend.COLUMN_TITLE)); //NOI18N
- } else if ((parentId != null) && (!parentId.isEmpty())) {
- // "parent" is set, so check it
- try {
- id = Integer.parseInt(parentId);
- } catch (final NumberFormatException e) {
- // Not valid number
- throw new IllegalArgumentException(e);
- }
+ } else if ((parentId == null) || (parentId == 0)) {
+ // "parent" is not set
+ throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", parentId));
}
// Try to check if title is used already
- if (this.isCategoryTitleUsed(title)) {
+ if (this.isCategoryTitleUsed(category)) {
// Title already used
- throw new CategoryTitleAlreadyUsedException(request);
+ throw new CategoryTitleAlreadyUsedException(category);
}
// The category is not found, so add it to database
- this.categoryFrontend.addCategory(title, id);
+ this.categoryFrontend.addCategory(title, parentId);
// Trace message
this.getLogger().trace("EXIT!"); //NOI18N
}
@Override
- public void doAdminAddProduct (final ServletRequest request) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, ProductTitleAlreadyUsedException {
+ public void doAdminAddProduct (final Product product) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, ProductTitleAlreadyUsedException {
// Trace message
- this.getLogger().trace(MessageFormat.format("request={0} - CALLED!", request)); //NOI18N
+ this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product)); //NOI18N
- // request must not be null
- if (null == request) {
+ // product must not be null
+ if (null == product) {
// Is null
- throw new NullPointerException("request is null"); //NOI18N
+ throw new NullPointerException("product is null"); //NOI18N
}
// Get title, price and category id
- String title = request.getParameter(ProductFrontend.COLUMN_TITLE);
- String price = request.getParameter(ProductFrontend.COLUMN_PRICE);
- String categoryId = request.getParameter(ProductFrontend.COLUMN_CATEGORY);
- String available = request.getParameter(ProductFrontend.COLUMN_AVAILABLE);
+ String title = product.getTitle();
+ Float price = product.getPrice();
+ Long categoryId = product.getCategoryId();
+ Boolean available = product.getAvailable();
// Debug message
this.getLogger().debug(MessageFormat.format("title={0},price={1},categoryId={2},available={3}", title, price, categoryId, available)); //NOI18N
- // Variables for converting
- Long id = null;
- Float p = null;
-
// Check all fields
if (null == title) {
// "title" not set
} else if (null == price) {
// "price" not set
throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", ProductFrontend.COLUMN_PRICE)); //NOI18N
- } else if (price.isEmpty()) {
- // Is left empty
- throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", ProductFrontend.COLUMN_PRICE)); //NOI18N
} else if (null == categoryId) {
// "title" not set
throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", ProductFrontend.COLUMN_CATEGORY)); //NOI18N
- } else if (categoryId.isEmpty()) {
- // Is left empty
- throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", ProductFrontend.COLUMN_CATEGORY)); //NOI18N
} else if (null == available) {
// "title" not set
throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", ProductFrontend.COLUMN_AVAILABLE)); //NOI18N
- } else if (available.isEmpty()) {
- // Is left empty
- throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", ProductFrontend.COLUMN_AVAILABLE)); //NOI18N
- } else if ((!"true".equals(available)) && (!"false".equals(available))) { //NOI18N
- // Invalid value
- throw new IllegalArgumentException(MessageFormat.format("{0} is invalid: {1}", ProductFrontend.COLUMN_AVAILABLE, available)); //NOI18N
- }
-
- // Parse numbers
- try {
- id = Long.parseLong(categoryId);
- p = Float.parseFloat(price);
- } catch (final NumberFormatException e) {
- // Not valid number
- throw new IllegalArgumentException(e);
}
- // Parse boolean
- Boolean a = Boolean.parseBoolean(available);
-
// Try to check if title is used already
- if (this.isProductTitleUsed(title)) {
+ if (this.isProductTitleUsed(product)) {
// Title already used
- throw new ProductTitleAlreadyUsedException(request);
+ throw new ProductTitleAlreadyUsedException(product);
}
// The product is not found, so add it to database
- this.productFrontend.addProduct(title, p, id, a);
+ this.productFrontend.addProduct(title, price, categoryId, available);
// Trace message
this.getLogger().trace("EXIT!"); //NOI18N
* @throws java.lang.IllegalAccessException If the method cannot be accessed
* @throws java.lang.reflect.InvocationTargetException Any other problems?
*/
- private boolean isProductTitleUsed (final ServletRequest request) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ private boolean isProductTitleUsed (final Product product) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// Trace message
- this.getLogger().trace(MessageFormat.format("request={0} - CALLED!", request)); //NOI18N
-
- // Init title
- String title = request.getParameter(ProductFrontend.COLUMN_TITLE);
+ this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product)); //NOI18N
// request must not be null and "title" must be found and non-empty
- if (null == request) {
+ if (null == product) {
// Abort here
throw new NullPointerException("request is null"); //NOI18N
- } else if (null == title) {
+ }
+
+ // Init title
+ String title = product.getTitle();
+
+ if (null == title) {
// title is not set
throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", ProductFrontend.COLUMN_TITLE)); //NOI18N
} else if (title.isEmpty()) {
}
@Override
- public void doAdminHandleProductForms (final ServletRequest request, final ServletResponse response) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, ProductTitleAlreadyUsedException {
- // Trace message
- this.getLogger().trace(MessageFormat.format("request={0},response={1} - CALLED!", request, response)); //NOI18N
-
- // request and response must both be set
- if (null == request) {
- // request is null
- throw new NullPointerException("request is null"); //NOI18N
- } else if (null == response) {
- // response is null
- throw new NullPointerException("response is null"); //NOI18N
- }
-
- // Is it post?
- if ("POST".equals(((HttpServletRequest) request).getMethod())) { //NOI18N
- // Is "add/edit/delete" set?
- if (request.getParameter("add") != null) { //NOI18N
- // Is it already added?
- if (this.isProductTitleUsed(request)) {
- // Debug message
- this.getLogger().debug("Already used, redirecting ..."); //NOI18N
-
- // Already added, so redirect here, else a ServletException will be thrown
- ((HttpServletResponse) response).sendRedirect(String.format("%s/admin/product.jsp?already=1", ((HttpServletRequest) request).getContextPath())); //NOI18N
- } else {
- // Add new product
- this.doAdminAddProduct(request);
-
- // Redirect to proper URL
- ((HttpServletResponse) response).sendRedirect(String.format("%s/admin/product.jsp?added=1", ((HttpServletRequest) request).getContextPath())); //NOI18N
- }
- } else if (request.getParameter("edit") != null) { //NOI18N
- // TODO
- } else if (request.getParameter("delete") != null) { //NOI18N
- // TODO
- }
-
- // Request not handled
- throw new IllegalArgumentException("request not handled."); //NOI18N
- }
-
- // Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
+ @Deprecated
+ public void doAdminHandleProductForms () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, ProductTitleAlreadyUsedException {
+ // Deprecated method called
+ throw new UnsupportedOperationException("Deprecated method has been called.");
}
@Override
- public void doAdminHandleCategoryForms (final ServletRequest request, final ServletResponse response) throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException {
- // Trace message
- this.getLogger().trace(MessageFormat.format("request={0},response={1} - CALLED!", request, response)); //NOI18N
-
- // request and response must both be set
- if (null == request) {
- // request is null
- throw new NullPointerException("request is null"); //NOI18N
- } else if (null == response) {
- // response is null
- throw new NullPointerException("response is null"); //NOI18N
- }
-
- // Is it post?
- if ("POST".equals(((HttpServletRequest) request).getMethod())) { //NOI18N
- // Is "add/edit/delete" set?
- if (request.getParameter("add") != null) { //NOI18N
- // Is the category title already used?
- if (this.isCategoryTitleUsed(request)) {
- // Debug message
- this.getLogger().debug("Already used, redirecting ..."); //NOI18N
-
- // Already added, so redirect here, else a ServletException will be thrown
- ((HttpServletResponse) response).sendRedirect(String.format("%s/admin/category.jsp?already=1", ((HttpServletRequest) request).getContextPath())); //NOI18N
- } else {
- // Add new category
- this.doAdminAddCategory(request);
-
- // Redirect to proper URL
- ((HttpServletResponse) response).sendRedirect(String.format("%s/admin/category.jsp?added=1", ((HttpServletRequest) request).getContextPath())); //NOI18N
- }
- } else if (request.getParameter("edit") != null) { //NOI18N
- // TODO
- } else if (request.getParameter("delete") != null) { //NOI18N
- // TODO
- }
-
- // Request not handled
- throw new IllegalArgumentException("request not handled."); //NOI18N
- }
-
- // Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
- }
-
- /**
- * Checks if category's title is already used.
- *
- * @param request Request instance
- * @return Whether the product title is already used
- * @throws java.io.IOException If any IO error occurs
- * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found in a file-based database backend's file ... ;-)
- * @throws java.sql.SQLException If any SQL error occurs
- * @throws org.mxchange.jcore.exceptions.CorruptedDatabaseFileException If the database file is damaged
- * @throws java.lang.NoSuchMethodException If a method was not found
- * @throws java.lang.IllegalAccessException If the method cannot be accessed
- * @throws java.lang.reflect.InvocationTargetException Any other problems?
- */
- private boolean isCategoryTitleUsed (final ServletRequest request) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
- // Trace message
- this.getLogger().trace(MessageFormat.format("request={0} - CALLED!", request)); //NOI18N
-
- // Init title
- String title = request.getParameter(CategoryFrontend.COLUMN_TITLE);
-
- // request must not be null and "title" must be found and non-empty
- if (null == request) {
- // Abort here
- throw new NullPointerException("request is null"); //NOI18N
- } else if (null == title) {
- // title is not set
- throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", CategoryFrontend.COLUMN_TITLE)); //NOI18N
- } else if (title.isEmpty()) {
- // Is left empty
- throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", CategoryFrontend.COLUMN_TITLE)); //NOI18N
- }
-
- // Default is not used
- boolean isUsed = this.isCategoryTitleUsed(title);
-
- // Trace message
- this.getLogger().trace(MessageFormat.format("isUsed={0} - EXIT!", isUsed)); //NOI18N
-
- // Return it
- return isUsed;
+ @Deprecated
+ public void doAdminHandleCategoryForms () throws IOException, BadTokenException, SQLException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, CategoryTitleAlreadyUsedException {
+ // Deprecated method called
+ throw new UnsupportedOperationException("Deprecated method has been called.");
}
@Override