From d17385f8c30ad8d82f275ab62d0f16386e7b74da Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 6 Apr 2018 23:32:15 +0200 Subject: [PATCH] Product-only: - created product helper bean and moved all product-related methods from generic to this bean - added view stubs for edit, delete and show of a generic product - fixed imports as "add events" now have own package MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../FinancialAdminProductWebRequestBean.java | 4 +- .../FinancialsProductListWebViewBean.java | 2 +- .../FinancialsProductWebViewHelperBean.java | 191 ++++++++++++++++++ ...ancialsProductWebViewHelperController.java | 28 +++ .../admin_form_product_data.tpl | 2 +- .../admin_form_category_data.tpl | 2 +- .../admin_generic_product_delete.xhtml | 29 +++ .../admin_generic_product_edit.xhtml | 29 +++ .../admin_generic_product_list.xhtml | 4 +- .../admin_generic_product_show.xhtml | 29 +++ .../admin_product_category_list.xhtml | 4 +- 11 files changed, 315 insertions(+), 9 deletions(-) create mode 100644 src/java/org/mxchange/jfinancials/beans/helper/product/FinancialsProductWebViewHelperBean.java create mode 100644 src/java/org/mxchange/jfinancials/beans/helper/product/FinancialsProductWebViewHelperController.java create mode 100644 web/admin/generic_product/admin_generic_product_delete.xhtml create mode 100644 web/admin/generic_product/admin_generic_product_edit.xhtml create mode 100644 web/admin/generic_product/admin_generic_product_show.xhtml diff --git a/src/java/org/mxchange/jfinancials/beans/generic_product/FinancialAdminProductWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/generic_product/FinancialAdminProductWebRequestBean.java index bf24a547..8f94c7f6 100644 --- a/src/java/org/mxchange/jfinancials/beans/generic_product/FinancialAdminProductWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/generic_product/FinancialAdminProductWebRequestBean.java @@ -27,8 +27,8 @@ import javax.inject.Named; import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; import org.mxchange.jfinancials.beans.BaseFinancialsBean; import org.mxchange.jfinancials.beans.generic_product.list.FinancialsProductListWebViewController; -import org.mxchange.jproduct.events.product.AddedProductEvent; -import org.mxchange.jproduct.events.product.ProductAddedEvent; +import org.mxchange.jproduct.events.product.added.AddedProductEvent; +import org.mxchange.jproduct.events.product.added.ProductAddedEvent; import org.mxchange.jproduct.exceptions.product.ProductAlreadyAddedException; import org.mxchange.jproduct.model.category.Category; import org.mxchange.jproduct.model.product.AdminProductSessionBeanRemote; 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 46401688..5e7290c6 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 @@ -32,7 +32,7 @@ import javax.faces.view.ViewScoped; import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jfinancials.beans.BaseFinancialsBean; -import org.mxchange.jproduct.events.product.AddedProductEvent; +import org.mxchange.jproduct.events.product.added.AddedProductEvent; import org.mxchange.jproduct.exceptions.product.ProductNotFoundException; import org.mxchange.jproduct.model.product.Product; import org.mxchange.jproduct.model.product.ProductSessionBeanRemote; diff --git a/src/java/org/mxchange/jfinancials/beans/helper/product/FinancialsProductWebViewHelperBean.java b/src/java/org/mxchange/jfinancials/beans/helper/product/FinancialsProductWebViewHelperBean.java new file mode 100644 index 00000000..4e805f6a --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/helper/product/FinancialsProductWebViewHelperBean.java @@ -0,0 +1,191 @@ +/* + * Copyright (C) 2016 - 2018 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.helper.product; + +import java.text.MessageFormat; +import javax.enterprise.event.Event; +import javax.enterprise.inject.Any; +import javax.faces.view.ViewScoped; +import javax.inject.Inject; +import javax.inject.Named; +import org.mxchange.jfinancials.beans.BaseFinancialsBean; +import org.mxchange.jfinancials.beans.localization.FinancialsLocalizationSessionController; +import org.mxchange.jproduct.events.product.created.CreatedProductEvent; +import org.mxchange.jproduct.events.product.created.ObservableCreatedProductEvent; +import org.mxchange.jproduct.model.category.Category; +import org.mxchange.jproduct.model.product.Product; + +/** + * A helper for product beans + *

+ * @author Roland Häder + */ +@Named ("productBeanHelper") +@ViewScoped +public class FinancialsProductWebViewHelperBean extends BaseFinancialsBean implements FinancialsProductWebViewHelperController { + + /** + * Serial number + */ + private static final long serialVersionUID = 17_258_793_567_145_701L; + + /** + * Localization controller + */ + @Inject + private FinancialsLocalizationSessionController localizationController; + + /** + * Product instance + */ + private Product product; + + /** + * An event fired when a product id has been converted to a product + * instance. + */ + @Inject + @Any + private Event productCreatedEvent; + + /** + * Default constructor + */ + public FinancialsProductWebViewHelperBean () { + // Call super constructor + super(); + } + + /** + * Getter for product instance + *

+ * @return Product instance + */ + public Product getProduct () { + return this.product; + } + + /** + * Setter for product instance + *

+ * @param product Product instance + */ + public void setProduct (final Product product) { + this.product = product; + } + + /** + * Notifies other controllers (backing beans) if a product id has been + * successfully converted to a Product instance. + */ + public void notifyControllerProductConverted () { + // Validate product instance + if (this.getProduct() == null) { + // Throw NPE + throw new NullPointerException("this.product is null"); //NOI18N + } else if (this.getProduct().getProductId() == null) { + // Throw NPE again + throw new NullPointerException("this.product.productId is null"); //NOI18N + } else if (this.getProduct().getProductId() < 1) { + // Not valid + throw new IllegalStateException(MessageFormat.format("this.product.productId={0} is not valid.", this.getProduct().getProductId())); //NOI18N + } + + // Set all fields: user + this.productCreatedEvent.fire(new CreatedProductEvent(this.getProduct())); + } + + /** + * Returns the product name and price. If null is provided, an empty string + * is returned. + *

+ * @param product Product instance + *

+ * @return Product name + */ + public String renderGenericProduct (final Product product) { + // Default is empty string, so let's get started + final StringBuilder sb = new StringBuilder(10); + + // Is a product set? + if (product instanceof Product) { + // Is product number given? + if (product.getProductNumber() != null) { + // Prepend it + sb.append(this.getMessageFromBundle("NUMBER")).append(" "); //NOI18N + sb.append(product.getProductNumber()); + sb.append(", "); //NOI18N + } + + // Add name and price + sb.append(this.getMessageFromBundle(product.getProductI18nKey())); + + // Is there any age group? + if (product.getProductAgeGroup() != null) { + // Show it + sb.append(", ").append(this.getMessageFromBundle(product.getProductAgeGroup().getI18nKey())); //NOI18N + } + + // Is there any size? + if ((product.getProductSize() != null) && (!product.getProductSize().isEmpty())) { + // Show size + sb.append(", ").append(this.getMessageFromBundle("SIZE")).append(product.getProductSize()); //NOI18N + } + + // Add price + sb.append(" ("); //NOI18N + sb.append(this.localizationController.formatCurrency(product.getProductGrossPrice().floatValue())); + sb.append(" "); //NOI18N + sb.append(product.getProductCurrencyCode()); + sb.append(")"); //NOI18N + } + + // Return it + return sb.toString(); + } + + /** + * Returns the category's i18n string translated. If null is provided, an + * empty string is returned. + *

+ * @param category Product category instance + *

+ * @return Category's i18n string translation + */ + public String renderProductCategory (final Category category) { + // Default is empty string, so let's get started + final StringBuilder sb = new StringBuilder(10); + + // Is a category set? + if (category instanceof Category) { + // Add title + sb.append(this.getMessageFromBundle(category.getCategoryI18nKey())); + + // Is a parent category set? + if (category.getParentCategory() instanceof Category) { + // Then add it in braces, too + sb.append(" ("); //NOI18N + sb.append(this.getMessageFromBundle(category.getParentCategory().getCategoryI18nKey())); + sb.append(")"); //NOI18N + } + } + + // Return it + return sb.toString(); + } + +} diff --git a/src/java/org/mxchange/jfinancials/beans/helper/product/FinancialsProductWebViewHelperController.java b/src/java/org/mxchange/jfinancials/beans/helper/product/FinancialsProductWebViewHelperController.java new file mode 100644 index 00000000..21d68f89 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/helper/product/FinancialsProductWebViewHelperController.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2016 - 2018 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.helper.product; + +import java.io.Serializable; + +/** + * An interface for product bean helper + *

+ * @author Roland Häder + */ +public interface FinancialsProductWebViewHelperController extends Serializable { + +} diff --git a/web/WEB-INF/templates/admin/generic_product/admin_form_product_data.tpl b/web/WEB-INF/templates/admin/generic_product/admin_form_product_data.tpl index 92020f1f..3e6288b6 100644 --- a/web/WEB-INF/templates/admin/generic_product/admin_form_product_data.tpl +++ b/web/WEB-INF/templates/admin/generic_product/admin_form_product_data.tpl @@ -23,7 +23,7 @@ > - + diff --git a/web/WEB-INF/templates/admin/product_category/admin_form_category_data.tpl b/web/WEB-INF/templates/admin/product_category/admin_form_category_data.tpl index 65dbfd42..19b2d1ca 100644 --- a/web/WEB-INF/templates/admin/product_category/admin_form_category_data.tpl +++ b/web/WEB-INF/templates/admin/product_category/admin_form_category_data.tpl @@ -20,7 +20,7 @@ > - + diff --git a/web/admin/generic_product/admin_generic_product_delete.xhtml b/web/admin/generic_product/admin_generic_product_delete.xhtml new file mode 100644 index 00000000..a04b5106 --- /dev/null +++ b/web/admin/generic_product/admin_generic_product_delete.xhtml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/web/admin/generic_product/admin_generic_product_edit.xhtml b/web/admin/generic_product/admin_generic_product_edit.xhtml new file mode 100644 index 00000000..faa55053 --- /dev/null +++ b/web/admin/generic_product/admin_generic_product_edit.xhtml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/web/admin/generic_product/admin_generic_product_list.xhtml b/web/admin/generic_product/admin_generic_product_list.xhtml index ce6deff3..dc38c6d9 100644 --- a/web/admin/generic_product/admin_generic_product_list.xhtml +++ b/web/admin/generic_product/admin_generic_product_list.xhtml @@ -84,7 +84,7 @@ title="#{project.FILTER_BY_MULTIPLE_PRODUCT_CATEGORIES_TITLE}" > - + @@ -242,7 +242,7 @@ - + diff --git a/web/admin/generic_product/admin_generic_product_show.xhtml b/web/admin/generic_product/admin_generic_product_show.xhtml new file mode 100644 index 00000000..ffa1deca --- /dev/null +++ b/web/admin/generic_product/admin_generic_product_show.xhtml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/web/admin/product_category/admin_product_category_list.xhtml b/web/admin/product_category/admin_product_category_list.xhtml index a2d215e4..0b90adf1 100644 --- a/web/admin/product_category/admin_product_category_list.xhtml +++ b/web/admin/product_category/admin_product_category_list.xhtml @@ -83,7 +83,7 @@ title="#{project.FILTER_BY_MULTIPLE_PRODUCT_CATEGORIES_TITLE}" > - + @@ -151,7 +151,7 @@ - + -- 2.39.5