From: Roland Häder Date: Fri, 24 Apr 2020 16:09:40 +0000 (+0200) Subject: Don't cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=abc07f0505bf6a06afddff4eb1bcb00d1b553766;p=jfinancials-ejb.git Don't cherry-pick: - renamed BaseFinancialsProjectEnterpriseBean to BaseFinancialsReceiptEnterpriseBean (project-specific) - introduced BaseFinancialsReceiptItemEnterpriseBean for generalizing some receipt-item related methods - implemented business method updateReceiptItem() Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jfinancials/enterprise/financial/BaseFinancialsProjectEnterpriseBean.java b/src/java/org/mxchange/jfinancials/enterprise/financial/BaseFinancialsProjectEnterpriseBean.java deleted file mode 100644 index 211200a..0000000 --- a/src/java/org/mxchange/jfinancials/enterprise/financial/BaseFinancialsProjectEnterpriseBean.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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; - -import java.text.MessageFormat; -import java.util.Date; -import org.mxchange.jfinancials.enterprise.BaseFinancialsEnterpriseBean; -import org.mxchange.jfinancials.model.receipt.BillableReceipt; -import org.mxchange.jfinancials.model.receipt.Receipts; - -/** - * A general bean for receipt-related methods that can be generalized. - *

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

- * @param detachedReceipt Receipt instance to merge - *

- * @return Detached receipt instance - */ - protected BillableReceipt mergeReceipt (final BillableReceipt detachedReceipt) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeReceipt: detachedReceipt={0} - CALLED!", detachedReceipt)); //NOI18N - - // The receipt instance must be valid - if (null == detachedReceipt) { - // Throw NPE again - throw new NullPointerException("detachedReceipt is null"); //NOI18N - } else if (detachedReceipt.getReceiptId() == null) { - // Throw NPE again - throw new NullPointerException("detachedReceipt.receiptId is null"); //NOI18N //NOI18N - } else if (detachedReceipt.getReceiptId() < 1) { - // Not valid - throw new IllegalStateException(MessageFormat.format("detachedReceipt.receiptId={0} is not valid.", detachedReceipt.getReceiptId())); //NOI18N - } - - // Set updated timestamp - // @TODO detachedReceipt.setReceiptUpdated(new Date()); - // Get receipt from it and find it - final BillableReceipt foundReceipt = this.getEntityManager().find(detachedReceipt.getClass(), detachedReceipt.getReceiptId()); - - // Should be found - assert (foundReceipt instanceof BillableReceipt) : MessageFormat.format("Receipt with id {0} not found, but should be.", detachedReceipt.getReceiptId()); //NOI18N - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeReceipt: foundReceipt.receiptId={0}", foundReceipt.getReceiptId())); //NOI18N - - // Copy all - Receipts.copyReceiptData(detachedReceipt, foundReceipt); - - // Merge receipt instance - final BillableReceipt managedReceipt = this.getEntityManager().merge(foundReceipt); - - // Set updated timestamp - managedReceipt.setReceiptUpdated(new Date()); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeReceipt: managedReceipt={0} - EXIT!", managedReceipt)); //NOI18N - - // Return detached receipt - return managedReceipt; - } - -} diff --git a/src/java/org/mxchange/jfinancials/enterprise/financial/receipt/BaseFinancialsReceiptEnterpriseBean.java b/src/java/org/mxchange/jfinancials/enterprise/financial/receipt/BaseFinancialsReceiptEnterpriseBean.java new file mode 100644 index 0000000..40e5f20 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/enterprise/financial/receipt/BaseFinancialsReceiptEnterpriseBean.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; + +import java.text.MessageFormat; +import java.util.Date; +import org.mxchange.jfinancials.enterprise.product.BaseFinancialsProductEnterpriseBean; +import org.mxchange.jfinancials.model.receipt.BillableReceipt; +import org.mxchange.jfinancials.model.receipt.Receipts; + +/** + * A general bean for receipt-related methods that can be generalized. + *

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

+ * @param detachedReceipt Receipt instance to merge + *

+ * @return Detached receipt instance + */ + protected BillableReceipt mergeReceipt (final BillableReceipt detachedReceipt) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeReceipt: detachedReceipt={0} - CALLED!", detachedReceipt)); //NOI18N + + // The receipt instance must be valid + if (null == detachedReceipt) { + // Throw NPE again + throw new NullPointerException("detachedReceipt is null"); //NOI18N + } else if (detachedReceipt.getReceiptId() == null) { + // Throw NPE again + throw new NullPointerException("detachedReceipt.receiptId is null"); //NOI18N //NOI18N + } else if (detachedReceipt.getReceiptId() < 1) { + // Not valid + throw new IllegalStateException(MessageFormat.format("detachedReceipt.receiptId={0} is not valid.", detachedReceipt.getReceiptId())); //NOI18N + } + + // Set updated timestamp + // @TODO detachedReceipt.setReceiptUpdated(new Date()); + // Get receipt from it and find it + final BillableReceipt foundReceipt = this.getEntityManager().find(detachedReceipt.getClass(), detachedReceipt.getReceiptId()); + + // Should be found + assert (foundReceipt instanceof BillableReceipt) : MessageFormat.format("Receipt with id {0} not found, but should be.", detachedReceipt.getReceiptId()); //NOI18N + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeReceipt: foundReceipt.receiptId={0}", foundReceipt.getReceiptId())); //NOI18N + + // Copy all + Receipts.copyReceiptData(detachedReceipt, foundReceipt); + + // Merge receipt instance + final BillableReceipt managedReceipt = this.getEntityManager().merge(foundReceipt); + + // Set updated timestamp + managedReceipt.setReceiptEntryUpdated(new Date()); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeReceipt: managedReceipt={0} - EXIT!", managedReceipt)); //NOI18N + + // Return detached receipt + return managedReceipt; + } + +} 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. *