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.persistence.NoResultException;
26 import javax.persistence.PersistenceException;
27 import javax.persistence.Query;
28 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
29 import org.mxchange.jcontacts.contact.Contact;
30 import org.mxchange.jcontacts.contact.ContactUtils;
31 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
32 import org.mxchange.jphone.phonenumbers.fax.FaxNumbers;
33 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
34 import org.mxchange.jphone.phonenumbers.landline.LandLineNumbers;
35 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
36 import org.mxchange.jphone.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.register.UserRegistrationSessionBeanRemote;
45 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
50 * @author Roland Häder<roland@mxchange.org>
52 @Stateless (name = "user", description = "A bean handling the user data")
53 public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean implements UserSessionBeanRemote {
58 private static final long serialVersionUID = 542_145_347_916L;
64 private UserRegistrationSessionBeanRemote registerBean;
69 public AddressbookUserSessionBean () {
70 // Call super constructor
71 super("jms/addressbook-queue-factory", "jms/addressbook-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 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 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 Query query = this.getEntityManager().createNamedQuery("AllPublicUsers", LoginUser.class); //NOI18N
108 query.setParameter("status", UserAccountStatus.CONFIRMED); //NOI18N
109 query.setParameter("mode", ProfileMode.PUBLIC); //NOI18N
112 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<User> allUsers () {
125 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsers: CALLED!", this.getClass().getSimpleName())); //NOI18N
128 Query query = this.getEntityManager().createNamedQuery("AllUsers", LoginUser.class); //NOI18N
131 List<User> users = query.getResultList();
134 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsers: users.size()={1} - EXIT!", this.getClass().getSimpleName(), users.size())); //NOI18N
141 public User confirmAccount (final User user, final String baseUrl) throws UserStatusConfirmedException, UserStatusLockedException {
143 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.confirmAccount: user={1},baseUrl={2} - CALLED!", this.getClass().getSimpleName(), user, baseUrl)); //NOI18N
145 // Parameter must be valid
148 throw new NullPointerException("user is null"); //NOI18N
149 } else if (user.getUserId() == null) {
151 throw new NullPointerException("user.userId is null"); //NOI18N
152 } else if (user.getUserId() < 1) {
154 throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", user.getUserId())); //NOI18N
155 } else if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) {
156 // Account is already confirmed
157 throw new UserStatusConfirmedException(user);
158 } else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) {
159 // Account is already confirmed
160 throw new UserStatusLockedException(user);
161 } else if (user.getUserConfirmKey() == null) {
163 throw new NullPointerException("user.userConfirmKey is null"); //NOI18N
164 } else if (null == baseUrl) {
166 throw new NullPointerException("baseUrl is null"); //NOI18N
167 } else if (baseUrl.isEmpty()) {
169 throw new IllegalArgumentException("baseUrl is empty"); //NOI18N
172 // Update user status and remove confirmation key
173 user.setUserAccountStatus(UserAccountStatus.CONFIRMED);
174 user.setUserConfirmKey(null);
175 user.setUserUpdated(new GregorianCalendar());
177 // Update user account
178 User updatedUser = this.updateUserData(user);
181 this.sendEmail("User account confirmed", "user_account_confirmed", updatedUser, baseUrl, null); //NOI18N
184 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.confirmAccount: updatedUser={1} - EXIT!", this.getClass().getSimpleName(), updatedUser)); //NOI18N
186 // Return updated instance
191 public User fillUserData (final User user) {
193 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fillUserData: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
195 // user should not be null
198 throw new NullPointerException("user is null"); //NOI18N
202 Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N
205 query.setParameter("userName", user.getUserName()); //NOI18N
207 // Initialize variable
208 User foundUser = null;
212 // Try to get single result
213 foundUser = (User) query.getSingleResult();
214 } catch (final NoResultException ex) {
216 this.getLoggerBeanLocal().logException(ex);
220 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fillUserData: foundUser={1} - EXIT!", this.getClass().getSimpleName(), foundUser)); //NOI18N
222 // Return prepared instance
227 public User findUserById (final Long userId) throws UserNotFoundException {
229 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findUserById: userId={1} - CALLED!", this.getClass().getSimpleName(), userId)); //NOI18N
231 // Is the parameter valid?
232 if (null == userId) {
234 throw new NullPointerException("userId is null"); //NOI18N
235 } else if (userId < 1) {
237 throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N
238 } else if (!this.ifUserIdExists(userId)) {
240 throw new UserNotFoundException(userId);
243 // Create query instance
244 Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N
247 query.setParameter("id", userId); //NOI18N
249 // Fetch the result, it should be there by now
250 User user = (User) query.getSingleResult();
253 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findUserById: user={1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N
260 public String generateRandomUserName () {
262 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateRandomUserName - CALLED!", this.getClass().getSimpleName())); //NOI18N
265 List<String> userList = this.getUserNameList();
268 String userName = null;
270 // Loop until a user name is found
271 while ((userName == null) || (userList.contains(userName))) {
272 // Generate random name
273 userName = UserUtils.generateRandomUserName();
277 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateRandomUserName: userName={1} - EXIT!", this.getClass().getSimpleName(), userName)); //NOI18N
279 // Found one, so return it
284 @SuppressWarnings ("unchecked")
285 public List<String> getEmailAddressList () {
287 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList: CALLED!", this.getClass().getSimpleName())); //NOI18N
290 Query query = this.getEntityManager().createNamedQuery("AllEmailAddresses", String.class); //NOI18N
293 List<String> emailAddressList = query.getResultList();
296 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList: emailAddressList.size()={1} - EXIT!", this.getClass().getSimpleName(), emailAddressList.size())); //NOI18N
299 return emailAddressList;
303 @SuppressWarnings ("unchecked")
304 public List<String> getUserNameList () {
306 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserNameList: CALLED!", this.getClass().getSimpleName())); //NOI18N
309 Query query = this.getEntityManager().createNamedQuery("AllUserNames", String.class); //NOI18N
312 List<String> userNameList = query.getResultList();
315 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserNameList: userNameList.size()={1} - EXIT!", this.getClass().getSimpleName(), userNameList.size())); //NOI18N
322 public boolean ifUserExists (final User user) {
324 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserExists: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
326 // userId should not be null
329 throw new NullPointerException("user is null"); //NOI18N
330 } else if (user.getUserId() == null) {
332 throw new NullPointerException("user.userId is null"); //NOI18N
333 } else if (user.getUserId() < 1) {
335 throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", user.getUserId())); //NOI18N
339 Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N
342 query.setParameter("id", user.getUserId()); //NOI18N
346 User dummy = (User) query.getSingleResult();
349 this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserExists: dummy.id={0} found.", dummy.getUserId())); //NOI18N
350 } catch (final NoResultException ex) {
352 this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserExists: getSingleResult() returned no result: {0}", ex)); //NOI18N
354 // User name does not exist
356 } catch (final PersistenceException ex) {
357 // Something bad happened
358 this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one user {0} found.", user, ex)); //NOI18N
365 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserExists: Found user {1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N
372 public boolean ifUserIdExists (final Long userId) {
374 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserIdExists: userId={1} - CALLED!", this.getClass().getSimpleName(), userId)); //NOI18N
376 // userId should not be null
377 if (null == userId) {
379 throw new NullPointerException("userId is null"); //NOI18N
380 } else if (userId < 1) {
382 throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", userId)); //NOI18N
386 Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N
389 query.setParameter("id", userId); //NOI18N
393 User dummy = (User) query.getSingleResult();
396 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserIdExists: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N
397 } catch (final NoResultException ex) {
399 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserIdExists: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N
401 // User name does not exist
403 } catch (final PersistenceException ex) {
404 // Something bad happened
405 this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one user id {0} found.", userId, ex)); //NOI18N
412 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserIdExists: Found userId={1} - EXIT!", this.getClass().getSimpleName(), userId)); //NOI18N
419 public boolean ifUserNameExists (final String userName) {
421 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserNameExists: userName={1} - CALLED!", this.getClass().getSimpleName(), userName)); //NOI18N
423 // userId should not be null
424 if (null == userName) {
426 throw new NullPointerException("userName is null"); //NOI18N
427 } else if (userName.isEmpty()) {
429 throw new NullPointerException("userName is empty"); //NOI18N
433 Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N
436 query.setParameter("userName", userName); //NOI18N
440 User dummy = (User) query.getSingleResult();
443 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserNameExists: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N
444 } catch (final NoResultException ex) {
446 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserNameExists: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N
448 // User name does not exist
453 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserNameExists: Found userName={1} - EXIT!", this.getClass().getSimpleName(), userName)); //NOI18N
460 public boolean isEmailAddressRegistered (final User user) {
462 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
464 // user should not be null
467 throw new NullPointerException("user is null"); //NOI18N
471 Query query = this.getEntityManager().createNamedQuery("SearchUserByEmailAddress", LoginUser.class); //NOI18N
474 query.setParameter("emailAddress", user.getUserContact().getContactEmailAddress()); //NOI18N
478 User dummy = (User) query.getSingleResult();
481 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isEmailAddressRegistered: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N
482 } catch (final NoResultException ex) {
484 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isEmailAddressRegistered: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N
486 // Email address does not exist
488 } catch (final PersistenceException ex) {
489 // Something bad happened
490 this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one email address {0} found.", user.getUserContact().getContactEmailAddress()), ex); //NOI18N
497 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: Returning true ... - EXIT!", this.getClass().getSimpleName())); //NOI18N
504 public boolean isUserNameRegistered (final User user) {
506 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isUserNameRegistered: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
508 // user should not be null
511 throw new NullPointerException("user is null"); //NOI18N
515 Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N
518 query.setParameter("userName", user.getUserName()); //NOI18N
522 User dummy = (User) query.getSingleResult();
525 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isUserNameRegistered: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N
526 } catch (final NoResultException ex) {
528 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isUserNameRegistered: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N
530 // User name does not exist
532 } catch (final PersistenceException ex) {
533 // Something bad happened
534 this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one email address {0} found.", user.getUserContact().getContactEmailAddress()), ex); //NOI18N
541 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isUserNameRegistered: Returning true ... - EXIT!", this.getClass().getSimpleName())); //NOI18N
548 public User updateUserData (final User user) {
550 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
552 // user should not be null
555 throw new NullPointerException("user is null"); //NOI18N
556 } else if (user.getUserId() == null) {
558 throw new NullPointerException("user.userId is null"); //NOI18N
559 } else if (user.getUserId() < 1) {
561 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
562 } else if (user.getUserAccountStatus() == null) {
564 throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
565 } else if (!this.ifUserExists(user)) {
566 // User does not exist
567 throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
570 // Remove contact instance as this is not updated
571 user.setUserContact(null);
574 User managedUser = this.getEntityManager().find(user.getClass(), user.getUserId());
577 assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
580 UserUtils.copyAll(user, managedUser);
583 managedUser.setUserUpdated(new GregorianCalendar());
586 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: managedUser={1} - CALLED!", this.getClass().getSimpleName(), managedUser)); //NOI18N
588 // Return updated instance
593 public PasswordHistory updateUserPassword (final User user, final String baseUrl) throws UserNotFoundException, UserStatusUnconfirmedException, UserStatusLockedException {
595 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPassword: user={1},baseUrl={2} - CALLED!", this.getClass().getSimpleName(), user, baseUrl)); //NOI18N
597 // user should not be null
600 throw new NullPointerException("user is null"); //NOI18N
601 } else if (user.getUserId() == null) {
603 throw new NullPointerException("user.userId is null"); //NOI18N
604 } else if (user.getUserId() < 1) {
606 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
607 } else if (user.getUserAccountStatus() == null) {
609 throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
610 } else if (user.getUserContact() == null) {
612 throw new NullPointerException("user.userContact is null"); //NOI18N
613 } else if (user.getUserContact().getContactId() == null) {
615 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
616 } else if (user.getUserContact().getContactId() < 1) {
618 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is invalid", user.getUserContact().getContactId())); //NOI18N
619 } else if (user.getUserContact().getContactPersonalTitle() == null) {
621 throw new NullPointerException("user.userContact.contactPersonalTitle is null"); //NOI18N
622 } else if (!this.ifUserExists(user)) {
623 // User does not exist
624 throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
625 } else if (null == baseUrl) {
627 throw new NullPointerException("baseUrl is null"); //NOI18N
628 } else if (baseUrl.isEmpty()) {
630 throw new IllegalArgumentException("baseUrl is empty"); //NOI18N
634 User updatedUser = this.updateUserData(user);
636 // Create history entry
637 PasswordHistory entry = new UserPasswordHistory(user.getUserEncryptedPassword(), updatedUser);
639 // Set created timestamp
640 entry.setUserPasswordHistoryCreated(new GregorianCalendar());
643 this.getEntityManager().persist(entry);
645 // Flush it to get id number back
646 this.getEntityManager().flush();
648 // Send email to user
649 this.sendEmail("User password change", "user_password_change", user, baseUrl, null); //NOI18N
652 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPassword: entry.userPasswordHistoryId={1} - EXIT!", this.getClass().getSimpleName(), entry.getUserPasswordHistoryId())); //NOI18N
659 public User updateUserPersonalData (final User user) {
661 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPersonalData: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
663 // user should not be null
666 throw new NullPointerException("user is null"); //NOI18N
667 } else if (user.getUserId() == null) {
669 throw new NullPointerException("user.userId is null"); //NOI18N
670 } else if (user.getUserId() < 1) {
672 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
673 } else if (user.getUserAccountStatus() == null) {
675 throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
676 } else if (!this.ifUserExists(user)) {
677 // User does not exist
678 throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
682 User managedUser = this.getEntityManager().find(user.getClass(), user.getUserId());
685 assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
688 UserUtils.copyAll(user, managedUser);
691 managedUser.setUserUpdated(new GregorianCalendar());
692 managedUser.getUserContact().setContactUpdated(new GregorianCalendar());
694 // Get contact from it and find it
695 Contact managedContact = this.getEntityManager().find(user.getUserContact().getClass(), user.getUserContact().getContactId());
698 assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", user.getUserContact().getContactId()); //NOI18N
701 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: managedContact.contactId={0}", managedContact.getContactId())); //NOI18N
704 ContactUtils.copyAll(user.getUserContact(), managedContact);
706 // Set it back in user
707 user.setUserContact(managedContact);
710 assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not merged, but should be.", user.getUserContact().getContactId()); //NOI18N
712 // Get mobile instance
713 DialableMobileNumber mobileNumber = managedContact.getContactMobileNumber();
715 // Is there a mobile instance set?
716 if (mobileNumber instanceof DialableMobileNumber) {
718 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: mobile.phoneId={0} is being updated ...", mobileNumber.getPhoneId())); //NOI18N
721 DialableMobileNumber foundMobile = this.getEntityManager().find(mobileNumber.getClass(), mobileNumber.getPhoneId());
724 assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N
726 // Then merge it, too
727 DialableMobileNumber managedMobile = this.getEntityManager().merge(foundMobile);
730 assert (managedMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", managedMobile.getPhoneId()); //NOI18N
733 MobileNumbers.copyAll(managedUser.getUserContact().getContactMobileNumber(), managedMobile);
736 managedContact.setContactMobileNumber(this.getManaged(mobileNumber, mobileNumber));
739 // Get mobile instance
740 DialableFaxNumber faxNumber = managedContact.getContactFaxNumber();
742 // Is there a fax instance set?
743 if (faxNumber instanceof DialableFaxNumber) {
745 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: faxNumber.phoneId={0} is being updated ...", faxNumber.getPhoneId())); //NOI18N
748 DialableFaxNumber foundFax = this.getEntityManager().find(faxNumber.getClass(), faxNumber.getPhoneId());
751 assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N
753 // Then merge it, too
754 DialableFaxNumber managedFax = this.getEntityManager().merge(foundFax);
757 assert (managedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", managedFax.getPhoneId()); //NOI18N
760 FaxNumbers.copyAll(managedUser.getUserContact().getContactFaxNumber(), managedFax);
763 managedContact.setContactFaxNumber(managedFax);
766 // Get mobile instance
767 DialableLandLineNumber landLineNumber = managedContact.getContactLandLineNumber();
769 // Is there a fax instance set?
770 if (landLineNumber instanceof DialableLandLineNumber) {
772 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLineNumber.phoneId={0} is being updated ...", landLineNumber.getPhoneId())); //NOI18N
775 DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLineNumber.getClass(), landLineNumber.getPhoneId());
778 assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
780 // Then merge it, too
781 DialableLandLineNumber managedLandLine = this.getEntityManager().merge(foundLandLine);
784 assert (managedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", managedLandLine.getPhoneId()); //NOI18N
787 LandLineNumbers.copyAll(managedUser.getUserContact().getContactLandLineNumber(), managedLandLine);
790 managedContact.setContactLandLineNumber(managedLandLine);
794 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPersonalData: entry.managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
796 // Return updated user instance