--- /dev/null
+/*
+ * 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 ();
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
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.
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());
+ }
+
}
/**
* 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);
@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
*/
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())) {
return false;
} else if (!Objects.equals(this.getReceiptIssued(), receipt.getReceiptIssued())) {
return false;
+ } else if (!Objects.equals(this.getReceiptSellerEmployee(), receipt.getReceiptSellerEmployee())) {
+ return false;
}
return true;
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;
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;
}
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
// 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