From: Roland Häder Date: Thu, 26 Oct 2017 18:27:14 +0000 (+0200) Subject: Maybe cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c66cf69bcc74d437f222ac09c73c1135f518e00d;p=jfinancials-war.git Maybe cherry-pick: - updated add methods to new way: + create a private createInstance() which copies all fields from backing bean to entity class + invoke that method before try/catch block + only cover method invocations in try() block that are really necessarry to catch thrown exceptions, e.g. clear() will never throw an exception, unless you make somthing *REALLY* horrible wrong + events should be fired after try/catch blocks, so the updated instance be declared before it (not initialized) Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jfinancials/beans/category/FinancialAdminCategoryWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/category/FinancialAdminCategoryWebRequestBean.java index ff82752b..3a746f2c 100644 --- a/src/java/org/mxchange/jfinancials/beans/category/FinancialAdminCategoryWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/category/FinancialAdminCategoryWebRequestBean.java @@ -55,9 +55,14 @@ public class FinancialAdminCategoryWebRequestBean extends BaseFinancialsBean imp /** * Remote bean for categories */ - @EJB(lookup = "java:global/jfinancials-ejb/adminCategory!org.mxchange.jproduct.model.category.AdminCategorySessionBeanRemote") + @EJB (lookup = "java:global/jfinancials-ejb/adminCategory!org.mxchange.jproduct.model.category.AdminCategorySessionBeanRemote") private AdminCategorySessionBeanRemote categoryBean; + /** + * Whether this category is shown in statistics + */ + private Boolean categoryShownInStatistics; + /** * Category categoryTitle */ @@ -83,26 +88,43 @@ public class FinancialAdminCategoryWebRequestBean extends BaseFinancialsBean imp * unexpected happened */ public void addCategory () throws FaceletException { - try { - // Create category - final Category category = new ProductCategory(); + // Create category + final Category category = this.createCategoryInstance(); - // Set fields - category.setParentCategory(this.getParentCategory()); - category.setCategoryTitle(this.getCategoryTitle()); + // Declare updated category instance + final Category updatedCategory; + try { // Deligate to remote bean - final Category updatedCategory = this.categoryBean.addProductCategory(category); - - // Fire event - this.categoryAddedEvent.fire(new CategoryAddedEvent(updatedCategory)); - - // Unset all older values - this.clear(); + updatedCategory = this.categoryBean.addProductCategory(category); } catch (final CategoryAlreadyAddedException ex) { // Continue to throw throw new FaceletException(ex); } + + // Fire event + this.categoryAddedEvent.fire(new CategoryAddedEvent(updatedCategory)); + + // Unset all older values + this.clear(); + } + + /** + * 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; } /** @@ -145,8 +167,22 @@ public class FinancialAdminCategoryWebRequestBean extends BaseFinancialsBean imp * Clears this bean (example: when category has been added) */ private void clear () { - this.setCategoryTitle(""); //NOI18N + // Clear all fields + this.setCategoryTitle(null); this.setParentCategory(null); } + /** + * Creates a category instance with all fields (except primary key) + *

+ * @return Category instance + */ + private Category createCategoryInstance () { + // Create category + final Category category = new ProductCategory(this.getCategoryTitle(), this.getParentCategory(), this.getCategoryShownInStatistics()); + + // Return it + return category; + } + } diff --git a/src/java/org/mxchange/jfinancials/beans/helper/FinancialsWebRequestHelperBean.java b/src/java/org/mxchange/jfinancials/beans/helper/FinancialsWebRequestHelperBean.java index 674b63f8..e07d84d9 100644 --- a/src/java/org/mxchange/jfinancials/beans/helper/FinancialsWebRequestHelperBean.java +++ b/src/java/org/mxchange/jfinancials/beans/helper/FinancialsWebRequestHelperBean.java @@ -27,6 +27,7 @@ import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEve import org.mxchange.jcontacts.model.contact.Contact; import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; import org.mxchange.jcontactsbusiness.model.department.Department; +import org.mxchange.jcontactsbusiness.model.employee.Employable; import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData; import org.mxchange.jfinancials.beans.BaseFinancialsBean; import org.mxchange.jfinancials.beans.localization.FinancialsLocalizationSessionController; @@ -45,7 +46,6 @@ import org.mxchange.jproduct.model.product.Product; import org.mxchange.jusercore.events.user.created.CreatedUserEvent; import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent; import org.mxchange.jusercore.model.user.User; -import org.mxchange.jcontactsbusiness.model.employee.Employable; /** * A general helper for beans @@ -527,7 +527,7 @@ public class FinancialsWebRequestHelperBean extends BaseFinancialsBean implement * available. If null is provided, an empty string is returned. *

* @param employee Employable instance -

+ *

* @return Contact's full name */ public String renderEmployee (final Employable employee) { @@ -628,7 +628,7 @@ public class FinancialsWebRequestHelperBean extends BaseFinancialsBean implement // Add name and price sb.append(product.getProductTitle()); sb.append(" ("); //NOI18N - sb.append(this.localizationController.formatCurrency(product.getProductPrice())); + sb.append(this.localizationController.formatCurrency(product.getProductGrossPrice())); sb.append(")"); //NOI18N } @@ -637,8 +637,7 @@ public class FinancialsWebRequestHelperBean extends BaseFinancialsBean implement } /** - * Returns the receipt. If null is provided, an empty string - * is returned. + * Returns the receipt. If null is provided, an empty string is returned. *

* @param receipt Receipt instance *

@@ -655,7 +654,7 @@ public class FinancialsWebRequestHelperBean extends BaseFinancialsBean implement sb.append(this.getMessageFromBundle(receipt.getReceiptPaymentType().getI18nKey())); // Is receipt number included? - if (receipt.getReceiptNumber() !=null) { + if (receipt.getReceiptNumber() != null) { // Append it sb.append(", ").append(this.getMessageFromBundle("RECEIPT_NUMBER")).append(" "); //NOI18N sb.append(receipt.getReceiptNumber()); diff --git a/src/java/org/mxchange/jfinancials/beans/product/FinancialAdminProductWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/product/FinancialAdminProductWebRequestBean.java index 8419a169..e212f615 100644 --- a/src/java/org/mxchange/jfinancials/beans/product/FinancialAdminProductWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/product/FinancialAdminProductWebRequestBean.java @@ -64,9 +64,14 @@ public class FinancialAdminProductWebRequestBean extends BaseFinancialsBean impl private Category productCategory; /** - * Property productPrice + * Product's gross price */ - private Float productPrice; + private Float productGrossPrice; + + /** + * Product's net price + */ + private Float productNetPrice; /** * Remote bean for products @@ -74,6 +79,11 @@ public class FinancialAdminProductWebRequestBean extends BaseFinancialsBean impl @EJB (lookup = "java:global/jfinancial-ejb/adminProduct!org.mxchange.jproduct.model.product.AdminProductSessionBeanRemote") private AdminProductSessionBeanRemote productRemoteBean; + /** + * Product's tax rate + */ + private Float productTaxRate; + /** * Property productTitle */ @@ -90,32 +100,28 @@ public class FinancialAdminProductWebRequestBean extends BaseFinancialsBean impl /** * Adds given product data from request to database *

- * @throws javax.faces.view.facelets.FaceletException If something - * unexpected happened + * @throws FaceletException If something unexpected happened */ public void addProduct () throws FaceletException { - try { - // Create product instance - final Product product = new GenericProduct(); + // Create product instance + final Product product = this.createProductInstance(); - // Add all - product.setProductAvailability(this.getProductAvailability()); - product.setProductCategory(this.getProductCategory()); - product.setProductPrice(this.getProductPrice()); - product.setProductTitle(this.getProductTitle()); + // Declare updated product instance + final Product updatedProduct; + try { // Call bean - final Product updatedProduct = this.productRemoteBean.addGenericProduct(product); - - // Fire event - this.addedProductEvent.fire(new ProductAddedEvent(updatedProduct)); - - // Set all to null - this.clear(); + updatedProduct = this.productRemoteBean.addGenericProduct(product); } catch (final ProductAlreadyAddedException ex) { // Continue to throw throw new FaceletException(ex); } + + // Fire event + this.addedProductEvent.fire(new ProductAddedEvent(updatedProduct)); + + // Set all to null + this.clear(); } /** @@ -155,21 +161,57 @@ public class FinancialAdminProductWebRequestBean extends BaseFinancialsBean impl } /** - * Getter for product's price property + * Getter for product's gross price + *

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

- * @return Product's price property + * @param productGrossPrice Product's gross price */ - public Float getProductPrice () { - return this.productPrice; + public void setProductGrossPrice (final Float productGrossPrice) { + this.productGrossPrice = productGrossPrice; } /** - * Setter for product's price property + * Getter for product's net price *

- * @param productPrice Product's price property + * @return Product's net price */ - public void setProductPrice (final Float productPrice) { - this.productPrice = productPrice; + public Float getProductNetPrice () { + return this.productNetPrice; + } + + /** + * Setter for product's net price + *

+ * @param productNetPrice Product's net price + */ + public void setProductNetPrice (final Float productNetPrice) { + this.productNetPrice = productNetPrice; + } + + /** + * Getter for product's tax rate + *

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

+ * @param productTaxRate Product's tax rate + */ + public void setProductTaxRate (final Float productTaxRate) { + this.productTaxRate = productTaxRate; } /** @@ -196,8 +238,27 @@ public class FinancialAdminProductWebRequestBean extends BaseFinancialsBean impl private void clear () { this.setProductAvailability(Boolean.FALSE); this.setProductCategory(null); - this.setProductPrice(null); + this.setProductNetPrice(null); + this.setProductTaxRate(null); + this.setProductGrossPrice(null); this.setProductTitle(null); } + /** + * Creates a product instance with all fields + *

+ * @return Product instance + */ + private Product createProductInstance () { + // Create product instance + final Product product = new GenericProduct(this.getProductTitle(), this.getProductGrossPrice(), this.getProductCategory(), this.getProductAvailability()); + + // Set all optional fields + product.setProductNetPrice(this.getProductNetPrice()); + product.setProductTaxRate(this.getProductTaxRate()); + + // Return it + return product; + } + }