]> git.mxchange.org Git - jfinancials-ejb.git/commitdiff
Don't cherry-pick:
authorRoland Häder <roland@mxchange.org>
Fri, 24 Apr 2020 16:09:40 +0000 (18:09 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 24 Apr 2020 16:09:40 +0000 (18:09 +0200)
- 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 <roland@mxchange.org>
src/java/org/mxchange/jfinancials/enterprise/financial/BaseFinancialsProjectEnterpriseBean.java [deleted file]
src/java/org/mxchange/jfinancials/enterprise/financial/receipt/BaseFinancialsReceiptEnterpriseBean.java [new file with mode: 0644]
src/java/org/mxchange/jfinancials/enterprise/financial/receipt_item/BaseFinancialsReceiptItemEnterpriseBean.java [new file with mode: 0644]
src/java/org/mxchange/jfinancials/enterprise/product/BaseFinancialsProductEnterpriseBean.java
src/java/org/mxchange/jfinancials/model/receipt/FinancialAdminReceiptSessionBean.java
src/java/org/mxchange/jfinancials/model/receipt/FinancialReceiptSessionBean.java
src/java/org/mxchange/jfinancials/model/receipt_item/FinancialAdminReceiptItemSessionBean.java

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 (file)
index 211200a..0000000
+++ /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 <http://www.gnu.org/licenses/>.
- */
-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.
- * <p>
- * @author Roland Haeder<roland@mxchange.org>
- */
-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
-        * <p>
-        * @param detachedReceipt Receipt instance to merge
-        * <p>
-        * @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 (file)
index 0000000..40e5f20
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+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.
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+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
+        * <p>
+        * @param detachedReceipt Receipt instance to merge
+        * <p>
+        * @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 (file)
index 0000000..c09aa9d
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+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.
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+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
+        * <p>
+        * @param detachedReceiptItem Receipt instance to merge
+        * <p>
+        * @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;
+       }
+
+}
index aee55220cd975d22bbca5559ee34aa18edb8cf9b..35e0787f175c0194660c9eedc2a733e4ef98ab7b 100644 (file)
@@ -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
index 05030baa454312883cd1033dcfed42fd28928b76..9a4b692687b45c6496db209074c71f8b6a3b63d8 100644 (file)
@@ -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<roland@mxchange.org>
  */
 @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) {
index 487470266ca0f32a02d1fcf6adf4c85c00373b2d..25e9046a4096f309015fb07a7f5d8262f647c1f1 100644 (file)
@@ -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);
index a2fd02650e3954daeb5e6fba7d74f3a688aea244..3c361f44677e8256e12f35377a8598917a77b0bb 100644 (file)
@@ -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<roland@mxchange.org>
  */
 @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.
         * <p>