From abc07f0505bf6a06afddff4eb1bcb00d1b553766 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 24 Apr 2020 18:09:40 +0200 Subject: [PATCH] Don't cherry-pick: - renamed BaseFinancialsProjectEnterpriseBean to BaseFinancialsReceiptEnterpriseBean (project-specific) - introduced BaseFinancialsReceiptItemEnterpriseBean for generalizing some receipt-item related methods - implemented business method updateReceiptItem() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../BaseFinancialsReceiptEnterpriseBean.java} | 10 +- ...seFinancialsReceiptItemEnterpriseBean.java | 94 +++++++++++++++++++ .../BaseFinancialsProductEnterpriseBean.java | 6 ++ .../FinancialAdminReceiptSessionBean.java | 6 +- .../receipt/FinancialReceiptSessionBean.java | 2 +- .../FinancialAdminReceiptItemSessionBean.java | 38 +++++++- 6 files changed, 145 insertions(+), 11 deletions(-) rename src/java/org/mxchange/jfinancials/enterprise/financial/{BaseFinancialsProjectEnterpriseBean.java => receipt/BaseFinancialsReceiptEnterpriseBean.java} (89%) create mode 100644 src/java/org/mxchange/jfinancials/enterprise/financial/receipt_item/BaseFinancialsReceiptItemEnterpriseBean.java diff --git a/src/java/org/mxchange/jfinancials/enterprise/financial/BaseFinancialsProjectEnterpriseBean.java b/src/java/org/mxchange/jfinancials/enterprise/financial/receipt/BaseFinancialsReceiptEnterpriseBean.java similarity index 89% rename from src/java/org/mxchange/jfinancials/enterprise/financial/BaseFinancialsProjectEnterpriseBean.java rename to src/java/org/mxchange/jfinancials/enterprise/financial/receipt/BaseFinancialsReceiptEnterpriseBean.java index 211200a..40e5f20 100644 --- a/src/java/org/mxchange/jfinancials/enterprise/financial/BaseFinancialsProjectEnterpriseBean.java +++ b/src/java/org/mxchange/jfinancials/enterprise/financial/receipt/BaseFinancialsReceiptEnterpriseBean.java @@ -14,11 +14,11 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.mxchange.jfinancials.enterprise.financial; +package org.mxchange.jfinancials.enterprise.financial.receipt; import java.text.MessageFormat; import java.util.Date; -import org.mxchange.jfinancials.enterprise.BaseFinancialsEnterpriseBean; +import org.mxchange.jfinancials.enterprise.product.BaseFinancialsProductEnterpriseBean; import org.mxchange.jfinancials.model.receipt.BillableReceipt; import org.mxchange.jfinancials.model.receipt.Receipts; @@ -27,7 +27,7 @@ import org.mxchange.jfinancials.model.receipt.Receipts; *

* @author Roland Haeder */ -public abstract class BaseFinancialsProjectEnterpriseBean extends BaseFinancialsEnterpriseBean { +public abstract class BaseFinancialsReceiptEnterpriseBean extends BaseFinancialsProductEnterpriseBean { /** * Serial number @@ -37,7 +37,7 @@ public abstract class BaseFinancialsProjectEnterpriseBean extends BaseFinancials /** * Protected constructor, no instance from this class. */ - protected BaseFinancialsProjectEnterpriseBean () { + protected BaseFinancialsReceiptEnterpriseBean () { super(); } @@ -82,7 +82,7 @@ public abstract class BaseFinancialsProjectEnterpriseBean extends BaseFinancials final BillableReceipt managedReceipt = this.getEntityManager().merge(foundReceipt); // Set updated timestamp - managedReceipt.setReceiptUpdated(new Date()); + managedReceipt.setReceiptEntryUpdated(new Date()); // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeReceipt: managedReceipt={0} - EXIT!", managedReceipt)); //NOI18N diff --git a/src/java/org/mxchange/jfinancials/enterprise/financial/receipt_item/BaseFinancialsReceiptItemEnterpriseBean.java b/src/java/org/mxchange/jfinancials/enterprise/financial/receipt_item/BaseFinancialsReceiptItemEnterpriseBean.java new file mode 100644 index 0000000..c09aa9d --- /dev/null +++ b/src/java/org/mxchange/jfinancials/enterprise/financial/receipt_item/BaseFinancialsReceiptItemEnterpriseBean.java @@ -0,0 +1,94 @@ +/* + * 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 Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jfinancials.enterprise.financial.receipt_item; + +import java.text.MessageFormat; +import java.util.Date; +import org.mxchange.jfinancials.enterprise.product.BaseFinancialsProductEnterpriseBean; +import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem; +import org.mxchange.jfinancials.model.receipt_item.ReceiptItems; + +/** + * A general bean for receipt item related methods that can be generalized. + *

+ * @author Roland Haeder + */ +public abstract class BaseFinancialsReceiptItemEnterpriseBean extends BaseFinancialsProductEnterpriseBean { + + /** + * Serial number + */ + private static final long serialVersionUID = 523_676_481_092_175_623L; + + /** + * Protected constructor, no instance from this class. + */ + protected BaseFinancialsReceiptItemEnterpriseBean () { + super(); + } + + /** + * Merges given receipt's data + *

+ * @param detachedReceiptItem Receipt instance to merge + *

+ * @return Detached receipt instance + */ + protected BillableReceiptItem mergeReceiptItem (final BillableReceiptItem detachedReceiptItem) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeReceiptItem: detachedReceipt={0} - CALLED!", detachedReceiptItem)); //NOI18N + + // The receipt instance must be valid + if (null == detachedReceiptItem) { + // Throw NPE again + throw new NullPointerException("detachedReceiptItem is null"); //NOI18N + } else if (detachedReceiptItem.getItemId() == null) { + // Throw NPE again + throw new NullPointerException("detachedReceiptItem.itemId is null"); //NOI18N //NOI18N + } else if (detachedReceiptItem.getItemId() < 1) { + // Not valid + throw new IllegalStateException(MessageFormat.format("detachedReceipt.itemId={0} is not valid.", detachedReceiptItem.getItemId())); //NOI18N + } + + // Set updated timestamp + // @TODO detachedReceipt.setReceiptUpdated(new Date()); + // Get receipt from it and find it + final BillableReceiptItem foundReceiptItem = this.getEntityManager().find(detachedReceiptItem.getClass(), detachedReceiptItem.getItemId()); + + // Should be found + assert (foundReceiptItem instanceof BillableReceiptItem) : MessageFormat.format("Receipt item with id {0} not found, but should be.", detachedReceiptItem.getItemId()); //NOI18N + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeReceipt: foundReceiptItem.itemId={0}", foundReceiptItem.getItemId())); //NOI18N + + // Copy all + ReceiptItems.copyReceiptItemData(detachedReceiptItem, foundReceiptItem); + + // Merge receipt item instance + final BillableReceiptItem managedReceiptItem = this.getEntityManager().merge(foundReceiptItem); + + // Set updated timestamp + managedReceiptItem.setItemEntryUpdated(new Date()); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeReceipt: managedReceiptItem={0} - EXIT!", managedReceiptItem)); //NOI18N + + // Return detached receipt + return managedReceiptItem; + } + +} diff --git a/src/java/org/mxchange/jfinancials/enterprise/product/BaseFinancialsProductEnterpriseBean.java b/src/java/org/mxchange/jfinancials/enterprise/product/BaseFinancialsProductEnterpriseBean.java index aee5522..35e0787 100644 --- a/src/java/org/mxchange/jfinancials/enterprise/product/BaseFinancialsProductEnterpriseBean.java +++ b/src/java/org/mxchange/jfinancials/enterprise/product/BaseFinancialsProductEnterpriseBean.java @@ -49,6 +49,9 @@ public abstract class BaseFinancialsProductEnterpriseBean extends BaseFinancials * @return Managed instance */ protected Category createManaged (final Category category) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: category={1} - CALLED!", this.getClass().getSimpleName(), category)); //NOI18N + // Validate parameter if (null == category) { // Throw NPE @@ -88,6 +91,9 @@ public abstract class BaseFinancialsProductEnterpriseBean extends BaseFinancials * @return Managed instance */ protected Product createManaged (final Product product) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: product={1} - CALLED!", this.getClass().getSimpleName(), product)); //NOI18N + // Validate parameter if (null == product) { // Throw NPE diff --git a/src/java/org/mxchange/jfinancials/model/receipt/FinancialAdminReceiptSessionBean.java b/src/java/org/mxchange/jfinancials/model/receipt/FinancialAdminReceiptSessionBean.java index 05030ba..9a4b692 100644 --- a/src/java/org/mxchange/jfinancials/model/receipt/FinancialAdminReceiptSessionBean.java +++ b/src/java/org/mxchange/jfinancials/model/receipt/FinancialAdminReceiptSessionBean.java @@ -21,7 +21,7 @@ import java.util.Date; import javax.ejb.EJB; import javax.ejb.Stateless; import org.mxchange.jcontactsbusiness.model.employee.Employable; -import org.mxchange.jfinancials.enterprise.financial.BaseFinancialsProjectEnterpriseBean; +import org.mxchange.jfinancials.enterprise.financial.receipt.BaseFinancialsReceiptEnterpriseBean; import org.mxchange.jfinancials.exceptions.receipt.ReceiptAlreadyAddedException; import org.mxchange.jfinancials.exceptions.receipt.ReceiptNotFoundException; import org.mxchange.jusercore.model.user.User; @@ -32,7 +32,7 @@ import org.mxchange.jusercore.model.user.User; * @author Roland Häder */ @Stateless (name = "adminFinancialReceipt", description = "A stateless session bean for handling receipts.") -public class FinancialAdminReceiptSessionBean extends BaseFinancialsProjectEnterpriseBean implements FinancialAdminReceiptSessionBeanRemote { +public class FinancialAdminReceiptSessionBean extends BaseFinancialsReceiptEnterpriseBean implements FinancialAdminReceiptSessionBeanRemote { /** * Serial number @@ -84,7 +84,7 @@ public class FinancialAdminReceiptSessionBean extends BaseFinancialsProjectEnter } // Add created instance - receipt.setReceiptCreated(new Date()); + receipt.setReceiptEntryCreated(new Date()); // Is user instance set? if (receipt.getReceiptUser() instanceof User) { diff --git a/src/java/org/mxchange/jfinancials/model/receipt/FinancialReceiptSessionBean.java b/src/java/org/mxchange/jfinancials/model/receipt/FinancialReceiptSessionBean.java index 4874702..25e9046 100644 --- a/src/java/org/mxchange/jfinancials/model/receipt/FinancialReceiptSessionBean.java +++ b/src/java/org/mxchange/jfinancials/model/receipt/FinancialReceiptSessionBean.java @@ -78,7 +78,7 @@ public class FinancialReceiptSessionBean extends BaseFinancialsEnterpriseBean im } // Add created instance - receipt.setReceiptCreated(new Date()); + receipt.setReceiptEntryCreated(new Date()); // Persist it this.getEntityManager().persist(receipt); diff --git a/src/java/org/mxchange/jfinancials/model/receipt_item/FinancialAdminReceiptItemSessionBean.java b/src/java/org/mxchange/jfinancials/model/receipt_item/FinancialAdminReceiptItemSessionBean.java index a2fd026..3c361f4 100644 --- a/src/java/org/mxchange/jfinancials/model/receipt_item/FinancialAdminReceiptItemSessionBean.java +++ b/src/java/org/mxchange/jfinancials/model/receipt_item/FinancialAdminReceiptItemSessionBean.java @@ -22,8 +22,9 @@ import java.util.List; import javax.ejb.EJB; import javax.ejb.Stateless; import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; -import org.mxchange.jfinancials.enterprise.product.BaseFinancialsProductEnterpriseBean; +import org.mxchange.jfinancials.enterprise.financial.receipt_item.BaseFinancialsReceiptItemEnterpriseBean; import org.mxchange.jfinancials.exceptions.receipt_item.ReceiptItemAlreadyAddedException; +import org.mxchange.jfinancials.exceptions.receipt_item.ReceiptItemNotFoundException; /** * A stateless bean for general purposes for receipt items @@ -31,7 +32,7 @@ import org.mxchange.jfinancials.exceptions.receipt_item.ReceiptItemAlreadyAddedE * @author Roland Häder */ @Stateless (name = "adminFinancialReceiptItem", description = "A stateless session bean for administrative purposes for receipt itemss.") -public class FinancialAdminReceiptItemSessionBean extends BaseFinancialsProductEnterpriseBean implements FinancialAdminReceiptItemSessionBeanRemote { +public class FinancialAdminReceiptItemSessionBean extends BaseFinancialsReceiptItemEnterpriseBean implements FinancialAdminReceiptItemSessionBeanRemote { /** * Serial number @@ -53,6 +54,9 @@ public class FinancialAdminReceiptItemSessionBean extends BaseFinancialsProductE if (null == receiptItem) { // Throw NPE throw new NullPointerException("receiptItem is null"); //NOI18N + } else if (receiptItem.getItemId() != null) { + // Throw IAE + throw new IllegalArgumentException("receiptItem.itemId is not null"); //NOI18N } else if (receiptItem.getItemProduct() == null) { // Throw it again throw new NullPointerException("receiptItem.itemProduct is null"); //NOI18N @@ -110,6 +114,36 @@ public class FinancialAdminReceiptItemSessionBean extends BaseFinancialsProductE return receiptItem; } + @Override + public BillableReceiptItem updateReceiptItem (final BillableReceiptItem receiptItem) throws ReceiptItemNotFoundException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateReceiptItem(): receiptItem={1} - CALLED!", this.getClass().getSimpleName(), receiptItem)); //NOI18N + + // Validate parameter + if (null == receiptItem) { + // Throw NPE + throw new NullPointerException("receiptItem is null"); //NOI18N + } else if (receiptItem.getItemId() == null) { + // Throw NPE again + throw new NullPointerException("receiptItem.itemId is null"); //NOI18N + } else if (receiptItem.getItemId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("receiptItem.itemId={0} is invalid", receiptItem.getItemId())); //NOI18N + } else if (!this.isReceiptItemRegistered(receiptItem)) { + // Not found + throw new ReceiptItemNotFoundException(receiptItem); + } + + // Merge data + final BillableReceiptItem updatedReceiptItem = this.mergeReceiptItem(receiptItem); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateReceiptItem(): updatedReceiptItem={1} - CALLED!", this.getClass().getSimpleName(), updatedReceiptItem)); //NOI18N + + // Return it + return updatedReceiptItem; + } + /** * Checks if given receipt item has already been added to receipt. *

-- 2.39.5