+++ /dev/null
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * 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 java.util.List;
-import javax.ejb.EJB;
-import javax.ejb.EJBException;
-import javax.ejb.Stateless;
-import javax.persistence.NoResultException;
-import javax.persistence.PersistenceException;
-import javax.persistence.Query;
-import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
-import org.mxchange.jcontacts.contact.Contact;
-import org.mxchange.jcontacts.contact.ContactUtils;
-import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.phonenumbers.fax.FaxNumbers;
-import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jphone.phonenumbers.landline.LandLineNumbers;
-import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
-import org.mxchange.jphone.phonenumbers.mobile.MobileNumbers;
-import org.mxchange.jusercore.exceptions.UserNotFoundException;
-import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
-import org.mxchange.jusercore.exceptions.UserStatusLockedException;
-import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException;
-import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
-import org.mxchange.jusercore.model.user.password_history.UserPasswordHistory;
-import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
-import org.mxchange.jusercore.model.user.register.UserRegistrationSessionBeanRemote;
-import org.mxchange.jusercore.model.user.status.UserAccountStatus;
-
-/**
- * A user EJB
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Stateless (name = "user", description = "A bean handling the user data")
-public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean implements UserSessionBeanRemote {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 542_145_347_916L;
-
- /**
- * Registration EJB
- */
- @EJB
- private UserRegistrationSessionBeanRemote registerBean;
-
- /**
- * Default constructor
- */
- public AddressbookUserSessionBean () {
- // Call super constructor
- super("jms/addressbook-queue-factory", "jms/addressbook-email-queue"); //NOI18N
- }
-
- @Override
- @SuppressWarnings ("unchecked")
- public List<User> allMemberPublicVisibleUsers () {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMemberPublicVisibleUsers: CALLED!", this.getClass().getSimpleName())); //NOI18N
-
- // Get named query
- Query query = this.getEntityManager().createNamedQuery("AllMemberPublicUsers", LoginUser.class); //NOI18N
-
- // Set parameters
- query.setParameter("status", UserAccountStatus.CONFIRMED); //NOI18N
- query.setParameter("members", ProfileMode.MEMBERS); //NOI18N
- query.setParameter("public", ProfileMode.PUBLIC); //NOI18N
-
- // Get result
- List<User> users = query.getResultList();
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMemberPublicVisibleUsers: users.size()={1} - EXIT!", this.getClass().getSimpleName(), users.size())); //NOI18N
-
- // Return full list
- return users;
- }
-
- @Override
- @SuppressWarnings ("unchecked")
- public List<User> allPublicUsers () {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allPublicUsers: CALLED!", this.getClass().getSimpleName())); //NOI18N
-
- // Get named query
- Query query = this.getEntityManager().createNamedQuery("AllPublicUsers", LoginUser.class); //NOI18N
-
- // Set parameters
- query.setParameter("status", UserAccountStatus.CONFIRMED); //NOI18N
- query.setParameter("mode", ProfileMode.PUBLIC); //NOI18N
-
- // Get result
- List<User> users = query.getResultList();
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allPublicUsers: users.size()={1} - EXIT!", this.getClass().getSimpleName(), users.size())); //NOI18N
-
- // Return full list
- return users;
- }
-
- @Override
- @SuppressWarnings ("unchecked")
- public List<User> allUsers () {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsers: CALLED!", this.getClass().getSimpleName())); //NOI18N
-
- // Get named query
- Query query = this.getEntityManager().createNamedQuery("AllUsers", LoginUser.class); //NOI18N
-
- // Get result
- List<User> users = query.getResultList();
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsers: users.size()={1} - EXIT!", this.getClass().getSimpleName(), users.size())); //NOI18N
-
- // Return full list
- return users;
- }
-
- @Override
- public User confirmAccount (final User user, final String baseUrl) throws UserStatusConfirmedException, UserStatusLockedException {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.confirmAccount: user={1},baseUrl={2} - CALLED!", this.getClass().getSimpleName(), user, baseUrl)); //NOI18N
-
- // Parameter must be valid
- 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
- } else if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) {
- // Account is already confirmed
- throw new UserStatusConfirmedException(user);
- } else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) {
- // Account is already confirmed
- throw new UserStatusLockedException(user);
- } else if (user.getUserConfirmKey() == null) {
- // Throw NPE
- throw new NullPointerException("user.userConfirmKey is null"); //NOI18N
- } else if (null == baseUrl) {
- // Throw it again
- throw new NullPointerException("baseUrl is null"); //NOI18N
- } else if (baseUrl.isEmpty()) {
- // Invalid parameter
- throw new IllegalArgumentException("baseUrl is empty"); //NOI18N
- }
-
- // Update user status and remove confirmation key
- user.setUserAccountStatus(UserAccountStatus.CONFIRMED);
- user.setUserConfirmKey(null);
- user.setUserUpdated(new GregorianCalendar());
-
- // Update user account
- User updatedUser = this.updateUserData(user);
-
- // Send out email
- this.sendEmail("User account confirmed", "user_account_confirmed", updatedUser, baseUrl, null); //NOI18N
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.confirmAccount: updatedUser={1} - EXIT!", this.getClass().getSimpleName(), updatedUser)); //NOI18N
-
- // Return updated instance
- return updatedUser;
- }
-
- @Override
- public User fillUserData (final User user) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fillUserData: 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
- }
-
- // Try to locate it
- Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N
-
- // Set parameter
- query.setParameter("userName", user.getUserName()); //NOI18N
-
- // Initialize variable
- User foundUser = null;
-
- // Try it
- try {
- // Try to get single result
- foundUser = (User) query.getSingleResult();
- } catch (final NoResultException ex) {
- // Log it
- this.getLoggerBeanLocal().logException(ex);
- }
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fillUserData: foundUser={1} - EXIT!", this.getClass().getSimpleName(), foundUser)); //NOI18N
-
- // Return prepared instance
- return foundUser;
- }
-
- @Override
- public User findUserById (final Long userId) throws UserNotFoundException {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findUserById: userId={1} - CALLED!", this.getClass().getSimpleName(), userId)); //NOI18N
-
- // Is the parameter valid?
- if (null == userId) {
- // Throw NPE
- throw new NullPointerException("userId is null"); //NOI18N
- } else if (userId < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N
- } else if (!this.ifUserIdExists(userId)) {
- // Does not exist
- throw new UserNotFoundException(userId);
- }
-
- // Create query instance
- Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N
-
- // Set user id
- query.setParameter("id", userId); //NOI18N
-
- // Fetch the result, it should be there by now
- User user = (User) query.getSingleResult();
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findUserById: user={1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N
-
- // Return found user
- return user;
- }
-
- @Override
- public String generateRandomUserName () {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateRandomUserName - CALLED!", this.getClass().getSimpleName())); //NOI18N
-
- // Get full list
- List<String> userList = this.getUserNameList();
-
- // Init variable
- String userName = null;
-
- // Loop until a user name is found
- while ((userName == null) || (userList.contains(userName))) {
- // Generate random name
- userName = UserUtils.generateRandomUserName();
- }
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateRandomUserName: userName={1} - EXIT!", this.getClass().getSimpleName(), userName)); //NOI18N
-
- // Found one, so return it
- return userName;
- }
-
- @Override
- @SuppressWarnings ("unchecked")
- public List<String> getEmailAddressList () {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList: CALLED!", this.getClass().getSimpleName())); //NOI18N
-
- // Get query
- Query query = this.getEntityManager().createNamedQuery("AllEmailAddresses", String.class); //NOI18N
-
- // Get result list
- List<String> emailAddressList = query.getResultList();
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList: emailAddressList.size()={1} - EXIT!", this.getClass().getSimpleName(), emailAddressList.size())); //NOI18N
-
- // Return it
- return emailAddressList;
- }
-
- @Override
- @SuppressWarnings ("unchecked")
- public List<String> getUserNameList () {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserNameList: CALLED!", this.getClass().getSimpleName())); //NOI18N
-
- // Get query
- Query query = this.getEntityManager().createNamedQuery("AllUserNames", String.class); //NOI18N
-
- // Get result list
- List<String> userNameList = query.getResultList();
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserNameList: userNameList.size()={1} - EXIT!", this.getClass().getSimpleName(), userNameList.size())); //NOI18N
-
- // Return it
- return userNameList;
- }
-
- @Override
- public boolean ifUserExists (final User user) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserExists: 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
- }
-
- // Generate query
- Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N
-
- // Set parameter
- query.setParameter("id", user.getUserId()); //NOI18N
-
- // Try this
- try {
- User dummy = (User) query.getSingleResult();
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserExists: dummy.id={0} found.", dummy.getUserId())); //NOI18N
- } catch (final NoResultException ex) {
- // Log it
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserExists: getSingleResult() returned no result: {0}", ex)); //NOI18N
-
- // User name does not exist
- return false;
- } catch (final PersistenceException ex) {
- // Something bad happened
- this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one user {0} found.", user, ex)); //NOI18N
-
- // Throw again
- throw ex;
- }
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserExists: Found user {1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N
-
- // Found it
- return true;
- }
-
- @Override
- public boolean ifUserIdExists (final Long userId) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserIdExists: userId={1} - CALLED!", this.getClass().getSimpleName(), userId)); //NOI18N
-
- // userId should not be null
- if (null == userId) {
- // Abort here
- throw new NullPointerException("userId is null"); //NOI18N
- } else if (userId < 1) {
- // Invalid number
- throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", userId)); //NOI18N
- }
-
- // Generate query
- Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N
-
- // Set parameter
- query.setParameter("id", userId); //NOI18N
-
- // Try this
- try {
- User dummy = (User) query.getSingleResult();
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserIdExists: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N
- } catch (final NoResultException ex) {
- // Log it
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserIdExists: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N
-
- // User name does not exist
- return false;
- } catch (final PersistenceException ex) {
- // Something bad happened
- this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one user id {0} found.", userId, ex)); //NOI18N
-
- // Throw again
- throw ex;
- }
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserIdExists: Found userId={1} - EXIT!", this.getClass().getSimpleName(), userId)); //NOI18N
-
- // Found it
- return true;
- }
-
- @Override
- public boolean ifUserNameExists (final String userName) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserNameExists: userName={1} - CALLED!", this.getClass().getSimpleName(), userName)); //NOI18N
-
- // userId should not be null
- if (null == userName) {
- // Abort here
- throw new NullPointerException("userName is null"); //NOI18N
- } else if (userName.isEmpty()) {
- // Abort here
- throw new NullPointerException("userName is empty"); //NOI18N
- }
-
- // Generate query
- Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N
-
- // Set parameter
- query.setParameter("userName", userName); //NOI18N
-
- // Try this
- try {
- User dummy = (User) query.getSingleResult();
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserNameExists: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N
- } catch (final NoResultException ex) {
- // Log it
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserNameExists: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N
-
- // User name does not exist
- return false;
- }
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserNameExists: Found userName={1} - EXIT!", this.getClass().getSimpleName(), userName)); //NOI18N
-
- // Found it
- return true;
- }
-
- @Override
- public boolean isEmailAddressRegistered (final User user) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: 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
- }
-
- // Generate query
- Query query = this.getEntityManager().createNamedQuery("SearchUserByEmailAddress", LoginUser.class); //NOI18N
-
- // Set parameter
- query.setParameter("emailAddress", user.getUserContact().getContactEmailAddress()); //NOI18N
-
- // Search for it
- try {
- User dummy = (User) query.getSingleResult();
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isEmailAddressRegistered: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N
- } catch (final NoResultException ex) {
- // Log it
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isEmailAddressRegistered: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N
-
- // Email address does not exist
- return false;
- } catch (final PersistenceException ex) {
- // Something bad happened
- this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one email address {0} found.", user.getUserContact().getContactEmailAddress()), ex); //NOI18N
-
- // Throw again
- throw ex;
- }
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: Returning true ... - EXIT!", this.getClass().getSimpleName())); //NOI18N
-
- // Found it
- return true;
- }
-
- @Override
- public boolean isUserNameRegistered (final User user) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isUserNameRegistered: 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
- }
-
- // Generate query
- Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N
-
- // Set parameter
- query.setParameter("userName", user.getUserName()); //NOI18N
-
- // Try this
- try {
- User dummy = (User) query.getSingleResult();
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isUserNameRegistered: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N
- } catch (final NoResultException ex) {
- // Log it
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isUserNameRegistered: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N
-
- // User name does not exist
- return false;
- } catch (final PersistenceException ex) {
- // Something bad happened
- this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one email address {0} found.", user.getUserContact().getContactEmailAddress()), ex); //NOI18N
-
- // Throw again
- throw ex;
- }
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isUserNameRegistered: Returning true ... - EXIT!", this.getClass().getSimpleName())); //NOI18N
-
- // Found it
- return true;
- }
-
- @Override
- public User updateUserData (final User user) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: 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) {
- // Throw NPE again
- throw new NullPointerException("user.userId is null"); //NOI18N
- } else if (user.getUserId() < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
- } else if (user.getUserAccountStatus() == null) {
- // Throw NPE again
- throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
- } else if (!this.ifUserExists(user)) {
- // User does not exist
- throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
- }
-
- // Remove contact instance as this is not updated
- user.setUserContact(null);
-
- // Find the instance
- User managedUser = this.getEntityManager().find(user.getClass(), user.getUserId());
-
- // Should be found!
- assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
-
- // Copy all data
- UserUtils.copyAll(user, managedUser);
-
- // Set as updated
- managedUser.setUserUpdated(new GregorianCalendar());
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: managedUser={1} - CALLED!", this.getClass().getSimpleName(), managedUser)); //NOI18N
-
- // Return updated instance
- return managedUser;
- }
-
- @Override
- public PasswordHistory updateUserPassword (final User user, final String baseUrl) throws UserNotFoundException, UserStatusUnconfirmedException, UserStatusLockedException {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPassword: user={1},baseUrl={2} - CALLED!", this.getClass().getSimpleName(), user, baseUrl)); //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) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
- } else if (user.getUserAccountStatus() == null) {
- // Throw NPE
- throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
- } else if (user.getUserContact() == null) {
- // Throw it again
- throw new NullPointerException("user.userContact is null"); //NOI18N
- } else if (user.getUserContact().getContactId() == null) {
- // .. and again
- throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
- } else if (user.getUserContact().getContactId() < 1) {
- // Invalid id
- throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is invalid", user.getUserContact().getContactId())); //NOI18N
- } else if (user.getUserContact().getContactPersonalTitle() == null) {
- // Throw NPE again
- throw new NullPointerException("user.userContact.contactPersonalTitle is null"); //NOI18N
- } else if (!this.ifUserExists(user)) {
- // User does not exist
- throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
- } else if (null == baseUrl) {
- // Throw it again
- throw new NullPointerException("baseUrl is null"); //NOI18N
- } else if (baseUrl.isEmpty()) {
- // Invalid parameter
- throw new IllegalArgumentException("baseUrl is empty"); //NOI18N
- }
-
- // Call other method
- User updatedUser = this.updateUserData(user);
-
- // Create history entry
- PasswordHistory entry = new UserPasswordHistory(user.getUserEncryptedPassword(), updatedUser);
-
- // Set created timestamp
- entry.setUserPasswordHistoryCreated(new GregorianCalendar());
-
- // Persist it
- this.getEntityManager().persist(entry);
-
- // Flush it to get id number back
- this.getEntityManager().flush();
-
- // Send email to user
- this.sendEmail("User password change", "user_password_change", user, baseUrl, null); //NOI18N
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPassword: entry.userPasswordHistoryId={1} - EXIT!", this.getClass().getSimpleName(), entry.getUserPasswordHistoryId())); //NOI18N
-
- // Return it
- return entry;
- }
-
- @Override
- public User updateUserPersonalData (final User user) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPersonalData: 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) {
- // Throw NPE again
- throw new NullPointerException("user.userId is null"); //NOI18N
- } else if (user.getUserId() < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
- } else if (user.getUserAccountStatus() == null) {
- // Throw NPE again
- throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
- } else if (!this.ifUserExists(user)) {
- // User does not exist
- throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
- }
-
- // Find the instance
- User managedUser = this.getEntityManager().find(user.getClass(), user.getUserId());
-
- // Should be found!
- assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
-
- // Copy all data
- UserUtils.copyAll(user, managedUser);
-
- // Set as updated
- managedUser.setUserUpdated(new GregorianCalendar());
- managedUser.getUserContact().setContactUpdated(new GregorianCalendar());
-
- // Get contact from it and find it
- Contact managedContact = this.getEntityManager().find(user.getUserContact().getClass(), user.getUserContact().getContactId());
-
- // Should be found
- assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", user.getUserContact().getContactId()); //NOI18N
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: managedContact.contactId={0}", managedContact.getContactId())); //NOI18N
-
- // Copy all
- ContactUtils.copyAll(user.getUserContact(), managedContact);
-
- // Set it back in user
- user.setUserContact(managedContact);
-
- // Should be found!
- assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not merged, but should be.", user.getUserContact().getContactId()); //NOI18N
-
- // Get mobile instance
- DialableMobileNumber mobileNumber = managedContact.getContactMobileNumber();
-
- // Is there a mobile instance set?
- if (mobileNumber instanceof DialableMobileNumber) {
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: mobile.phoneId={0} is being updated ...", mobileNumber.getPhoneId())); //NOI18N
-
- // Then find it, too
- DialableMobileNumber foundMobile = this.getEntityManager().find(mobileNumber.getClass(), mobileNumber.getPhoneId());
-
- // Should be there
- assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N
-
- // Then merge it, too
- DialableMobileNumber managedMobile = this.getEntityManager().merge(foundMobile);
-
- // Should be there
- assert (managedMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", managedMobile.getPhoneId()); //NOI18N
-
- // Copy all
- MobileNumbers.copyAll(managedUser.getUserContact().getContactMobileNumber(), managedMobile);
-
- // Set it back
- managedContact.setContactMobileNumber(this.getManaged(mobileNumber, mobileNumber));
- }
-
- // Get mobile instance
- DialableFaxNumber faxNumber = managedContact.getContactFaxNumber();
-
- // Is there a fax instance set?
- if (faxNumber instanceof DialableFaxNumber) {
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: faxNumber.phoneId={0} is being updated ...", faxNumber.getPhoneId())); //NOI18N
-
- // Then find it, too
- DialableFaxNumber foundFax = this.getEntityManager().find(faxNumber.getClass(), faxNumber.getPhoneId());
-
- // Should be there
- assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N
-
- // Then merge it, too
- DialableFaxNumber managedFax = this.getEntityManager().merge(foundFax);
-
- // Should be there
- assert (managedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", managedFax.getPhoneId()); //NOI18N
-
- // Copy all
- FaxNumbers.copyAll(managedUser.getUserContact().getContactFaxNumber(), managedFax);
-
- // Set it back
- managedContact.setContactFaxNumber(managedFax);
- }
-
- // Get mobile instance
- DialableLandLineNumber landLineNumber = managedContact.getContactLandLineNumber();
-
- // Is there a fax instance set?
- if (landLineNumber instanceof DialableLandLineNumber) {
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLineNumber.phoneId={0} is being updated ...", landLineNumber.getPhoneId())); //NOI18N
-
- // Then find it, too
- DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLineNumber.getClass(), landLineNumber.getPhoneId());
-
- // Should be there
- assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
-
- // Then merge it, too
- DialableLandLineNumber managedLandLine = this.getEntityManager().merge(foundLandLine);
-
- // Should be there
- assert (managedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", managedLandLine.getPhoneId()); //NOI18N
-
- // Copy all
- LandLineNumbers.copyAll(managedUser.getUserContact().getContactLandLineNumber(), managedLandLine);
-
- // Set it back
- managedContact.setContactLandLineNumber(managedLandLine);
- }
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPersonalData: entry.managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
-
- // Return updated user instance
- return managedUser;
- }
-
-}