From 962b61d992d57cab5cdca906abc9d97b3fe3d116 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 23 Sep 2017 14:06:24 +0200 Subject: [PATCH] Please repeat/cherry-pick: - added lookup attribute to @EJB annotation as some lookup did not work as expected and this is "guranteed" to work (if you have the right JNDI name, of course) - plus all these EJBs can now be more distributed over separate EJB modules allowing a distributed operation over several data centers, awsome words, right? ;-) - sorted members in base database bean MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../PizzaAdminContactPhoneSessionBean.java | 2 +- .../PizzaAdminBusinessDataSessionBean.java | 2 +- .../PizzaAdminBranchOfficeSessionBean.java | 2 +- .../model/user/PizzaAdminUserSessionBean.java | 12 +- .../model/user/PizzaUserSessionBean.java | 2 +- .../PizzaUserEmailChangeSessionBean.java | 2 +- .../user/login/PizzaUserLoginSessionBean.java | 14 +- .../PizzaUserRegistrationSessionBean.java | 44 +--- .../PizzaResendLinkSessionBean.java | 4 +- .../enterprise/BasePizzaEnterpriseBean.java | 189 ++++++++++++++++++ 10 files changed, 205 insertions(+), 68 deletions(-) diff --git a/src/java/org/mxchange/jcontacts/model/phone/PizzaAdminContactPhoneSessionBean.java b/src/java/org/mxchange/jcontacts/model/phone/PizzaAdminContactPhoneSessionBean.java index 39e4642..89beec2 100644 --- a/src/java/org/mxchange/jcontacts/model/phone/PizzaAdminContactPhoneSessionBean.java +++ b/src/java/org/mxchange/jcontacts/model/phone/PizzaAdminContactPhoneSessionBean.java @@ -46,7 +46,7 @@ public class PizzaAdminContactPhoneSessionBean extends BasePizzaEnterpriseBean i /** * Contact EJB */ - @EJB + @EJB (lookup = "java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote") private ContactSessionBeanRemote contactBean; /** diff --git a/src/java/org/mxchange/jcontactsbusiness/model/basicdata/PizzaAdminBusinessDataSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/basicdata/PizzaAdminBusinessDataSessionBean.java index 76ef917..c6c220c 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/basicdata/PizzaAdminBusinessDataSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/basicdata/PizzaAdminBusinessDataSessionBean.java @@ -44,7 +44,7 @@ public class PizzaAdminBusinessDataSessionBean extends BasePizzaEnterpriseBean i /** * Administrative EJB */ - @EJB + @EJB (lookup = "java:global/pizzaservice-ejb/basicCompanyData!org.mxchange.jcontactsbusiness.model.basicdata.BasicCompanyDataSessionBeanRemote") private BasicCompanyDataSessionBeanRemote businessDataBean; /** diff --git a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/PizzaAdminBranchOfficeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/PizzaAdminBranchOfficeSessionBean.java index df3d230..0f036c0 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/PizzaAdminBranchOfficeSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/PizzaAdminBranchOfficeSessionBean.java @@ -45,7 +45,7 @@ public class PizzaAdminBranchOfficeSessionBean extends BasePizzaEnterpriseBean i /** * General branch office bean */ - @EJB + @EJB (lookup = "java:global/pizzaservice-ejb/branchOffice!org.mxchange.jcontactsbusiness.model.branchoffice.BranchOfficeSessionBeanRemote") private BranchOfficeSessionBeanRemote branchOfficeBean; /** diff --git a/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java index 27f6efd..aeb2eb7 100644 --- a/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java @@ -44,16 +44,10 @@ public class PizzaAdminUserSessionBean extends BasePizzaEnterpriseBean implement */ private static final long serialVersionUID = 542_145_347_916L; - /** - * Registration EJB - */ - @EJB - private UserRegistrationSessionBeanRemote registerBean; - /** * Regular user bean */ - @EJB + @EJB (lookup = "java:global/pizzaservice-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote") private UserSessionBeanRemote userBean; /** @@ -79,10 +73,10 @@ public class PizzaAdminUserSessionBean extends BasePizzaEnterpriseBean implement } // Check if user is registered - if (this.registerBean.isUserNameRegistered(user)) { + if (this.userBean.isUserNameRegistered(user)) { // Abort here throw new UserNameAlreadyRegisteredException(user); - } else if (this.registerBean.isEmailAddressRegistered(user)) { + } else if (this.userBean.isEmailAddressRegistered(user)) { // Abort here throw new EmailAddressAlreadyRegisteredException(user); } diff --git a/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java index 381d68b..728f10b 100644 --- a/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java @@ -59,7 +59,7 @@ public class PizzaUserSessionBean extends BasePizzaEnterpriseBean implements Use /** * Registration EJB */ - @EJB + @EJB (lookup = "java:global/pizzaservice-ejb/userRegistration!org.mxchange.juserlogincore.model.user.register.UserRegistrationSessionBeanRemote") private UserRegistrationSessionBeanRemote registerBean; /** 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 1b3f036..eb8530e 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 @@ -46,7 +46,7 @@ public class PizzaUserEmailChangeSessionBean extends BasePizzaEnterpriseBean imp /** * User bean */ - @EJB + @EJB (lookup = "java:global/pizzaservice-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote") private UserSessionBeanRemote userBean; /** diff --git a/src/java/org/mxchange/juserlogincore/model/user/login/PizzaUserLoginSessionBean.java b/src/java/org/mxchange/juserlogincore/model/user/login/PizzaUserLoginSessionBean.java index e69bbdd..67724c7 100644 --- a/src/java/org/mxchange/juserlogincore/model/user/login/PizzaUserLoginSessionBean.java +++ b/src/java/org/mxchange/juserlogincore/model/user/login/PizzaUserLoginSessionBean.java @@ -44,16 +44,10 @@ public class PizzaUserLoginSessionBean extends BasePizzaEnterpriseBean implement */ private static final long serialVersionUID = 21_785_978_127_581_965L; - /** - * Registration EJB - */ - @EJB - private UserRegistrationSessionBeanRemote registerBean; - /** * User EJB */ - @EJB + @EJB (lookup = "java:global/pizzaservice-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote") private UserSessionBeanRemote userBean; /** @@ -69,10 +63,6 @@ public class PizzaUserLoginSessionBean extends BasePizzaEnterpriseBean implement // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.loginUser: container={1} - CALLED!", this.getClass().getSimpleName(), container)); //NOI18N - // Check some beans - assert (this.userBean instanceof UserSessionBeanRemote) : "this.userBean is not set"; //NOI18N - assert (this.registerBean instanceof UserRegistrationSessionBeanRemote) : "this.registerBean is not set"; //NOI18N - // user should not be null if (null == container) { // Abort here @@ -89,7 +79,7 @@ public class PizzaUserLoginSessionBean extends BasePizzaEnterpriseBean implement } // Is the account there? - if (!this.registerBean.isUserNameRegistered(container.getUser())) { + if (!this.userBean.isUserNameRegistered(container.getUser())) { // Not registered throw new UserNotFoundException(container.getUser()); } diff --git a/src/java/org/mxchange/juserlogincore/model/user/register/PizzaUserRegistrationSessionBean.java b/src/java/org/mxchange/juserlogincore/model/user/register/PizzaUserRegistrationSessionBean.java index 269a624..35d3439 100644 --- a/src/java/org/mxchange/juserlogincore/model/user/register/PizzaUserRegistrationSessionBean.java +++ b/src/java/org/mxchange/juserlogincore/model/user/register/PizzaUserRegistrationSessionBean.java @@ -48,13 +48,13 @@ public class PizzaUserRegistrationSessionBean extends BasePizzaEnterpriseBean im /** * Administrative user bean */ - @EJB + @EJB (lookup = "java:global/pizzaservice-ejb/adminUser!org.mxchange.jusercore.model.user.AdminUserSessionBeanRemote") private AdminUserSessionBeanRemote adminUserBean; /** * Regular user EJB */ - @EJB + @EJB (lookup = "java:global/pizzaservice-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote") private UserSessionBeanRemote userBean; /** @@ -111,42 +111,6 @@ public class PizzaUserRegistrationSessionBean extends BasePizzaEnterpriseBean im return confirmationKey; } - @Override - public boolean isEmailAddressRegistered (final User user) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N - - // Check bean - assert (this.userBean instanceof UserSessionBeanRemote) : "this.userBean is not set"; //NOI18N - - // user should not be null - if (null == user) { - // Abort here - throw new NullPointerException("user is null"); //NOI18N - } - - // Call other bean - return this.userBean.isEmailAddressRegistered(user); - } - - @Override - public boolean isUserNameRegistered (final User user) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isUserNameRegistered: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N - - // Check bean - assert (this.userBean instanceof UserSessionBeanRemote) : "this.userBean is not set"; //NOI18N - - // user should not be null - if (null == user) { - // Abort here - throw new NullPointerException("user is null"); //NOI18N - } - - // Call other bean - return this.userBean.isUserNameRegistered(user); - } - @Override public User registerUser (final User user, final String baseUrl, final String randomPassword) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException { // Trace message @@ -168,10 +132,10 @@ public class PizzaUserRegistrationSessionBean extends BasePizzaEnterpriseBean im } // Check if user is registered - if (this.isUserNameRegistered(user)) { + if (this.userBean.isUserNameRegistered(user)) { // Abort here throw new UserNameAlreadyRegisteredException(user); - } else if (this.isEmailAddressRegistered(user)) { + } else if (this.userBean.isEmailAddressRegistered(user)) { // Abort here throw new EmailAddressAlreadyRegisteredException(user); } diff --git a/src/java/org/mxchange/juserlogincore/model/user/resendlink/PizzaResendLinkSessionBean.java b/src/java/org/mxchange/juserlogincore/model/user/resendlink/PizzaResendLinkSessionBean.java index 3c90a1d..8c4da3b 100644 --- a/src/java/org/mxchange/juserlogincore/model/user/resendlink/PizzaResendLinkSessionBean.java +++ b/src/java/org/mxchange/juserlogincore/model/user/resendlink/PizzaResendLinkSessionBean.java @@ -46,13 +46,13 @@ public class PizzaResendLinkSessionBean extends BasePizzaEnterpriseBean implemen /** * Registration bean */ - @EJB + @EJB (lookup = "java:global/pizzaservice-ejb/userRegistration!org.mxchange.juserlogincore.model.user.register.UserRegistrationSessionBeanRemote") private UserRegistrationSessionBeanRemote registerBean; /** * Regular user bean */ - @EJB + @EJB (lookup = "java:global/pizzaservice-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote") private UserSessionBeanRemote userBean; /** diff --git a/src/java/org/mxchange/pizzaapplication/enterprise/BasePizzaEnterpriseBean.java b/src/java/org/mxchange/pizzaapplication/enterprise/BasePizzaEnterpriseBean.java index 45512cb..82fa989 100644 --- a/src/java/org/mxchange/pizzaapplication/enterprise/BasePizzaEnterpriseBean.java +++ b/src/java/org/mxchange/pizzaapplication/enterprise/BasePizzaEnterpriseBean.java @@ -85,6 +85,195 @@ public abstract class BasePizzaEnterpriseBean extends BaseEnterpriseBean { super(factoryJndi, queueJndi); } + /** + * Get back a managed instance from given contact + *

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

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

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

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

+ * @param basicData Unmanaged/detached basic data instance + *

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

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

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

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

+ * @return Managed user instance + */ + protected User createManaged (final User user) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N + + // user should not be null + if (null == user) { + // Abort here + throw new NullPointerException("user is null"); //NOI18N + } else if (user.getUserId() == null) { + // Id is set + throw new NullPointerException("user.userId is null"); //NOI18N + } else if (user.getUserId() < 1) { + // Id is set + throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is null", user.getUserId())); //NOI18N + } else if (user.getUserContact() == null) { + // Throw NPE again + throw new NullPointerException("user.userContact is null"); //NOI18N + } else if (user.getUserContact().getContactId() == null) { + // Throw NPE again + throw new NullPointerException("user.userContact.contactId is null"); //NOI18N + } else if (user.getUserContact().getContactId() < 1) { + // Not valid id number + throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is not valid", user.getUserContact().getContactId())); //NOI18N# + } + + // Try to find it (should be there) + final User managedUser = this.getEntityManager().find(LoginUser.class, user.getUserId()); + + // Should be there + assert (managedUser instanceof User) : "managedUser is null"; //NOI18N + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N + + // Return it + return managedUser; + } + /** * Updates all contact's phone entry's created timestamps *

-- 2.39.5