]> git.mxchange.org Git - jjobs-ejb.git/commitdiff
added business method addUser() and took code from registerUser as both is (at persis...
authorRoland Haeder <roland@mxchange.org>
Tue, 12 Apr 2016 16:54:57 +0000 (18:54 +0200)
committerRoland Haeder <roland@mxchange.org>
Tue, 12 Apr 2016 17:34:39 +0000 (19:34 +0200)
src/java/org/mxchange/jusercore/model/register/JobsUserRegistrationSessionBean.java
src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java

index 07c14f82c2383c5e639ebd1ebe51163fda348317..42286209b98866499a5d070777f3a0e4111d5539 100644 (file)
@@ -17,7 +17,6 @@
 package org.mxchange.jusercore.model.register;
 
 import java.text.MessageFormat;
-import java.util.GregorianCalendar;
 import javax.ejb.EJB;
 import javax.ejb.Stateless;
 import org.mxchange.jcoreee.database.BaseDatabaseBean;
@@ -101,18 +100,11 @@ public class JobsUserRegistrationSessionBean extends BaseDatabaseBean implements
                        throw new EmailAddressAlreadyRegisteredException(user);
                }
 
-               // Set created timestamp
-               user.setUserCreated(new GregorianCalendar());
-               user.getUserContact().setContactCreated(new GregorianCalendar());
-
-               // Persist it
-               this.getEntityManager().persist(user);
-
-               // Flush to get id back
-               this.getEntityManager().flush();
+               // Call other EJB
+               User addedUser = this.userBean.addUser(user);
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("registerUser: user={0},user.id={1} - EXIT!", user, user.getUserId())); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("registerUser: addedUser={0},addedUser.userIdd={1} - EXIT!", addedUser, addedUser.getUserId())); //NOI18N
 
                // Return it
                return user;
index defb3efc49491ff707cd5f5a6b6f67fbef32a288..8d734e4a4fc7febef515a17f0c84b6d7f03d1f5b 100644 (file)
@@ -19,6 +19,7 @@ package org.mxchange.jusercore.model.user;
 import java.text.MessageFormat;
 import java.util.GregorianCalendar;
 import java.util.List;
+import javax.ejb.EJB;
 import javax.ejb.EJBException;
 import javax.ejb.Stateless;
 import javax.persistence.NoResultException;
@@ -29,6 +30,9 @@ import org.mxchange.jcoreee.database.BaseDatabaseBean;
 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
+import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
+import org.mxchange.jusercore.model.register.PizzaUserRegistrationSessionBean;
 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
 
@@ -45,12 +49,55 @@ public class JobsUserSessionBean extends BaseDatabaseBean implements UserSession
         */
        private static final long serialVersionUID = 542_145_347_916L;
 
+       /**
+        * Registration bean
+        */
+       @EJB
+       private PizzaUserRegistrationSessionBean registerBean;
+
        /**
         * Default constructor
         */
        public JobsUserSessionBean () {
        }
 
+       @Override
+       public User addUser (final User user) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("addUser: user={0} - CALLED!", user)); //NOI18N
+
+               // user should not be null
+               if (null == user) {
+                       // Abort here
+                       throw new NullPointerException("user is null"); //NOI18N
+               }
+
+               // Check if user is registered
+               if (this.registerBean.isUserNameRegistered(user)) {
+                       // Abort here
+                       throw new UserNameAlreadyRegisteredException(user);
+               } else if (this.registerBean.isEmailAddressRegistered(user)) {
+                       // Abort here
+                       throw new EmailAddressAlreadyRegisteredException(user);
+               }
+
+               // Set created timestamp
+               user.setUserCreated(new GregorianCalendar());
+               user.getUserContact().setContactCreated(new GregorianCalendar());
+
+               // Persist it
+               this.getEntityManager().persist(user);
+
+               // Flush to get id back
+               this.getEntityManager().flush();
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("addUser: user={0},user.id={1} - EXIT!", user, user.getUserId())); //NOI18N
+
+               // Return it
+               return user;
+       }
+
        @Override
        @SuppressWarnings ("unchecked")
        public List<User> allMemberPublicVisibleUsers () {