From 98838b634499adeac52627720e7b7a4cf3fd3fb2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 8 Apr 2020 17:40:00 +0200 Subject: [PATCH] Continued: - 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 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../ObservableReceiptUpdatedEvent.java | 36 ++++++++++ .../receipt/updated/ReceiptUpdatedEvent.java | 66 +++++++++++++++++++ .../receipt/ReceiptNotFoundException.java | 11 ++++ .../model/receipt/BillableReceipt.java | 14 ++++ .../model/receipt/FinancialReceipt.java | 25 +++++++ .../jfinancials/model/receipt/Receipts.java | 64 ++++++++++++++---- 6 files changed, 202 insertions(+), 14 deletions(-) create mode 100644 src/org/mxchange/jfinancials/events/receipt/updated/ObservableReceiptUpdatedEvent.java create mode 100644 src/org/mxchange/jfinancials/events/receipt/updated/ReceiptUpdatedEvent.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 index 0000000..26fd541 --- /dev/null +++ b/src/org/mxchange/jfinancials/events/receipt/updated/ObservableReceiptUpdatedEvent.java @@ -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 . + */ +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. + *

+ * @author Roland Häder + */ +public interface ObservableReceiptUpdatedEvent extends Serializable { + + /** + * Getter for receipt instance + *

+ * @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 index 0000000..66f7f2c --- /dev/null +++ b/src/org/mxchange/jfinancials/events/receipt/updated/ReceiptUpdatedEvent.java @@ -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 . + */ +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 + *

+ * @author Roland Haeder + */ +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 + *

+ * @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; + } + +} diff --git a/src/org/mxchange/jfinancials/exceptions/receipt/ReceiptNotFoundException.java b/src/org/mxchange/jfinancials/exceptions/receipt/ReceiptNotFoundException.java index 685f4de..3881c65 100644 --- a/src/org/mxchange/jfinancials/exceptions/receipt/ReceiptNotFoundException.java +++ b/src/org/mxchange/jfinancials/exceptions/receipt/ReceiptNotFoundException.java @@ -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 + *

+ * @param receipt Receipt instance + */ + public ReceiptNotFoundException (final BillableReceipt receipt) { + // Invoke other contructor + this(receipt.getReceiptId()); + } + } diff --git a/src/org/mxchange/jfinancials/model/receipt/BillableReceipt.java b/src/org/mxchange/jfinancials/model/receipt/BillableReceipt.java index 34e180b..61a10f3 100644 --- a/src/org/mxchange/jfinancials/model/receipt/BillableReceipt.java +++ b/src/org/mxchange/jfinancials/model/receipt/BillableReceipt.java @@ -69,6 +69,20 @@ public interface BillableReceipt extends Comparable, Serializab /** * Setter for when this receipt has been created in database *

+ * @param receiptUpdated Receipt updated timestamp + */ + void setReceiptUpdated (final Date receiptUpdated); + + /** + * Getter for when this receipt has been updated in database + *

+ * @return Receipt updated timestamp + */ + Date getReceiptUpdated (); + + /** + * Setter for when this receipt has been updated in database + *

* @param receiptCreated Receipt creation timestamp */ void setReceiptCreated (final Date receiptCreated); diff --git a/src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java b/src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java index cf79ac8..02a93af 100644 --- a/src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java +++ b/src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java @@ -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; } diff --git a/src/org/mxchange/jfinancials/model/receipt/Receipts.java b/src/org/mxchange/jfinancials/model/receipt/Receipts.java index 13a056a..f5adc06 100644 --- a/src/org/mxchange/jfinancials/model/receipt/Receipts.java +++ b/src/org/mxchange/jfinancials/model/receipt/Receipts.java @@ -58,6 +58,42 @@ public class Receipts implements Serializable { return receipt1.compareTo(receipt2); } + /** + * Copies all fields from source receipt to target receipt. + *

+ * @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 -- 2.39.5