]> git.mxchange.org Git - pizzaservice-ejb.git/commitdiff
Please repeat/cherry-pick:
authorRoland Häder <roland@mxchange.org>
Sat, 23 Sep 2017 12:06:24 +0000 (14:06 +0200)
committerRoland Häder <roland@mxchange.org>
Mon, 9 Mar 2020 16:59:58 +0000 (17:59 +0100)
- 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

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jcontacts/model/phone/PizzaAdminContactPhoneSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/basicdata/PizzaAdminBusinessDataSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/branchoffice/PizzaAdminBranchOfficeSessionBean.java
src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java
src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java
src/java/org/mxchange/jusercore/model/user/email_address/PizzaUserEmailChangeSessionBean.java
src/java/org/mxchange/juserlogincore/model/user/login/PizzaUserLoginSessionBean.java
src/java/org/mxchange/juserlogincore/model/user/register/PizzaUserRegistrationSessionBean.java
src/java/org/mxchange/juserlogincore/model/user/resendlink/PizzaResendLinkSessionBean.java
src/java/org/mxchange/pizzaapplication/enterprise/BasePizzaEnterpriseBean.java

index 39e4642cfdadc3cb54d42f40825756ab4900919b..89beec26e196e2cf0f95fa6fd10ee2a1990b5337 100644 (file)
@@ -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;
 
        /**
index 76ef917fc4a4bad57adacba9233f882d2847bd03..c6c220c5382f390986ba02ceaa3d60ff67e53505 100644 (file)
@@ -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;
 
        /**
index df3d2300413bc2de4f7a7e61600a5168fd9f8881..0f036c0fef5d24b3ec8034d3f75ced29948363da 100644 (file)
@@ -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;
 
        /**
index 27f6efdf520ca21ba923b4c0b94701500e929239..aeb2eb710e97c6f5877557491bae2e78572a023a 100644 (file)
@@ -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);
                }
index 381d68b0cf5eb3b68771c554d273dc8bdcbfc34d..728f10bee21c141798ee930260fb3144ebbf847f 100644 (file)
@@ -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;
 
        /**
index 1b3f0361dc7db20983f07259213f1f3806bf922b..eb8530e1e3c78ae7a55ec6ecbb3bc92089deae00 100644 (file)
@@ -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;
 
        /**
index e69bbdd163f946fecf92c616ed9ce1e6505a52d6..67724c78ac8c4a5af01c04f40f48c1658dfd54cf 100644 (file)
@@ -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());
                }
index 269a6244e7c18cf29e92cb57b2e2305075f69d81..35d343926720a39c9497e0dbaeb4ed406dd500b6 100644 (file)
@@ -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);
                }
index 3c90a1dfcec0fcce9694d13bb9cce4d530a05f68..8c4da3b007db7aa1a53df5964753b352f13b9cda 100644 (file)
@@ -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;
 
        /**
index 45512cbbff2536bb86c5e3a7775365b3339e4771..82fa989228bbc732f9ee96aef26b615a8e1b077e 100644 (file)
@@ -85,6 +85,195 @@ public abstract class BasePizzaEnterpriseBean extends BaseEnterpriseBean {
                super(factoryJndi, queueJndi);
        }
 
+       /**
+        * Get back a managed instance from given contact
+        * <p>
+        * @param contact Unmanaged/detached contact instance
+        * <p>
+        * @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
+        * <p>
+        * @param country Unmanaged/detached country instance
+        * <p>
+        * @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
+        * <p>
+        * @param basicData Unmanaged/detached basic data instance
+        * <p>
+        * @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
+        * <p>
+        * @param employee Unmanaged/detached employee instance
+        * <p>
+        * @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
+        * <p>
+        * @param user Unmanaged/detached user instance
+        * <p>
+        * @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
         * <p>