From c82d19508f64a9e3dafbc0bedc349f4fb8a1e2e1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 8 Apr 2020 20:59:37 +0200 Subject: [PATCH] Product-only: - moved addProduct() method to "admin-product-action" controller MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../FinancialAdminProductWebRequestBean.java | 446 ------------------ ...lAdminGenericProductActionWebViewBean.java | 116 +++-- 2 files changed, 78 insertions(+), 484 deletions(-) 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 9c24e3df..f422320e 100644 --- a/src/java/org/mxchange/jfinancials/beans/generic_product/FinancialAdminProductWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/generic_product/FinancialAdminProductWebRequestBean.java @@ -16,25 +16,9 @@ */ package org.mxchange.jfinancials.beans.generic_product; -import java.math.BigDecimal; -import javax.ejb.EJB; import javax.enterprise.context.RequestScoped; -import javax.enterprise.event.Event; -import javax.enterprise.inject.Any; -import javax.faces.view.facelets.FaceletException; -import javax.inject.Inject; 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.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; -import org.mxchange.jproduct.model.product.GenericProduct; -import org.mxchange.jproduct.model.product.Product; -import org.mxchange.jproduct.model.product.agegroup.AgeGroup; /** * Main application class @@ -50,100 +34,6 @@ public class FinancialAdminProductWebRequestBean extends BaseFinancialsBean impl */ private static final long serialVersionUID = 5_819_375_183_472_871L; - /** - * Event for added product - */ - @Inject - @Any - private Event addedProductEvent; - - /** - * Remote bean for products - */ - @EJB (lookup = "java:global/jfinancials-ejb/adminProduct!org.mxchange.jproduct.model.product.AdminProductSessionBeanRemote") - private AdminProductSessionBeanRemote adminProductBean; - - /** - * Product's age group - */ - private AgeGroup productAgeGroup; - - /** - * Availability - */ - private Boolean productAvailability; - - /** - * Barcode number - */ - private String productBarCodeNumber; - - /** - * Category instance - */ - private Category productCategory; - - /** - * Product's price currency code like EUR or USD - */ - private String productCurrencyCode; - - /** - * Product's gross price - */ - private BigDecimal productGrossPrice; - - /** - * I18n key of product - */ - private String productI18nKey; - - /** - * Product id - */ - private Long productId; - - /** - * Product list controller - */ - @Inject - private FinancialsProductListWebViewController productListController; - - /** - * Product's manufacturing/producing company - */ - private BasicData productManufacturer; - - /** - * Product's net price - */ - private BigDecimal productNetPrice; - - /** - * Product number - */ - private Long productNumber; - - /** - * Product size (for shoes, clothings) - */ - private String productSize; - - /** - * Product's tax rate - */ - private BigDecimal productTaxRate; - - /** - * Product's unit amount - */ - private BigDecimal productUnitAmount; - - /** - * Product's i18n key - */ - private String productUnitI18nKey; - /** * Default constructor */ @@ -152,340 +42,4 @@ public class FinancialAdminProductWebRequestBean extends BaseFinancialsBean impl super(); } - /** - * Adds given product data from request to database - *

- * @throws FaceletException If something unexpected happened - */ - public void addProduct () throws FaceletException { - // Is product i18n key already used? - if (this.productListController.isProductI18nKeyAdded(this.getProductI18nKey())) { - // Then throw exception - throw new FaceletException("Product i18n key " + this.getProductI18nKey() + " already added."); - } - - // Create product instance - final Product product = this.createProductInstance(); - - // Declare updated product instance - final Product updatedProduct; - - try { - // Call EJB - updatedProduct = this.adminProductBean.addGenericProduct(product); - } catch (final ProductAlreadyAddedException ex) { - // Continue to throw - throw new FaceletException(ex); - } - - // Fire event - this.addedProductEvent.fire(new ProductAddedEvent(updatedProduct)); - } - - /** - * Getter for product's age group - *

- * @return Product's age group - */ - public AgeGroup getProductAgeGroup () { - return this.productAgeGroup; - } - - /** - * Setter for product's age group - *

- * @param productAgeGroup Product's age group - */ - public void setProductAgeGroup (final AgeGroup productAgeGroup) { - this.productAgeGroup = productAgeGroup; - } - - /** - * Getter for product's available - *

- * @return Product's available - */ - public Boolean getProductAvailability () { - return this.productAvailability; - } - - /** - * Setter for product's available - *

- * @param productAvailability Product's available - */ - public void setProductAvailability (final Boolean productAvailability) { - this.productAvailability = productAvailability; - } - - /** - * Getter for product's bar-code number - *

- * @return Product's bar-code number - */ - public String getProductBarCodeNumber () { - return this.productBarCodeNumber; - } - - /** - * Setter for product's bar-code number - *

- * @param productBarCodeNumber Product's bar-code number - */ - public void setProductBarCodeNumber (final String productBarCodeNumber) { - this.productBarCodeNumber = productBarCodeNumber; - } - - /** - * Getter for product's category - *

- * @return Product's category - */ - public Category getProductCategory () { - return this.productCategory; - } - - /** - * Setter for product's category instance - *

- * @param productCategory Product's category instance - */ - public void setProductCategory (final Category productCategory) { - this.productCategory = productCategory; - } - - /** - * Getter for product's price currency code - *

- * @return Product's price currency code - */ - public String getProductCurrencyCode () { - return this.productCurrencyCode; - } - - /** - * Setter for product's price currency code - *

- * @param productCurrencyCode Product's price currency code - */ - public void setProductCurrencyCode (final String productCurrencyCode) { - this.productCurrencyCode = productCurrencyCode; - } - - /** - * Getter for product's gross price - *

- * @return Product's gross price - */ - public BigDecimal getProductGrossPrice () { - return this.productGrossPrice; - } - - /** - * Setter for product's gross price - *

- * @param productGrossPrice Product's gross price - */ - public void setProductGrossPrice (final BigDecimal productGrossPrice) { - this.productGrossPrice = productGrossPrice; - } - - /** - * Getter for product unit's i18n key - *

- * @return Product's i18n key - */ - public String getProductI18nKey () { - return this.productI18nKey; - } - - /** - * Setter for product unit's i18n key - *

- * @param productI18nKey Product's i18n key - */ - public void setProductI18nKey (final String productI18nKey) { - this.productI18nKey = productI18nKey; - } - - /** - * Getter for product id - *

- * @return Product id - */ - public Long getProductId () { - return this.productId; - } - - /** - * Setter for product id - *

- * @param productId Product id - */ - public void setProductId (final Long productId) { - this.productId = productId; - } - - /** - * Getter for product's manufacturing/producing company - *

- * @return Product's manufacturing/producing company - */ - public BasicData getProductManufacturer () { - return this.productManufacturer; - } - - /** - * Setter for product's manufacturing/producing company - *

- * @param productManufacturer Product's manufacturing/producing company - */ - public void setProductManufacturer (final BasicData productManufacturer) { - this.productManufacturer = productManufacturer; - } - - /** - * Getter for product's net price - *

- * @return Product's net price - */ - public BigDecimal getProductNetPrice () { - return this.productNetPrice; - } - - /** - * Setter for product's net price - *

- * @param productNetPrice Product's net price - */ - public void setProductNetPrice (final BigDecimal productNetPrice) { - this.productNetPrice = productNetPrice; - } - - /** - * Getter for product's number - *

- * @return Product's number - */ - public Long getProductNumber () { - return this.productNumber; - } - - /** - * Setter for product's number - *

- * @param productNumber Product's number - */ - public void setProductNumber (final Long productNumber) { - this.productNumber = productNumber; - } - - /** - * Getter for product's size - *

- * @return Product's size - */ - public String getProductSize () { - return this.productSize; - } - - /** - * Setter for product's size - *

- * @param productSize Product's size - */ - public void setProductSize (final String productSize) { - this.productSize = productSize; - } - - /** - * Getter for product's tax rate - *

- * @return Product's tax rate - */ - public BigDecimal getProductTaxRate () { - return this.productTaxRate; - } - - /** - * Setter for product's tax rate - *

- * @param productTaxRate Product's tax rate - */ - public void setProductTaxRate (final BigDecimal productTaxRate) { - this.productTaxRate = productTaxRate; - } - - /** - * Getter for product's unit amount - *

- * @return Product's unit amount - */ - public BigDecimal getProductUnitAmount () { - return this.productUnitAmount; - } - - /** - * Setter for product's unit amount - *

- * @param productUnitAmount Product's unit amount - */ - public void setProductUnitAmount (final BigDecimal productUnitAmount) { - this.productUnitAmount = productUnitAmount; - } - - /** - * Getter for product unit's i18n key - *

- * @return Product's i18n key - */ - public String getProductUnitI18nKey () { - return this.productUnitI18nKey; - } - - /** - * Setter for product unit's i18n key - *

- * @param productUnitI18nKey Product unit's i18n key - */ - public void setProductUnitI18nKey (final String productUnitI18nKey) { - this.productUnitI18nKey = productUnitI18nKey; - } - - /** - * Creates a product instance with all fields - *

- * @return Product instance - */ - private Product createProductInstance () { - // Create product instance - final Product product = new GenericProduct( - this.getProductI18nKey(), - this.getProductGrossPrice(), - this.getProductCurrencyCode(), - this.getProductCategory(), - this.getProductAvailability(), - this.getProductUnitAmount(), - this.getProductUnitI18nKey() - ); - - // Set all optional fields - product.setProductAgeGroup(this.getProductAgeGroup()); - product.setProductBarCodeNumber(this.getProductBarCodeNumber()); - product.setProductManufacturer(this.getProductManufacturer()); - product.setProductNumber(this.getProductNumber()); - product.setProductNetPrice(this.getProductNetPrice()); - product.setProductSize(this.getProductSize()); - product.setProductTaxRate(this.getProductTaxRate()); - - // Is product id set? - if (this.getProductId() instanceof Long) { - // Set it, too - product.setProductId(this.getProductId()); - } - - // Return it - return product; - } - } diff --git a/src/java/org/mxchange/jfinancials/beans/generic_product/action/FinancialAdminGenericProductActionWebViewBean.java b/src/java/org/mxchange/jfinancials/beans/generic_product/action/FinancialAdminGenericProductActionWebViewBean.java index 4422c5b2..cad332b4 100644 --- a/src/java/org/mxchange/jfinancials/beans/generic_product/action/FinancialAdminGenericProductActionWebViewBean.java +++ b/src/java/org/mxchange/jfinancials/beans/generic_product/action/FinancialAdminGenericProductActionWebViewBean.java @@ -28,8 +28,11 @@ 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.added.AddedProductEvent; +import org.mxchange.jproduct.events.product.added.ProductAddedEvent; import org.mxchange.jproduct.events.product.updated.ObservableProductUpdatedEvent; import org.mxchange.jproduct.events.product.updated.ProductUpdatedEvent; +import org.mxchange.jproduct.exceptions.product.ProductAlreadyAddedException; import org.mxchange.jproduct.exceptions.product.ProductNotFoundException; import org.mxchange.jproduct.model.category.Category; import org.mxchange.jproduct.model.product.AdminProductSessionBeanRemote; @@ -51,6 +54,13 @@ public class FinancialAdminGenericProductActionWebViewBean extends BaseFinancial */ private static final long serialVersionUID = 5_819_375_183_472_872L; + /** + * Event for added currentProduct + */ + @Inject + @Any + private Event addedProductEvent; + /** * Remote bean for products */ @@ -60,7 +70,7 @@ public class FinancialAdminGenericProductActionWebViewBean extends BaseFinancial /** * Product instance */ - private Product product; + private Product currentProduct; /** * Product's age group @@ -93,7 +103,7 @@ public class FinancialAdminGenericProductActionWebViewBean extends BaseFinancial private BigDecimal productGrossPrice; /** - * I18n key of product + * I18n key of currentProduct */ private String productI18nKey; @@ -144,7 +154,7 @@ public class FinancialAdminGenericProductActionWebViewBean extends BaseFinancial private String productUnitI18nKey; /** - * Event for updated product + * Event for updated currentProduct */ @Inject @Any @@ -159,55 +169,85 @@ public class FinancialAdminGenericProductActionWebViewBean extends BaseFinancial } /** - * Copies all product's properties back to this bean. + * Adds given product data from request to database + *

+ * @throws FaceletException If something unexpected happened + */ + public void addProduct () throws FaceletException { + // Is product i18n key already used? + if (this.productListController.isProductI18nKeyAdded(this.getProductI18nKey())) { + // Then throw exception + throw new FaceletException("Product i18n key " + this.getProductI18nKey() + " already added."); + } + + // Create current product instance + final Product product = this.createProductInstance(); + + // Declare updated current product instance + final Product updatedProduct; + + try { + // Call EJB + updatedProduct = this.adminProductBean.addGenericProduct(product); + } catch (final ProductAlreadyAddedException ex) { + // Continue to throw + throw new FaceletException(ex); + } + + // Fire event + this.addedProductEvent.fire(new ProductAddedEvent(updatedProduct)); + } + + /** + * Copies all currentProduct's properties back to this bean. */ public void copyAllProductProperties () { - // Validate product instance - if (this.getProduct() == null) { + // Validate current product instance + if (this.getCurrentProduct() == null) { // Throw NPE throw new NullPointerException("this.product is null"); //NOI18N - } else if (this.getProduct().getProductId() == null) { + } else if (this.getCurrentProduct().getProductId() == null) { // Throw NPE again throw new NullPointerException("this.product.productId is null"); //NOI18N - } else if (this.getProduct().getProductId() < 1) { + } else if (this.getCurrentProduct().getProductId() < 1) { // Not valid - throw new IllegalStateException(MessageFormat.format("this.product.productId={0} is not valid.", this.getProduct().getProductId())); //NOI18N + throw new IllegalStateException(MessageFormat.format("this.product.productId={0} is not valid.", this.getCurrentProduct().getProductId())); //NOI18N } // Now copy all fields - this.setProductAgeGroup(this.getProduct().getProductAgeGroup()); - this.setProductAvailability(this.getProduct().getProductAvailability()); - this.setProductBarCodeNumber(this.getProduct().getProductBarCodeNumber()); - this.setProductCategory(this.getProduct().getProductCategory()); - this.setProductCurrencyCode(this.getProduct().getProductCurrencyCode()); - this.setProductGrossPrice(this.getProduct().getProductGrossPrice()); - this.setProductI18nKey(this.getProduct().getProductI18nKey()); - this.setProductId(this.getProduct().getProductId()); - this.setProductManufacturer(this.getProduct().getProductManufacturer()); - this.setProductNetPrice(this.getProduct().getProductNetPrice()); - this.setProductNumber(this.getProduct().getProductNumber()); - this.setProductSize(this.getProduct().getProductSize()); - this.setProductTaxRate(this.getProduct().getProductTaxRate()); - this.setProductUnitAmount(this.getProduct().getProductUnitAmount()); - this.setProductUnitI18nKey(this.getProduct().getProductUnitI18nKey()); - } - - /** - * Getter for product instance + this.setProductAgeGroup(this.getCurrentProduct().getProductAgeGroup()); + this.setProductAvailability(this.getCurrentProduct().getProductAvailability()); + this.setProductBarCodeNumber(this.getCurrentProduct().getProductBarCodeNumber()); + this.setProductCategory(this.getCurrentProduct().getProductCategory()); + this.setProductCurrencyCode(this.getCurrentProduct().getProductCurrencyCode()); + this.setProductGrossPrice(this.getCurrentProduct().getProductGrossPrice()); + this.setProductI18nKey(this.getCurrentProduct().getProductI18nKey()); + this.setProductId(this.getCurrentProduct().getProductId()); + this.setProductManufacturer(this.getCurrentProduct().getProductManufacturer()); + this.setProductNetPrice(this.getCurrentProduct().getProductNetPrice()); + this.setProductNumber(this.getCurrentProduct().getProductNumber()); + this.setProductSize(this.getCurrentProduct().getProductSize()); + this.setProductTaxRate(this.getCurrentProduct().getProductTaxRate()); + this.setProductUnitAmount(this.getCurrentProduct().getProductUnitAmount()); + this.setProductUnitI18nKey(this.getCurrentProduct().getProductUnitI18nKey()); + } + + /** + * Getter for current product instance *

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

- * @param product Product instance + * @param currentProduct Current product instance */ - public void setProduct (final Product product) { - this.product = product; + public void setCurrentProduct (final Product currentProduct) { + this.currentProduct = currentProduct; } /** @@ -486,10 +526,10 @@ public class FinancialAdminGenericProductActionWebViewBean extends BaseFinancial * @throws FaceletException If something unexpected happened */ public void updateProduct () throws FaceletException { - // Get product instance + // Get new product instance final Product newProduct = this.createProductInstance(); - // Check if product instance is in helper and valid + // Check if current product instance is in helper and valid if (null == newProduct) { // Throw NPE throw new NullPointerException("newProduct is null"); //NOI18N @@ -541,12 +581,12 @@ public class FinancialAdminGenericProductActionWebViewBean extends BaseFinancial } /** - * Creates a product instance with all fields + * Creates a new product instance with all fields *

* @return Product instance */ private Product createProductInstance () { - // Create product instance + // Create new product instance final Product newProduct = new GenericProduct( this.getProductI18nKey(), this.getProductGrossPrice(), -- 2.39.5