]> git.mxchange.org Git - jfinancials-ejb.git/commitdiff
Don't cherry-pick:
authorRoland Häder <roland@mxchange.org>
Fri, 22 Sep 2017 22:21:32 +0000 (00:21 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 22 Sep 2017 22:21:32 +0000 (00:21 +0200)
- need to change java.util.Calendar (bye bye) to java.util.Date in favour of
  PrimeFaces' p:calendar [!] tag

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jfinancials/model/receipt/FinancialAdminReceiptSessionBean.java
src/java/org/mxchange/jfinancials/model/receipt/FinancialReceiptSessionBean.java

index 8b4b615e0e16acb1996cf050bdbb270b60cd1087..021e3bc33db5dae9a9523983d4458757e3d33b2d 100644 (file)
 package org.mxchange.jfinancials.model.receipt;
 
 import java.text.MessageFormat;
-import java.util.GregorianCalendar;
-import java.util.List;
-import java.util.Objects;
+import java.util.Date;
+import javax.ejb.EJB;
 import javax.ejb.Stateless;
-import javax.persistence.Query;
 import org.mxchange.jfinancials.database.BaseFinancialsDatabaseBean;
 import org.mxchange.jfinancials.exceptions.ReceiptAlreadyAddedException;
 import org.mxchange.jusercore.model.user.User;
 
 /**
- * A stateless bean for general purposes for receipts
+ * A stateless bean for administrative purposes for receipts
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-@Stateless (name = "financialReceipt", description = "A stateless session bean for handling receipts.")
-public class FinancialReceiptSessionBean extends BaseFinancialsDatabaseBean implements FinancialReceiptSessionBeanRemote {
+@Stateless (name = "adminFinancialReceipt", description = "A stateless session bean for handling receipts.")
+public class FinancialAdminReceiptSessionBean extends BaseFinancialsDatabaseBean implements FinancialAdminReceiptSessionBeanRemote {
 
        /**
         * Serial number
         */
        private static final long serialVersionUID = 659_868_076_723_741L;
 
+       /**
+        * General receipt bean
+        */
+       @EJB
+       private FinancialReceiptSessionBean receiptBean;
+
        @Override
        public BillableReceipt addReceipt (final BillableReceipt receipt) throws ReceiptAlreadyAddedException {
                // Trace message
@@ -72,13 +76,13 @@ public class FinancialReceiptSessionBean extends BaseFinancialsDatabaseBean impl
                } else if ((receipt.getReceiptUser() instanceof User) && receipt.getReceiptUser().getUserId() < 1) {
                        // Throw NPE again
                        throw new NullPointerException(MessageFormat.format("receipt.receiptUser.userId={0} is not valid", receipt.getReceiptUser().getUserId()));
-               } else if (this.isReceiptRegistered(receipt)) {
+               } else if (this.receiptBean.isReceiptRegistered(receipt)) {
                        // Has already been registered
                        throw new ReceiptAlreadyAddedException(receipt);
                }
 
                // Add created instance
-               receipt.setReceiptCreated(new GregorianCalendar());
+               receipt.setReceiptCreated(new Date());
 
                // Persist it
                this.getEntityManager().persist(receipt);
@@ -90,96 +94,4 @@ public class FinancialReceiptSessionBean extends BaseFinancialsDatabaseBean impl
                return receipt;
        }
 
-       @Override
-       @SuppressWarnings ("unchecked")
-       public List<BillableReceipt> allReceipts () {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allReceipts(): CALLED!", this.getClass().getSimpleName()));
-
-               // Query all
-               final Query query = this.getEntityManager().createNamedQuery("AllReceipts");
-
-               // Get all
-               final List<BillableReceipt> receipts = query.getResultList();
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allReceipts(): receipts.size()={1} EXIT!", this.getClass().getSimpleName(), receipts.size()));
-
-               // Return it
-               return receipts;
-       }
-
-       @Override
-       @SuppressWarnings ("unchecked")
-       public List<BillableReceipt> allUsersReceipts (final User user) {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsersReceipts(): user={1} - CALLED!", this.getClass().getSimpleName(), user));
-
-               // Validate parameter
-               if (null == user) {
-                       // Throw NPE
-                       throw new NullPointerException("user is null");
-               } else if (user.getUserId() == null) {
-                       // Throw it again
-                       throw new NullPointerException("user.userId is null");
-               } else if (user.getUserId() < 1) {
-                       // Throw IAE
-                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId()));
-               }
-
-               // Query all
-               final Query query = this.getEntityManager().createNamedQuery("SearchAllUserReceipts");
-
-               // Add parameter
-               query.setParameter("receiptUser", user);
-
-               // Get all
-               final List<BillableReceipt> receipts = query.getResultList();
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsersReceipts(): receipts.size()={1} EXIT!", this.getClass().getSimpleName(), receipts.size()));
-
-               // Return it
-               return receipts;
-       }
-
-       /**
-        * Checks if given receipt is already persisted by checking receipt number
-        * and branch office combination.
-        * <p>
-        * @param receipt Receipt instance
-        * <p>
-        * @return Whether the receipt has already been registered
-        */
-       private boolean isReceiptRegistered (final BillableReceipt receipt) {
-               // Get all receipts
-               final List<BillableReceipt> receipts = this.allReceipts();
-
-               // Is the list empty?
-               if (receipts.isEmpty()) {
-                       // Abort here
-                       return false;
-               }
-
-               // Default is not found
-               boolean isFound = false;
-
-               // Now, check each entry
-               for (final BillableReceipt foundReceipt : receipts) {
-                       // Is same entity or same receipt number and branch office found?
-                       if (Objects.equals(foundReceipt, receipt)) {
-                               // Yes, then stop searching
-                               isFound = true;
-                               break;
-                       } else if (Receipts.isSameReceipt(foundReceipt, receipt)){
-                               // Yes, then stop searching
-                               isFound = true;
-                               break;
-                       }
-               }
-
-               // Return flag
-               return isFound;
-       }
-
 }
index 8b4b615e0e16acb1996cf050bdbb270b60cd1087..84a6228a8abbbdbccba14b0f91766c134034f4c4 100644 (file)
@@ -17,7 +17,7 @@
 package org.mxchange.jfinancials.model.receipt;
 
 import java.text.MessageFormat;
-import java.util.GregorianCalendar;
+import java.util.Date;
 import java.util.List;
 import java.util.Objects;
 import javax.ejb.Stateless;
@@ -78,7 +78,7 @@ public class FinancialReceiptSessionBean extends BaseFinancialsDatabaseBean impl
                }
 
                // Add created instance
-               receipt.setReceiptCreated(new GregorianCalendar());
+               receipt.setReceiptCreated(new Date());
 
                // Persist it
                this.getEntityManager().persist(receipt);
@@ -151,7 +151,7 @@ public class FinancialReceiptSessionBean extends BaseFinancialsDatabaseBean impl
         * <p>
         * @return Whether the receipt has already been registered
         */
-       private boolean isReceiptRegistered (final BillableReceipt receipt) {
+       public boolean isReceiptRegistered (final BillableReceipt receipt) {
                // Get all receipts
                final List<BillableReceipt> receipts = this.allReceipts();