From: Roland Häder Date: Fri, 22 Sep 2017 22:21:32 +0000 (+0200) Subject: Don't cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=459e85b805b62c04c427ec260d2fd0985b56ab66;p=jfinancials-ejb.git Don't cherry-pick: - 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 --- diff --git a/src/java/org/mxchange/jfinancials/model/receipt/FinancialAdminReceiptSessionBean.java b/src/java/org/mxchange/jfinancials/model/receipt/FinancialAdminReceiptSessionBean.java index 8b4b615..021e3bc 100644 --- a/src/java/org/mxchange/jfinancials/model/receipt/FinancialAdminReceiptSessionBean.java +++ b/src/java/org/mxchange/jfinancials/model/receipt/FinancialAdminReceiptSessionBean.java @@ -17,28 +17,32 @@ 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 *

* @author Roland Häder */ -@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 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 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 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 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. - *

- * @param receipt Receipt instance - *

- * @return Whether the receipt has already been registered - */ - private boolean isReceiptRegistered (final BillableReceipt receipt) { - // Get all receipts - final List 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; - } - } diff --git a/src/java/org/mxchange/jfinancials/model/receipt/FinancialReceiptSessionBean.java b/src/java/org/mxchange/jfinancials/model/receipt/FinancialReceiptSessionBean.java index 8b4b615..84a6228 100644 --- a/src/java/org/mxchange/jfinancials/model/receipt/FinancialReceiptSessionBean.java +++ b/src/java/org/mxchange/jfinancials/model/receipt/FinancialReceiptSessionBean.java @@ -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 *

* @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 receipts = this.allReceipts();