]> git.mxchange.org Git - addressbook-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:26 +0000 (19:34 +0200)
src/java/org/mxchange/jusercore/model/register/AddressbookUserRegistrationSessionBean.java
src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java

index 250611c62d5f9a69a4d546c760d49ebe82bdfe7b..0cc610f5d1489c1f61aec3c876600415a96991f9 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 AddressbookUserRegistrationSessionBean extends BaseDatabaseBean imp
                        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 ca8f7dbfa09098c28a192884358000210acb4394..36fc47d8f7d4b9e95438851bffeac89a25034e9c 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 AddressbookUserSessionBean extends BaseDatabaseBean implements User
         */
        private static final long serialVersionUID = 542_145_347_916L;
 
+       /**
+        * Registration bean
+        */
+       @EJB
+       private PizzaUserRegistrationSessionBean registerBean;
+
        /**
         * Default constructor
         */
        public AddressbookUserSessionBean () {
        }
 
+       @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 () {