From 9186caf770af8b200e79c5487819cdde0bebe104 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 13 Mar 2018 23:21:16 +0100 Subject: [PATCH] Don't cherry-pick: - updated persistence.xml with new entities (bonus cards and such) - added (not done with with this commit) new project dependencies, like juser-activity-lib, jcustomer-core and jcustomer-lib - implemented protected methodsfor creating managed instances of Product - receipt items now reference an "item manufacturer" which is a BasicData instance - discounts may be added multiple times, so never consider them as being added - ignore more string for internationalization - changed copyright to Free Software Foundation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- nbproject/build-impl.xml | 48 ++-- nbproject/project.properties | 13 +- nbproject/project.xml | 5 +- src/conf/persistence.xml | 4 +- .../database/BaseFinancialsDatabaseBean.java | 258 ++++++++++++++---- .../BaseFinancialsProductDatabaseBean.java | 46 +++- .../income/FinancialIncomeSessionBean.java | 91 ++++++ .../FinancialAdminReceiptSessionBean.java | 24 +- .../receipt/FinancialReceiptSessionBean.java | 46 ++-- .../FinancialAdminReceiptItemSessionBean.java | 37 ++- .../FinancialReceiptItemSessionBean.java | 7 +- 11 files changed, 457 insertions(+), 122 deletions(-) create mode 100644 src/java/org/mxchange/jfinancials/model/income/FinancialIncomeSessionBean.java diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml index 8a670fe..d838054 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -851,16 +851,19 @@ exists or setup the property manually. For example like this: + - + + + @@ -875,23 +878,26 @@ exists or setup the property manually. For example like this: + - + + + - + @@ -899,21 +905,24 @@ exists or setup the property manually. For example like this: - - - + + + - - - - - - - - - - - + + + + + + + + + + + + + + @@ -924,16 +933,19 @@ exists or setup the property manually. For example like this: + - + + + diff --git a/nbproject/project.properties b/nbproject/project.properties index 307a88f..7005315 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -23,6 +23,8 @@ endorsed.classpath= excludes= file.reference.jcontacts-business-core.jar=lib/jcontacts-business-core.jar file.reference.jcontacts-business-lib.jar=lib/jcontacts-business-lib.jar +file.reference.jcustomer-core.jar=lib/jcustomer-core.jar +file.reference.jcustomer-lib.jar=lib/jcustomer-lib.jar file.reference.jfinancials-mailer.jar=lib/jfinancials-mailer.jar file.reference.cdi-api.jar=lib/cdi-api.jar file.reference.jcontacts-core.jar=lib/jcontacts-core.jar @@ -37,6 +39,7 @@ file.reference.jphone-lib.jar=lib/jphone-lib.jar file.reference.jproduct-core.jar=lib/jproduct-core.jar file.reference.jproduct-lib.jar=lib/jproduct-lib.jar file.reference.juser-activity-core.jar=lib/juser-activity-core.jar +file.reference.juser-activity-lib.jar=lib/juser-activity-lib.jar file.reference.juser-core.jar=lib/juser-core.jar file.reference.juser-lib.jar=lib/juser-lib.jar file.reference.juser-login-core.jar=lib/juser-login-core.jar @@ -45,7 +48,7 @@ includes=** j2ee.compile.on.save=true j2ee.deploy.on.save=true j2ee.platform=1.7 -j2ee.platform.classpath=${j2ee.server.home}/modules/endorsed/javax.annotation-api.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar:${j2ee.server.home}/modules/javax.batch-api.jar:${j2ee.server.home}/modules/javax.security.auth.message-api.jar:${j2ee.server.home}/modules/javax.faces.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl-api.jar:${j2ee.server.home}/modules/javax.transaction-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/javax.mail.jar:${j2ee.server.home}/modules/javax.interceptor-api.jar:${j2ee.server.home}/modules/javax.inject.jar:${j2ee.server.home}/modules/javax.resource-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent-api.jar:${j2ee.server.home}/modules/javax.el.jar:${j2ee.server.home}/modules/javax.ejb-api.jar:${j2ee.server.home}/modules/javax.xml.rpc-api.jar:${j2ee.server.home}/modules/javax.security.jacc-api.jar:${j2ee.server.home}/modules/javax.json.jar:${j2ee.server.home}/modules/javax.xml.registry-api.jar:${j2ee.server.home}/modules/javax.websocket-api.jar:${j2ee.server.home}/modules/javax.management.j2ee-api.jar:${j2ee.server.home}/modules/javax.servlet-api.jar:${j2ee.server.home}/modules/javax.jms-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl.jar:${j2ee.server.home}/modules/javax.enterprise.deploy-api.jar:${j2ee.server.home}/modules/javax.ws.rs-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp-api.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/cdi-api.jar:${j2ee.server.home}/modules/javax.persistence.jar:${j2ee.server.middleware}/mq/lib/jaxm-api.jar +j2ee.platform.classpath=${j2ee.server.home}/modules/endorsed/javax.annotation-api.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar:${j2ee.server.home}/modules/javax.batch-api.jar:${j2ee.server.home}/modules/javax.security.enterprise-api.jar:${j2ee.server.home}/modules/javax.security.enterprise.jar:${j2ee.server.home}/modules/javax.security.auth.message-api.jar:${j2ee.server.home}/modules/javax.faces.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl-api.jar:${j2ee.server.home}/modules/javax.transaction-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/javax.mail.jar:${j2ee.server.home}/modules/javax.interceptor-api.jar:${j2ee.server.home}/modules/javax.inject.jar:${j2ee.server.home}/modules/javax.resource-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent-api.jar:${j2ee.server.home}/modules/javax.el.jar:${j2ee.server.home}/modules/javax.ejb-api.jar:${j2ee.server.home}/modules/javax.xml.rpc-api.jar:${j2ee.server.home}/modules/javax.security.jacc-api.jar:${j2ee.server.home}/modules/javax.json.jar:${j2ee.server.home}/modules/javax.xml.registry-api.jar:${j2ee.server.home}/modules/javax.websocket-api.jar:${j2ee.server.home}/modules/javax.management.j2ee-api.jar:${j2ee.server.home}/modules/javax.servlet-api.jar:${j2ee.server.home}/modules/javax.jms-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl.jar:${j2ee.server.home}/modules/javax.enterprise.deploy-api.jar:${j2ee.server.home}/modules/javax.ws.rs-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp-api.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/cdi-api.jar:${j2ee.server.home}/modules/javax.persistence.jar:${j2ee.server.middleware}/mq/lib/jaxm-api.jar j2ee.platform.embeddableejb.classpath=${j2ee.server.home}/lib/embedded/glassfish-embedded-static-shell.jar j2ee.platform.wscompile.classpath=${j2ee.server.home}/modules/webservices-osgi.jar j2ee.platform.wsgen.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar @@ -63,16 +66,19 @@ javac.classpath=\ ${file.reference.jphone-core.jar}:\ ${file.reference.jphone-lib.jar}:\ ${file.reference.jcontacts-core.jar}:\ + ${file.reference.jcontacts-lib.jar}:\ ${file.reference.jcontacts-business-core.jar}:\ ${file.reference.jcontacts-business-lib.jar}:\ - ${file.reference.jcontacts-lib.jar}:\ ${file.reference.jproduct-core.jar}:\ + ${file.reference.jcustomer-core.jar}:\ + ${file.reference.jcustomer-lib.jar}:\ ${file.reference.jproduct-lib.jar}:\ ${file.reference.juser-core.jar}:\ ${file.reference.juser-lib.jar}:\ ${file.reference.juser-login-core.jar}:\ ${file.reference.juser-login-lib.jar}:\ ${file.reference.juser-activity-core.jar}:\ + ${file.reference.juser-activity-lib.jar}:\ ${file.reference.jmailer-ee.jar}:\ ${reference.jfinancials-core.jar}:\ ${reference.jfinancials-lib.jar}:\ @@ -123,6 +129,8 @@ runmain.jvmargs= source.encoding=UTF-8 source.reference.jcontacts-business-core.jar=../jcontacts-business-core/src/ source.reference.jcontacts-business-lib.jar=../jcontacts-business-lib/src/ +source.reference.jcustomer-core.jar=../jcustomer-core/src/ +source.reference.jcustomer-lib.jar=../jcustomer-lib/src/ source.reference.jfinancials-mailer.jar=../jfinancials-mailer/src/ source.reference.jcontacts-core.jar=../jcontacts-core/src/ source.reference.jcontacts-lib.jar=../jcontacts-lib/src/ @@ -136,6 +144,7 @@ source.reference.jphone-lib.jar=../jphone-lib/src/ source.reference.jproduct-core.jar=../jproduct-core/src/ source.reference.jproduct-lib.jar=../jproduct-lib/src/ source.reference.juser-activity-core.jar=../juser-activity-core/src/ +source.reference.juser-activity-lib.jar=../juser-activity-lib/src/ source.reference.juser-core.jar=../juser-core/src/ source.reference.juser-lib.jar=../juser-lib/src/ source.reference.juser-login-core.jar=../juser-login-core/src/ diff --git a/nbproject/project.xml b/nbproject/project.xml index bc50468..b4b207e 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -12,16 +12,19 @@ file.reference.jphone-core.jar file.reference.jphone-lib.jar file.reference.jcontacts-core.jar + file.reference.jcontacts-lib.jar file.reference.jcontacts-business-core.jar file.reference.jcontacts-business-lib.jar - file.reference.jcontacts-lib.jar file.reference.jproduct-core.jar + file.reference.jcustomer-core.jar + file.reference.jcustomer-lib.jar file.reference.jproduct-lib.jar file.reference.juser-core.jar file.reference.juser-lib.jar file.reference.juser-login-core.jar file.reference.juser-login-lib.jar file.reference.juser-activity-core.jar + file.reference.juser-activity-lib.jar file.reference.jmailer-ee.jar reference.jfinancials-core.jar reference.jfinancials-lib.jar diff --git a/src/conf/persistence.xml b/src/conf/persistence.xml index 61a44e2..8ce6eb6 100644 --- a/src/conf/persistence.xml +++ b/src/conf/persistence.xml @@ -7,7 +7,7 @@ org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice org.mxchange.jcontactsbusiness.model.department.BusinessDepartment org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee - org.mxchange.jcontactsbusiness.model.headquarters.BusinessHeadquarters + org.mxchange.jcontactsbusiness.model.headquarter.BusinessHeadquarter org.mxchange.jcontactsbusiness.model.jobposition.EmployeePosition org.mxchange.jcontactsbusiness.model.logo.BusinessLogo org.mxchange.jcontactsbusiness.model.opening_time.BusinessOpeningTime @@ -25,6 +25,8 @@ org.mxchange.jusercore.model.user.LoginUser org.mxchange.jusercore.model.user.activity.UserActivityLog org.mxchange.jusercore.model.user.password_history.UserPasswordHistory + org.mxchange.jcustomercore.model.customer.ContactCustomer + org.mxchange.jfinancials.model.bonus_card.FinancialBonusCard false diff --git a/src/java/org/mxchange/jfinancials/database/BaseFinancialsDatabaseBean.java b/src/java/org/mxchange/jfinancials/database/BaseFinancialsDatabaseBean.java index 9e0d2b7..f2faacd 100644 --- a/src/java/org/mxchange/jfinancials/database/BaseFinancialsDatabaseBean.java +++ b/src/java/org/mxchange/jfinancials/database/BaseFinancialsDatabaseBean.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 Free Software Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,19 +29,16 @@ import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import org.mxchange.jcontacts.model.contact.Contact; import org.mxchange.jcontacts.model.contact.ContactUtils; -import org.mxchange.jcontacts.model.contact.UserContact; import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; -import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; -import org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice; -import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee; +import org.mxchange.jcontactsbusiness.model.department.Department; import org.mxchange.jcontactsbusiness.model.employee.Employable; -import org.mxchange.jcontactsbusiness.model.headquarters.BusinessHeadquarters; -import org.mxchange.jcontactsbusiness.model.headquarters.Headquarter; +import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; +import org.mxchange.jcontactsbusiness.model.jobposition.JobPosition; import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; -import org.mxchange.jcoreee.database.BaseDatabaseBean; +import org.mxchange.jcoreee.bean.ejb.BaseEnterpriseBean; import org.mxchange.jcountry.model.data.Country; -import org.mxchange.jcountry.model.data.CountryData; +import org.mxchange.jfinancials.model.receipt.BillableReceipt; import org.mxchange.jmailee.model.delivery.wrapper.EmailDeliveryWrapper; import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery; import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; @@ -50,8 +47,8 @@ import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumbers; import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumbers; +import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider; import org.mxchange.jphone.utils.PhoneUtils; -import org.mxchange.jusercore.model.user.LoginUser; import org.mxchange.jusercore.model.user.User; import org.mxchange.jusercore.model.user.UserUtils; @@ -60,7 +57,7 @@ import org.mxchange.jusercore.model.user.UserUtils; *

* @author Roland Häder */ -public abstract class BaseFinancialsDatabaseBean extends BaseDatabaseBean { +public abstract class BaseFinancialsDatabaseBean extends BaseEnterpriseBean { /** * Serial number @@ -103,14 +100,14 @@ public abstract class BaseFinancialsDatabaseBean extends BaseDatabaseBean { throw new NullPointerException("contact is null"); //NOI18N } else if (contact.getContactId() == null) { // Id is set - throw new NullPointerException("contact.contactId is null"); //NOI18N + throw new NullPointerException("contact.branchId is null"); //NOI18N } else if (contact.getContactId() < 1) { // Id is set - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N + throw new IllegalArgumentException(MessageFormat.format("contact.branchId={0} is invalid", contact.getContactId())); //NOI18N } // Try to find it (should be there) - final Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId()); + final Contact managedContact = this.getEntityManager().find(contact.getClass(), contact.getContactId()); // Should be there assert (managedContact instanceof Contact) : "managedContact is null"; //NOI18N @@ -146,7 +143,7 @@ public abstract class BaseFinancialsDatabaseBean extends BaseDatabaseBean { } // Try to find it (should be there) - final Country managedCountry = this.getEntityManager().find(CountryData.class, country.getCountryId()); + final Country managedCountry = this.getEntityManager().find(country.getClass(), country.getCountryId()); // Should be there assert (managedCountry instanceof Country) : "managedCountry is null"; //NOI18N @@ -182,7 +179,7 @@ public abstract class BaseFinancialsDatabaseBean extends BaseDatabaseBean { } // Try to find it (should be there) - final BasicData managedBasicData = this.getEntityManager().find(BusinessBasicData.class, basicData.getBasicDataId()); + final BasicData managedBasicData = this.getEntityManager().find(basicData.getClass(), basicData.getBasicDataId()); // Should be there assert (managedBasicData instanceof BasicData) : "managedBasicData is null"; //NOI18N @@ -197,31 +194,31 @@ public abstract class BaseFinancialsDatabaseBean extends BaseDatabaseBean { /** * Get back a managed instance from given branch office *

- * @param headquarter Unmanaged/detached branch office instance + * @param branchOffice Unmanaged/detached branch office instance *

- * @return Managed basic data instance + * @return Managed branch office instance */ - protected BranchOffice createManaged (final BranchOffice headquarter) { + protected BranchOffice createManaged (final BranchOffice branchOffice) { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: headquarter={1} - CALLED!", this.getClass().getSimpleName(), headquarter)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: branchOffice={1} - CALLED!", this.getClass().getSimpleName(), branchOffice)); //NOI18N // user should not be null - if (null == headquarter) { + if (null == branchOffice) { // Abort here - throw new NullPointerException("headquarter is null"); //NOI18N - } else if (headquarter.getBranchId() == null) { + throw new NullPointerException("branchOffice is null"); //NOI18N + } else if (branchOffice.getBranchId() == null) { // Id is set - throw new NullPointerException("headquarter.headquarterId is null"); //NOI18N - } else if (headquarter.getBranchId() < 1) { + throw new NullPointerException("branchOffice.branchId is null"); //NOI18N + } else if (branchOffice.getBranchId() < 1) { // Id is set - throw new IllegalArgumentException(MessageFormat.format("headquarter.headquarterId={0} is invalid", headquarter.getBranchId())); //NOI18N + throw new IllegalArgumentException(MessageFormat.format("branchOffice.branchId={0} is invalid", branchOffice.getBranchId())); //NOI18N } // Try to find it (should be there) - final BranchOffice managedBranchOffice = this.getEntityManager().find(BusinessBranchOffice.class, headquarter.getBranchId()); + final BranchOffice managedBranchOffice = this.getEntityManager().find(branchOffice.getClass(), branchOffice.getBranchId()); // Should be there - assert (managedBranchOffice instanceof BasicData) : "managedBranchOffice is null"; //NOI18N + assert (managedBranchOffice instanceof BranchOffice) : "managedBranchOffice is null"; //NOI18N // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedBranchOffice={1} - EXIT!", this.getClass().getSimpleName(), managedBranchOffice)); //NOI18N @@ -230,6 +227,42 @@ public abstract class BaseFinancialsDatabaseBean extends BaseDatabaseBean { return managedBranchOffice; } + /** + * Get back a managed instance from given department + *

+ * @param department Unmanaged/detached department instance + *

+ * @return Managed department instance + */ + protected Department createManaged (final Department department) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: department={1} - CALLED!", this.getClass().getSimpleName(), department)); //NOI18N + + // user should not be null + if (null == department) { + // Abort here + throw new NullPointerException("department is null"); //NOI18N + } else if (department.getDepartmentId() == null) { + // Id is set + throw new NullPointerException("department.departmentId is null"); //NOI18N + } else if (department.getDepartmentId() < 1) { + // Id is set + throw new IllegalArgumentException(MessageFormat.format("department.departmentId={0} is invalid", department.getDepartmentId())); //NOI18N + } + + // Try to find it (should be there) + final Department managedDepartment = this.getEntityManager().find(department.getClass(), department.getDepartmentId()); + + // Should be there + assert (managedDepartment instanceof Department) : "managedDepartment is null"; //NOI18N + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedDepartment={1} - EXIT!", this.getClass().getSimpleName(), managedDepartment)); //NOI18N + + // Return it + return managedDepartment; + } + /** * Get back a managed instance from given employee *

@@ -254,7 +287,7 @@ public abstract class BaseFinancialsDatabaseBean extends BaseDatabaseBean { } // Try to find it (should be there) - final Employable managedEmployee = this.getEntityManager().find(BusinessEmployee.class, employee.getEmployeeId()); + final Employable managedEmployee = this.getEntityManager().find(employee.getClass(), employee.getEmployeeId()); // Should be there assert (managedEmployee instanceof Employable) : "managedEmployee is null"; //NOI18N @@ -267,39 +300,111 @@ public abstract class BaseFinancialsDatabaseBean extends BaseDatabaseBean { } /** - * Get back a managed instance from given headquarters + * Get back a managed instance from given headquarter *

- * @param headquarters Unmanaged/detached headquarters instance + * @param headquarter Unmanaged/detached headquarter instance *

* @return Managed basic data instance */ - protected Headquarter createManaged (final Headquarter headquarters) { + protected Headquarter createManaged (final Headquarter headquarter) { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: headquarter={1} - CALLED!", this.getClass().getSimpleName(), headquarters)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: headquarter={1} - CALLED!", this.getClass().getSimpleName(), headquarter)); //NOI18N // user should not be null - if (null == headquarters) { + if (null == headquarter) { // Abort here throw new NullPointerException("headquarter is null"); //NOI18N - } else if (headquarters.getHeadquartersId() == null) { + } else if (headquarter.getHeadquarterId() == null) { + // Id is set + throw new NullPointerException("headquarter.headquarterId is null"); //NOI18N + } else if (headquarter.getHeadquarterId() < 1) { + // Id is set + throw new IllegalArgumentException(MessageFormat.format("headquarter.headquarterId={0} is invalid", headquarter.getHeadquarterId())); //NOI18N + } + + // Try to find it (should be there) + final Headquarter managedHeadquarter = this.getEntityManager().find(headquarter.getClass(), headquarter.getHeadquarterId()); + + // Should be there + assert (managedHeadquarter instanceof BasicData) : "managedHeadquarter is null"; //NOI18N + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedHeadquarter={1} - EXIT!", this.getClass().getSimpleName(), managedHeadquarter)); //NOI18N + + // Return it + return managedHeadquarter; + } + + /** + * Get back a managed instance from given job position + *

+ * @param jobPosition Unmanaged/detached job position instance + *

+ * @return Managed job position instance + */ + protected JobPosition createManaged (final JobPosition jobPosition) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: jobPosition={1} - CALLED!", this.getClass().getSimpleName(), jobPosition)); //NOI18N + + // user should not be null + if (null == jobPosition) { + // Abort here + throw new NullPointerException("jobPosition is null"); //NOI18N + } else if (jobPosition.getJobPositionId() == null) { + // Id is set + throw new NullPointerException("jobPosition.jobPositionId is null"); //NOI18N + } else if (jobPosition.getJobPositionId() < 1) { + // Id is set + throw new IllegalArgumentException(MessageFormat.format("jobPosition.jobPositionId={0} is invalid", jobPosition.getJobPositionId())); //NOI18N + } + + // Try to find it (should be there) + final JobPosition managedJobPosition = this.getEntityManager().find(jobPosition.getClass(), jobPosition.getJobPositionId()); + + // Should be there + assert (managedJobPosition instanceof JobPosition) : "managedJobPosition is null"; //NOI18N + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedJobPosition={1} - EXIT!", this.getClass().getSimpleName(), managedJobPosition)); //NOI18N + + // Return it + return managedJobPosition; + } + + /** + * Get back a managed instance from given mobile provider + *

+ * @param mobileProvider Unmanaged/detached mobile provider instance + *

+ * @return Managed mobile provider instance + */ + protected MobileProvider createManaged (final MobileProvider mobileProvider) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: mobileProvider={1} - CALLED!", this.getClass().getSimpleName(), mobileProvider)); //NOI18N + + // user should not be null + if (null == mobileProvider) { + // Abort here + throw new NullPointerException("mobileProvider is null"); //NOI18N + } else if (mobileProvider.getProviderId() == null) { // Id is set - throw new NullPointerException("headquarter.headquartersId is null"); //NOI18N - } else if (headquarters.getHeadquartersId() < 1) { + throw new NullPointerException("mobileProvider.providerId is null"); //NOI18N + } else if (mobileProvider.getProviderId() < 1) { // Id is set - throw new IllegalArgumentException(MessageFormat.format("headquarter.headquartersId={0} is invalid", headquarters.getHeadquartersId())); //NOI18N + throw new IllegalArgumentException(MessageFormat.format("mobileProvider.providerId={0} is invalid", mobileProvider.getProviderId())); //NOI18N } // Try to find it (should be there) - final Headquarter managedHeadquarters = this.getEntityManager().find(BusinessHeadquarters.class, headquarters.getHeadquartersId()); + final MobileProvider managedMobileProvider = this.getEntityManager().find(mobileProvider.getClass(), mobileProvider.getProviderId()); // Should be there - assert (managedHeadquarters instanceof BasicData) : "managedHeadquarters is null"; //NOI18N + assert (managedMobileProvider instanceof MobileProvider) : "managedMobileProvider is null"; //NOI18N // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedHeadquarters={1} - EXIT!", this.getClass().getSimpleName(), managedHeadquarters)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedMobileProvider={1} - EXIT!", this.getClass().getSimpleName(), managedMobileProvider)); //NOI18N // Return it - return managedHeadquarters; + return managedMobileProvider; } /** @@ -335,7 +440,7 @@ public abstract class BaseFinancialsDatabaseBean extends BaseDatabaseBean { } // Try to find it (should be there) - final User managedUser = this.getEntityManager().find(LoginUser.class, user.getUserId()); + final User managedUser = this.getEntityManager().find(user.getClass(), user.getUserId()); // Should be there assert (managedUser instanceof User) : "managedUser is null"; //NOI18N @@ -347,6 +452,51 @@ public abstract class BaseFinancialsDatabaseBean extends BaseDatabaseBean { return managedUser; } + /** + * Get back a managed instance from given receipt + *

+ * @param receipt Unmanaged/detached receipt instance + *

+ * @return Managed receipt instance + */ + protected BillableReceipt createManaged (final BillableReceipt receipt) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: receipt={1} - CALLED!", this.getClass().getSimpleName(), receipt)); //NOI18N + + // receipt should not be null + if (null == receipt) { + // Abort here + throw new NullPointerException("receipt is null"); //NOI18N + } else if (receipt.getReceiptId() == null) { + // Id is set + throw new NullPointerException("receipt.receiptId is null"); //NOI18N + } else if (receipt.getReceiptId() < 1) { + // Id is set + throw new IllegalArgumentException(MessageFormat.format("receipt.receiptId={0} is invalid", receipt.getReceiptId())); //NOI18N + } else if (receipt.getReceiptBranchOffice() == null) { + // Throw NPE again + throw new NullPointerException("receipt.receiptBranchOffice is null"); //NOI18N + } else if (receipt.getReceiptBranchOffice().getBranchId() == null) { + // Throw NPE again + throw new NullPointerException("receipt.receiptBranchOffice.contactId is null"); //NOI18N + } else if (receipt.getReceiptBranchOffice().getBranchId() < 1) { + // Not valid id number + throw new IllegalArgumentException(MessageFormat.format("receipt.receiptBranchOffice.contactId={0} is not valid", receipt.getReceiptBranchOffice().getBranchId())); //NOI18N# + } + + // Try to find it (should be there) + final BillableReceipt managedReceipt = this.getEntityManager().find(receipt.getClass(), receipt.getReceiptId()); + + // Should be there + assert (managedReceipt instanceof BillableReceipt) : "managedReceipt is null"; //NOI18N + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedReceipt={1} - EXIT!", this.getClass().getSimpleName(), managedReceipt)); //NOI18N + + // Return it + return managedReceipt; + } + /** * Sets created timestamp on all opening times. *

@@ -360,10 +510,10 @@ public abstract class BaseFinancialsDatabaseBean extends BaseDatabaseBean { // Validate parameter if (null == openingTimes) { // Throw NPE - throw new NullPointerException("openingTimes is null"); + throw new NullPointerException("openingTimes is null"); //NOI18N } else if (openingTimes.isEmpty()) { // Throw IAE - throw new IllegalArgumentException("openingTimes is empty"); + throw new IllegalArgumentException("openingTimes is empty"); //NOI18N } // Walk through whole list @@ -371,7 +521,7 @@ public abstract class BaseFinancialsDatabaseBean extends BaseDatabaseBean { // Id should not be set if (openingTime.getOpeningId() != null) { // Abort here - throw new IllegalStateException("openingTime.openingId is not null"); + throw new IllegalStateException("openingTime.openingId is not null"); //NOI18N } // Set created timestamp @@ -394,7 +544,7 @@ public abstract class BaseFinancialsDatabaseBean extends BaseDatabaseBean { throw new NullPointerException("contact is null"); //NOI18N } else if (contact.getContactId() != null) { // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is unexpected.", contact.getContactId())); + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is unexpected.", contact.getContactId())); //NOI18N } // Get all phone instances @@ -451,7 +601,7 @@ public abstract class BaseFinancialsDatabaseBean extends BaseDatabaseBean { throw new NullPointerException("branchOffice is null"); //NOI18N } else if (branchOffice.getBranchId() != null) { // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("branchOffice.branchId={0} is unexpected.", branchOffice.getBranchId())); + throw new IllegalArgumentException(MessageFormat.format("branchOffice.branchId={0} is unexpected.", branchOffice.getBranchId())); //NOI18N } // Get all phone instances @@ -486,7 +636,7 @@ public abstract class BaseFinancialsDatabaseBean extends BaseDatabaseBean { /** * Updates all branch office's phone entry's created timestamps *

- * @param headquarter Headquarters instance to update + * @param headquarter Headquarter instance to update */ protected void setAllPhoneEntriesCreated (final Headquarter headquarter) { // Trace message @@ -496,14 +646,14 @@ public abstract class BaseFinancialsDatabaseBean extends BaseDatabaseBean { if (null == headquarter) { // Throw NPE again throw new NullPointerException("headquarter is null"); //NOI18N - } else if (headquarter.getHeadquartersId() != null) { + } else if (headquarter.getHeadquarterId() != null) { // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("headquarter.branchId={0} is unexpected.", headquarter.getHeadquartersId())); + throw new IllegalArgumentException(MessageFormat.format("headquarter.branchId={0} is unexpected.", headquarter.getHeadquarterId())); //NOI18N } // Get all phone instances - final DialableLandLineNumber landLineNumber = headquarter.getHeadquartersLandLineNumber(); - final DialableFaxNumber faxNumber = headquarter.getHeadquartersFaxNumber(); + final DialableLandLineNumber landLineNumber = headquarter.getHeadquarterLandLineNumber(); + final DialableFaxNumber faxNumber = headquarter.getHeadquarterFaxNumber(); // Debug message this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllPhoneEntriesCreated: landLineNumber={0},faxNumber={1}", landLineNumber, faxNumber)); //NOI18N @@ -545,7 +695,7 @@ public abstract class BaseFinancialsDatabaseBean extends BaseDatabaseBean { throw new NullPointerException("basicData is null"); //NOI18N } else if (basicData.getBasicDataId() != null) { // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("basicData.basicDataId={0} is unexpected.", basicData.getBasicDataId())); + throw new IllegalArgumentException(MessageFormat.format("basicData.basicDataId={0} is unexpected.", basicData.getBasicDataId())); //NOI18N } // Get all phone instances diff --git a/src/java/org/mxchange/jfinancials/database/product/BaseFinancialsProductDatabaseBean.java b/src/java/org/mxchange/jfinancials/database/product/BaseFinancialsProductDatabaseBean.java index 6331338..bf5b5d0 100644 --- a/src/java/org/mxchange/jfinancials/database/product/BaseFinancialsProductDatabaseBean.java +++ b/src/java/org/mxchange/jfinancials/database/product/BaseFinancialsProductDatabaseBean.java @@ -19,6 +19,7 @@ package org.mxchange.jfinancials.database.product; import java.text.MessageFormat; import org.mxchange.jfinancials.database.BaseFinancialsDatabaseBean; import org.mxchange.jproduct.model.category.Category; +import org.mxchange.jproduct.model.product.Product; /** * A general bean for product-related methods that can be generalized. @@ -51,16 +52,16 @@ public abstract class BaseFinancialsProductDatabaseBean extends BaseFinancialsDa if (null == category) { // Throw NPE throw new NullPointerException("category is null"); - } else if(category.getCategoryI18nKey() == null) { + } else if (category.getCategoryI18nKey() == null) { // Throw it again throw new NullPointerException("category.categoryTitle is null"); } else if (category.getCategoryI18nKey().isEmpty()) { // Throw it again throw new IllegalArgumentException("category.categoryTitle is empty"); - } else if(category.getCategoryId() == null) { + } else if (category.getCategoryId() == null) { // Throw it again throw new NullPointerException("category.categoryId is null"); - } else if(category.getCategoryId() < 1) { + } else if (category.getCategoryId() < 1) { // Throw it again throw new IllegalArgumentException(MessageFormat.format("category.categoryId={0} is not valid.", category.getCategoryId())); } @@ -78,4 +79,43 @@ public abstract class BaseFinancialsProductDatabaseBean extends BaseFinancialsDa return managedCategory; } + /** + * Creates a managed instance from given product instance + *

+ * @param product Unmanaged product instance + *

+ * @return Managed instance + */ + protected Product createManaged (final Product product) { + // Validate parameter + if (null == product) { + // Throw NPE + throw new NullPointerException("product is null"); + } else if (product.getProductI18nKey() == null) { + // Throw it again + throw new NullPointerException("product.productTitle is null"); + } else if (product.getProductI18nKey().isEmpty()) { + // Throw it again + throw new IllegalArgumentException("product.productTitle is empty"); + } else if (product.getProductId() == null) { + // Throw it again + throw new NullPointerException("product.productId is null"); + } else if (product.getProductId() < 1) { + // Throw it again + throw new IllegalArgumentException(MessageFormat.format("product.productId={0} is not valid.", product.getProductId())); + } + + // Try to find it + final Product managedProduct = this.getEntityManager().find(product.getClass(), product.getProductId()); + + // Should be there + assert (managedProduct instanceof Product) : "managedProduct is null"; //NOI18N + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedProduct={1} - EXIT!", this.getClass().getSimpleName(), managedProduct)); //NOI18N + + // Return it + return managedProduct; + } + } diff --git a/src/java/org/mxchange/jfinancials/model/income/FinancialIncomeSessionBean.java b/src/java/org/mxchange/jfinancials/model/income/FinancialIncomeSessionBean.java new file mode 100644 index 0000000..f039c00 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/model/income/FinancialIncomeSessionBean.java @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2017, 2018 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.model.income; + +import java.text.MessageFormat; +import java.util.Date; +import javax.ejb.Stateless; +import org.mxchange.jfinancials.database.BaseFinancialsDatabaseBean; + +/** + * A stateless bean for general purposes for incomes + *

+ * @author Roland Häder + */ +@Stateless (name = "financialIncome", description = "A stateless session bean for handling income.") +public class FinancialIncomeSessionBean extends BaseFinancialsDatabaseBean implements FinancialIncomeSessionBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 659_868_076_723_741L; + + @Override + public BillableIncome addIncome (final BillableIncome income) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addIncome(): income={1} - CALLED!", this.getClass().getSimpleName(), income)); //NOI18N + + // Validate parameter + if (null == income) { + // Throw NPE + throw new NullPointerException("income is null"); //NOI18N + } else if (income.getIncomeId() != null) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("income.incomeId={0} is not expected.", income.getIncomeId())); //NOI18N + } else if (income.getIncomeEnabled() == null) { + // Throw it again + throw new NullPointerException("income.incomeEnabled is null"); //NOI18N + } else if (income.getIncomeInterval() == null) { + // Throw it again + throw new NullPointerException("income.incomeInterval is null"); //NOI18N + } else if (income.getIncomeSingleAmount() == null) { + // Throw it again + throw new NullPointerException("income.incomeSingleAmount is null"); //NOI18N + } else if (income.getIncomeSingleAmount() < 0) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("income.incomeSingleAmount={0} is invalid.", income.getIncomeSingleAmount())); //NOI18N + } else if (income.getIncomeTitle() == null) { + // Throw NPE + throw new NullPointerException("income.incomeTitle is null"); //NOI18N + } else if (income.getIncomeTitle().isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("income.incomeTitle is empty"); //NOI18N + } else if (income.getIncomeUser() == null) { + // Throw NPE + throw new NullPointerException("income.incomeUser is null"); //NOI18N + } else if (income.getIncomeUser().getUserId() == null) { + // Throw NPE again + throw new NullPointerException("income.incomeUser.userId is null"); //NOI18N + } else if (income.getIncomeUser().getUserId() < 0) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("income.incomeUser.userId={0} is invalid.", income.getIncomeUser().getUserId())); //NOI18N + } + + // Add created instance + income.setIncomeCreated(new Date()); + + // Persist it + this.getEntityManager().persist(income); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addIncome(): income.incomeId={1} - EXIT!", this.getClass().getSimpleName(), income.getIncomeId())); //NOI18N + + // Return it + return income; + } + +} diff --git a/src/java/org/mxchange/jfinancials/model/receipt/FinancialAdminReceiptSessionBean.java b/src/java/org/mxchange/jfinancials/model/receipt/FinancialAdminReceiptSessionBean.java index ee4754c..f5e1de6 100644 --- a/src/java/org/mxchange/jfinancials/model/receipt/FinancialAdminReceiptSessionBean.java +++ b/src/java/org/mxchange/jfinancials/model/receipt/FinancialAdminReceiptSessionBean.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Roland Häder + * Copyright (C) 2017, 2018 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 @@ -47,36 +47,36 @@ public class FinancialAdminReceiptSessionBean extends BaseFinancialsDatabaseBean @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)); + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addReceipt(): receipt={1} - CALLED!", this.getClass().getSimpleName(), receipt)); //NOI18N // Validate parameter if (null == receipt) { // Throw NPE - throw new NullPointerException("receipt is null"); + throw new NullPointerException("receipt is null"); //NOI18N } else if (receipt.getReceiptId() != null) { // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("receipt.receiptId={0} is not expected.", receipt.getReceiptId())); + throw new IllegalArgumentException(MessageFormat.format("receipt.receiptId={0} is not expected.", receipt.getReceiptId())); //NOI18N } else if (receipt.getReceiptIssued() == null) { // Throw NPE again - throw new NullPointerException("receipt.receiptIssued is null"); + throw new NullPointerException("receipt.receiptIssued is null"); //NOI18N } else if (receipt.getReceiptBranchOffice() == null) { // Throw it again - throw new NullPointerException("receipt.receiptBranchOffice is null"); + throw new NullPointerException("receipt.receiptBranchOffice is null"); //NOI18N } else if (receipt.getReceiptBranchOffice().getBranchId() == null) { // Throw it again - throw new NullPointerException("receipt.receiptBranchOffice.branchId is null"); + throw new NullPointerException("receipt.receiptBranchOffice.branchId is null"); //NOI18N } else if (receipt.getReceiptBranchOffice().getBranchId() < 1) { // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("receipt.receiptBranchOffice.branchId={0} is not valid.", receipt.getReceiptBranchOffice().getBranchId())); + throw new IllegalArgumentException(MessageFormat.format("receipt.receiptBranchOffice.branchId={0} is not valid.", receipt.getReceiptBranchOffice().getBranchId())); //NOI18N } else if (receipt.getReceiptPaymentType() == null) { // Throw NPE - throw new NullPointerException("receipt.receiptPaymentType is null"); + throw new NullPointerException("receipt.receiptPaymentType is null"); //NOI18N } else if ((receipt.getReceiptUser() instanceof User) && receipt.getReceiptUser().getUserId() == null) { // Throw NPE again - throw new NullPointerException("receipt.receiptUser.userId is null"); + throw new NullPointerException("receipt.receiptUser.userId is null"); //NOI18N } 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())); + throw new NullPointerException(MessageFormat.format("receipt.receiptUser.userId={0} is not valid", receipt.getReceiptUser().getUserId())); //NOI18N } else if (this.receiptBean.isReceiptRegistered(receipt)) { // Has already been registered throw new ReceiptAlreadyAddedException(receipt); @@ -107,7 +107,7 @@ public class FinancialAdminReceiptSessionBean extends BaseFinancialsDatabaseBean this.getEntityManager().persist(receipt); // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addReceipt(): receipt.receiptId={1} - EXIT!", this.getClass().getSimpleName(), receipt.getReceiptId())); + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addReceipt(): receipt.receiptId={1} - EXIT!", this.getClass().getSimpleName(), receipt.getReceiptId())); //NOI18N // Return it return receipt; diff --git a/src/java/org/mxchange/jfinancials/model/receipt/FinancialReceiptSessionBean.java b/src/java/org/mxchange/jfinancials/model/receipt/FinancialReceiptSessionBean.java index a7da53d..1ebe94c 100644 --- a/src/java/org/mxchange/jfinancials/model/receipt/FinancialReceiptSessionBean.java +++ b/src/java/org/mxchange/jfinancials/model/receipt/FinancialReceiptSessionBean.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Roland Häder + * Copyright (C) 2017, 2018 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 @@ -42,36 +42,36 @@ public class FinancialReceiptSessionBean extends BaseFinancialsDatabaseBean impl @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)); + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addReceipt(): receipt={1} - CALLED!", this.getClass().getSimpleName(), receipt)); //NOI18N // Validate parameter if (null == receipt) { // Throw NPE - throw new NullPointerException("receipt is null"); + throw new NullPointerException("receipt is null"); //NOI18N } else if (receipt.getReceiptId() != null) { // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("receipt.receiptId={0} is not expected.", receipt.getReceiptId())); + throw new IllegalArgumentException(MessageFormat.format("receipt.receiptId={0} is not expected.", receipt.getReceiptId())); //NOI18N } else if (receipt.getReceiptIssued() == null) { // Throw NPE again - throw new NullPointerException("receipt.receiptIssued is null"); + throw new NullPointerException("receipt.receiptIssued is null"); //NOI18N } else if (receipt.getReceiptBranchOffice() == null) { // Throw it again - throw new NullPointerException("receipt.receiptBranchOffice is null"); + throw new NullPointerException("receipt.receiptBranchOffice is null"); //NOI18N } else if (receipt.getReceiptBranchOffice().getBranchId() == null) { // Throw it again - throw new NullPointerException("receipt.receiptBranchOffice.branchId is null"); + throw new NullPointerException("receipt.receiptBranchOffice.branchId is null"); //NOI18N } else if (receipt.getReceiptBranchOffice().getBranchId() < 1) { // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("receipt.receiptBranchOffice.branchId={0} is not valid.", receipt.getReceiptBranchOffice().getBranchId())); + throw new IllegalArgumentException(MessageFormat.format("receipt.receiptBranchOffice.branchId={0} is not valid.", receipt.getReceiptBranchOffice().getBranchId())); //NOI18N } else if (receipt.getReceiptPaymentType() == null) { // Throw NPE - throw new NullPointerException("receipt.receiptPaymentType is null"); + throw new NullPointerException("receipt.receiptPaymentType is null"); //NOI18N } else if ((receipt.getReceiptUser() instanceof User) && receipt.getReceiptUser().getUserId() == null) { // Throw NPE again - throw new NullPointerException("receipt.receiptUser.userId is null"); + throw new NullPointerException("receipt.receiptUser.userId is null"); //NOI18N } 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())); + throw new NullPointerException(MessageFormat.format("receipt.receiptUser.userId={0} is not valid", receipt.getReceiptUser().getUserId())); //NOI18N } else if (this.isReceiptRegistered(receipt)) { // Has already been registered throw new ReceiptAlreadyAddedException(receipt); @@ -84,7 +84,7 @@ public class FinancialReceiptSessionBean extends BaseFinancialsDatabaseBean impl this.getEntityManager().persist(receipt); // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addReceipt(): receipt.receiptId={1} - EXIT!", this.getClass().getSimpleName(), receipt.getReceiptId())); + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addReceipt(): receipt.receiptId={1} - EXIT!", this.getClass().getSimpleName(), receipt.getReceiptId())); //NOI18N // Return it return receipt; @@ -94,16 +94,16 @@ public class FinancialReceiptSessionBean extends BaseFinancialsDatabaseBean impl @SuppressWarnings ("unchecked") public List allReceipts () { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allReceipts(): CALLED!", this.getClass().getSimpleName())); + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allReceipts(): CALLED!", this.getClass().getSimpleName())); //NOI18N // Query all - final Query query = this.getEntityManager().createNamedQuery("AllReceipts"); + final Query query = this.getEntityManager().createNamedQuery("AllReceipts"); //NOI18N // 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())); + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allReceipts(): receipts.size()={1} EXIT!", this.getClass().getSimpleName(), receipts.size())); //NOI18N // Return it return receipts; @@ -113,31 +113,31 @@ public class FinancialReceiptSessionBean extends BaseFinancialsDatabaseBean impl @SuppressWarnings ("unchecked") public List allUsersReceipts (final User user) { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsersReceipts(): user={1} - CALLED!", this.getClass().getSimpleName(), user)); + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsersReceipts(): user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N // Validate parameter if (null == user) { // Throw NPE - throw new NullPointerException("user is null"); + throw new NullPointerException("user is null"); //NOI18N } else if (user.getUserId() == null) { // Throw it again - throw new NullPointerException("user.userId is null"); + throw new NullPointerException("user.userId is null"); //NOI18N } else if (user.getUserId() < 1) { // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); + throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N } // Query all - final Query query = this.getEntityManager().createNamedQuery("SearchAllUserReceipts"); + final Query query = this.getEntityManager().createNamedQuery("SearchAllUserReceipts"); //NOI18N // Add parameter - query.setParameter("receiptUser", user); + query.setParameter("receiptUser", user); //NOI18N // 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())); + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsersReceipts(): receipts.size()={1} EXIT!", this.getClass().getSimpleName(), receipts.size())); //NOI18N // Return it return receipts; @@ -164,7 +164,7 @@ public class FinancialReceiptSessionBean extends BaseFinancialsDatabaseBean impl // Yes, then stop searching isFound = true; break; - } else if (Receipts.isSameReceipt(foundReceipt, receipt)){ + } else if (Receipts.isSameReceipt(foundReceipt, receipt)) { // Yes, then stop searching isFound = true; break; 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 00846af..56253f3 100644 --- a/src/java/org/mxchange/jfinancials/model/receipt_item/FinancialAdminReceiptItemSessionBean.java +++ b/src/java/org/mxchange/jfinancials/model/receipt_item/FinancialAdminReceiptItemSessionBean.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Roland Häder + * Copyright (C) 2017, 2018 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 @@ -21,7 +21,8 @@ import java.util.Date; import java.util.List; import javax.ejb.EJB; import javax.ejb.Stateless; -import org.mxchange.jfinancials.database.BaseFinancialsDatabaseBean; +import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; +import org.mxchange.jfinancials.database.product.BaseFinancialsProductDatabaseBean; import org.mxchange.jfinancials.exceptions.receipt_item.ReceiptItemAlreadyAddedException; /** @@ -30,7 +31,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 BaseFinancialsDatabaseBean implements FinancialAdminReceiptItemSessionBeanRemote { +public class FinancialAdminReceiptItemSessionBean extends BaseFinancialsProductDatabaseBean implements FinancialAdminReceiptItemSessionBeanRemote { /** * Serial number @@ -40,7 +41,7 @@ public class FinancialAdminReceiptItemSessionBean extends BaseFinancialsDatabase /** * General EJB */ - @EJB (lookup = "java:global/jfinancials-ejb/financialReceiptItem!org.mxchange.jfinancials.model.receipt.item.FinancialReceiptItemSessionBeanRemote") + @EJB (lookup = "java:global/jfinancials-ejb/financialReceiptItem!org.mxchange.jfinancials.model.receipt_item.FinancialReceiptItemSessionBeanRemote") private FinancialReceiptItemSessionBeanRemote receiptItemBean; @Override @@ -61,7 +62,10 @@ public class FinancialAdminReceiptItemSessionBean extends BaseFinancialsDatabase } else if (receiptItem.getItemProduct().getProductId() < 1) { // Throw IAE throw new IllegalArgumentException(MessageFormat.format("receiptItem.itemProduct.productId={0} is invalid.", receiptItem.getItemProduct().getProductId())); //NOI18N - } else if (receiptItem.getItemProductQuantity() < 1) { + } else if (receiptItem.getItemProductQuantity() == null) { + // Throw it again + throw new NullPointerException("receiptItem.itemProductQuantity is null"); //NOI18N + } else if (receiptItem.getItemProductQuantity().doubleValue() <= 0.0) { // Throw IAE again throw new IllegalArgumentException(MessageFormat.format("receiptItem.itemProductQuantity={0} is invalid.", receiptItem.getItemProductQuantity())); //NOI18N } else if (receiptItem.getItemReceipt() == null) { @@ -78,6 +82,21 @@ public class FinancialAdminReceiptItemSessionBean extends BaseFinancialsDatabase throw new ReceiptItemAlreadyAddedException(receiptItem); } + // Make product managed + receiptItem.setItemProduct(this.createManaged(receiptItem.getItemProduct())); + + // Make receipt managed + receiptItem.setItemReceipt(this.createManaged(receiptItem.getItemReceipt())); + + // Is a manufacturer/producer set? + if (receiptItem.getItemManufacturer() instanceof BasicData) { + // Then get managed instance from it + final BasicData basicData = this.createManaged(receiptItem.getItemManufacturer()); + + // Set it back + receiptItem.setItemManufacturer(basicData); + } + // Add created timestamp receiptItem.setItemCreated(new Date()); @@ -102,6 +121,12 @@ public class FinancialAdminReceiptItemSessionBean extends BaseFinancialsDatabase // Default is not found boolean isFound = false; + // Is the item type a discount? + if (receiptItem.getItemIsDiscount()) { + // Yes, then allow it multiple items + return false; + } + /* * Get all receipt's receipt items. No need to look global as people may * buy the same item again and again ... ;-) @@ -111,7 +136,7 @@ public class FinancialAdminReceiptItemSessionBean extends BaseFinancialsDatabase // Loop through all entries for (final BillableReceiptItem item : receiptItems) { // Is it the same item? - if (ReceiptItems.isSameReceiptItem(item, receiptItem)) { + if (ReceiptItems.isSameReceiptItem(item, receiptItem) && (!item.getItemIsRefund())) { // Found it isFound = true; break; diff --git a/src/java/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItemSessionBean.java b/src/java/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItemSessionBean.java index 2608749..b2b8cf0 100644 --- a/src/java/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItemSessionBean.java +++ b/src/java/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItemSessionBean.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Roland Häder + * Copyright (C) 2017, 2018 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 @@ -57,7 +57,10 @@ public class FinancialReceiptItemSessionBean extends BaseFinancialsDatabaseBean } else if (receiptItem.getItemProduct().getProductId() < 1) { // Throw IAE throw new IllegalArgumentException(MessageFormat.format("receiptItem.itemProduct.productId={0} is invalid.", receiptItem.getItemProduct().getProductId())); //NOI18N - } else if (receiptItem.getItemProductQuantity() < 1) { + } else if (receiptItem.getItemProductQuantity() == null) { + // Throw it again + throw new NullPointerException("receiptItem.itemProductQuantity is null"); //NOI18N + } else if (receiptItem.getItemProductQuantity().doubleValue() <= 0.0) { // Throw IAE again throw new IllegalArgumentException(MessageFormat.format("receiptItem.itemProductQuantity={0} is invalid.", receiptItem.getItemProductQuantity())); //NOI18N } else if (receiptItem.getItemReceipt() == null) { -- 2.39.5