2 * Copyright (C) 2016 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jusercore.model.register;
19 import java.text.MessageFormat;
21 import javax.ejb.Stateless;
22 import org.mxchange.jcoreee.database.BaseDatabaseBean;
23 import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
24 import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
25 import org.mxchange.jusercore.model.user.User;
26 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
29 * A session bean for user registration
31 * @author Roland Haeder<roland@mxchange.org>
33 @Stateless (name = "register", mappedName = "ejb/stateless-pizza-register", description = "A bean handling the user registration")
34 public class PizzaUserRegistrationSessionBean extends BaseDatabaseBean implements UserRegistrationSessionBeanRemote {
39 private static final long serialVersionUID = 12_348_958_986_818_627L;
45 private UserSessionBeanRemote userBean;
48 public boolean isEmailAddressRegistered (final User user) {
50 this.getLoggerBeanLocal().logTrace(MessageFormat.format("isEmailAddressRegistered: user={0} - CALLED!", user)); //NOI18N
53 assert(this.userBean instanceof UserSessionBeanRemote) : "this.userBean is not set"; //NOI18N
55 // user should not be null
58 throw new NullPointerException("user is null"); //NOI18N
62 return this.userBean.isEmailAddressReqistered(user);
66 public boolean isUserNameRegistered (final User user) {
68 this.getLoggerBeanLocal().logTrace(MessageFormat.format("isUserNameRegistered: user={0} - CALLED!", user)); //NOI18N
71 assert(this.userBean instanceof UserSessionBeanRemote) : "this.userBean is not set"; //NOI18N
73 // user should not be null
76 throw new NullPointerException("user is null"); //NOI18N
80 return this.userBean.isUserNameReqistered(user);
84 public User registerUser (final User user) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException {
86 this.getLoggerBeanLocal().logTrace(MessageFormat.format("registerUser: user={0} - CALLED!", user)); //NOI18N
88 // user should not be null
91 throw new NullPointerException("user is null"); //NOI18N
94 // Check if user is registered
95 if (this.isUserNameRegistered(user)) {
97 throw new UserNameAlreadyRegisteredException(user);
98 } else if (this.isEmailAddressRegistered(user)) {
100 throw new EmailAddressAlreadyRegisteredException(user);
104 User addedUser = this.userBean.addUser(user);
107 this.getLoggerBeanLocal().logTrace(MessageFormat.format("registerUser: addedUser={0},addedUser.userIdd={1} - EXIT!", addedUser, addedUser.getUserId())); //NOI18N