]> git.mxchange.org Git - jfinancials-war.git/commitdiff
Maybe cherry-pick:
authorRoland Häder <roland@mxchange.org>
Thu, 26 Oct 2017 18:27:14 +0000 (20:27 +0200)
committerRoland Häder <roland@mxchange.org>
Thu, 26 Oct 2017 18:29:55 +0000 (20:29 +0200)
- updated add methods to new way:
  + create a private create<Entity>Instance() 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<Entity>
    instance be declared before it (not initialized)

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jfinancials/beans/category/FinancialAdminCategoryWebRequestBean.java
src/java/org/mxchange/jfinancials/beans/helper/FinancialsWebRequestHelperBean.java
src/java/org/mxchange/jfinancials/beans/product/FinancialAdminProductWebRequestBean.java

index ff82752b368b05d572776ff3393d2ed34c791ab1..3a746f2c58e18913d3248565ccbfc7759592974c 100644 (file)
@@ -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
+        * <p>
+        * @return Whether category is shown in statistics
+        */
+       public Boolean getCategoryShownInStatistics () {
+               return this.categoryShownInStatistics;
+       }
+
+       /**
+        * Setter for whether category is shown in statistics
+        * <p>
+        * @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)
+        * <p>
+        * @return Category instance
+        */
+       private Category createCategoryInstance () {
+               // Create category
+               final Category category = new ProductCategory(this.getCategoryTitle(), this.getParentCategory(), this.getCategoryShownInStatistics());
+
+               // Return it
+               return category;
+       }
+
 }
index 674b63f8dcb7f9298d472e3c50544b53d28a193e..e07d84d97f554e59d613693c1c4b02d28f3b5a28 100644 (file)
@@ -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.
         * <p>
         * @param employee Employable instance
- <p>
       * <p>
         * @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.
         * <p>
         * @param receipt Receipt instance
         * <p>
@@ -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());
index 8419a1692e7bc5db286055c39db4a0585b9817d8..e212f6156e6b09ff0ec6307165dbddeca054c7e4 100644 (file)
@@ -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
         * <p>
-        * @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
+        * <p>
+        * @return Product's gross price
+        */
+       public Float getProductGrossPrice () {
+               return this.productGrossPrice;
+       }
+
+       /**
+        * Setter for product's gross price
         * <p>
-        * @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
         * <p>
-        * @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
+        * <p>
+        * @param productNetPrice Product's net price
+        */
+       public void setProductNetPrice (final Float productNetPrice) {
+               this.productNetPrice = productNetPrice;
+       }
+
+       /**
+        * Getter for product's tax rate
+        * <p>
+        * @return Product's tax rate
+        */
+       public Float getProductTaxRate () {
+               return this.productTaxRate;
+       }
+
+       /**
+        * Setter for product's tax rate
+        * <p>
+        * @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
+        * <p>
+        * @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;
+       }
+
 }