2 * Copyright (C) 2016, 2017 Roland Häder
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.user;
19 import java.text.MessageFormat;
20 import java.util.Date;
21 import java.util.List;
23 import javax.ejb.EJBException;
24 import javax.ejb.Stateless;
25 import javax.persistence.NoResultException;
26 import javax.persistence.PersistenceException;
27 import javax.persistence.Query;
28 import org.mxchange.jcontacts.model.contact.Contact;
29 import org.mxchange.jcontacts.model.contact.ContactUtils;
30 import org.mxchange.jjobs.database.BaseJobsDatabaseBean;
31 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
32 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumbers;
33 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
34 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumbers;
35 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
36 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumbers;
37 import org.mxchange.jusercore.exceptions.UserNotFoundException;
38 import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
39 import org.mxchange.jusercore.exceptions.UserStatusLockedException;
40 import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException;
41 import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
42 import org.mxchange.jusercore.model.user.password_history.UserPasswordHistory;
43 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
44 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
45 import org.mxchange.juserlogincore.model.user.register.UserRegistrationSessionBeanRemote;
50 * @author Roland Häder<roland@mxchange.org>
52 @Stateless (name = "user", description = "A bean handling the user data")
53 public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSessionBeanRemote {
58 private static final long serialVersionUID = 542_145_347_916L;
64 private UserRegistrationSessionBeanRemote registerBean;
69 public JobsUserSessionBean () {
70 // Call super constructor
71 super("jms/jjobs-queue-factory", "jms/jjobs-email-queue"); //NOI18N
75 @SuppressWarnings ("unchecked")
76 public List<User> allMemberPublicVisibleUsers () {
78 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMemberPublicVisibleUsers: CALLED!", this.getClass().getSimpleName())); //NOI18N
81 final Query query = this.getEntityManager().createNamedQuery("AllMemberPublicUsers", LoginUser.class); //NOI18N
84 query.setParameter("status", UserAccountStatus.CONFIRMED); //NOI18N
85 query.setParameter("members", ProfileMode.MEMBERS); //NOI18N
86 query.setParameter("public", ProfileMode.PUBLIC); //NOI18N
89 final List<User> users = query.getResultList();
92 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMemberPublicVisibleUsers: users.size()={1} - EXIT!", this.getClass().getSimpleName(), users.size())); //NOI18N
99 @SuppressWarnings ("unchecked")
100 public List<User> allPublicUsers () {
102 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allPublicUsers: CALLED!", this.getClass().getSimpleName())); //NOI18N
105 final Query query = this.getEntityManager().createNamedQuery("AllPublicUsers", LoginUser.class); //NOI18N
108 query.setParameter("status", UserAccountStatus.CONFIRMED); //NOI18N
109 query.setParameter("mode", ProfileMode.PUBLIC); //NOI18N
112 final List<User> users = query.getResultList();
115 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allPublicUsers: users.size()={1} - EXIT!", this.getClass().getSimpleName(), users.size())); //NOI18N
122 @SuppressWarnings ("unchecked")
123 public List<String> allUserNames () {
125 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserNameList: CALLED!", this.getClass().getSimpleName())); //NOI18N
128 final Query query = this.getEntityManager().createNamedQuery("AllUserNames", String.class); //NOI18N
131 final List<String> userNameList = query.getResultList();
134 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserNameList: userNameList.size()={1} - EXIT!", this.getClass().getSimpleName(), userNameList.size())); //NOI18N
141 @SuppressWarnings ("unchecked")
142 public List<User> allUsers () {
144 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsers: CALLED!", this.getClass().getSimpleName())); //NOI18N
147 final Query query = this.getEntityManager().createNamedQuery("AllUsers", LoginUser.class); //NOI18N
150 final List<User> users = query.getResultList();
153 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsers: users.size()={1} - EXIT!", this.getClass().getSimpleName(), users.size())); //NOI18N
160 public User confirmAccount (final User user, final String baseUrl) throws UserStatusConfirmedException, UserStatusLockedException {
162 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.confirmAccount: user={1},baseUrl={2} - CALLED!", this.getClass().getSimpleName(), user, baseUrl)); //NOI18N
164 // Parameter must be valid
167 throw new NullPointerException("user is null"); //NOI18N
168 } else if (user.getUserId() == null) {
170 throw new NullPointerException("user.userId is null"); //NOI18N
171 } else if (user.getUserId() < 1) {
173 throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", user.getUserId())); //NOI18N
174 } else if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) {
175 // Account is already confirmed
176 throw new UserStatusConfirmedException(user);
177 } else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) {
178 // Account is already confirmed
179 throw new UserStatusLockedException(user);
180 } else if (user.getUserConfirmKey() == null) {
182 throw new NullPointerException("user.userConfirmKey is null"); //NOI18N
183 } else if (null == baseUrl) {
185 throw new NullPointerException("baseUrl is null"); //NOI18N
186 } else if (baseUrl.isEmpty()) {
188 throw new IllegalArgumentException("baseUrl is empty"); //NOI18N
191 // Update user account
192 final User managedUser = this.updateUserData(user);
194 // Update user status and remove confirmation key
195 managedUser.setUserAccountStatus(UserAccountStatus.CONFIRMED);
196 managedUser.setUserConfirmKey(null);
197 managedUser.setUserUpdated(new Date());
200 this.sendEmail("User account confirmed", "user_account_confirmed", managedUser, baseUrl, null); //NOI18N
203 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.confirmAccount: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
205 // Return updated instance
210 public User fillUserData (final User user) throws UserNotFoundException {
212 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fillUserData: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
214 // user should not be null
217 throw new NullPointerException("user is null"); //NOI18N
218 } else if (user.getUserName() == null) {
220 throw new NullPointerException("user.userName is null");
221 } else if (user.getUserName().isEmpty()) {
223 throw new IllegalArgumentException("user.userName is empty");
224 } else if (!this.ifUserExists(user)) {
225 // User does not exist
226 throw new UserNotFoundException(user);
230 final Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N
233 query.setParameter("param", user.getUserName()); //NOI18N
235 // Initialize variable
236 final User foundUser;
240 // Try to get single result
241 foundUser = (User) query.getSingleResult();
242 } catch (final NoResultException ex) {
244 this.getLoggerBeanLocal().logException(ex);
249 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fillUserData: foundUser={1} - EXIT!", this.getClass().getSimpleName(), foundUser)); //NOI18N
251 // Return prepared instance
256 public User findUserById (final Long userId) throws UserNotFoundException {
258 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findUserById: userId={1} - CALLED!", this.getClass().getSimpleName(), userId)); //NOI18N
260 // Is the parameter valid?
261 if (null == userId) {
263 throw new NullPointerException("userId is null"); //NOI18N
264 } else if (userId < 1) {
266 throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N
267 } else if (!this.ifUserIdExists(userId)) {
269 throw new UserNotFoundException(userId);
272 // Create query instance
273 final Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N
276 query.setParameter("id", userId); //NOI18N
278 // Fetch the result, it should be there by now
279 final User user = (User) query.getSingleResult();
282 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findUserById: user={1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N
289 public String generateRandomUserName () {
291 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateRandomUserName - CALLED!", this.getClass().getSimpleName())); //NOI18N
294 final List<String> userList = this.allUserNames();
297 String userName = null;
299 // Loop until a user name is found
300 while ((userName == null) || (userList.contains(userName))) {
301 // Generate random name
302 userName = UserUtils.generateRandomUserName();
306 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateRandomUserName: userName={1} - EXIT!", this.getClass().getSimpleName(), userName)); //NOI18N
308 // Found one, so return it
313 @SuppressWarnings ("unchecked")
314 public List<String> getEmailAddressList () {
316 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList: CALLED!", this.getClass().getSimpleName())); //NOI18N
319 final Query query = this.getEntityManager().createNamedQuery("AllEmailAddresses", String.class); //NOI18N
322 final List<String> emailAddressList = query.getResultList();
325 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList: emailAddressList.size()={1} - EXIT!", this.getClass().getSimpleName(), emailAddressList.size())); //NOI18N
328 return emailAddressList;
332 public boolean ifUserExists (final User user) {
334 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserExists: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
336 // userId should not be null
339 throw new NullPointerException("user is null"); //NOI18N
340 } else if (user.getUserId() == null) {
342 throw new NullPointerException("user.userId is null"); //NOI18N
343 } else if (user.getUserId() < 1) {
345 throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", user.getUserId())); //NOI18N
349 final Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N
352 query.setParameter("id", user.getUserId()); //NOI18N
356 // Try to get single result
357 final User dummy = (User) query.getSingleResult();
360 this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserExists: dummy.id={0} found.", dummy.getUserId())); //NOI18N
361 } catch (final NoResultException ex) {
363 this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserExists: getSingleResult() returned no result: {0}", ex)); //NOI18N
365 // User name does not exist
367 } catch (final PersistenceException ex) {
368 // Something bad happened
369 this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one user {0} found.", user, ex)); //NOI18N
376 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserExists: Found user {1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N
383 public boolean ifUserIdExists (final Long userId) {
385 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserIdExists: userId={1} - CALLED!", this.getClass().getSimpleName(), userId)); //NOI18N
387 // userId should not be null
388 if (null == userId) {
390 throw new NullPointerException("userId is null"); //NOI18N
391 } else if (userId < 1) {
393 throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", userId)); //NOI18N
397 final Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N
400 query.setParameter("id", userId); //NOI18N
404 // Try to get single result
405 final User dummy = (User) query.getSingleResult();
408 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserIdExists: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N
409 } catch (final NoResultException ex) {
411 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserIdExists: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N
413 // User name does not exist
415 } catch (final PersistenceException ex) {
416 // Something bad happened
417 this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one user id {0} found.", userId, ex)); //NOI18N
424 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserIdExists: Found userId={1} - EXIT!", this.getClass().getSimpleName(), userId)); //NOI18N
431 public boolean ifUserNameExists (final String userName) {
433 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserNameExists: userName={1} - CALLED!", this.getClass().getSimpleName(), userName)); //NOI18N
435 // userId should not be null
436 if (null == userName) {
438 throw new NullPointerException("userName is null"); //NOI18N
439 } else if (userName.isEmpty()) {
441 throw new NullPointerException("userName is empty"); //NOI18N
445 final Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N
448 query.setParameter("param", userName); //NOI18N
452 // Try to get single result
453 final User dummy = (User) query.getSingleResult();
456 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserNameExists: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N
457 } catch (final NoResultException ex) {
459 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserNameExists: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N
461 // User name does not exist
466 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserNameExists: Found userName={1} - EXIT!", this.getClass().getSimpleName(), userName)); //NOI18N
473 public boolean isEmailAddressRegistered (final User user) {
475 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
477 // user should not be null
480 throw new NullPointerException("user is null"); //NOI18N
484 final Query query = this.getEntityManager().createNamedQuery("SearchUserByEmailAddress", LoginUser.class); //NOI18N
487 query.setParameter("param", user.getUserContact().getContactEmailAddress()); //NOI18N
491 // Try to get single result
492 final User dummy = (User) query.getSingleResult();
495 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isEmailAddressRegistered: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N
496 } catch (final NoResultException ex) {
498 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isEmailAddressRegistered: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N
500 // Email address does not exist
502 } catch (final PersistenceException ex) {
503 // Something bad happened
504 this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one email address {0} found.", user.getUserContact().getContactEmailAddress()), ex); //NOI18N
511 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: Returning true ... - EXIT!", this.getClass().getSimpleName())); //NOI18N
518 public boolean isUserNameRegistered (final User user) {
520 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isUserNameRegistered: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
522 // user should not be null
525 throw new NullPointerException("user is null"); //NOI18N
529 final Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N
532 query.setParameter("param", user.getUserName()); //NOI18N
536 // Try to get single result
537 final User dummy = (User) query.getSingleResult();
540 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isUserNameRegistered: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N
541 } catch (final NoResultException ex) {
543 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isUserNameRegistered: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N
545 // User name does not exist
547 } catch (final PersistenceException ex) {
548 // Something bad happened
549 this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one email address {0} found.", user.getUserContact().getContactEmailAddress()), ex); //NOI18N
556 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isUserNameRegistered: Returning true ... - EXIT!", this.getClass().getSimpleName())); //NOI18N
563 public User updateUserData (final User user) {
565 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
567 // user should not be null
570 throw new NullPointerException("user is null"); //NOI18N
571 } else if (user.getUserId() == null) {
573 throw new NullPointerException("user.userId is null"); //NOI18N
574 } else if (user.getUserId() < 1) {
576 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
577 } else if (user.getUserAccountStatus() == null) {
579 throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
580 } else if (!this.ifUserExists(user)) {
581 // User does not exist
582 throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
586 final User foundUser = this.getEntityManager().find(user.getClass(), user.getUserId());
589 assert (foundUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
592 final User managedUser = this.getEntityManager().merge(foundUser);
595 assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
598 UserUtils.copyAll(user, managedUser);
601 managedUser.setUserUpdated(new Date());
604 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
606 // Return updated instance
611 public PasswordHistory updateUserPassword (final User user, final String baseUrl) throws UserNotFoundException, UserStatusUnconfirmedException, UserStatusLockedException {
613 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPassword: user={1},baseUrl={2} - CALLED!", this.getClass().getSimpleName(), user, baseUrl)); //NOI18N
615 // user should not be null
618 throw new NullPointerException("user is null"); //NOI18N
619 } else if (user.getUserId() == null) {
621 throw new NullPointerException("user.userId is null"); //NOI18N
622 } else if (user.getUserId() < 1) {
624 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
625 } else if (user.getUserName() == null) {
627 throw new NullPointerException("user.userName is null"); //NOI18N
628 } else if (user.getUserName().isEmpty()) {
630 throw new IllegalArgumentException("user.userName is empty"); //NOI18N
631 } else if (user.getUserAccountStatus() == null) {
633 throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
634 } else if (user.getUserContact() == null) {
636 throw new NullPointerException("user.userContact is null"); //NOI18N
637 } else if (user.getUserContact().getContactId() == null) {
639 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
640 } else if (user.getUserContact().getContactId() < 1) {
642 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is invalid", user.getUserContact().getContactId())); //NOI18N
643 } else if (user.getUserContact().getContactPersonalTitle() == null) {
645 throw new NullPointerException("user.userContact.contactPersonalTitle is null"); //NOI18N
646 } else if (!this.ifUserExists(user)) {
647 // User does not exist
648 throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
649 } else if (null == baseUrl) {
651 throw new NullPointerException("baseUrl is null"); //NOI18N
652 } else if (baseUrl.isEmpty()) {
654 throw new IllegalArgumentException("baseUrl is empty"); //NOI18N
658 final User managedUser = this.updateUserData(user);
660 // Update user account
661 managedUser.setUserUpdated(new Date());
663 // Create history entry
664 PasswordHistory entry = new UserPasswordHistory(user.getUserEncryptedPassword(), managedUser);
666 // Set created timestamp
667 entry.setUserPasswordHistoryCreated(new Date());
669 // Merge user to make sure it is not re-persisted
670 final User mergedUser = this.getEntityManager().merge(managedUser);
671 entry.setUserPasswordHistoryUser(mergedUser);
674 this.getEntityManager().persist(entry);
676 // Send email to user
677 this.sendEmail("User password change", "user_password_change", managedUser, baseUrl, null); //NOI18N
680 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPassword: entry.userPasswordHistoryId={1} - EXIT!", this.getClass().getSimpleName(), entry.getUserPasswordHistoryId())); //NOI18N
687 public User updateUserPersonalData (final User user) {
689 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPersonalData: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
691 // user should not be null
694 throw new NullPointerException("user is null"); //NOI18N
695 } else if (user.getUserId() == null) {
697 throw new NullPointerException("user.userId is null"); //NOI18N
698 } else if (user.getUserId() < 1) {
700 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
701 } else if (user.getUserAccountStatus() == null) {
703 throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
704 } else if (!this.ifUserExists(user)) {
705 // User does not exist
706 throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
710 final User managedUser = this.getEntityManager().find(user.getClass(), user.getUserId());
713 assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
716 UserUtils.copyAll(user, managedUser);
719 managedUser.setUserUpdated(new Date());
720 managedUser.getUserContact().setContactUpdated(new Date());
722 // Get contact from it and find it
723 final Contact foundContact = this.getEntityManager().find(managedUser.getUserContact().getClass(), managedUser.getUserContact().getContactId());
726 assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", user.getUserContact().getContactId()); //NOI18N
729 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: contact.contactId={0}", foundContact.getContactId())); //NOI18N
731 // Merge contact instance
732 final Contact managedContact = this.getEntityManager().merge(foundContact);
735 ContactUtils.copyAll(user.getUserContact(), managedContact);
737 // Set it back in user
738 user.setUserContact(managedContact);
741 assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not merged, but should be.", user.getUserContact().getContactId()); //NOI18N
743 // Get mobile instance
744 final DialableMobileNumber mobileNumber = managedContact.getContactMobileNumber();
746 // Is there a mobile instance set?
747 if (mobileNumber instanceof DialableMobileNumber) {
749 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: mobile.phoneId={0} is being updated ...", mobileNumber.getPhoneId())); //NOI18N
752 final DialableMobileNumber foundMobile = this.getEntityManager().find(mobileNumber.getClass(), mobileNumber.getPhoneId());
755 assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N
757 // Then merge it, too
758 final DialableMobileNumber managedMobile = this.getEntityManager().merge(foundMobile);
761 assert (managedMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", managedMobile.getPhoneId()); //NOI18N
764 MobileNumbers.copyAll(managedUser.getUserContact().getContactMobileNumber(), managedMobile);
767 managedContact.setContactMobileNumber(this.getManaged(mobileNumber, mobileNumber));
770 // Get mobile instance
771 final DialableFaxNumber faxNumber = managedContact.getContactFaxNumber();
773 // Is there a fax instance set?
774 if (faxNumber instanceof DialableFaxNumber) {
776 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: faxNumber.phoneId={0} is being updated ...", faxNumber.getPhoneId())); //NOI18N
779 final DialableFaxNumber foundFax = this.getEntityManager().find(faxNumber.getClass(), faxNumber.getPhoneId());
782 assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N
784 // Then merge it, too
785 final DialableFaxNumber managedFax = this.getEntityManager().merge(foundFax);
788 assert (managedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", managedFax.getPhoneId()); //NOI18N
791 FaxNumbers.copyAll(managedUser.getUserContact().getContactFaxNumber(), managedFax);
794 managedContact.setContactFaxNumber(managedFax);
797 // Get mobile instance
798 final DialableLandLineNumber landLineNumber = managedContact.getContactLandLineNumber();
800 // Is there a fax instance set?
801 if (landLineNumber instanceof DialableLandLineNumber) {
803 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLineNumber.phoneId={0} is being updated ...", landLineNumber.getPhoneId())); //NOI18N
806 final DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLineNumber.getClass(), landLineNumber.getPhoneId());
809 assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
811 // Then merge it, too
812 final DialableLandLineNumber managedLandLine = this.getEntityManager().merge(foundLandLine);
815 assert (managedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", managedLandLine.getPhoneId()); //NOI18N
818 LandLineNumbers.copyAll(managedUser.getUserContact().getContactLandLineNumber(), managedLandLine);
821 managedContact.setContactLandLineNumber(managedLandLine);
825 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPersonalData: entry.managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
827 // Return updated user instance