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.GregorianCalendar;
21 import java.util.List;
23 import javax.ejb.EJBException;
24 import javax.ejb.Stateless;
25 import javax.mail.Address;
26 import javax.mail.internet.AddressException;
27 import javax.mail.internet.InternetAddress;
28 import javax.persistence.NoResultException;
29 import javax.persistence.PersistenceException;
30 import javax.persistence.Query;
31 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
32 import org.mxchange.jcontacts.contact.Contact;
33 import org.mxchange.jcontacts.contact.ContactUtils;
34 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
35 import org.mxchange.jphone.phonenumbers.fax.FaxNumbers;
36 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
37 import org.mxchange.jphone.phonenumbers.landline.LandLineNumbers;
38 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
39 import org.mxchange.jphone.phonenumbers.mobile.MobileNumbers;
40 import org.mxchange.jusercore.exceptions.UserNotFoundException;
41 import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
42 import org.mxchange.jusercore.exceptions.UserStatusLockedException;
43 import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException;
44 import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
45 import org.mxchange.jusercore.model.user.password_history.UserPasswordHistory;
46 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
47 import org.mxchange.jusercore.model.user.register.UserRegistrationSessionBeanRemote;
48 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
53 * @author Roland Häder<roland@mxchange.org>
55 @Stateless (name = "user", description = "A bean handling the user data")
56 public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean implements UserSessionBeanRemote {
61 private static final long serialVersionUID = 542_145_347_916L;
67 private UserRegistrationSessionBeanRemote registerBean;
72 public AddressbookUserSessionBean () {
73 // Call super constructor
78 @SuppressWarnings ("unchecked")
79 public List<User> allMemberPublicVisibleUsers () {
81 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMemberPublicVisibleUsers: CALLED!", this.getClass().getSimpleName())); //NOI18N
84 Query query = this.getEntityManager().createNamedQuery("AllMemberPublicUsers", LoginUser.class); //NOI18N
87 query.setParameter("status", UserAccountStatus.CONFIRMED); //NOI18N
88 query.setParameter("members", ProfileMode.MEMBERS); //NOI18N
89 query.setParameter("public", ProfileMode.PUBLIC); //NOI18N
92 List<User> users = query.getResultList();
95 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMemberPublicVisibleUsers: users.size()={1} - EXIT!", this.getClass().getSimpleName(), users.size())); //NOI18N
102 @SuppressWarnings ("unchecked")
103 public List<User> allPublicUsers () {
105 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allPublicUsers: CALLED!", this.getClass().getSimpleName())); //NOI18N
108 Query query = this.getEntityManager().createNamedQuery("AllPublicUsers", LoginUser.class); //NOI18N
111 query.setParameter("status", UserAccountStatus.CONFIRMED); //NOI18N
112 query.setParameter("mode", ProfileMode.PUBLIC); //NOI18N
115 List<User> users = query.getResultList();
118 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allPublicUsers: users.size()={1} - EXIT!", this.getClass().getSimpleName(), users.size())); //NOI18N
125 @SuppressWarnings ("unchecked")
126 public List<User> allUsers () {
128 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsers: CALLED!", this.getClass().getSimpleName())); //NOI18N
131 Query query = this.getEntityManager().createNamedQuery("AllUsers", LoginUser.class); //NOI18N
134 List<User> users = query.getResultList();
137 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsers: users.size()={1} - EXIT!", this.getClass().getSimpleName(), users.size())); //NOI18N
144 public User confirmAccount (final User user, final String baseUrl) throws UserStatusConfirmedException, UserStatusLockedException {
146 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.confirmAccount: user={1},baseUrl={2} - CALLED!", this.getClass().getSimpleName(), user, baseUrl)); //NOI18N
148 // Parameter must be valid
151 throw new NullPointerException("user is null"); //NOI18N
152 } else if (user.getUserId() == null) {
154 throw new NullPointerException("user.userId is null"); //NOI18N
155 } else if (user.getUserId() < 1) {
157 throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", user.getUserId())); //NOI18N
158 } else if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) {
159 // Account is already confirmed
160 throw new UserStatusConfirmedException(user);
161 } else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) {
162 // Account is already confirmed
163 throw new UserStatusLockedException(user);
164 } else if (user.getUserConfirmKey() == null) {
166 throw new NullPointerException("user.userConfirmKey is null"); //NOI18N
167 } else if (null == baseUrl) {
169 throw new NullPointerException("baseUrl is null"); //NOI18N
170 } else if (baseUrl.isEmpty()) {
172 throw new IllegalArgumentException("baseUrl is empty"); //NOI18N
175 // Update user status and remove confirmation key
176 user.setUserAccountStatus(UserAccountStatus.CONFIRMED);
177 user.setUserConfirmKey(null);
178 user.setUserUpdated(new GregorianCalendar());
180 // Update user account
181 User updatedUser = this.updateUserData(user);
184 Address emailAddress;
187 // Create email address and set
188 emailAddress = new InternetAddress(updatedUser.getUserContact().getContactEmailAddress());
189 } catch (final AddressException ex) {
191 throw new EJBException(ex);
195 this.sendEmail("User account confirmed", "user_account_confirmed", emailAddress, updatedUser, baseUrl, null); //NOI18N
198 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.confirmAccount: updatedUser={1} - EXIT!", this.getClass().getSimpleName(), updatedUser)); //NOI18N
200 // Return updated instance
205 public User fillUserData (final User user) {
207 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fillUserData: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
209 // user should not be null
212 throw new NullPointerException("user is null"); //NOI18N
216 Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N
219 query.setParameter("userName", user.getUserName()); //NOI18N
221 // Initialize variable
222 User foundUser = null;
226 // Try to get single result
227 foundUser = (User) query.getSingleResult();
228 } catch (final NoResultException ex) {
230 this.getLoggerBeanLocal().logException(ex);
234 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fillUserData: foundUser={1} - EXIT!", this.getClass().getSimpleName(), foundUser)); //NOI18N
236 // Return prepared instance
241 public User findUserById (final Long userId) throws UserNotFoundException {
243 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findUserById: userId={1} - CALLED!", this.getClass().getSimpleName(), userId)); //NOI18N
245 // Is the parameter valid?
246 if (null == userId) {
248 throw new NullPointerException("userId is null"); //NOI18N
249 } else if (userId < 1) {
251 throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N
252 } else if (!this.ifUserIdExists(userId)) {
254 throw new UserNotFoundException(userId);
257 // Create query instance
258 Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N
261 query.setParameter("id", userId); //NOI18N
263 // Fetch the result, it should be there by now
264 User user = (User) query.getSingleResult();
267 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findUserById: user={1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N
274 public String generateRandomUserName () {
276 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateRandomUserName - CALLED!", this.getClass().getSimpleName())); //NOI18N
279 List<String> userList = this.getUserNameList();
282 String userName = null;
284 // Loop until a user name is found
285 while ((userName == null) || (userList.contains(userName))) {
286 // Generate random name
287 userName = UserUtils.generateRandomUserName();
291 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateRandomUserName: userName={1} - EXIT!", this.getClass().getSimpleName(), userName)); //NOI18N
293 // Found one, so return it
298 @SuppressWarnings ("unchecked")
299 public List<String> getEmailAddressList () {
301 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList: CALLED!", this.getClass().getSimpleName())); //NOI18N
304 Query query = this.getEntityManager().createNamedQuery("AllEmailAddresses", String.class); //NOI18N
307 List<String> emailAddressList = query.getResultList();
310 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList: emailAddressList.size()={1} - EXIT!", this.getClass().getSimpleName(), emailAddressList.size())); //NOI18N
313 return emailAddressList;
317 @SuppressWarnings ("unchecked")
318 public List<String> getUserNameList () {
320 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserNameList: CALLED!", this.getClass().getSimpleName())); //NOI18N
323 Query query = this.getEntityManager().createNamedQuery("AllUserNames", String.class); //NOI18N
326 List<String> userNameList = query.getResultList();
329 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserNameList: userNameList.size()={1} - EXIT!", this.getClass().getSimpleName(), userNameList.size())); //NOI18N
336 public boolean ifUserExists (final User user) {
338 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserExists: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
340 // userId should not be null
343 throw new NullPointerException("user is null"); //NOI18N
344 } else if (user.getUserId() == null) {
346 throw new NullPointerException("user.userId is null"); //NOI18N
347 } else if (user.getUserId() < 1) {
349 throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", user.getUserId())); //NOI18N
353 Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N
356 query.setParameter("id", user.getUserId()); //NOI18N
360 User dummy = (User) query.getSingleResult();
363 this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserExists: dummy.id={0} found.", dummy.getUserId())); //NOI18N
364 } catch (final NoResultException ex) {
366 this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserExists: getSingleResult() returned no result: {0}", ex)); //NOI18N
368 // User name does not exist
370 } catch (final PersistenceException ex) {
371 // Something bad happened
372 this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one user {0} found.", user, ex)); //NOI18N
379 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserExists: Found user {1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N
386 public boolean ifUserIdExists (final Long userId) {
388 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserIdExists: userId={1} - CALLED!", this.getClass().getSimpleName(), userId)); //NOI18N
390 // userId should not be null
391 if (null == userId) {
393 throw new NullPointerException("userId is null"); //NOI18N
394 } else if (userId < 1) {
396 throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", userId)); //NOI18N
400 Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N
403 query.setParameter("id", userId); //NOI18N
407 User dummy = (User) query.getSingleResult();
410 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserIdExists: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N
411 } catch (final NoResultException ex) {
413 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserIdExists: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N
415 // User name does not exist
417 } catch (final PersistenceException ex) {
418 // Something bad happened
419 this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one user id {0} found.", userId, ex)); //NOI18N
426 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserIdExists: Found userId={1} - EXIT!", this.getClass().getSimpleName(), userId)); //NOI18N
433 public boolean ifUserNameExists (final String userName) {
435 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserNameExists: userName={1} - CALLED!", this.getClass().getSimpleName(), userName)); //NOI18N
437 // userId should not be null
438 if (null == userName) {
440 throw new NullPointerException("userName is null"); //NOI18N
441 } else if (userName.isEmpty()) {
443 throw new NullPointerException("userName is empty"); //NOI18N
447 Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N
450 query.setParameter("userName", userName); //NOI18N
454 User dummy = (User) query.getSingleResult();
457 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserNameExists: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N
458 } catch (final NoResultException ex) {
460 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserNameExists: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N
462 // User name does not exist
467 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserNameExists: Found userName={1} - EXIT!", this.getClass().getSimpleName(), userName)); //NOI18N
474 public boolean isEmailAddressRegistered (final User user) {
476 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
478 // user should not be null
481 throw new NullPointerException("user is null"); //NOI18N
485 Query query = this.getEntityManager().createNamedQuery("SearchUserByEmailAddress", LoginUser.class); //NOI18N
488 query.setParameter("emailAddress", user.getUserContact().getContactEmailAddress()); //NOI18N
492 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 Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N
532 query.setParameter("userName", user.getUserName()); //NOI18N
536 User dummy = (User) query.getSingleResult();
539 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isUserNameRegistered: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N
540 } catch (final NoResultException ex) {
542 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isUserNameRegistered: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N
544 // User name does not exist
546 } catch (final PersistenceException ex) {
547 // Something bad happened
548 this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one email address {0} found.", user.getUserContact().getContactEmailAddress()), ex); //NOI18N
555 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isUserNameRegistered: Returning true ... - EXIT!", this.getClass().getSimpleName())); //NOI18N
562 public User updateUserData (final User user) {
564 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
566 // user should not be null
569 throw new NullPointerException("user is null"); //NOI18N
570 } else if (user.getUserId() == null) {
572 throw new NullPointerException("user.userId is null"); //NOI18N
573 } else if (user.getUserId() < 1) {
575 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
576 } else if (user.getUserAccountStatus() == null) {
578 throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
579 } else if (!this.ifUserExists(user)) {
580 // User does not exist
581 throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
584 // Remove contact instance as this is not updated
585 user.setUserContact(null);
588 User managedUser = this.getEntityManager().find(user.getClass(), user.getUserId());
591 assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
594 UserUtils.copyAll(user, managedUser);
597 managedUser.setUserUpdated(new GregorianCalendar());
600 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: managedUser={1} - CALLED!", this.getClass().getSimpleName(), managedUser)); //NOI18N
602 // Return updated instance
607 public PasswordHistory updateUserPassword (final User user, final String baseUrl) throws UserNotFoundException, UserStatusUnconfirmedException, UserStatusLockedException {
609 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPassword: user={1},baseUrl={2} - CALLED!", this.getClass().getSimpleName(), user, baseUrl)); //NOI18N
611 // user should not be null
614 throw new NullPointerException("user is null"); //NOI18N
615 } else if (user.getUserId() == null) {
617 throw new NullPointerException("user.userId is null"); //NOI18N
618 } else if (user.getUserId() < 1) {
620 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
621 } else if (user.getUserAccountStatus() == null) {
623 throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
624 } else if (user.getUserContact() == null) {
626 throw new NullPointerException("user.userContact is null"); //NOI18N
627 } else if (user.getUserContact().getContactId() == null) {
629 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
630 } else if (user.getUserContact().getContactId() < 1) {
632 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is invalid", user.getUserContact().getContactId())); //NOI18N
633 } else if (user.getUserContact().getContactPersonalTitle() == null) {
635 throw new NullPointerException("user.userContact.contactPersonalTitle is null"); //NOI18N
636 } else if (!this.ifUserExists(user)) {
637 // User does not exist
638 throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
639 } else if (null == baseUrl) {
641 throw new NullPointerException("baseUrl is null"); //NOI18N
642 } else if (baseUrl.isEmpty()) {
644 throw new IllegalArgumentException("baseUrl is empty"); //NOI18N
648 User updatedUser = this.updateUserData(user);
650 // Create history entry
651 PasswordHistory entry = new UserPasswordHistory(user.getUserEncryptedPassword(), updatedUser);
653 // Set created timestamp
654 entry.setUserPasswordHistoryCreated(new GregorianCalendar());
657 this.getEntityManager().persist(entry);
659 // Flush it to get id number back
660 this.getEntityManager().flush();
663 Address emailAddress;
666 // Create email address and set
667 emailAddress = new InternetAddress(updatedUser.getUserContact().getContactEmailAddress());
668 } catch (final AddressException ex) {
670 throw new EJBException(ex);
673 // Send email to user
674 this.sendEmail("User password change", "user_password_change", emailAddress, user, baseUrl, null); //NOI18N
677 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPassword: entry.userPasswordHistoryId={1} - EXIT!", this.getClass().getSimpleName(), entry.getUserPasswordHistoryId())); //NOI18N
684 public User updateUserPersonalData (final User user) {
686 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPersonalData: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
688 // user should not be null
691 throw new NullPointerException("user is null"); //NOI18N
692 } else if (user.getUserId() == null) {
694 throw new NullPointerException("user.userId is null"); //NOI18N
695 } else if (user.getUserId() < 1) {
697 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
698 } else if (user.getUserAccountStatus() == null) {
700 throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
701 } else if (!this.ifUserExists(user)) {
702 // User does not exist
703 throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
707 User managedUser = this.getEntityManager().find(user.getClass(), user.getUserId());
710 assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
713 UserUtils.copyAll(user, managedUser);
716 managedUser.setUserUpdated(new GregorianCalendar());
717 managedUser.getUserContact().setContactUpdated(new GregorianCalendar());
719 // Get contact from it and find it
720 Contact managedContact = this.getEntityManager().find(user.getUserContact().getClass(), user.getUserContact().getContactId());
723 assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", user.getUserContact().getContactId()); //NOI18N
726 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: managedContact.contactId={0}", managedContact.getContactId())); //NOI18N
729 ContactUtils.copyAll(user.getUserContact(), managedContact);
731 // Set it back in user
732 user.setUserContact(managedContact);
735 assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not merged, but should be.", user.getUserContact().getContactId()); //NOI18N
737 // Get mobile instance
738 DialableMobileNumber mobileNumber = managedContact.getContactMobileNumber();
740 // Is there a mobile instance set?
741 if (mobileNumber instanceof DialableMobileNumber) {
743 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: mobile.phoneId={0} is being updated ...", mobileNumber.getPhoneId())); //NOI18N
746 DialableMobileNumber foundMobile = this.getEntityManager().find(mobileNumber.getClass(), mobileNumber.getPhoneId());
749 assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N
751 // Then merge it, too
752 DialableMobileNumber managedMobile = this.getEntityManager().merge(foundMobile);
755 assert (managedMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", managedMobile.getPhoneId()); //NOI18N
758 MobileNumbers.copyAll(managedUser.getUserContact().getContactMobileNumber(), managedMobile);
761 managedContact.setContactMobileNumber(this.getManaged(mobileNumber, mobileNumber));
764 // Get mobile instance
765 DialableFaxNumber faxNumber = managedContact.getContactFaxNumber();
767 // Is there a fax instance set?
768 if (faxNumber instanceof DialableFaxNumber) {
770 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: faxNumber.phoneId={0} is being updated ...", faxNumber.getPhoneId())); //NOI18N
773 DialableFaxNumber foundFax = this.getEntityManager().find(faxNumber.getClass(), faxNumber.getPhoneId());
776 assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N
778 // Then merge it, too
779 DialableFaxNumber managedFax = this.getEntityManager().merge(foundFax);
782 assert (managedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", managedFax.getPhoneId()); //NOI18N
785 FaxNumbers.copyAll(managedUser.getUserContact().getContactFaxNumber(), managedFax);
788 managedContact.setContactFaxNumber(managedFax);
791 // Get mobile instance
792 DialableLandLineNumber landLineNumber = managedContact.getContactLandLineNumber();
794 // Is there a fax instance set?
795 if (landLineNumber instanceof DialableLandLineNumber) {
797 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLineNumber.phoneId={0} is being updated ...", landLineNumber.getPhoneId())); //NOI18N
800 DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLineNumber.getClass(), landLineNumber.getPhoneId());
803 assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
805 // Then merge it, too
806 DialableLandLineNumber managedLandLine = this.getEntityManager().merge(foundLandLine);
809 assert (managedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", managedLandLine.getPhoneId()); //NOI18N
812 LandLineNumbers.copyAll(managedUser.getUserContact().getContactLandLineNumber(), managedLandLine);
815 managedContact.setContactLandLineNumber(managedLandLine);
819 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPersonalData: entry.managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
821 // Return updated user instance