From: Roland Häder Date: Thu, 30 Apr 2020 21:38:27 +0000 (+0200) Subject: Product-only: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4a1db98d8b930c5c90591519f46a3c7b973e6c2a;p=jfinancials-war.git Product-only: - added administrative action backing bean for product categories and moved addProductCategory() method over there. - added admin-edit-product-category view - implemented editProductCategory() - renamed backing bean property allCategories to allProductCategories - added missing i18n strings Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jfinancials/beans/generic_product/list/FinancialsProductListWebViewBean.java b/src/java/org/mxchange/jfinancials/beans/generic_product/list/FinancialsProductListWebViewBean.java index 45fbd855..30a544c6 100644 --- a/src/java/org/mxchange/jfinancials/beans/generic_product/list/FinancialsProductListWebViewBean.java +++ b/src/java/org/mxchange/jfinancials/beans/generic_product/list/FinancialsProductListWebViewBean.java @@ -213,11 +213,11 @@ public class FinancialsProductListWebViewBean extends BaseFinancialsBean impleme * Initialization of this bean */ @PostConstruct - public void init () { + public void initializeList () { // Is cache there? if (!this.productCache.iterator().hasNext()) { // "Walk" through all entries and add to cache - for (final Product product : this.productBean.fetchAllProducts()) { + for (final Product product : this.productBean.fetchAllGenericProducts()) { // Add it by primary key this.productCache.put(product.getProductId(), product); } @@ -237,8 +237,7 @@ public class FinancialsProductListWebViewBean extends BaseFinancialsBean impleme public int compare (final Product product1, final Product product2) { return product1.getProductId() > product2.getProductId() ? 1 : product1.getProductId() < product2.getProductId() ? -1 : 0; } - } - ); + }); // Set whole list this.setFilteredProducts(this.getAllProducts()); diff --git a/src/java/org/mxchange/jfinancials/beans/product_category/FinancialAdminCategoryWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/product_category/FinancialAdminCategoryWebRequestBean.java deleted file mode 100644 index e1a5185c..00000000 --- a/src/java/org/mxchange/jfinancials/beans/product_category/FinancialAdminCategoryWebRequestBean.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 Free Software Foundation - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jfinancials.beans.product_category; - -import javax.ejb.EJB; -import javax.enterprise.context.RequestScoped; -import javax.enterprise.event.Event; -import javax.enterprise.inject.Any; -import javax.faces.FacesException; -import javax.faces.view.facelets.FaceletException; -import javax.inject.Inject; -import javax.inject.Named; -import org.mxchange.jfinancials.beans.BaseFinancialsBean; -import org.mxchange.jfinancials.beans.product_category.list.FinancialsCategoryListWebViewController; -import org.mxchange.jproduct.events.category.added.AddedCategoryEvent; -import org.mxchange.jproduct.events.category.added.CategoryAddedEvent; -import org.mxchange.jproduct.exceptions.category.CategoryAlreadyAddedException; -import org.mxchange.jproduct.model.category.AdminCategorySessionBeanRemote; -import org.mxchange.jproduct.model.category.Category; -import org.mxchange.jproduct.model.category.ProductCategory; - -/** - * Main application class - *

- * @author Roland Häder - */ -@Named ("adminCategoryController") -@RequestScoped -public class FinancialAdminCategoryWebRequestBean extends BaseFinancialsBean implements FinancialAdminCategoryWebRequestController { - - /** - * Serial number - */ - private static final long serialVersionUID = 5_819_375_183_472_871L; - - /** - * Event for added shop categories - */ - @Inject - @Any - private Event categoryAddedEvent; - - /** - * Remote bean for categories - */ - @EJB (lookup = "java:global/jfinancials-ejb/adminCategory!org.mxchange.jproduct.model.category.AdminCategorySessionBeanRemote") - private AdminCategorySessionBeanRemote categoryBean; - - /** - * Category categoryI18nKey - */ - private String categoryI18nKey; - - /** - * General category controller - */ - @Inject - private FinancialsCategoryListWebViewController categoryListController; - - /** - * Whether this category is shown in statistics - */ - private Boolean categoryShownInStatistics; - - /** - * Parent category - */ - private Category parentCategory; - - /** - * Default constructor - */ - public FinancialAdminCategoryWebRequestBean () { - // Call super constructor - super(); - } - - /** - * Adds given category data from request to database - *

- * @throws FaceletException If something unexpected happened - */ - public void addCategory () throws FaceletException { - // Is i18n key already used? - if (this.categoryListController.isCategoryI18nKeyAdded(this.getCategoryI18nKey())) { - // Throw exception - throw new FacesException("Category i18n key " + this.getCategoryI18nKey() + " is already used."); - } - - // Create category - final Category category = this.createCategoryInstance(); - - // Declare updated category instance - final Category updatedCategory; - - try { - // Deligate to remote bean - updatedCategory = this.categoryBean.addProductCategory(category); - } catch (final CategoryAlreadyAddedException ex) { - // Continue to throw - throw new FacesException(ex); - } - - // Fire event - this.categoryAddedEvent.fire(new CategoryAddedEvent(updatedCategory)); - } - - /** - * Getter for category i18n key - *

- * @return Category i18n key - */ - public String getCategoryI18nKey () { - return this.categoryI18nKey; - } - - /** - * Setter for category i18n key - *

- * @param categoryI18nKey Category i18n key - */ - public void setCategoryI18nKey (final String categoryI18nKey) { - this.categoryI18nKey = categoryI18nKey; - } - - /** - * Getter for whether category is shown in statistics - *

- * @return Whether category is shown in statistics - */ - public Boolean getCategoryShownInStatistics () { - return this.categoryShownInStatistics; - } - - /** - * Setter for whether category is shown in statistics - *

- * @param categoryShownInStatistics Whether category is shown in statistics - */ - public void setCategoryShownInStatistics (final Boolean categoryShownInStatistics) { - this.categoryShownInStatistics = categoryShownInStatistics; - } - - /** - * Getter for parent id - *

- * @return Parent id - */ - public Category getParentCategory () { - return this.parentCategory; - } - - /** - * Setter for parent category - *

- * @param parentCategory Parent category to set - */ - public void setParentCategory (final Category parentCategory) { - this.parentCategory = parentCategory; - } - - /** - * Creates a category instance with all fields (except primary key) - *

- * @return Category instance - */ - private Category createCategoryInstance () { - // Create category - final Category category = new ProductCategory( - this.getCategoryI18nKey(), - this.getCategoryShownInStatistics() - ); - - // Set all optional fields - category.setParentCategory(this.getParentCategory()); - - // Return it - return category; - } - -} diff --git a/src/java/org/mxchange/jfinancials/beans/product_category/FinancialAdminCategoryWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/product_category/FinancialAdminCategoryWebRequestController.java deleted file mode 100644 index 740d0f89..00000000 --- a/src/java/org/mxchange/jfinancials/beans/product_category/FinancialAdminCategoryWebRequestController.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 Free Software Foundation - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jfinancials.beans.product_category; - -import java.io.Serializable; - -/** - * An interface for product controllers for "ADMIN" role - *

- * @author Roland Häder - */ -public interface FinancialAdminCategoryWebRequestController extends Serializable { - -} diff --git a/src/java/org/mxchange/jfinancials/beans/product_category/FinancialAdminProductCategoryWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/product_category/FinancialAdminProductCategoryWebRequestBean.java new file mode 100644 index 00000000..edc7f1a0 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/product_category/FinancialAdminProductCategoryWebRequestBean.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2016 - 2020 Free Software Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jfinancials.beans.product_category; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; +import org.mxchange.jfinancials.beans.BaseFinancialsBean; + +/** + * Administrative backing bean for product categories application class + *

+ * @author Roland Häder + */ +@Named ("adminProductCategoryController") +@RequestScoped +public class FinancialAdminProductCategoryWebRequestBean extends BaseFinancialsBean implements FinancialAdminProductCategoryWebRequestController { + + /** + * Serial number + */ + private static final long serialVersionUID = 5_819_375_183_472_871L; + + /** + * Default constructor + */ + public FinancialAdminProductCategoryWebRequestBean () { + // Call super constructor + super(); + } + +} diff --git a/src/java/org/mxchange/jfinancials/beans/product_category/FinancialAdminProductCategoryWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/product_category/FinancialAdminProductCategoryWebRequestController.java new file mode 100644 index 00000000..8c13ad59 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/product_category/FinancialAdminProductCategoryWebRequestController.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2016 - 2020 Free Software Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jfinancials.beans.product_category; + +import java.io.Serializable; + +/** + * An interface for product controllers for "ADMIN" role + *

+ * @author Roland Häder + */ +public interface FinancialAdminProductCategoryWebRequestController extends Serializable { + +} diff --git a/src/java/org/mxchange/jfinancials/beans/product_category/FinancialCategoryWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/product_category/FinancialCategoryWebRequestBean.java deleted file mode 100644 index 80e8d4ab..00000000 --- a/src/java/org/mxchange/jfinancials/beans/product_category/FinancialCategoryWebRequestBean.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 Free Software Foundation - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jfinancials.beans.product_category; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Named; -import org.mxchange.jfinancials.beans.BaseFinancialsBean; - -/** - * General (product) category controller - *

- * @author Roland Häder - */ -@Named ("categoryController") -@RequestScoped -public class FinancialCategoryWebRequestBean extends BaseFinancialsBean implements FinancialCategoryWebRequestController { - - /** - * Serial number - */ - private static final long serialVersionUID = 58_137_539_530_279L; - - /** - * Default constructor - */ - public FinancialCategoryWebRequestBean () { - // Call super constructor - super(); - } - -} diff --git a/src/java/org/mxchange/jfinancials/beans/product_category/FinancialCategoryWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/product_category/FinancialCategoryWebRequestController.java deleted file mode 100644 index 5a25e845..00000000 --- a/src/java/org/mxchange/jfinancials/beans/product_category/FinancialCategoryWebRequestController.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 Free Software Foundation - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jfinancials.beans.product_category; - -import java.io.Serializable; - -/** - * An interface for (product) categories - *

- * @author Roland Häder - */ -public interface FinancialCategoryWebRequestController extends Serializable { - -} diff --git a/src/java/org/mxchange/jfinancials/beans/product_category/FinancialProductCategoryWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/product_category/FinancialProductCategoryWebRequestBean.java new file mode 100644 index 00000000..86f70d42 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/product_category/FinancialProductCategoryWebRequestBean.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2016 - 2020 Free Software Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jfinancials.beans.product_category; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; +import org.mxchange.jfinancials.beans.BaseFinancialsBean; + +/** + * General (product) category controller + *

+ * @author Roland Häder + */ +@Named ("categoryController") +@RequestScoped +public class FinancialProductCategoryWebRequestBean extends BaseFinancialsBean implements FinancialProductCategoryWebRequestController { + + /** + * Serial number + */ + private static final long serialVersionUID = 58_137_539_530_279L; + + /** + * Default constructor + */ + public FinancialProductCategoryWebRequestBean () { + // Call super constructor + super(); + } + +} diff --git a/src/java/org/mxchange/jfinancials/beans/product_category/FinancialProductCategoryWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/product_category/FinancialProductCategoryWebRequestController.java new file mode 100644 index 00000000..5b7d63cf --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/product_category/FinancialProductCategoryWebRequestController.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2016 - 2020 Free Software Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jfinancials.beans.product_category; + +import java.io.Serializable; + +/** + * An interface for (product) categories + *

+ * @author Roland Häder + */ +public interface FinancialProductCategoryWebRequestController extends Serializable { + +} diff --git a/src/java/org/mxchange/jfinancials/beans/product_category/action/FinancialAdminProductCategoryActionWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/product_category/action/FinancialAdminProductCategoryActionWebRequestBean.java new file mode 100644 index 00000000..87d7c80e --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/product_category/action/FinancialAdminProductCategoryActionWebRequestBean.java @@ -0,0 +1,326 @@ +/* + * Copyright (C) 2016 - 2020 Free Software Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jfinancials.beans.product_category.action; + +import java.text.MessageFormat; +import java.util.Objects; +import javax.ejb.EJB; +import javax.enterprise.context.RequestScoped; +import javax.enterprise.event.Event; +import javax.enterprise.inject.Any; +import javax.faces.FacesException; +import javax.faces.application.FacesMessage; +import javax.inject.Inject; +import javax.inject.Named; +import org.mxchange.jfinancials.beans.BaseFinancialsBean; +import org.mxchange.jfinancials.beans.product_category.list.FinancialsCategoryListWebViewController; +import org.mxchange.jproduct.events.category.added.AdminAddedCategoryEvent; +import org.mxchange.jproduct.events.category.added.ObservableAdminAddedCategoryEvent; +import org.mxchange.jproduct.events.category.updated.AdminUpdatedCategoryEvent; +import org.mxchange.jproduct.events.category.updated.ObservableAdminUpdatedCategoryEvent; +import org.mxchange.jproduct.exceptions.category.CategoryAlreadyAddedException; +import org.mxchange.jproduct.exceptions.category.CategoryNotFoundException; +import org.mxchange.jproduct.model.category.AdminCategorySessionBeanRemote; +import org.mxchange.jproduct.model.category.Categories; +import org.mxchange.jproduct.model.category.Category; +import org.mxchange.jproduct.model.category.ProductCategory; + +/** + * Administrative action backing bean for product categories + *

+ * @author Roland Häder + */ +@Named ("adminProductCategoryActionController") +@RequestScoped +public class FinancialAdminProductCategoryActionWebRequestBean extends BaseFinancialsBean implements FinancialAdminProductCategoryActionWebRequestController { + + /** + * Serial number + */ + private static final long serialVersionUID = 5_819_375_183_472_873L; + + /** + * Event for added shop categories + */ + @Inject + @Any + private Event adminAddedCategoryEvent; + + /** + * Remote bean for categories + */ + @EJB (lookup = "java:global/jfinancials-ejb/adminCategory!org.mxchange.jproduct.model.category.AdminCategorySessionBeanRemote") + private AdminCategorySessionBeanRemote adminCategoryBean; + + /** + * Event for added shop categories + */ + @Inject + @Any + private Event adminUpdatedCategoryEvent; + + /** + * Category categoryI18nKey + */ + private String categoryI18nKey; + + /** + * Category's primary key + */ + private Long categoryId; + + /** + * Whether this category is shown in statistics + */ + private Boolean categoryShownInStatistics; + + /** + * Currently worked on category + */ + private Category currentCategory; + + /** + * Parent category + */ + private Category parentCategory; + + /** + * General category controller + */ + @Inject + private FinancialsCategoryListWebViewController productCategoryListController; + + /** + * Default constructor + */ + public FinancialAdminProductCategoryActionWebRequestBean () { + // Call super constructor + super(); + } + + /** + * Adds given category data from request to database + */ + public void addCategory () { + // Is i18n key already used? + if (this.productCategoryListController.isCategoryI18nKeyAdded(this.getCategoryI18nKey())) { + // Throw exception + throw new FacesException(MessageFormat.format("Category i18n key {0} is already used.", this.getCategoryI18nKey())); //NOI18N + } + + // Create category + final Category category = this.createCategoryInstance(); + + // Declare updated category instance + final Category updatedCategory; + + try { + // Deligate to remote bean + updatedCategory = this.adminCategoryBean.addProductCategory(category); + } catch (final CategoryAlreadyAddedException ex) { + // Continue to throw + throw new FacesException(ex); + } + + // Fire event + this.adminAddedCategoryEvent.fire(new AdminAddedCategoryEvent(updatedCategory)); + } + + /** + * Copies all properties from current category instance to backing bean + * properties. + */ + public void copyAllCategoryProperties () { + // Check if current category is set + if (this.getCurrentCategory() == null) { + // Throw NPE + throw new NullPointerException("this.currentCategory is null"); //NOI18N + } else if (this.getCurrentCategory().getCategoryId() == null) { + // Throw NPE again + throw new NullPointerException("this.currentCategory.categoryId is null"); //NOI18N + } else if (this.getCurrentCategory().getCategoryId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("this.currentCategory.categoryId={0} is invalid", this.getCurrentCategory().getCategoryId())); //NOI18N + } + + // Copy all fields, except timestamps + this.setCategoryI18nKey(this.getCurrentCategory().getCategoryI18nKey()); + this.setCategoryId(this.getCurrentCategory().getCategoryId()); + this.setCategoryShownInStatistics(this.getCurrentCategory().getCategoryShownInStatistics()); + this.setParentCategory(this.getCurrentCategory().getParentCategory()); + } + + /** + * Getter for category i18n key + *

+ * @return Category i18n key + */ + public String getCategoryI18nKey () { + return this.categoryI18nKey; + } + + /** + * Setter for category i18n key + *

+ * @param categoryI18nKey Category i18n key + */ + public void setCategoryI18nKey (final String categoryI18nKey) { + this.categoryI18nKey = categoryI18nKey; + } + + /** + * Getter for category's primary key + *

+ * @return Category's primary key + */ + public Long getCategoryId () { + return this.categoryId; + } + + /** + * Setter for category's primary key + *

+ * @param categoryId Current category + */ + public void setCategoryId (final Long categoryId) { + this.categoryId = categoryId; + } + + /** + * Getter for whether category is shown in statistics + *

+ * @return Whether category is shown in statistics + */ + public Boolean getCategoryShownInStatistics () { + return this.categoryShownInStatistics; + } + + /** + * Setter for whether category is shown in statistics + *

+ * @param categoryShownInStatistics Whether category is shown in statistics + */ + public void setCategoryShownInStatistics (final Boolean categoryShownInStatistics) { + this.categoryShownInStatistics = categoryShownInStatistics; + } + + /** + * Getter for current category + *

+ * @return Current category + */ + public Category getCurrentCategory () { + return this.currentCategory; + } + + /** + * Setter for current category + *

+ * @param currentCategory Current category + */ + public void setCurrentCategory (final Category currentCategory) { + this.currentCategory = currentCategory; + } + + /** + * Getter for parent id + *

+ * @return Parent id + */ + public Category getParentCategory () { + return this.parentCategory; + } + + /** + * Setter for parent category + *

+ * @param parentCategory Parent category to set + */ + public void setParentCategory (final Category parentCategory) { + this.parentCategory = parentCategory; + } + + /** + * Updates given category data from request to database + *

+ * @return Redirection outcome + */ + public String updateCategory () { + // Check if current category is set + if (this.getCurrentCategory() == null) { + // Throw NPE + throw new NullPointerException("this.currentCategory is null"); //NOI18N + } else if (this.getCurrentCategory().getCategoryId() == null) { + // Throw NPE again + throw new NullPointerException("this.currentCategory.categoryId is null"); //NOI18N + } else if (this.getCurrentCategory().getCategoryId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("this.currentCategory.categoryId={0} is invalid.", this.getCurrentCategory().getCategoryId())); //NOI18N + } + + // Create category + final Category category = this.createCategoryInstance(); + + // Has the product changed? + if (Objects.equals(category, this.getCurrentCategory())) { + // Is the same product data, output message + this.showFacesMessage("admin-form-edit-product-category:categoryI18nKey", "ADMIN_PRODUCT_CATEGORY_NOT_UPDATED", FacesMessage.SEVERITY_WARN); //NOI18N + return ""; //NOI18N + } + + // Copy all fields from it to current + Categories.copyCategoryData(category, this.getCurrentCategory()); + + // Declare updated category instance + final Category updatedCategory; + + try { + // Deligate to remote bean + updatedCategory = this.adminCategoryBean.updateProductCategory(this.getCurrentCategory()); + } catch (final CategoryNotFoundException ex) { + // Continue to throw + throw new FacesException(ex); + } + + // Fire event + this.adminUpdatedCategoryEvent.fire(new AdminUpdatedCategoryEvent(updatedCategory)); + + // Return outcome to admin-list + return "admin_list_product_categories"; //NOI18N + } + + /** + * Creates a category instance with all fields (except primary key) + *

+ * @return Category instance + */ + private Category createCategoryInstance () { + // Create category + final Category category = new ProductCategory( + this.getCategoryI18nKey(), + this.getCategoryShownInStatistics() + ); + + // Set all optional fields + category.setCategoryId(this.getCategoryId()); + category.setParentCategory(this.getParentCategory()); + + // Return it + return category; + } + +} diff --git a/src/java/org/mxchange/jfinancials/beans/product_category/action/FinancialAdminProductCategoryActionWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/product_category/action/FinancialAdminProductCategoryActionWebRequestController.java new file mode 100644 index 00000000..abc8dc6f --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/product_category/action/FinancialAdminProductCategoryActionWebRequestController.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2016 - 2020 Free Software Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jfinancials.beans.product_category.action; + +import java.io.Serializable; + +/** + * An interface for product controllers for "ADMIN" role + *

+ * @author Roland Häder + */ +public interface FinancialAdminProductCategoryActionWebRequestController extends Serializable { + +} diff --git a/src/java/org/mxchange/jfinancials/beans/product_category/list/FinancialsCategoryListWebViewBean.java b/src/java/org/mxchange/jfinancials/beans/product_category/list/FinancialsCategoryListWebViewBean.java index bd850fc3..34aa90e3 100644 --- a/src/java/org/mxchange/jfinancials/beans/product_category/list/FinancialsCategoryListWebViewBean.java +++ b/src/java/org/mxchange/jfinancials/beans/product_category/list/FinancialsCategoryListWebViewBean.java @@ -19,6 +19,7 @@ package org.mxchange.jfinancials.beans.product_category.list; import fish.payara.cdi.jsr107.impl.NamedCache; import java.text.MessageFormat; import java.util.Comparator; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Objects; @@ -30,7 +31,8 @@ import javax.faces.view.ViewScoped; import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jfinancials.beans.BaseFinancialsBean; -import org.mxchange.jproduct.events.category.added.AddedCategoryEvent; +import org.mxchange.jproduct.events.category.added.ObservableAdminAddedCategoryEvent; +import org.mxchange.jproduct.events.category.updated.ObservableAdminUpdatedCategoryEvent; import org.mxchange.jproduct.exceptions.category.CategoryNotFoundException; import org.mxchange.jproduct.model.category.Category; import org.mxchange.jproduct.model.category.CategorySessionBeanRemote; @@ -40,7 +42,7 @@ import org.mxchange.jproduct.model.category.CategorySessionBeanRemote; *

* @author Roland Haeder */ -@Named ("categoryListController") +@Named ("productCategoryListController") @ViewScoped public class FinancialsCategoryListWebViewBean extends BaseFinancialsBean implements FinancialsCategoryListWebViewController { @@ -52,7 +54,7 @@ public class FinancialsCategoryListWebViewBean extends BaseFinancialsBean implem /** * List of all categories */ - private final List allCategories; + private final List allProductCategories; /** * EJB for general category stuff @@ -70,7 +72,7 @@ public class FinancialsCategoryListWebViewBean extends BaseFinancialsBean implem /** * A list of filtered categories */ - private List filteredCategories; + private List filteredProductCategories; /** * Selected category @@ -85,7 +87,7 @@ public class FinancialsCategoryListWebViewBean extends BaseFinancialsBean implem super(); // Init list - this.allCategories = new LinkedList<>(); + this.allProductCategories = new LinkedList<>(); } /** @@ -93,7 +95,7 @@ public class FinancialsCategoryListWebViewBean extends BaseFinancialsBean implem *

* @param event Event to be observed */ - public void afterCategoryAddedEvent (@Observes final AddedCategoryEvent event) { + public void afterAdminAddedCategoryEvent (@Observes final ObservableAdminAddedCategoryEvent event) { // Is all valid? if (null == event) { // Throw NPE @@ -111,7 +113,33 @@ public class FinancialsCategoryListWebViewBean extends BaseFinancialsBean implem // Add the category this.categoryCache.put(event.getAddedCategory().getCategoryId(), event.getAddedCategory()); - this.getAllCategories().add(event.getAddedCategory()); + this.uniqueAddProductCategory(event.getAddedCategory()); + } + + /** + * Observes events fired after a new product category has been updated + *

+ * @param event Event to be observed + */ + public void afterAdminUpdatedCategoryEvent (@Observes final ObservableAdminUpdatedCategoryEvent event) { + // Is all valid? + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUpdatedCategory() == null) { + // Throw again ... + throw new NullPointerException("event.updatedCategory is null"); //NOI18N + } else if (event.getUpdatedCategory().getCategoryId() == null) { + // And again ... + throw new NullPointerException("event.updatedCategory.categoryId is null"); //NOI18N + } else if (event.getUpdatedCategory().getCategoryId() < 1) { + // Id is invalid + throw new IllegalArgumentException(MessageFormat.format("event.updatedCategory.categoryId={0} is not valid.", event.getUpdatedCategory().getCategoryId())); //NOI18N + } + + // Add the category + this.categoryCache.put(event.getUpdatedCategory().getCategoryId(), event.getUpdatedCategory()); + this.uniqueAddProductCategory(event.getUpdatedCategory()); } @Override @@ -141,9 +169,9 @@ public class FinancialsCategoryListWebViewBean extends BaseFinancialsBean implem * @return All categories */ @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public List getAllCategories () { + public List getAllProductCategories () { // Return it - return this.allCategories; + return this.allProductCategories; } /** @@ -152,18 +180,18 @@ public class FinancialsCategoryListWebViewBean extends BaseFinancialsBean implem * @return Filtered category list */ @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public List getFilteredCategories () { - return this.filteredCategories; + public List getFilteredProductCategories () { + return this.filteredProductCategories; } /** * Setter for filtered category list *

- * @param filteredCategories Filtered category list + * @param filteredProductCategories Filtered category list */ @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") - public void setFilteredCategories (final List filteredCategories) { - this.filteredCategories = filteredCategories; + public void setFilteredProductCategories (final List filteredProductCategories) { + this.filteredProductCategories = filteredProductCategories; } /** @@ -188,26 +216,26 @@ public class FinancialsCategoryListWebViewBean extends BaseFinancialsBean implem * Initialization of this bean */ @PostConstruct - public void init () { + public void initializeList () { // Is cache there? if (!this.categoryCache.iterator().hasNext()) { // "Walk" through all entries and add to cache - for (final Category category : this.categoryBean.fetchAllCategories()) { + for (final Category category : this.categoryBean.fetchAllProductCategories()) { // Add it by primary key this.categoryCache.put(category.getCategoryId(), category); } } // Is the list empty, but filled cache? - if (this.allCategories.isEmpty() && this.categoryCache.iterator().hasNext()) { + if (this.getAllProductCategories().isEmpty() && this.categoryCache.iterator().hasNext()) { // Build up list for (final Cache.Entry currentEntry : this.categoryCache) { // Add to list - this.allCategories.add(currentEntry.getValue()); + this.getAllProductCategories().add(currentEntry.getValue()); } // Sort list - this.allCategories.sort(new Comparator() { + this.getAllProductCategories().sort(new Comparator() { @Override public int compare (final Category category1, final Category category2) { return category1.getCategoryId() > category2.getCategoryId() ? 1 : category1.getCategoryId() < category2.getCategoryId() ? -1 : 0; @@ -216,7 +244,7 @@ public class FinancialsCategoryListWebViewBean extends BaseFinancialsBean implem ); // Set whole list - this.setFilteredCategories(this.getAllCategories()); + this.setFilteredProductCategories(this.getAllProductCategories()); } } @@ -235,7 +263,7 @@ public class FinancialsCategoryListWebViewBean extends BaseFinancialsBean implem boolean isFound = false; // Check all added,products - for (final Category category : this.getAllCategories()) { + for (final Category category : this.getAllProductCategories()) { // Is i18n key the same? if (Objects.equals(category.getCategoryI18nKey(), categoryI18nKey)) { // Found it @@ -248,4 +276,30 @@ public class FinancialsCategoryListWebViewBean extends BaseFinancialsBean implem return isFound; } + /** + * Uniquely adds given category to "all" list + *

+ * @param category Category instance + */ + private void uniqueAddProductCategory (final Category category) { + // Get iterator from + final Iterator iterator = this.getAllProductCategories().iterator(); + + // Loop through all + while (iterator.hasNext()) { + // Get current element + final Category currentCategory = iterator.next(); + + // Does primary key match? + if (Objects.equals(category.getCategoryId(), currentCategory.getCategoryId())) { + // Remove it and stop iterating + iterator.remove(); + break; + } + } + + // Re-add it + this.getAllProductCategories().add(category); + } + } diff --git a/src/java/org/mxchange/localization/product_de_DE.properties b/src/java/org/mxchange/localization/product_de_DE.properties index 36d982fb..166e2e93 100644 --- a/src/java/org/mxchange/localization/product_de_DE.properties +++ b/src/java/org/mxchange/localization/product_de_DE.properties @@ -205,3 +205,14 @@ ERROR_PRODUCT_FSC_NUMBER_NOT_VALID=Fehler: FSC-Nummer des Produktes entspricht n ADMIN_GENERIC_PRODUCT_NOT_UPDATED=Sie haben keine Aenderungen am dem Produkt vorgenommen. ADMIN_PRODUCT_FSC_NUMBER_HEADER=FSC-Nummer: PRODUCT_FSC_NUMBER_TITLE=The FSC-Nummer des Produktes. +ERROR_PARAMETER_CATEGORY_ID_NOT_SET=Fehler: Parameter "categoryId" ist nicht gesetzt. +PARAMETER_CATEGORY_ID_INVALID=Produkt mit Parameter "categoryId" nicht gefunden. +PAGE_TITLE_ADMIN_PRODUCT_CATEGORY_EDIT=Produktkategorien editieren +CONTENT_TITLE_ADMIN_PRODUCT_CATEGORY_EDIT=Produktkategorien editieren: +#@TODO Please fix German umlauts! +ADMIN_EDIT_PRODUCT_CATEGORY_MINIMUM_DATA=Geben Sie mindestens den I18n-Schluessel ein, um diese Produktkategorie zu editieren. +#@TODO Please fix German umlauts! +BUTTON_ADMIN_EDIT_PRODUCT_CATEGORY=Produktkategorie aendern +ADMIN_EDIT_PRODUCT_CATEGORY_TITLE=Produktkategorie mit Id {0} editieren: +#@TODO Please fix German umlauts! +ADMIN_PRODUCT_CATEGORY_NOT_UPDATED=Sie haben die Produktkategorie nicht gaendert. diff --git a/src/java/org/mxchange/localization/product_en_US.properties b/src/java/org/mxchange/localization/product_en_US.properties index e2e86e0b..aff88ae3 100644 --- a/src/java/org/mxchange/localization/product_en_US.properties +++ b/src/java/org/mxchange/localization/product_en_US.properties @@ -164,3 +164,11 @@ ERROR_PRODUCT_FSC_NUMBER_NOT_VALID=Error: FSC number not valid format: Cxxxxxx ADMIN_GENERIC_PRODUCT_NOT_UPDATED=You have not changed any product data. ADMIN_PRODUCT_FSC_NUMBER_HEADER=FSC number: PRODUCT_FSC_NUMBER_TITLE=The FSC number of the product. +ERROR_PARAMETER_CATEGORY_ID_NOT_SET=Error: Parameter "categoryId" is not set. +PARAMETER_CATEGORY_ID_INVALID=Product category with given "categoryId" not found. +PAGE_TITLE_ADMIN_PRODUCT_CATEGORY_EDIT=Edit product category +CONTENT_TITLE_ADMIN_PRODUCT_CATEGORY_EDIT=Edit product category: +ADMIN_EDIT_PRODUCT_CATEGORY_MINIMUM_DATA=Please enter at least the i18n key to edit this product category. +BUTTON_ADMIN_EDIT_PRODUCT_CATEGORY=Change product category +ADMIN_EDIT_PRODUCT_CATEGORY_TITLE=Edit product category Id {0}: +ADMIN_PRODUCT_CATEGORY_NOT_UPDATED=You have not changed the product category. diff --git a/web/WEB-INF/faces-config.xml b/web/WEB-INF/faces-config.xml index 532c3a14..fa377e6c 100644 --- a/web/WEB-INF/faces-config.xml +++ b/web/WEB-INF/faces-config.xml @@ -971,6 +971,14 @@ /admin/product_category/admin_product_category_assign_parent.xhtml + + /admin/product_category/admin_product_category_edit.xhtml + + admin_list_product_categories + /admin/product_category/admin_product_category_list.xhtml + + + /admin/generic_product/admin_generic_product_list.xhtml diff --git a/web/WEB-INF/templates/admin/generic_product/admin_form_generic_product_data.tpl b/web/WEB-INF/templates/admin/generic_product/admin_form_generic_product_data.tpl index 29ad4f67..2cb9d062 100644 --- a/web/WEB-INF/templates/admin/generic_product/admin_form_generic_product_data.tpl +++ b/web/WEB-INF/templates/admin/generic_product/admin_form_generic_product_data.tpl @@ -37,7 +37,7 @@ /> + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/web/admin/generic_product/admin_generic_product_list.xhtml b/web/admin/generic_product/admin_generic_product_list.xhtml index cb23b86b..b13f54eb 100644 --- a/web/admin/generic_product/admin_generic_product_list.xhtml +++ b/web/admin/generic_product/admin_generic_product_list.xhtml @@ -158,7 +158,7 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/web/admin/product_category/admin_product_category_list.xhtml b/web/admin/product_category/admin_product_category_list.xhtml index 9f5f9f64..67c61b13 100644 --- a/web/admin/product_category/admin_product_category_list.xhtml +++ b/web/admin/product_category/admin_product_category_list.xhtml @@ -21,10 +21,10 @@ @@ -128,7 +128,7 @@ - + - - + + - + - + - + - + - + - + - + @@ -276,57 +276,7 @@ - - - - - - - - - - - - - - - - - - - - - +