*/
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
*/
private static final long serialVersionUID = 5_819_375_183_472_871L;
- /**
- * Event for added product
- */
- @Inject
- @Any
- private Event<AddedProductEvent> 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
*/
super();
}
- /**
- * Adds given product data from request to database
- * <p>
- * @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
- * <p>
- * @return Product's age group
- */
- public AgeGroup getProductAgeGroup () {
- return this.productAgeGroup;
- }
-
- /**
- * Setter for product's age group
- * <p>
- * @param productAgeGroup Product's age group
- */
- public void setProductAgeGroup (final AgeGroup productAgeGroup) {
- this.productAgeGroup = productAgeGroup;
- }
-
- /**
- * Getter for product's available
- * <p>
- * @return Product's available
- */
- public Boolean getProductAvailability () {
- return this.productAvailability;
- }
-
- /**
- * Setter for product's available
- * <p>
- * @param productAvailability Product's available
- */
- public void setProductAvailability (final Boolean productAvailability) {
- this.productAvailability = productAvailability;
- }
-
- /**
- * Getter for product's bar-code number
- * <p>
- * @return Product's bar-code number
- */
- public String getProductBarCodeNumber () {
- return this.productBarCodeNumber;
- }
-
- /**
- * Setter for product's bar-code number
- * <p>
- * @param productBarCodeNumber Product's bar-code number
- */
- public void setProductBarCodeNumber (final String productBarCodeNumber) {
- this.productBarCodeNumber = productBarCodeNumber;
- }
-
- /**
- * Getter for product's category
- * <p>
- * @return Product's category
- */
- public Category getProductCategory () {
- return this.productCategory;
- }
-
- /**
- * Setter for product's category instance
- * <p>
- * @param productCategory Product's category instance
- */
- public void setProductCategory (final Category productCategory) {
- this.productCategory = productCategory;
- }
-
- /**
- * Getter for product's price currency code
- * <p>
- * @return Product's price currency code
- */
- public String getProductCurrencyCode () {
- return this.productCurrencyCode;
- }
-
- /**
- * Setter for product's price currency code
- * <p>
- * @param productCurrencyCode Product's price currency code
- */
- public void setProductCurrencyCode (final String productCurrencyCode) {
- this.productCurrencyCode = productCurrencyCode;
- }
-
- /**
- * Getter for product's gross price
- * <p>
- * @return Product's gross price
- */
- public BigDecimal getProductGrossPrice () {
- return this.productGrossPrice;
- }
-
- /**
- * Setter for product's gross price
- * <p>
- * @param productGrossPrice Product's gross price
- */
- public void setProductGrossPrice (final BigDecimal productGrossPrice) {
- this.productGrossPrice = productGrossPrice;
- }
-
- /**
- * Getter for product unit's i18n key
- * <p>
- * @return Product's i18n key
- */
- public String getProductI18nKey () {
- return this.productI18nKey;
- }
-
- /**
- * Setter for product unit's i18n key
- * <p>
- * @param productI18nKey Product's i18n key
- */
- public void setProductI18nKey (final String productI18nKey) {
- this.productI18nKey = productI18nKey;
- }
-
- /**
- * Getter for product id
- * <p>
- * @return Product id
- */
- public Long getProductId () {
- return this.productId;
- }
-
- /**
- * Setter for product id
- * <p>
- * @param productId Product id
- */
- public void setProductId (final Long productId) {
- this.productId = productId;
- }
-
- /**
- * Getter for product's manufacturing/producing company
- * <p>
- * @return Product's manufacturing/producing company
- */
- public BasicData getProductManufacturer () {
- return this.productManufacturer;
- }
-
- /**
- * Setter for product's manufacturing/producing company
- * <p>
- * @param productManufacturer Product's manufacturing/producing company
- */
- public void setProductManufacturer (final BasicData productManufacturer) {
- this.productManufacturer = productManufacturer;
- }
-
- /**
- * Getter for product's net price
- * <p>
- * @return Product's net price
- */
- public BigDecimal getProductNetPrice () {
- return this.productNetPrice;
- }
-
- /**
- * Setter for product's net price
- * <p>
- * @param productNetPrice Product's net price
- */
- public void setProductNetPrice (final BigDecimal productNetPrice) {
- this.productNetPrice = productNetPrice;
- }
-
- /**
- * Getter for product's number
- * <p>
- * @return Product's number
- */
- public Long getProductNumber () {
- return this.productNumber;
- }
-
- /**
- * Setter for product's number
- * <p>
- * @param productNumber Product's number
- */
- public void setProductNumber (final Long productNumber) {
- this.productNumber = productNumber;
- }
-
- /**
- * Getter for product's size
- * <p>
- * @return Product's size
- */
- public String getProductSize () {
- return this.productSize;
- }
-
- /**
- * Setter for product's size
- * <p>
- * @param productSize Product's size
- */
- public void setProductSize (final String productSize) {
- this.productSize = productSize;
- }
-
- /**
- * Getter for product's tax rate
- * <p>
- * @return Product's tax rate
- */
- public BigDecimal getProductTaxRate () {
- return this.productTaxRate;
- }
-
- /**
- * Setter for product's tax rate
- * <p>
- * @param productTaxRate Product's tax rate
- */
- public void setProductTaxRate (final BigDecimal productTaxRate) {
- this.productTaxRate = productTaxRate;
- }
-
- /**
- * Getter for product's unit amount
- * <p>
- * @return Product's unit amount
- */
- public BigDecimal getProductUnitAmount () {
- return this.productUnitAmount;
- }
-
- /**
- * Setter for product's unit amount
- * <p>
- * @param productUnitAmount Product's unit amount
- */
- public void setProductUnitAmount (final BigDecimal productUnitAmount) {
- this.productUnitAmount = productUnitAmount;
- }
-
- /**
- * Getter for product unit's i18n key
- * <p>
- * @return Product's i18n key
- */
- public String getProductUnitI18nKey () {
- return this.productUnitI18nKey;
- }
-
- /**
- * Setter for product unit's i18n key
- * <p>
- * @param productUnitI18nKey Product unit's i18n key
- */
- public void setProductUnitI18nKey (final String productUnitI18nKey) {
- this.productUnitI18nKey = productUnitI18nKey;
- }
-
- /**
- * Creates a product instance with all fields
- * <p>
- * @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;
- }
-
}
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;
*/
private static final long serialVersionUID = 5_819_375_183_472_872L;
+ /**
+ * Event for added currentProduct
+ */
+ @Inject
+ @Any
+ private Event<AddedProductEvent> addedProductEvent;
+
/**
* Remote bean for products
*/
/**
* Product instance
*/
- private Product product;
+ private Product currentProduct;
/**
* Product's age group
private BigDecimal productGrossPrice;
/**
- * I18n key of product
+ * I18n key of currentProduct
*/
private String productI18nKey;
private String productUnitI18nKey;
/**
- * Event for updated product
+ * Event for updated currentProduct
*/
@Inject
@Any
}
/**
- * Copies all product's properties back to this bean.
+ * Adds given product data from request to database
+ * <p>
+ * @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
* <p>
* @return Product instance
*/
- public Product getProduct () {
- return this.product;
+ public Product getCurrentProduct () {
+ return this.currentProduct;
}
/**
- * Setter for product instance
+ * Setter for current product instance
* <p>
- * @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;
}
/**
* @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
}
/**
- * Creates a product instance with all fields
+ * Creates a new product instance with all fields
* <p>
* @return Product instance
*/
private Product createProductInstance () {
- // Create product instance
+ // Create new product instance
final Product newProduct = new GenericProduct(
this.getProductI18nKey(),
this.getProductGrossPrice(),