- splitted user bean into general (old) and administrative user bean. This allows more distribution and not centralization of all business methods on one (then later even monolithic) EJB
- requires juser-lib.jar to be updated
Signed-off-by: Roland Häder <roland@haeder.net>
Signed-off-by: Roland Häder <roland@mxchange.org>
import org.mxchange.jcontacts.contact.Contact;
import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
+import org.mxchange.jusercore.model.user.AdminUserSessionBeanRemote;
import org.mxchange.jusercore.model.user.LoginUser;
import org.mxchange.jusercore.model.user.User;
import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
private static final long serialVersionUID = 12_348_958_986_818_627L;
/**
- * User EJB
+ * Administrative user bean
+ */
+ @EJB
+ private AdminUserSessionBeanRemote adminUserBean;
+
+ /**
+ * Regular user EJB
*/
@EJB
private UserSessionBeanRemote userBean;
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
+ assert (this.userBean instanceof UserSessionBeanRemote) : "this.userBean is not set"; //NOI18N
// user should not be null
if (null == user) {
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
+ assert (this.userBean instanceof UserSessionBeanRemote) : "this.userBean is not set"; //NOI18N
// user should not be null
if (null == user) {
}
// Call other EJB
- User addedUser = this.userBean.addUser(user);
+ User addedUser = this.adminUserBean.addUser(user);
// Init variable
Address emailAddress;
--- /dev/null
+/*
+ * Copyright (C) 2016 Cho-Time GmbH
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jusercore.model.user;
+
+import java.text.MessageFormat;
+import java.util.GregorianCalendar;
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
+import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
+import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote;
+import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean;
+
+/**
+ * An administrative user EJB
+ * <p>
+ * @author Roland Haeder<rhaeder@cho-time.de>
+ */
+@Stateless (name = "user", description = "A bean handling the user data")
+public class PizzaAdminUserSessionBean extends BasePizzaDatabaseBean implements AdminUserSessionBeanRemote {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 542_145_347_916L;
+
+ /**
+ * Registration EJB
+ */
+ @EJB
+ private UserRegistrationSessionBeanRemote registerBean;
+
+ /**
+ * Regular user bean
+ */
+ @EJB
+ private UserSessionBeanRemote userBean;
+
+ /**
+ * Default constructor
+ */
+ public PizzaAdminUserSessionBean () {
+ }
+
+ @Override
+ public User addUser (final User user) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addUser: 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) {
+ // Not allowed here
+ throw new IllegalStateException(MessageFormat.format("user.userId must be null, is: {0}", user.getUserId())); //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());
+
+ // Update cellphone, land-line and fax instance
+ this.setAllContactPhoneEntriesCreated(user.getUserContact());
+
+ // Persist it
+ this.getEntityManager().persist(user);
+
+ // Flush to get id back
+ this.getEntityManager().flush();
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addUser: user={1},user.userId={2} - EXIT!", this.getClass().getSimpleName(), user, user.getUserId())); //NOI18N
+
+ // Return it
+ return user;
+ }
+
+ @Override
+ public User linkUser (final User user) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkUser: user={0} - 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() instanceof Long) {
+ // Id is set
+ throw new IllegalArgumentException("user.userId is not null"); //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
+ } else if (user.getUserAccountStatus() == null) {
+ // Throw NPE again
+ throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
+ } else if (this.userBean.ifUserNameExists(user.getUserName())) {
+ // Name already found
+ throw new UserNameAlreadyRegisteredException(user.getUserName());
+ }
+
+ // Try to find the contact
+ Contact foundContact = this.getEntityManager().find(user.getUserContact().getClass(), user.getUserContact().getContactId());
+
+ // Set detached object in rexcruiter instance
+ user.setUserContact(foundContact);
+
+ // Set timestamp
+ user.setUserCreated(new GregorianCalendar());
+
+ // Perist it
+ this.getEntityManager().persist(user);
+
+ // Flush it to get updated instance back
+ this.getEntityManager().flush();
+
+ // Log trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkUser: user={1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N
+
+ // Return updated instanc
+ return user;
+ }
+
+}
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.exceptions.UserNotFoundException;
import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
import org.mxchange.jusercore.exceptions.UserStatusLockedException;
public PizzaUserSessionBean () {
}
- @Override
- public User addUser (final User user) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addUser: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
-
- // userId should not be null
- if (null == user) {
- // Abort here
- throw new NullPointerException("user is null"); //NOI18N
- } else if (user.getUserId() == null) {
- // Abort here
- throw new NullPointerException("user.userId is null"); //NOI18N
- } else if (user.getUserId() < 1) {
- // Invalid number
- throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", user.getUserId())); //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());
-
- // Update cellphone, land-line and fax instance
- this.setAllContactPhoneEntriesCreated(user.getUserContact());
-
- // Persist it
- this.getEntityManager().persist(user);
-
- // Flush to get id back
- this.getEntityManager().flush();
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addUser: user={1},user.userId={2} - EXIT!", this.getClass().getSimpleName(), user, user.getUserId())); //NOI18N
-
- // Return it
- return user;
- }
-
@Override
@SuppressWarnings ("unchecked")
public List<User> allMemberPublicVisibleUsers () {
return true;
}
- @Override
- public User linkUser (final User user) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkUser: user={0} - 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() instanceof Long) {
- // Id is set
- throw new IllegalArgumentException("user.userId is not null"); //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
- } else if (user.getUserAccountStatus() == null) {
- // Throw NPE again
- throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
- } else if (this.ifUserNameExists(user.getUserName())) {
- // Name already found
- throw new UserNameAlreadyRegisteredException(user.getUserName());
- }
-
- // Try to find the contact
- Contact foundContact = this.getEntityManager().find(user.getUserContact().getClass(), user.getUserContact().getContactId());
-
- // Set detached object in rexcruiter instance
- user.setUserContact(foundContact);
-
- // Set timestamp
- user.setUserCreated(new GregorianCalendar());
-
- // Perist it
- this.getEntityManager().persist(user);
-
- // Flush it to get updated instance back
- this.getEntityManager().flush();
-
- // Log trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkUser: user={1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N
-
- // Return updated instanc
- return user;
- }
-
@Override
public User updateUserData (final User user) {
// Trace message
+++ /dev/null
-/*
- * Copyright (C) 2016 Cho-Time GmbH
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jusercore.model.user.password_history;
-
-import de.chotime.landingpage.database.BaseLandingDatabaseBean;
-import java.text.MessageFormat;
-import java.util.List;
-import javax.ejb.Stateless;
-import javax.persistence.Query;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * A user password history EJB
- * <p>
- * @author Roland Haeder<rhaeder@cho-time.de>
- */
-@Stateless (name = "userPasswordHistory", description = "A stateless EJB for user's password history. This bean does return the full user's password history and not limited. The application then needs to limit it to it's purpose.")
-public class LandingUserPasswordHistorySessionBean extends BaseLandingDatabaseBean implements UserPasswordHistorySessionBeanRemote {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 395_767_546_195_014L;
-
- /**
- * Default constructor
- */
- public LandingUserPasswordHistorySessionBean () {
- }
-
- @Override
- @SuppressWarnings ("unchecked")
- public List<PasswordHistory> getUserPasswordHistory (final User user) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserPasswordHistory(): user={1} - EXIT!", 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) {
- // Throw NPE again
- throw new NullPointerException("user.userId is null"); //NOI18N
- } else if (user.getUserId() < 1) {
- // Illegal id number
- throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not allowed.", user.getUserId())); //NOI18N
- }
-
- // Get named query
- Query query = this.getEntityManager().createNamedQuery("AllUsersHistoryEntries", UserPasswordHistory.class); //NOI18N
-
- // Set parameter
- query.setParameter("user", user); //NOI18N
-
- // Get full history
- List<PasswordHistory> history = query.getResultList();
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserPasswordHistory(): history.size()={1} - EXIT !", this.getClass().getSimpleName(), history.size())); //NOI18N
-
- // Return it
- return history;
- }
-
-}
--- /dev/null
+/*
+ * Copyright (C) 2016 Cho-Time GmbH
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jusercore.model.user.password_history;
+
+import java.text.MessageFormat;
+import java.util.List;
+import javax.ejb.Stateless;
+import javax.persistence.Query;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean;
+
+/**
+ * A user password history EJB
+ * <p>
+ * @author Roland Haeder<rhaeder@cho-time.de>
+ */
+@Stateless (name = "userPasswordHistory", description = "A stateless EJB for user's password history. This bean does return the full user's password history and not limited. The application then needs to limit it to it's purpose.")
+public class PizzaUserPasswordHistorySessionBean extends BasePizzaDatabaseBean implements UserPasswordHistorySessionBeanRemote {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 395_767_546_195_014L;
+
+ /**
+ * Default constructor
+ */
+ public PizzaUserPasswordHistorySessionBean () {
+ }
+
+ @Override
+ @SuppressWarnings ("unchecked")
+ public List<PasswordHistory> getUserPasswordHistory (final User user) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserPasswordHistory(): user={1} - EXIT!", 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) {
+ // Throw NPE again
+ throw new NullPointerException("user.userId is null"); //NOI18N
+ } else if (user.getUserId() < 1) {
+ // Illegal id number
+ throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not allowed.", user.getUserId())); //NOI18N
+ }
+
+ // Get named query
+ Query query = this.getEntityManager().createNamedQuery("AllUsersHistoryEntries", UserPasswordHistory.class); //NOI18N
+
+ // Set parameter
+ query.setParameter("user", user); //NOI18N
+
+ // Get full history
+ List<PasswordHistory> history = query.getResultList();
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserPasswordHistory(): history.size()={1} - EXIT !", this.getClass().getSimpleName(), history.size())); //NOI18N
+
+ // Return it
+ return history;
+ }
+
+}