From 9df30b8fa72d65b721320f802b2bfccb2bdde6e9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 23 Sep 2017 00:20:50 +0200 Subject: [PATCH] Please cherry-pick: - need to change java.util.Calendar (bye bye) to java.util.Date in favour of PrimeFaces' p:calendar [!] tag MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../contact/PizzaAdminContactSessionBean.java | 4 +- .../PizzaAdminContactPhoneSessionBean.java | 8 +- .../PizzaAdminBusinessDataSessionBean.java | 4 +- .../PizzaAdminBranchOfficeSessionBean.java | 4 +- .../model/data/PizzaCountrySingletonBean.java | 4 +- .../PizzaAdminMobileProviderSessionBean.java | 4 +- .../phone/PizzaAdminPhoneSessionBean.java | 8 +- .../model/user/PizzaAdminUserSessionBean.java | 10 +- .../model/user/PizzaUserSessionBean.java | 14 +- .../PizzaUserEmailChangeSessionBean.java | 4 +- ...Bean.java => BasePizzaEnterpriseBean.java} | 23 ++- .../FinancialAdminReceiptSessionBean.java | 185 ++++++++++++++++++ 12 files changed, 230 insertions(+), 42 deletions(-) rename src/java/org/mxchange/pizzaaplication/database/{BasePizzaDatabaseBean.java => BasePizzaEnterpriseBean.java} (98%) create mode 100644 src/java/org/mxchange/pizzaaplication/model/receipt/FinancialAdminReceiptSessionBean.java diff --git a/src/java/org/mxchange/jcontacts/model/contact/PizzaAdminContactSessionBean.java b/src/java/org/mxchange/jcontacts/model/contact/PizzaAdminContactSessionBean.java index 2b8c12f..9481760 100644 --- a/src/java/org/mxchange/jcontacts/model/contact/PizzaAdminContactSessionBean.java +++ b/src/java/org/mxchange/jcontacts/model/contact/PizzaAdminContactSessionBean.java @@ -17,7 +17,7 @@ package org.mxchange.jcontacts.model.contact; import java.text.MessageFormat; -import java.util.GregorianCalendar; +import java.util.Date; import javax.ejb.Stateless; import javax.persistence.NoResultException; import javax.persistence.Query; @@ -64,7 +64,7 @@ public class PizzaAdminContactSessionBean extends BasePizzaDatabaseBean implemen } // Set created timestamp - contact.setContactCreated(new GregorianCalendar()); + contact.setContactCreated(new Date()); // Set all created timestamps, if instance is there this.setAllContactPhoneEntriesCreated(contact); diff --git a/src/java/org/mxchange/jcontacts/model/phone/PizzaAdminContactPhoneSessionBean.java b/src/java/org/mxchange/jcontacts/model/phone/PizzaAdminContactPhoneSessionBean.java index bff8e8f..b0bd0c5 100644 --- a/src/java/org/mxchange/jcontacts/model/phone/PizzaAdminContactPhoneSessionBean.java +++ b/src/java/org/mxchange/jcontacts/model/phone/PizzaAdminContactPhoneSessionBean.java @@ -17,7 +17,7 @@ package org.mxchange.jcontacts.model.phone; import java.text.MessageFormat; -import java.util.GregorianCalendar; +import java.util.Date; import java.util.Objects; import javax.ejb.EJB; import javax.ejb.Stateless; @@ -264,7 +264,7 @@ public class PizzaAdminContactPhoneSessionBean extends BasePizzaDatabaseBean imp } // Set created instance - faxNumber.setPhoneEntryCreated(new GregorianCalendar()); + faxNumber.setPhoneEntryCreated(new Date()); // Set fax number in contact contact.setContactFaxNumber(faxNumber); @@ -321,7 +321,7 @@ public class PizzaAdminContactPhoneSessionBean extends BasePizzaDatabaseBean imp } // Set created instance - landLineNumber.setPhoneEntryCreated(new GregorianCalendar()); + landLineNumber.setPhoneEntryCreated(new Date()); // Set landLine number in contact contact.setContactLandLineNumber(landLineNumber); @@ -372,7 +372,7 @@ public class PizzaAdminContactPhoneSessionBean extends BasePizzaDatabaseBean imp } // Set created instance - mobileNumber.setPhoneEntryCreated(new GregorianCalendar()); + mobileNumber.setPhoneEntryCreated(new Date()); // Set mobile number in contact contact.setContactMobileNumber(mobileNumber); diff --git a/src/java/org/mxchange/jcontactsbusiness/model/basicdata/PizzaAdminBusinessDataSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/basicdata/PizzaAdminBusinessDataSessionBean.java index c52dc87..0f93109 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/basicdata/PizzaAdminBusinessDataSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/basicdata/PizzaAdminBusinessDataSessionBean.java @@ -17,7 +17,7 @@ package org.mxchange.jcontactsbusiness.model.basicdata; import java.text.MessageFormat; -import java.util.GregorianCalendar; +import java.util.Date; import java.util.List; import java.util.Objects; import javax.ejb.EJB; @@ -72,7 +72,7 @@ public class PizzaAdminBusinessDataSessionBean extends BasePizzaDatabaseBean imp } // Now add current date - basicData.setCompanyCreated(new GregorianCalendar()); + basicData.setCompanyCreated(new Date()); // Is there a owner set? if (basicData.getCompanyUserOwner() instanceof User) { diff --git a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/PizzaAdminBranchOfficeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/PizzaAdminBranchOfficeSessionBean.java index b8f30c2..f50e3dc 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/PizzaAdminBranchOfficeSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/PizzaAdminBranchOfficeSessionBean.java @@ -17,7 +17,7 @@ package org.mxchange.jcontactsbusiness.model.branchoffice; import java.text.MessageFormat; -import java.util.GregorianCalendar; +import java.util.Date; import java.util.List; import javax.ejb.EJB; import javax.ejb.Stateless; @@ -72,7 +72,7 @@ public class PizzaAdminBranchOfficeSessionBean extends BasePizzaDatabaseBean imp } // Add created timestamp - branchOffice.setBranchCreated(new GregorianCalendar()); + branchOffice.setBranchCreated(new Date()); // Is user instance set? if (branchOffice.getBranchCompany() instanceof BusinessBasicData) { diff --git a/src/java/org/mxchange/jcountry/model/data/PizzaCountrySingletonBean.java b/src/java/org/mxchange/jcountry/model/data/PizzaCountrySingletonBean.java index 7f3b2bc..f938dd8 100644 --- a/src/java/org/mxchange/jcountry/model/data/PizzaCountrySingletonBean.java +++ b/src/java/org/mxchange/jcountry/model/data/PizzaCountrySingletonBean.java @@ -17,7 +17,7 @@ package org.mxchange.jcountry.model.data; import java.text.MessageFormat; -import java.util.GregorianCalendar; +import java.util.Date; import java.util.List; import javax.ejb.Singleton; import javax.ejb.Startup; @@ -72,7 +72,7 @@ public class PizzaCountrySingletonBean extends BasePizzaDatabaseBean implements } // Add timestamp - country.setCountryEntryCreated(new GregorianCalendar()); + country.setCountryEntryCreated(new Date()); // It is not added, so persist it this.getEntityManager().persist(country); diff --git a/src/java/org/mxchange/jphone/model/phonenumbers/mobileprovider/PizzaAdminMobileProviderSessionBean.java b/src/java/org/mxchange/jphone/model/phonenumbers/mobileprovider/PizzaAdminMobileProviderSessionBean.java index 4d9adf2..d0c6a14 100644 --- a/src/java/org/mxchange/jphone/model/phonenumbers/mobileprovider/PizzaAdminMobileProviderSessionBean.java +++ b/src/java/org/mxchange/jphone/model/phonenumbers/mobileprovider/PizzaAdminMobileProviderSessionBean.java @@ -17,7 +17,7 @@ package org.mxchange.jphone.model.phonenumbers.mobileprovider; import java.text.MessageFormat; -import java.util.GregorianCalendar; +import java.util.Date; import javax.ejb.Stateless; import org.mxchange.jphone.exceptions.MobileProviderAlreadyAddedException; import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean; @@ -79,7 +79,7 @@ public class PizzaAdminMobileProviderSessionBean extends BasePizzaDatabaseBean i } // Set creation timestamp - mobileProvider.setProviderEntryCreated(new GregorianCalendar()); + mobileProvider.setProviderEntryCreated(new Date()); // Persist it this.getEntityManager().persist(mobileProvider); diff --git a/src/java/org/mxchange/jphone/model/phonenumbers/phone/PizzaAdminPhoneSessionBean.java b/src/java/org/mxchange/jphone/model/phonenumbers/phone/PizzaAdminPhoneSessionBean.java index de0958e..d023dfd 100644 --- a/src/java/org/mxchange/jphone/model/phonenumbers/phone/PizzaAdminPhoneSessionBean.java +++ b/src/java/org/mxchange/jphone/model/phonenumbers/phone/PizzaAdminPhoneSessionBean.java @@ -17,7 +17,7 @@ package org.mxchange.jphone.model.phonenumbers.phone; import java.text.MessageFormat; -import java.util.GregorianCalendar; +import java.util.Date; import javax.ejb.Stateless; import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; import org.mxchange.jphone.model.phonenumbers.fax.FaxNumbers; @@ -235,7 +235,7 @@ public class PizzaAdminPhoneSessionBean extends BasePizzaDatabaseBean implements // Set updated timestamp FaxNumbers.copyAll(faxNumber, managedNumber); - managedNumber.setPhoneEntryUpdated(new GregorianCalendar()); + managedNumber.setPhoneEntryUpdated(new Date()); // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateFaxData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N @@ -293,7 +293,7 @@ public class PizzaAdminPhoneSessionBean extends BasePizzaDatabaseBean implements // Set updated timestamp LandLineNumbers.copyAll(landLineNumber, managedNumber); - managedNumber.setPhoneEntryUpdated(new GregorianCalendar()); + managedNumber.setPhoneEntryUpdated(new Date()); // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateLandLineData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N @@ -345,7 +345,7 @@ public class PizzaAdminPhoneSessionBean extends BasePizzaDatabaseBean implements // Set updated timestamp MobileNumbers.copyAll(mobileNumber, managedNumber); - managedNumber.setPhoneEntryUpdated(new GregorianCalendar()); + managedNumber.setPhoneEntryUpdated(new Date()); // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateMobileData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N diff --git a/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java index e451aef..976b865 100644 --- a/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java @@ -17,7 +17,7 @@ package org.mxchange.jusercore.model.user; import java.text.MessageFormat; -import java.util.GregorianCalendar; +import java.util.Date; import javax.ejb.EJB; import javax.ejb.Stateless; import org.mxchange.jcontacts.model.contact.Contact; @@ -88,8 +88,8 @@ public class PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements } // Set created timestamp - user.setUserCreated(new GregorianCalendar()); - user.getUserContact().setContactCreated(new GregorianCalendar()); + user.setUserCreated(new Date()); + user.getUserContact().setContactCreated(new Date()); // Update cellphone, land-line and fax instance this.setAllContactPhoneEntriesCreated(user.getUserContact()); @@ -185,7 +185,7 @@ public class PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements user.setUserContact(foundContact); // Set timestamp - user.setUserCreated(new GregorianCalendar()); + user.setUserCreated(new Date()); // Perist it this.getEntityManager().persist(user); @@ -246,7 +246,7 @@ public class PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements // Set as locked, set timestamp and lock reason user.setUserAccountStatus(UserAccountStatus.LOCKED); - user.setUserLastLocked(new GregorianCalendar()); + user.setUserLastLocked(new Date()); user.setUserLastLockedReason(userLockReason); // Update user diff --git a/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java index 9653c09..9fa1b74 100644 --- a/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java @@ -17,7 +17,7 @@ package org.mxchange.jusercore.model.user; import java.text.MessageFormat; -import java.util.GregorianCalendar; +import java.util.Date; import java.util.List; import javax.ejb.EJB; import javax.ejb.EJBException; @@ -194,7 +194,7 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS // Update user status and remove confirmation key managedUser.setUserAccountStatus(UserAccountStatus.CONFIRMED); managedUser.setUserConfirmKey(null); - managedUser.setUserUpdated(new GregorianCalendar()); + managedUser.setUserUpdated(new Date()); // Send out email this.sendEmail("User account confirmed", "user_account_confirmed", managedUser, baseUrl, null); //NOI18N @@ -598,7 +598,7 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS UserUtils.copyAll(user, managedUser); // Set as updated - managedUser.setUserUpdated(new GregorianCalendar()); + managedUser.setUserUpdated(new Date()); // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N @@ -658,13 +658,13 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS final User managedUser = this.updateUserData(user); // Update user account - managedUser.setUserUpdated(new GregorianCalendar()); + managedUser.setUserUpdated(new Date()); // Create history entry PasswordHistory entry = new UserPasswordHistory(user.getUserEncryptedPassword(), managedUser); // Set created timestamp - entry.setUserPasswordHistoryCreated(new GregorianCalendar()); + entry.setUserPasswordHistoryCreated(new Date()); // Merge user to make sure it is not re-persisted final User mergedUser = this.getEntityManager().merge(managedUser); @@ -716,8 +716,8 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS UserUtils.copyAll(user, managedUser); // Set as updated - managedUser.setUserUpdated(new GregorianCalendar()); - managedUser.getUserContact().setContactUpdated(new GregorianCalendar()); + managedUser.setUserUpdated(new Date()); + managedUser.getUserContact().setContactUpdated(new Date()); // Get contact from it and find it final Contact foundContact = this.getEntityManager().find(managedUser.getUserContact().getClass(), managedUser.getUserContact().getContactId()); diff --git a/src/java/org/mxchange/jusercore/model/user/email_address/PizzaUserEmailChangeSessionBean.java b/src/java/org/mxchange/jusercore/model/user/email_address/PizzaUserEmailChangeSessionBean.java index 6383c7d..5518554 100644 --- a/src/java/org/mxchange/jusercore/model/user/email_address/PizzaUserEmailChangeSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/email_address/PizzaUserEmailChangeSessionBean.java @@ -17,7 +17,7 @@ package org.mxchange.jusercore.model.user.email_address; import java.text.MessageFormat; -import java.util.GregorianCalendar; +import java.util.Date; import java.util.List; import javax.ejb.EJB; import javax.ejb.EJBException; @@ -106,7 +106,7 @@ public class PizzaUserEmailChangeSessionBean extends BasePizzaDatabaseBean imple } // The email change is not (yet) there, add secure hash and "created" timestamp - emailChange.setEmailChangeCreated(new GregorianCalendar()); + emailChange.setEmailChangeCreated(new Date()); this.generateSecureHash(emailChange); // Make user managed diff --git a/src/java/org/mxchange/pizzaaplication/database/BasePizzaDatabaseBean.java b/src/java/org/mxchange/pizzaaplication/database/BasePizzaEnterpriseBean.java similarity index 98% rename from src/java/org/mxchange/pizzaaplication/database/BasePizzaDatabaseBean.java rename to src/java/org/mxchange/pizzaaplication/database/BasePizzaEnterpriseBean.java index 3ae9d62..c7caf4d 100644 --- a/src/java/org/mxchange/pizzaaplication/database/BasePizzaDatabaseBean.java +++ b/src/java/org/mxchange/pizzaaplication/database/BasePizzaEnterpriseBean.java @@ -17,7 +17,7 @@ package org.mxchange.pizzaaplication.database; import java.text.MessageFormat; -import java.util.GregorianCalendar; +import java.util.Date; import java.util.Objects; import java.util.Properties; import javax.ejb.EJBException; @@ -54,7 +54,7 @@ import org.mxchange.jusercore.model.user.UserUtils; *

* @author Roland Häder */ -public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean { +public abstract class BasePizzaEnterpriseBean extends BaseDatabaseBean { /** * Serial number @@ -64,7 +64,7 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean { /** * Protected constructor */ - protected BasePizzaDatabaseBean () { + protected BasePizzaEnterpriseBean () { // Call super constructor super(); } @@ -75,7 +75,7 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean { * @param factoryJndi JNDI name for queue factory * @param queueJndi JNDI name for email queue */ - protected BasePizzaDatabaseBean (final String factoryJndi, final String queueJndi) { + protected BasePizzaEnterpriseBean (final String factoryJndi, final String queueJndi) { // Call super constructor super(factoryJndi, queueJndi); } @@ -109,7 +109,7 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean { this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N // Set updated timestamp - landLineNumber.setPhoneEntryCreated(new GregorianCalendar()); + landLineNumber.setPhoneEntryCreated(new Date()); } // Is a fax number instance set? @@ -118,7 +118,7 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean { this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N // Set updated timestamp - faxNumber.setPhoneEntryCreated(new GregorianCalendar()); + faxNumber.setPhoneEntryCreated(new Date()); } // Is a mobile number instance set? @@ -127,7 +127,7 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean { this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for mobile number ...", this.getClass().getSimpleName())); //NOI18N // Set updated timestamp - mobileNumber.setPhoneEntryCreated(new GregorianCalendar()); + mobileNumber.setPhoneEntryCreated(new Date()); } // Trace message @@ -499,6 +499,9 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean { throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N } + // Set updated timestamp + detachedContact.setContactUpdated(new Date()); + // Get contact from it and find it final Contact foundContact = this.getEntityManager().find(detachedContact.getClass(), detachedContact.getContactId()); @@ -881,7 +884,7 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean { this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N // Set updated timestamp - landLineNumber.setPhoneEntryUpdated(new GregorianCalendar()); + landLineNumber.setPhoneEntryUpdated(new Date()); } // Is a fax number instance set? @@ -890,7 +893,7 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean { this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N // Set updated timestamp - faxNumber.setPhoneEntryUpdated(new GregorianCalendar()); + faxNumber.setPhoneEntryUpdated(new Date()); } // Is a mobile number instance set? @@ -899,7 +902,7 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean { this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for mobile number ...", this.getClass().getSimpleName())); //NOI18N // Set updated timestamp - mobileNumber.setPhoneEntryUpdated(new GregorianCalendar()); + mobileNumber.setPhoneEntryUpdated(new Date()); } // Trace message diff --git a/src/java/org/mxchange/pizzaaplication/model/receipt/FinancialAdminReceiptSessionBean.java b/src/java/org/mxchange/pizzaaplication/model/receipt/FinancialAdminReceiptSessionBean.java new file mode 100644 index 0000000..8b4b615 --- /dev/null +++ b/src/java/org/mxchange/pizzaaplication/model/receipt/FinancialAdminReceiptSessionBean.java @@ -0,0 +1,185 @@ +/* + * Copyright (C) 2017 Roland Häder + * + * 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.model.receipt; + +import java.text.MessageFormat; +import java.util.GregorianCalendar; +import java.util.List; +import java.util.Objects; +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 + *

+ * @author Roland Häder + */ +@Stateless (name = "financialReceipt", description = "A stateless session bean for handling receipts.") +public class FinancialReceiptSessionBean extends BaseFinancialsDatabaseBean implements FinancialReceiptSessionBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 659_868_076_723_741L; + + @Override + public BillableReceipt addReceipt (final BillableReceipt receipt) throws ReceiptAlreadyAddedException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addReceipt(): receipt={1} - CALLED!", this.getClass().getSimpleName(), receipt)); + + // Validate parameter + if (null == receipt) { + // Throw NPE + throw new NullPointerException("receipt is null"); + } else if (receipt.getReceiptId() != null) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("receipt.receiptId={0} is not expected.", receipt.getReceiptId())); + } else if (receipt.getReceiptIssued() == null) { + // Throw NPE again + throw new NullPointerException("receipt.receiptIssued is null"); + } else if (receipt.getReceiptBranchOffice() == null) { + // Throw it again + throw new NullPointerException("receipt.receiptBranchOffice is null"); + } else if (receipt.getReceiptBranchOffice().getBranchId() == null) { + // Throw it again + throw new NullPointerException("receipt.receiptBranchOffice.branchId is null"); + } else if (receipt.getReceiptBranchOffice().getBranchId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("receipt.receiptBranchOffice.branchId={0} is not valid.", receipt.getReceiptBranchOffice().getBranchId())); + } else if (receipt.getReceiptPaymentType() == null) { + // Throw NPE + throw new NullPointerException("receipt.receiptPaymentType is null"); + } else if ((receipt.getReceiptUser() instanceof User) && receipt.getReceiptUser().getUserId() == null) { + // Throw NPE again + throw new NullPointerException("receipt.receiptUser.userId is null"); + } 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)) { + // Has already been registered + throw new ReceiptAlreadyAddedException(receipt); + } + + // Add created instance + receipt.setReceiptCreated(new GregorianCalendar()); + + // Persist it + this.getEntityManager().persist(receipt); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addReceipt(): receipt.receiptId={1} - EXIT!", this.getClass().getSimpleName(), receipt.getReceiptId())); + + // Return it + 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; + } + +} -- 2.39.5