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;
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;
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;
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;
*/
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 () {