]> git.mxchange.org Git - jbonuscard-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Wed, 8 Apr 2020 15:40:00 +0000 (17:40 +0200)
committerRoland Häder <roland@mxchange.org>
Wed, 8 Apr 2020 15:40:00 +0000 (17:40 +0200)
- added receiptSequenceNumber and receiptSellerEmployee to equals()/hashCode()
  methods as they need to be equal, too.
- added Receipts.copyAll()
- added event for updated receipt data
- added receipt_updated entity property

Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jfinancials/events/receipt/updated/ObservableReceiptUpdatedEvent.java [new file with mode: 0644]
src/org/mxchange/jfinancials/events/receipt/updated/ReceiptUpdatedEvent.java [new file with mode: 0644]
src/org/mxchange/jfinancials/exceptions/receipt/ReceiptNotFoundException.java
src/org/mxchange/jfinancials/model/receipt/BillableReceipt.java
src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java
src/org/mxchange/jfinancials/model/receipt/Receipts.java

diff --git a/src/org/mxchange/jfinancials/events/receipt/updated/ObservableReceiptUpdatedEvent.java b/src/org/mxchange/jfinancials/events/receipt/updated/ObservableReceiptUpdatedEvent.java
new file mode 100644 (file)
index 0000000..26fd541
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2017 - 2020 Free Software Foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jfinancials.events.receipt.updated;
+
+import java.io.Serializable;
+import org.mxchange.jfinancials.model.receipt.BillableReceipt;
+
+/**
+ * An interface for events being fired when a receipt instance has been added.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface ObservableReceiptUpdatedEvent extends Serializable {
+
+       /**
+        * Getter for receipt instance
+        * <p>
+        * @return Receipt instance
+        */
+       BillableReceipt getReceipt ();
+
+}
diff --git a/src/org/mxchange/jfinancials/events/receipt/updated/ReceiptUpdatedEvent.java b/src/org/mxchange/jfinancials/events/receipt/updated/ReceiptUpdatedEvent.java
new file mode 100644 (file)
index 0000000..66f7f2c
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2017 - 2020 Free Software Foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jfinancials.events.receipt.updated;
+
+import java.text.MessageFormat;
+import org.mxchange.jfinancials.model.receipt.BillableReceipt;
+
+/**
+ * An event being fired when a new receipt has been added
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+public class ReceiptUpdatedEvent implements ObservableReceiptUpdatedEvent {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 157_582_667_163_548L;
+
+       /**
+        * New receipt instance being added
+        */
+       private final BillableReceipt receipt;
+
+       /**
+        * Constructor with receipt instance
+        * <p>
+        * @param receipt Receipt instance
+        */
+       public ReceiptUpdatedEvent (final BillableReceipt receipt) {
+               // Validate parameter
+               if (null == receipt) {
+                       // Throw NPE
+                       throw new NullPointerException("receipt is null");
+               } else if (receipt.getReceiptId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("receipt.receiptId is null");
+               } else if (receipt.getReceiptId() < 1) {
+                       // Throw NPE again
+                       throw new NullPointerException(MessageFormat.format("receipt.receiptId={0} is not valid", receipt.getReceiptId()));
+               }
+
+               // Set it here
+               this.receipt = receipt;
+       }
+
+       @Override
+       public BillableReceipt getReceipt () {
+               return this.receipt;
+       }
+
+}
index 685f4de9f6bdd0eec0673fd8193560a91ca6f9c3..3881c65894e6978096c9ce8dafe5b47879e4640c 100644 (file)
@@ -17,6 +17,7 @@
 package org.mxchange.jfinancials.exceptions.receipt;
 
 import java.text.MessageFormat;
+import org.mxchange.jfinancials.model.receipt.BillableReceipt;
 
 /**
  * This exception is thrown when a receipt was not found.
@@ -47,4 +48,14 @@ public class ReceiptNotFoundException extends Exception {
                super(MessageFormat.format("Receipt with id {0} was not found.", receiptId));
        }
 
+       /**
+        * Constructor with receipt instance
+        * <p>
+        * @param receipt Receipt instance
+        */
+       public ReceiptNotFoundException (final BillableReceipt receipt) {
+               // Invoke other contructor
+               this(receipt.getReceiptId());
+       }
+
 }
index 34e180ba95273371227549d4734f4fddcda4b3c3..61a10f3c4324ffb301f9547fce738488f793b98a 100644 (file)
@@ -69,6 +69,20 @@ public interface BillableReceipt extends Comparable<BillableReceipt>, Serializab
        /**
         * Setter for when this receipt has been created in database
         * <p>
+        * @param receiptUpdated Receipt updated timestamp
+        */
+       void setReceiptUpdated (final Date receiptUpdated);
+
+       /**
+        * Getter for when this receipt has been updated in database
+        * <p>
+        * @return Receipt updated timestamp
+        */
+       Date getReceiptUpdated ();
+
+       /**
+        * Setter for when this receipt has been updated in database
+        * <p>
         * @param receiptCreated Receipt creation timestamp
         */
        void setReceiptCreated (final Date receiptCreated);
index cf79ac88b50bf351550fac345ceee343089bbb96..02a93af142f292ca8a5c17bd89785bc6c57feab7 100644 (file)
@@ -159,6 +159,13 @@ public class FinancialReceipt implements BillableReceipt {
        @Column (name = "receipt_transaction_number")
        private Long receiptTransactionNumber;
 
+       /**
+        * When this receipt entry has been updated
+        */
+       @Temporal (TemporalType.TIMESTAMP)
+       @Column (name = "receipt_updated")
+       private Date receiptUpdated;
+
        /**
         * Which user this receipt belongs to
         */
@@ -301,6 +308,8 @@ public class FinancialReceipt implements BillableReceipt {
                        return false;
                } else if (!Objects.equals(this.getReceiptNumber(), receipt.getReceiptNumber())) {
                        return false;
+               } else if (!Objects.equals(this.getReceiptRegisterNumber(), receipt.getReceiptRegisterNumber())) {
+                       return false;
                } else if (!Objects.equals(this.getReceiptSequenceNumber(), receipt.getReceiptSequenceNumber())) {
                        return false;
                } else if (!Objects.equals(this.getReceiptTransactionNumber(), receipt.getReceiptTransactionNumber())) {
@@ -313,6 +322,8 @@ public class FinancialReceipt implements BillableReceipt {
                        return false;
                } else if (!Objects.equals(this.getReceiptIssued(), receipt.getReceiptIssued())) {
                        return false;
+               } else if (!Objects.equals(this.getReceiptSellerEmployee(), receipt.getReceiptSellerEmployee())) {
+                       return false;
                }
 
                return true;
@@ -442,6 +453,18 @@ public class FinancialReceipt implements BillableReceipt {
                this.receiptTransactionNumber = receiptTransactionNumber;
        }
 
+       @Override
+       @SuppressWarnings ("ReturnOfDateField")
+       public Date getReceiptUpdated () {
+               return this.receiptUpdated;
+       }
+
+       @Override
+       @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+       public void setReceiptUpdated (final Date receiptUpdated) {
+               this.receiptUpdated = receiptUpdated;
+       }
+
        @Override
        public User getReceiptUser () {
                return this.receiptUser;
@@ -458,11 +481,13 @@ public class FinancialReceipt implements BillableReceipt {
 
                hash = 89 * hash + Objects.hashCode(this.getReceiptId());
                hash = 89 * hash + Objects.hashCode(this.getReceiptNumber());
+               hash = 89 * hash + Objects.hashCode(this.getReceiptRegisterNumber());
                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 13a056a820235a3e2cebc43421257cd10ff4be4e..f5adc062469b3774c9eae3c2963756da71fb25e6 100644 (file)
@@ -58,6 +58,42 @@ public class Receipts implements Serializable {
                return receipt1.compareTo(receipt2);
        }
 
+       /**
+        * Copies all fields from source receipt to target receipt.
+        * <p>
+        * @param sourceReceipt Source receipt instance
+        * @param targetReceipt Target Receipt instance
+        */
+       public static void copyAll (final BillableReceipt sourceReceipt, final BillableReceipt targetReceipt) {
+               // Both should not be null
+               if (null == sourceReceipt) {
+                       // Throw NPE
+                       throw new NullPointerException("sourceReceipt is null"); //NOI18N
+               } else if (null == targetReceipt) {
+                       // Throw NPE
+                       throw new NullPointerException("targetReceipt is null"); //NOI18N
+               } else if (Objects.equals(sourceReceipt, targetReceipt)) {
+                       // Is exactly the same!
+                       throw new IllegalArgumentException("sourcerReceipt and targetReceipt are the same."); //NOI18N
+               }
+
+               // Copy all fields
+               targetReceipt.setReceiptBarCodeNumber(sourceReceipt.getReceiptBarCodeNumber());
+               targetReceipt.setReceiptBonusCard(sourceReceipt.getReceiptBonusCard());
+               targetReceipt.setReceiptBranchOffice(sourceReceipt.getReceiptBranchOffice());
+               targetReceipt.setReceiptCreated(sourceReceipt.getReceiptCreated());
+               targetReceipt.setReceiptId(sourceReceipt.getReceiptId());
+               targetReceipt.setReceiptIssued(sourceReceipt.getReceiptIssued());
+               targetReceipt.setReceiptNumber(sourceReceipt.getReceiptNumber());
+               targetReceipt.setReceiptPaymentType(sourceReceipt.getReceiptPaymentType());
+               targetReceipt.setReceiptRegisterNumber(sourceReceipt.getReceiptRegisterNumber());
+               targetReceipt.setReceiptSellerEmployee(sourceReceipt.getReceiptSellerEmployee());
+               targetReceipt.setReceiptSequenceNumber(sourceReceipt.getReceiptSequenceNumber());
+               targetReceipt.setReceiptTransactionNumber(sourceReceipt.getReceiptTransactionNumber());
+               targetReceipt.setReceiptUpdated(sourceReceipt.getReceiptUpdated());
+               targetReceipt.setReceiptUser(sourceReceipt.getReceiptUser());
+       }
+
        /**
         * Checks whether both receipts are the same, means not true entity equality
         * but if the receipt in general terms does already exist. A pre-check on
@@ -78,46 +114,46 @@ public class Receipts implements Serializable {
                // Validate parameter
                if (null == receipt1) {
                        // Throw NPE
-                       throw new NullPointerException("receipt1 is null");
+                       throw new NullPointerException("receipt1 is null"); //NOI18N
                } else if ((receipt1.getReceiptId() instanceof Long) && (receipt1.getReceiptId() < 1)) {
                        // Throw IAE
-                       throw new IllegalArgumentException(MessageFormat.format("receipt1.receiptId={0} is not valid.", receipt1.getReceiptId()));
+                       throw new IllegalArgumentException(MessageFormat.format("receipt1.receiptId={0} is not valid.", receipt1.getReceiptId())); //NOI18N
                } else if (receipt1.getReceiptBranchOffice() == null) {
                        // Throw NPE
-                       throw new NullPointerException("receipt1.receiptBranchOffice is null");
+                       throw new NullPointerException("receipt1.receiptBranchOffice is null"); //NOI18N
                } else if (receipt1.getReceiptBranchOffice().getBranchId() == null) {
                        // Throw NPE
-                       throw new NullPointerException("receipt1.receiptBranchOffice.branchId is null");
+                       throw new NullPointerException("receipt1.receiptBranchOffice.branchId is null"); //NOI18N
                } else if (receipt1.getReceiptBranchOffice().getBranchId() < 1) {
                        // Throw NPE
-                       throw new NullPointerException(MessageFormat.format("receipt1.receiptBranchOffice.branchId={0} is not valid", receipt1.getReceiptBranchOffice().getBranchId()));
+                       throw new NullPointerException(MessageFormat.format("receipt1.receiptBranchOffice.branchId={0} is not valid", receipt1.getReceiptBranchOffice().getBranchId())); //NOI18N
                } else if ((receipt1.getReceiptNumber() != null) && (receipt1.getReceiptNumber().isEmpty())) {
                        // Throw IAE
-                       throw new IllegalArgumentException("receipt1.receiptNumber is empty.");
+                       throw new IllegalArgumentException("receipt1.receiptNumber is empty."); //NOI18N
                } else if (receipt1.getReceiptPaymentType() == null) {
                        // Throw NPE
-                       throw new NullPointerException("receipt1.receiptPaymentType is null");
+                       throw new NullPointerException("receipt1.receiptPaymentType is null"); //NOI18N
                } else if (null == receipt2) {
                        // Throw NPE
-                       throw new NullPointerException("receipt2 is null");
+                       throw new NullPointerException("receipt2 is null"); //NOI18N
                } else if ((receipt2.getReceiptId() instanceof Long) && (receipt2.getReceiptId() < 1)) {
                        // Throw IAE
-                       throw new IllegalArgumentException(MessageFormat.format("receipt2.receiptId={0} is not valid.", receipt2.getReceiptId()));
+                       throw new IllegalArgumentException(MessageFormat.format("receipt2.receiptId={0} is not valid.", receipt2.getReceiptId())); //NOI18N
                } else if (receipt2.getReceiptBranchOffice() == null) {
                        // Throw NPE
-                       throw new NullPointerException("receipt2.receiptBranchOffice is null");
+                       throw new NullPointerException("receipt2.receiptBranchOffice is null"); //NOI18N
                } else if (receipt2.getReceiptBranchOffice().getBranchId() == null) {
                        // Throw NPE
-                       throw new NullPointerException("receipt2.receiptBranchOffice.branchId is null");
+                       throw new NullPointerException("receipt2.receiptBranchOffice.branchId is null"); //NOI18N
                } else if (receipt2.getReceiptBranchOffice().getBranchId() < 1) {
                        // Throw NPE
-                       throw new NullPointerException(MessageFormat.format("receipt2.receiptBranchOffice.branchId={0} is not valid", receipt2.getReceiptBranchOffice().getBranchId()));
+                       throw new NullPointerException(MessageFormat.format("receipt2.receiptBranchOffice.branchId={0} is not valid", receipt2.getReceiptBranchOffice().getBranchId())); //NOI18N
                } else if ((receipt2.getReceiptNumber() != null) && (receipt2.getReceiptNumber().isEmpty())) {
                        // Throw IAE
-                       throw new IllegalArgumentException("receipt2.receiptNumber is empty.");
+                       throw new IllegalArgumentException("receipt2.receiptNumber is empty."); //NOI18N
                } else if (receipt2.getReceiptPaymentType() == null) {
                        // Throw NPE
-                       throw new NullPointerException("receipt2.receiptPaymentType is null");
+                       throw new NullPointerException("receipt2.receiptPaymentType is null"); //NOI18N
                }
 
                // Now check all individually