]> git.mxchange.org Git - jfinancials-war.git/commitdiff
Product-only:
authorRoland Häder <roland@mxchange.org>
Fri, 6 Apr 2018 21:32:15 +0000 (23:32 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 6 Apr 2018 21:34:22 +0000 (23:34 +0200)
- 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

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jfinancials/beans/generic_product/FinancialAdminProductWebRequestBean.java
src/java/org/mxchange/jfinancials/beans/generic_product/list/FinancialsProductListWebViewBean.java
src/java/org/mxchange/jfinancials/beans/helper/product/FinancialsProductWebViewHelperBean.java [new file with mode: 0644]
src/java/org/mxchange/jfinancials/beans/helper/product/FinancialsProductWebViewHelperController.java [new file with mode: 0644]
web/WEB-INF/templates/admin/generic_product/admin_form_product_data.tpl
web/WEB-INF/templates/admin/product_category/admin_form_category_data.tpl
web/admin/generic_product/admin_generic_product_delete.xhtml [new file with mode: 0644]
web/admin/generic_product/admin_generic_product_edit.xhtml [new file with mode: 0644]
web/admin/generic_product/admin_generic_product_list.xhtml
web/admin/generic_product/admin_generic_product_show.xhtml [new file with mode: 0644]
web/admin/product_category/admin_product_category_list.xhtml

index bf24a54723bf9488f9b4863b3ef9146ec675b52b..8f94c7f6dc3c7ab3e7ae1595bcc528b6081d8091 100644 (file)
@@ -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;
index 46401688f8ba334354932f3fb0812bb9d2c8dfc4..5e7290c66b8fc0a2590a91a8537acfb67eeaaf69 100644 (file)
@@ -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 (file)
index 0000000..4e805f6
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+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
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@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<ObservableCreatedProductEvent> productCreatedEvent;
+
+       /**
+        * Default constructor
+        */
+       public FinancialsProductWebViewHelperBean () {
+               // Call super constructor
+               super();
+       }
+
+       /**
+        * Getter for product instance
+        * <p>
+        * @return Product instance
+        */
+       public Product getProduct () {
+               return this.product;
+       }
+
+       /**
+        * Setter for product instance
+        * <p>
+        * @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.
+        * <p>
+        * @param product Product instance
+        * <p>
+        * @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.
+        * <p>
+        * @param category Product category instance
+        * <p>
+        * @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 (file)
index 0000000..21d68f8
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jfinancials.beans.helper.product;
+
+import java.io.Serializable;
+
+/**
+ * An interface for product bean helper
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface FinancialsProductWebViewHelperController extends Serializable {
+
+}
index 92020f1f32102754fa1c68d6999f3107355b6ee2..3e6288b6d9da21fe82e1d9a10f1ebfaf8b0c6285 100644 (file)
@@ -23,7 +23,7 @@
                                >
                                <f:converter converterId="ProductCategoryConverter" />
                                <f:selectItem itemValue="#{null}" itemLabel="#{msg.PLEASE_SELECT}" noSelectionOption="true" itemDisabled="true" />
-                               <f:selectItems value="#{categoryListController.allCategories}" var="category" itemValue="#{category}" itemLabel="#{beanHelper.renderProductCategory(category)}" />
+                               <f:selectItems value="#{categoryListController.allCategories}" var="category" itemValue="#{category}" itemLabel="#{productBeanHelper.renderProductCategory(category)}" />
                        </p:selectOneMenu>
 
                        <p:outputLabel for="productI18nKey" value="#{project.ADMIN_ENTER_GENERIC_PRODUCT_I18N_KEY}" />
index 65dbfd42c2e4cace5cf16a4ef4f620d815c62b30..19b2d1cade1384da349475ca4554193ce0229a27 100644 (file)
@@ -20,7 +20,7 @@
                                >
                                <f:converter converterId="ProductCategoryConverter" />
                                <f:selectItem itemValue="#{null}" itemLabel="#{msg.NONE_SELECTED}" />
-                               <f:selectItems value="#{categoryListController.allCategories}" var="category" itemValue="#{category}" itemLabel="#{beanHelper.renderProductCategory(category)}" />
+                               <f:selectItems value="#{categoryListController.allCategories}" var="category" itemValue="#{category}" itemLabel="#{productBeanHelper.renderProductCategory(category)}" />
                        </p:selectOneMenu>
 
                        <p:outputLabel for="categoryI18nKey" value="#{project.ADMIN_ENTER_CATEGORY_I18N_KEY}" />
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 (file)
index 0000000..a04b510
--- /dev/null
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<ui:composition template="/WEB-INF/templates/admin/admin_base.tpl"
+                               xmlns="http://www.w3.org/1999/xhtml"
+                               xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
+                               xmlns:h="http://xmlns.jcp.org/jsf/html"
+                               xmlns:f="http://xmlns.jcp.org/jsf/core"
+                               xmlns:p="http://primefaces.org/ui"
+                               >
+
+       <ui:define name="metadata">
+               <f:metadata>
+                       <f:viewParam id="productId" name="productId" value="#{productBeanHelper.product}" converter="GenericProductConverter" required="true" requiredMessage="#{project.ERROR_PARAMETER_PRODUCT_ID_NOT_SET}" converterMessage="#{project.PARAMETER_PRODUCT_ID_INVALID}" />
+                       <f:viewAction onPostback="true" action="#{productBeanHelper.notifyControllerProductConverted()}" />
+               </f:metadata>
+       </ui:define>
+
+       <ui:define name="document_admin_title">
+               <h:outputText value="#{project.PAGE_TITLE_ADMIN_GENERIC_PRODUCT_DELETE}" />
+       </ui:define>
+
+       <ui:define name="content_header">
+               <h:outputText value="#{project.CONTENT_TITLE_ADMIN_GENERIC_PRODUCT_DELETE}" />
+       </ui:define>
+
+       <ui:define name="content">
+               <p:message for="productId" showSummary="true" />
+               <!-- @TODO Here goes your content. //-->
+       </ui:define>
+</ui:composition>
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 (file)
index 0000000..faa5505
--- /dev/null
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<ui:composition template="/WEB-INF/templates/admin/admin_base.tpl"
+                               xmlns="http://www.w3.org/1999/xhtml"
+                               xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
+                               xmlns:h="http://xmlns.jcp.org/jsf/html"
+                               xmlns:f="http://xmlns.jcp.org/jsf/core"
+                               xmlns:p="http://primefaces.org/ui"
+                               >
+
+       <ui:define name="metadata">
+               <f:metadata>
+                       <f:viewParam id="productId" name="productId" value="#{productBeanHelper.product}" converter="GenericProductConverter" required="true" requiredMessage="#{project.ERROR_PARAMETER_PRODUCT_ID_NOT_SET}" converterMessage="#{project.PARAMETER_PRODUCT_ID_INVALID}" />
+                       <f:viewAction onPostback="true" action="#{productBeanHelper.notifyControllerProductConverted()}" />
+               </f:metadata>
+       </ui:define>
+
+       <ui:define name="document_admin_title">
+               <h:outputText value="#{project.PAGE_TITLE_ADMIN_GENERIC_PRODUCT_EDIT}" />
+       </ui:define>
+
+       <ui:define name="content_header">
+               <h:outputText value="#{project.CONTENT_TITLE_ADMIN_GENERIC_PRODUCT_EDIT}" />
+       </ui:define>
+
+       <ui:define name="content">
+               <p:message for="productId" showSummary="true" />
+               <!-- @TODO Here goes your content. //-->
+       </ui:define>
+</ui:composition>
index ce6deff342e9e5429c3e29166728e6783df0ff53..dc38c6d988bbe6c4726144a8ae055f5f620a9175 100644 (file)
@@ -84,7 +84,7 @@
                                                        title="#{project.FILTER_BY_MULTIPLE_PRODUCT_CATEGORIES_TITLE}"
                                                        >
                                                        <f:converter converterId="ProductCategoryConverter" />
-                                                       <f:selectItems value="#{categoryListController.allCategories}" var="category" itemValue="#{category}" itemLabel="#{beanHelper.renderProductCategory(category)}" />
+                                                       <f:selectItems value="#{categoryListController.allCategories}" var="category" itemValue="#{category}" itemLabel="#{productBeanHelper.renderProductCategory(category)}" />
                                                </p:selectCheckboxMenu>
                                        </f:facet>
 
                        </p:dialog>
                </h:form>
 
-               <h:form>
+               <h:form id="form-add-product">
                        <p:panelGrid columns="1" styleClass="table table-full" layout="grid">
                                <f:facet name="header">
                                        <h:outputText value="#{project.ADMIN_ADD_GENERIC_PRODUCT_TITLE}" />
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 (file)
index 0000000..ffa1dec
--- /dev/null
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<ui:composition template="/WEB-INF/templates/admin/admin_base.tpl"
+                               xmlns="http://www.w3.org/1999/xhtml"
+                               xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
+                               xmlns:h="http://xmlns.jcp.org/jsf/html"
+                               xmlns:f="http://xmlns.jcp.org/jsf/core"
+                               xmlns:p="http://primefaces.org/ui"
+                               >
+
+       <ui:define name="metadata">
+               <f:metadata>
+                       <f:viewParam id="productId" name="productId" value="#{productBeanHelper.product}" converter="GenericProductConverter" required="true" requiredMessage="#{project.ERROR_PARAMETER_PRODUCT_ID_NOT_SET}" converterMessage="#{project.PARAMETER_PRODUCT_ID_INVALID}" />
+                       <f:viewAction onPostback="true" action="#{productBeanHelper.notifyControllerProductConverted()}" />
+               </f:metadata>
+       </ui:define>
+
+       <ui:define name="document_admin_title">
+               <h:outputText value="#{project.PAGE_TITLE_ADMIN_SHOW_GENERIC_PRODUCT}" />
+       </ui:define>
+
+       <ui:define name="content_header">
+               <h:outputText value="#{project.CONTENT_TITLE_ADMIN_SHOW_GENERIC_PRODUCT}" />
+       </ui:define>
+
+       <ui:define name="content">
+               <p:message for="productId" showSummary="true" />
+               <!-- @TODO Here goes your content. //-->
+       </ui:define>
+</ui:composition>
index a2d215e47f6bc03b3039bf9f8f548a8d270ae010..0b90adf16c418bd19940c8f9a981fce896ca3980 100644 (file)
@@ -83,7 +83,7 @@
                                                        title="#{project.FILTER_BY_MULTIPLE_PRODUCT_CATEGORIES_TITLE}"
                                                        >
                                                        <f:converter converterId="ProductCategoryConverter" />
-                                                       <f:selectItems value="#{categoryListController.allCategories}" var="category" itemValue="#{category}" itemLabel="#{beanHelper.renderProductCategory(category)}" />
+                                                       <f:selectItems value="#{categoryListController.allCategories}" var="category" itemValue="#{category}" itemLabel="#{productBeanHelper.renderProductCategory(category)}" />
                                                </p:selectCheckboxMenu>
                                        </f:facet>
 
                        </p:dialog>
                </h:form>
 
-               <h:form>
+               <h:form id="form-add-category">
                        <p:panelGrid columns="1" styleClass="table table-full" layout="grid">
                                <f:facet name="header">
                                        <h:outputText value="#{project.ADMIN_ADD_PRODUCT_CATEGORY_TITLE}" />