]> git.mxchange.org Git - jfinancials-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 26 Apr 2020 19:04:57 +0000 (21:04 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 26 Apr 2020 19:04:57 +0000 (21:04 +0200)
- renamed fooCreated/Updated to fooEntryCreated/Updated
- always "validate" parameter, means checking on null, empty string, invalid
  values like zero or negative numbers for primary keys and so on.

Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jfinancials/model/income/BillableIncome.java
src/org/mxchange/jfinancials/model/income/FinancialIncome.java
src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java
src/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItem.java

index 397bcbc41473f48938791bbe92fd96421b7db9e0..80d248207056f7089f39c36d4612c7a0697781bc 100644 (file)
@@ -43,20 +43,6 @@ public interface BillableIncome extends Comparable<BillableIncome>, Serializable
         */
        void setIncomeId (final Long incomeId);
 
-       /**
-        * Getter for income-created timestamp
-        * <p>
-        * @return Income-created timestamp
-        */
-       Date getIncomeCreated ();
-
-       /**
-        * Setter for income-created timestamp
-        * <p>
-        * @param incomeCreated Income-created timestamp
-        */
-       void setIncomeCreated (final Date incomeCreated);
-
        /**
         * Getter for whether income is enabled
         * <p>
@@ -114,32 +100,46 @@ public interface BillableIncome extends Comparable<BillableIncome>, Serializable
        void setIncomeTitle (final String incomeTitle);
 
        /**
-        * Getter for income-updated timestamp
+        * Getter for connected user account
         * <p>
-        * @return Income-updated timestamp
+        * @return Connected user account
         */
-       Date getIncomeUpdated ();
+       User getIncomeUser ();
 
        /**
-        * Setter for income-updated timestamp
+        * Setter for connected user account
+        * <p>
+        * @param incomeUser Connected user account
+        */
+       void setIncomeUser (final User incomeUser);
+
+       /**
+        * Getter for income-created timestamp
         * <p>
-        * @param incomeUpdated Income-updated timestamp
+        * @return Income-created timestamp
         */
-       void setIncomeUpdated (final Date incomeUpdated);
+       Date getIncomeEntryCreated ();
 
        /**
-        * Getter for connected user account
+        * Setter for income-created timestamp
         * <p>
-        * @return Connected user account
+        * @param incomeEntryCreated Income-created timestamp
         */
-       User getIncomeUser ();
+       void setIncomeEntryCreated (final Date incomeEntryCreated);
 
        /**
-        * Setter for connected user account
+        * Getter for income-updated timestamp
         * <p>
-        * @param incomeUser Connected user account
+        * @return Income-updated timestamp
         */
-       void setIncomeUser (final User incomeUser);
+       Date getIncomeEntryUpdated ();
+
+       /**
+        * Setter for income-updated timestamp
+        * <p>
+        * @param incomeEntryUpdated Income-updated timestamp
+        */
+       void setIncomeEntryUpdated (final Date incomeEntryUpdated);
 
        @Override
        boolean equals (final Object object);
index 08e6225a5f57ef373c32154f600cb7a516fa9d51..d29806cf213a342a615f34084307eb0f059dc40f 100644 (file)
@@ -17,6 +17,7 @@
 package org.mxchange.jfinancials.model.income;
 
 import java.math.BigDecimal;
+import java.text.MessageFormat;
 import java.util.Date;
 import java.util.Objects;
 import javax.persistence.Basic;
@@ -55,21 +56,28 @@ public class FinancialIncome implements BillableIncome {
        @Transient
        private static final long serialVersionUID = 173_587_690_625_524L;
 
+       /**
+        * Income enabled (default) or disabled (no longer receiving income but need
+        * to keep it for statistics).
+        */
+       @Basic (optional = false)
+       @Column (name = "income_enabled", nullable = false)
+       private Boolean incomeEnabled;
+
        /**
         * Income created timestamp
         */
        @Basic (optional = false)
        @Temporal (TemporalType.TIMESTAMP)
-       @Column (name = "income_created", nullable = false, updatable = false)
-       private Date incomeCreated;
+       @Column (name = "income_entry_created", nullable = false, updatable = false)
+       private Date incomeEntryCreated;
 
        /**
-        * Income enabled (default) or disabled (no longer receiving income but need
-        * to keep it for statistics).
+        * Income updated timestamp
         */
-       @Basic (optional = false)
-       @Column (name = "income_enabled", nullable = false)
-       private Boolean incomeEnabled;
+       @Temporal (TemporalType.TIMESTAMP)
+       @Column (name = "income_entry_updated", insertable = false)
+       private Date incomeEntryUpdated;
 
        /**
         * Income id (primary key)
@@ -101,13 +109,6 @@ public class FinancialIncome implements BillableIncome {
        @Column (name = "income_title", nullable = false)
        private String incomeTitle;
 
-       /**
-        * Income updated timestamp
-        */
-       @Temporal (TemporalType.TIMESTAMP)
-       @Column (name = "income_updated", insertable = false)
-       private Date incomeUpdated;
-
        /**
         * Connected user account
         */
@@ -129,19 +130,48 @@ public class FinancialIncome implements BillableIncome {
         * @param incomeSingleAmount Single amount
         * @param incomeInterval     Interval
         * @param incomeUser         Connected user
+        * @param incomeEnabled      Whether this income is enabled
         */
-       public FinancialIncome (final String incomeTitle, final BigDecimal incomeSingleAmount, final FinancialInterval incomeInterval, final User incomeUser) {
+       public FinancialIncome (final String incomeTitle, final BigDecimal incomeSingleAmount, final FinancialInterval incomeInterval, final User incomeUser, final Boolean incomeEnabled) {
                // Invoke default constructor
                this();
 
+               // Validate all parameter
+               if (null == incomeEnabled) {
+                       // Throw NPE
+                       throw new NullPointerException("incomeEnabled is null"); //NOI18N
+               } else if (null == incomeInterval) {
+                       // Throw NPE again
+                       throw new NullPointerException("incomeInterval is null"); //NOI18N
+               } else if (null == incomeSingleAmount) {
+                       // Throw NPE again
+                       throw new NullPointerException("incomeSingleAmount is null"); //NOI18N
+               } else if (incomeSingleAmount.floatValue() < 0.0f) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("incomeSingleAmount={0} is not valid.", incomeSingleAmount)); //NOI18N
+               } else if (null == incomeTitle) {
+                       // Throw NPE
+                       throw new NullPointerException("incomeTitle is null"); //NOI18N
+               } else if (incomeTitle.isEmpty()) {
+                       // Throw IAE
+                       throw new IllegalArgumentException("incomeTitle is empty"); //NOI18N
+               } else if (null == incomeUser) {
+                       // Throw NPE
+                       throw new NullPointerException("incomeUser is null"); //NOI18N
+               } else if (incomeUser.getUserId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("incomeUser.userId is null"); //NOI18N
+               } else if (incomeUser.getUserId() < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("incomeUser.userId={0} is not valid.", incomeUser.getUserId())); //NOI18N
+               }
+
                // Set all fields
                this.incomeTitle = incomeTitle;
                this.incomeSingleAmount = incomeSingleAmount;
                this.incomeInterval = incomeInterval;
                this.incomeUser = incomeUser;
-
-               // Enable this income by default
-               this.incomeEnabled = Boolean.TRUE;
+               this.incomeEnabled = incomeEnabled;
        }
 
        @Override
@@ -186,36 +216,55 @@ public class FinancialIncome implements BillableIncome {
 
                final BillableIncome other = (BillableIncome) object;
 
-               if (!Objects.equals(this.getIncomeTitle(), other.getIncomeTitle())) {
+               if (!Objects.equals(this.getIncomeEnabled(), other.getIncomeEnabled())) {
                        return false;
                } else if (!Objects.equals(this.getIncomeId(), other.getIncomeId())) {
                        return false;
+               } else if (!Objects.equals(this.getIncomeInterval(), other.getIncomeInterval())) {
+                       return false;
+               } else if (!Objects.equals(this.getIncomeSingleAmount(), other.getIncomeSingleAmount())) {
+                       return false;
+               } else if (!Objects.equals(this.getIncomeTitle(), other.getIncomeTitle())) {
+                       return false;
                } else if (!Objects.equals(this.getIncomeUser(), other.getIncomeUser())) {
                        return false;
                }
+
                return true;
        }
 
+       @Override
+       public Boolean getIncomeEnabled () {
+               return this.incomeEnabled;
+       }
+
+       @Override
+       public void setIncomeEnabled (Boolean incomeEnabled) {
+               this.incomeEnabled = incomeEnabled;
+       }
+
        @Override
        @SuppressWarnings ("ReturnOfDateField")
-       public Date getIncomeCreated () {
-               return this.incomeCreated;
+       public Date getIncomeEntryCreated () {
+               return this.incomeEntryCreated;
        }
 
        @Override
        @SuppressWarnings ("AssignmentToDateFieldFromParameter")
-       public void setIncomeCreated (Date incomeCreated) {
-               this.incomeCreated = incomeCreated;
+       public void setIncomeEntryCreated (Date incomeEntryCreated) {
+               this.incomeEntryCreated = incomeEntryCreated;
        }
 
        @Override
-       public Boolean getIncomeEnabled () {
-               return this.incomeEnabled;
+       @SuppressWarnings ("ReturnOfDateField")
+       public Date getIncomeEntryUpdated () {
+               return this.incomeEntryUpdated;
        }
 
        @Override
-       public void setIncomeEnabled (Boolean incomeEnabled) {
-               this.incomeEnabled = incomeEnabled;
+       @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+       public void setIncomeEntryUpdated (Date incomeEntryUpdated) {
+               this.incomeEntryUpdated = incomeEntryUpdated;
        }
 
        @Override
@@ -258,18 +307,6 @@ public class FinancialIncome implements BillableIncome {
                this.incomeTitle = incomeTitle;
        }
 
-       @Override
-       @SuppressWarnings ("ReturnOfDateField")
-       public Date getIncomeUpdated () {
-               return this.incomeUpdated;
-       }
-
-       @Override
-       @SuppressWarnings ("AssignmentToDateFieldFromParameter")
-       public void setIncomeUpdated (Date incomeUpdated) {
-               this.incomeUpdated = incomeUpdated;
-       }
-
        @Override
        public User getIncomeUser () {
                return this.incomeUser;
@@ -284,7 +321,10 @@ public class FinancialIncome implements BillableIncome {
        public int hashCode () {
                int hash = 3;
 
+               hash = 29 * hash + Objects.hashCode(this.getIncomeEnabled());
                hash = 29 * hash + Objects.hashCode(this.getIncomeId());
+               hash = 29 * hash + Objects.hashCode(this.getIncomeInterval());
+               hash = 29 * hash + Objects.hashCode(this.getIncomeSingleAmount());
                hash = 29 * hash + Objects.hashCode(this.getIncomeTitle());
                hash = 29 * hash + Objects.hashCode(this.getIncomeUser());
 
index b882db42ce3ec4a273c68393d62f4af7bd769574..e49f149acdc2f2b3ff4430c5aa76b26ab45a3540 100644 (file)
@@ -63,8 +63,7 @@ import org.mxchange.jusercore.model.user.Users;
 )
 @NamedQueries (
                {
-                       @NamedQuery (name = "AllReceipts", query = "SELECT r FROM receipts AS r ORDER BY r.receiptId ASC"),
-                       @NamedQuery (name = "SearchAllUserReceipts", query = "SELECT r FROM receipts AS r WHERE r.receiptUser = :receiptUser ORDER BY r.receiptId ASC")
+                       @NamedQuery (name = "AllReceipts", query = "SELECT r FROM receipts AS r ORDER BY r.receiptId ASC")
                }
 )
 @SuppressWarnings ("PersistenceUnitPresent")
@@ -304,25 +303,29 @@ public class FinancialReceipt implements BillableReceipt {
                final BillableReceipt receipt = (BillableReceipt) object;
 
                // Now check some distincting class fields
-               if (!Objects.equals(this.getReceiptId(), receipt.getReceiptId())) {
+               if (!Objects.equals(this.getReceiptBarCodeNumber(), receipt.getReceiptBarCodeNumber())) {
                        return false;
-               } else if (!Objects.equals(this.getReceiptNumber(), receipt.getReceiptNumber())) {
+               } else if (!Objects.equals(this.getReceiptBonusCard(), receipt.getReceiptBonusCard())) {
                        return false;
-               } else if (!Objects.equals(this.getReceiptRegisterNumber(), receipt.getReceiptRegisterNumber())) {
+               } else if (!Objects.equals(this.getReceiptBranchOffice(), receipt.getReceiptBranchOffice())) {
                        return false;
-               } else if (!Objects.equals(this.getReceiptSequenceNumber(), receipt.getReceiptSequenceNumber())) {
+               } else if (!Objects.equals(this.getReceiptId(), receipt.getReceiptId())) {
                        return false;
-               } else if (!Objects.equals(this.getReceiptTransactionNumber(), receipt.getReceiptTransactionNumber())) {
+               } else if (!Objects.equals(this.getReceiptIssued(), receipt.getReceiptIssued())) {
+                       return false;
+               } else if (!Objects.equals(this.getReceiptNumber(), receipt.getReceiptNumber())) {
                        return false;
                } else if (this.getReceiptPaymentType() != receipt.getReceiptPaymentType()) {
                        return false;
-               } else if (!Objects.equals(this.getReceiptBranchOffice(), receipt.getReceiptBranchOffice())) {
+               } else if (!Objects.equals(this.getReceiptRegisterNumber(), receipt.getReceiptRegisterNumber())) {
                        return false;
-               } else if (!Objects.equals(this.getReceiptUser(), receipt.getReceiptUser())) {
+               } else if (!Objects.equals(this.getReceiptSellerEmployee(), receipt.getReceiptSellerEmployee())) {
                        return false;
-               } else if (!Objects.equals(this.getReceiptIssued(), receipt.getReceiptIssued())) {
+               } else if (!Objects.equals(this.getReceiptSequenceNumber(), receipt.getReceiptSequenceNumber())) {
                        return false;
-               } else if (!Objects.equals(this.getReceiptSellerEmployee(), receipt.getReceiptSellerEmployee())) {
+               } else if (!Objects.equals(this.getReceiptTransactionNumber(), receipt.getReceiptTransactionNumber())) {
+                       return false;
+               } else if (!Objects.equals(this.getReceiptUser(), receipt.getReceiptUser())) {
                        return false;
                }
 
@@ -479,15 +482,18 @@ public class FinancialReceipt implements BillableReceipt {
        public int hashCode () {
                int hash = 5;
 
+               hash = 89 * hash + Objects.hashCode(this.getReceiptBarCodeNumber());
+               hash = 89 * hash + Objects.hashCode(this.getReceiptBonusCard());
+               hash = 89 * hash + Objects.hashCode(this.getReceiptBranchOffice());
                hash = 89 * hash + Objects.hashCode(this.getReceiptId());
+               hash = 89 * hash + Objects.hashCode(this.getReceiptIssued());
                hash = 89 * hash + Objects.hashCode(this.getReceiptNumber());
+               hash = 89 * hash + Objects.hashCode(this.getReceiptPaymentType());
                hash = 89 * hash + Objects.hashCode(this.getReceiptRegisterNumber());
+               hash = 89 * hash + Objects.hashCode(this.getReceiptSellerEmployee());
                hash = 89 * hash + Objects.hashCode(this.getReceiptSequenceNumber());
                hash = 89 * hash + Objects.hashCode(this.getReceiptTransactionNumber());
-               hash = 89 * hash + Objects.hashCode(this.getReceiptPaymentType());
-               hash = 89 * hash + Objects.hashCode(this.getReceiptBranchOffice());
                hash = 89 * hash + Objects.hashCode(this.getReceiptUser());
-               hash = 89 * hash + Objects.hashCode(this.getReceiptSellerEmployee());
 
                return hash;
        }
index 379d455ebcdd152a935e9f8ab20c52a1f917fa93..b42b36bba30047027324e03c85f0aa0820de5f84 100644 (file)
@@ -17,6 +17,7 @@
 package org.mxchange.jfinancials.model.receipt_item;
 
 import java.math.BigDecimal;
+import java.text.MessageFormat;
 import java.util.Date;
 import java.util.Objects;
 import javax.persistence.Basic;
@@ -57,9 +58,7 @@ import org.mxchange.jproduct.model.product.Products;
 )
 @NamedQueries (
                {
-                       @NamedQuery (name = "AllReceiptItems", query = "SELECT ri FROM receipt_items AS ri ORDER BY ri.itemId ASC"),
-                       @NamedQuery (name = "SearchAssignedReceiptItems", query = "SELECT ri FROM receipt_items AS ri WHERE ri.itemReceipt = :itemReceipt ORDER BY ri.itemId ASC"),
-                       @NamedQuery (name = "SearchAllUserReceiptItems", query = "SELECT ri FROM receipt_items AS ri JOIN receipts AS r ON ri.itemReceipt=r WHERE r.receiptUser = :receiptUser ORDER BY ri.itemId ASC")
+                       @NamedQuery (name = "AllReceiptItems", query = "SELECT ri FROM receipt_items AS ri ORDER BY ri.itemId ASC")
                }
 )
 @SuppressWarnings ("PersistenceUnitPresent")
@@ -95,7 +94,7 @@ public class FinancialReceiptItem implements BillableReceiptItem {
         * When this item has been updated
         */
        @Temporal (TemporalType.TIMESTAMP)
-       @Column (name = "item_entry_updated", insertable = false, nullable = false)
+       @Column (name = "item_entry_updated", insertable = false)
        private Date itemEntryUpdated;
 
        /**
@@ -190,6 +189,33 @@ public class FinancialReceiptItem implements BillableReceiptItem {
                // Call other constructor
                this();
 
+               // Validate parameter
+               if (null == itemProduct) {
+                       // Throw NPE
+                       throw new NullPointerException("itemProduct is null"); //NOI18N
+               } else if (itemProduct.getProductId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("itemProduct.productId is null"); //NOI18N
+               } else if (itemProduct.getProductId() < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("itemProduct.productId={0} is not valid.", itemProduct.getProductId())); //NOI18N
+               } else if (null == itemProductQuantity) {
+                       // Throw NPE
+                       throw new NullPointerException("itemProductQuanity is null"); //NOI18N
+               } else if (itemProductQuantity.floatValue() < 0) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("itemProductQuanity={0} is not valid.", itemProductQuantity)); //NOI18N
+               } else if (null == itemReceipt) {
+                       // Throw NPE
+                       throw new NullPointerException("itemReceipt is null"); //NOI18N
+               } else if (itemReceipt.getReceiptId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("itemReceipt.receiptId is null"); //NOI18N
+               } else if (itemReceipt.getReceiptId() < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("itemReceipt.receiptId={0} is not valid.", itemReceipt.getReceiptId())); //NOI18N
+               }
+
                // Set all values
                this.itemProduct = itemProduct;
                this.itemProductQuantity = itemProductQuantity;
@@ -254,6 +280,8 @@ public class FinancialReceiptItem implements BillableReceiptItem {
                        return false;
                } else if (!Objects.equals(this.getItemGrossPrice(), receiptItem.getItemGrossPrice())) {
                        return false;
+               } else if (!Objects.equals(this.getItemId(), receiptItem.getItemId())) {
+                       return false;
                } else if (!Objects.equals(this.getItemIsDiscount(), receiptItem.getItemIsDiscount())) {
                        return false;
                } else if (!Objects.equals(this.getItemIsRefund(), receiptItem.getItemIsRefund())) {