2 * Copyright (C) 2016 Roland Haeder
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.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
34 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
35 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
36 import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
37 import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
38 import org.mxchange.jusercore.exceptions.UserNotFoundException;
39 import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
40 import org.mxchange.jusercore.exceptions.UserStatusLockedException;
41 import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException;
42 import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote;
43 import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
44 import org.mxchange.jusercore.model.user.password_history.UserPasswordHistory;
45 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
46 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
51 * @author Roland Haeder<roland@mxchange.org>
53 @Stateless (name = "user", description = "A bean handling the user data")
54 public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean implements UserSessionBeanRemote {
59 private static final long serialVersionUID = 542_145_347_916L;
65 private UserRegistrationSessionBeanRemote registerBean;
70 public AddressbookUserSessionBean () {
74 public User addUser (final User user) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException {
76 this.getLoggerBeanLocal().logTrace(MessageFormat.format("addUser: user={0} - CALLED!", user)); //NOI18N
78 // user should not be null
81 throw new NullPointerException("user is null"); //NOI18N
82 } else if (user.getUserId() != null) {
84 throw new IllegalStateException(MessageFormat.format("user.userId must be null, is: {0}", user.getUserId())); //NOI18N
87 // Check if user is registered
88 if (this.registerBean.isUserNameRegistered(user)) {
90 throw new UserNameAlreadyRegisteredException(user);
91 } else if (this.registerBean.isEmailAddressRegistered(user)) {
93 throw new EmailAddressAlreadyRegisteredException(user);
96 // Set created timestamp
97 user.setUserCreated(new GregorianCalendar());
98 user.getUserContact().setContactCreated(new GregorianCalendar());
100 // Update cellphone, land-line and fax instance
101 this.setAllContactPhoneEntriesCreated(user.getUserContact());
104 this.getEntityManager().persist(user);
106 // Flush to get id back
107 this.getEntityManager().flush();
110 this.getLoggerBeanLocal().logTrace(MessageFormat.format("addUser: user={0},user.id={1} - EXIT!", user, user.getUserId())); //NOI18N
117 @SuppressWarnings ("unchecked")
118 public List<User> allMemberPublicVisibleUsers () {
120 this.getLoggerBeanLocal().logTrace("allMemberPublicVisibleUsers: CALLED!"); //NOI18N
123 Query query = this.getEntityManager().createNamedQuery("AllMemberPublicUsers", LoginUser.class); //NOI18N
126 query.setParameter("status", UserAccountStatus.CONFIRMED); //NOI18N
127 query.setParameter("members", ProfileMode.MEMBERS); //NOI18N
128 query.setParameter("public", ProfileMode.PUBLIC); //NOI18N
131 List<User> users = query.getResultList();
134 this.getLoggerBeanLocal().logTrace(MessageFormat.format("allMemberPublicVisibleUsers: users.size()={0} - EXIT!", users.size())); //NOI18N
141 @SuppressWarnings ("unchecked")
142 public List<User> allPublicUsers () {
144 this.getLoggerBeanLocal().logTrace("allPublicUsers: CALLED!"); //NOI18N
147 Query query = this.getEntityManager().createNamedQuery("AllPublicUsers", LoginUser.class); //NOI18N
150 query.setParameter("status", UserAccountStatus.CONFIRMED); //NOI18N
151 query.setParameter("mode", ProfileMode.PUBLIC); //NOI18N
154 List<User> users = query.getResultList();
157 this.getLoggerBeanLocal().logTrace(MessageFormat.format("allPublicUsers: users.size()={0} - EXIT!", users.size())); //NOI18N
164 @SuppressWarnings ("unchecked")
165 public List<User> allUsers () {
167 this.getLoggerBeanLocal().logTrace("allUsers: CALLED!"); //NOI18N
170 Query query = this.getEntityManager().createNamedQuery("AllUsers", LoginUser.class); //NOI18N
173 List<User> users = query.getResultList();
176 this.getLoggerBeanLocal().logTrace(MessageFormat.format("allUsers: users.size()={0} - EXIT!", users.size())); //NOI18N
183 public User confirmAccount (final User user, final String baseUrl) throws UserStatusConfirmedException, UserStatusLockedException {
185 this.getLoggerBeanLocal().logTrace(MessageFormat.format("confirmAccount: user={0},baseUrl={1} - CALLED!", user, baseUrl)); //NOI18N
187 // Parameter must be valid
190 throw new NullPointerException("user is null"); //NOI18N
191 } else if (user.getUserId() == null) {
193 throw new NullPointerException("user.userId is null"); //NOI18N
194 } else if (user.getUserId() < 1) {
196 throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", user.getUserId())); //NOI18N
197 } else if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) {
198 // Account is already confirmed
199 throw new UserStatusConfirmedException(user);
200 } else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) {
201 // Account is already confirmed
202 throw new UserStatusLockedException(user);
203 } else if (user.getUserConfirmKey() == null) {
205 throw new NullPointerException("user.userConfirmKey is null"); //NOI18N
208 // Update user status and remove confirmation key
209 user.setUserAccountStatus(UserAccountStatus.CONFIRMED);
210 user.setUserConfirmKey(null);
211 user.setUserUpdated(new GregorianCalendar());
213 // Update user account
214 User updatedUser = this.updateUserData(user);
217 Address emailAddress;
220 // Create email address and set
221 emailAddress = new InternetAddress(updatedUser.getUserContact().getContactEmailAddress());
222 } catch (final AddressException ex) {
224 throw new EJBException(ex);
228 this.sendEmail("Account confirmed", "account_confirmed", emailAddress, updatedUser, baseUrl); //NOI18N
231 this.getLoggerBeanLocal().logTrace(MessageFormat.format("confirmAccount: updatedUser={0} - EXIT!", updatedUser)); //NOI18N
233 // Return updated instance
238 public User fillUserData (final User user) {
240 this.getLoggerBeanLocal().logTrace(MessageFormat.format("fillUserData: user={0} - CALLED!", user)); //NOI18N
242 // user should not be null
245 throw new NullPointerException("user is null"); //NOI18N
249 Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N
252 query.setParameter("userName", user.getUserName()); //NOI18N
254 // Initialize variable
255 User foundUser = null;
259 // Try to get single result
260 foundUser = (User) query.getSingleResult();
261 } catch (final NoResultException ex) {
263 this.getLoggerBeanLocal().logException(ex);
267 this.getLoggerBeanLocal().logTrace(MessageFormat.format("fillUserData: foundUser={0} - EXIT!", foundUser)); //NOI18N
269 // Return prepared instance
274 public User findUserById (final Long userId) throws UserNotFoundException {
276 this.getLoggerBeanLocal().logTrace(MessageFormat.format("findUserById: userId={0} - CALLED!", userId)); //NOI18N
278 // Is the parameter valid?
279 if (null == userId) {
281 throw new NullPointerException("userId is null"); //NOI18N
282 } else if (userId < 1) {
284 throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N
285 } else if (!this.ifUserIdExists(userId)) {
287 throw new UserNotFoundException(userId);
290 // Create query instance
291 Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N
294 query.setParameter("id", userId); //NOI18N
296 // Fetch the result, it should be there by now
297 User user = (User) query.getSingleResult();
300 this.getLoggerBeanLocal().logTrace(MessageFormat.format("findUserById: user={0} - EXIT!", user)); //NOI18N
307 public String generateRandomUserName () {
309 this.getLoggerBeanLocal().logTrace("generateRandomUserName - CALLED!"); //NOI18N
312 List<String> userList = this.getUserNameList();
315 String userName = null;
317 // Loop until a user name is found
318 while ((userName == null) || (userList.contains(userName))) {
319 // Generate random name
320 userName = UserUtils.generateRandomUserName();
324 this.getLoggerBeanLocal().logTrace(MessageFormat.format("generateRandomUserName: userName={0} - EXIT!", userName)); //NOI18N
326 // Found one, so return it
331 @SuppressWarnings ("unchecked")
332 public List<String> getEmailAddressList () {
334 Query query = this.getEntityManager().createNamedQuery("AllEmailAddresses", String.class); //NOI18N
337 List<String> emailAddressList = query.getResultList();
340 return emailAddressList;
344 @SuppressWarnings ("unchecked")
345 public List<String> getUserNameList () {
347 Query query = this.getEntityManager().createNamedQuery("AllUserNames", String.class); //NOI18N
350 List<String> userNameList = query.getResultList();
357 public boolean ifUserExists (final User user) {
359 this.getLoggerBeanLocal().logTrace(MessageFormat.format("ifUserExists: user={0} - CALLED!", user)); //NOI18N
361 // userId should not be null
364 throw new NullPointerException("user is null"); //NOI18N
365 } else if (user.getUserId() == null) {
367 throw new NullPointerException("user.userId is null"); //NOI18N
368 } else if (user.getUserId() < 1) {
370 throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", user.getUserId())); //NOI18N
374 Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N
377 query.setParameter("id", user.getUserId()); //NOI18N
381 User dummy = (User) query.getSingleResult();
384 this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserExists: dummy.id={0} found.", dummy.getUserId())); //NOI18N
385 } catch (final NoResultException ex) {
387 this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserExists: getSingleResult() returned no result: {0}", ex)); //NOI18N
389 // User name does not exist
391 } catch (final PersistenceException ex) {
392 // Something bad happened
393 this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one user {0} found.", user, ex)); //NOI18N
400 this.getLoggerBeanLocal().logTrace(MessageFormat.format("ifUserExists: Found user {0} - EXIT!", user)); //NOI18N
407 public boolean ifUserIdExists (final Long userId) {
409 this.getLoggerBeanLocal().logTrace(MessageFormat.format("ifUserIdExists: userId={0} - CALLED!", userId)); //NOI18N
411 // userId should not be null
412 if (null == userId) {
414 throw new NullPointerException("userId is null"); //NOI18N
415 } else if (userId < 1) {
417 throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", userId)); //NOI18N
421 Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N
424 query.setParameter("id", userId); //NOI18N
428 User dummy = (User) query.getSingleResult();
431 this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserIdExists: dummy.id={0} found.", dummy.getUserId())); //NOI18N
432 } catch (final NoResultException ex) {
434 this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserIdExists: getSingleResult() returned no result: {0}", ex)); //NOI18N
436 // User name does not exist
438 } catch (final PersistenceException ex) {
439 // Something bad happened
440 this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one user id {0} found.", userId, ex)); //NOI18N
447 this.getLoggerBeanLocal().logTrace(MessageFormat.format("ifUserIdExists: Found user id {0} - EXIT!", userId)); //NOI18N
454 public boolean ifUserNameExists (final String userName) {
456 this.getLoggerBeanLocal().logTrace(MessageFormat.format("ifUserNameExists: userName={0} - CALLED!", userName)); //NOI18N
458 // userId should not be null
459 if (null == userName) {
461 throw new NullPointerException("userName is null"); //NOI18N
462 } else if (userName.isEmpty()) {
464 throw new NullPointerException("userName is empty"); //NOI18N
468 Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N
471 query.setParameter("userName", userName); //NOI18N
475 User dummy = (User) query.getSingleResult();
478 this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserNameExists: dummy.id={0} found.", dummy.getUserId())); //NOI18N
479 } catch (final NoResultException ex) {
481 this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserNameExists: getSingleResult() returned no result: {0}", ex)); //NOI18N
483 // User name does not exist
488 this.getLoggerBeanLocal().logTrace(MessageFormat.format("ifUserNameExists: Found user name {0} - EXIT!", userName)); //NOI18N
495 public boolean isEmailAddressRegistered (final User user) {
497 this.getLoggerBeanLocal().logTrace(MessageFormat.format("isEmailAddressRegistered: user={0} - CALLED!", user)); //NOI18N
499 // user should not be null
502 throw new NullPointerException("user is null"); //NOI18N
506 Query query = this.getEntityManager().createNamedQuery("SearchUserByEmailAddress", LoginUser.class); //NOI18N
509 query.setParameter("emailAddress", user.getUserContact().getContactEmailAddress()); //NOI18N
513 User dummy = (User) query.getSingleResult();
516 this.getLoggerBeanLocal().logDebug(MessageFormat.format("isEmailAddressRegistered: dummy.id={0} found.", dummy.getUserId())); //NOI18N
517 } catch (final NoResultException ex) {
519 this.getLoggerBeanLocal().logDebug(MessageFormat.format("isEmailAddressRegistered: getSingleResult() returned no result: {0}", ex)); //NOI18N
521 // Email address does not exist
523 } catch (final PersistenceException ex) {
524 // Something bad happened
525 this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one email address {0} found.", user.getUserContact().getContactEmailAddress()), ex); //NOI18N
536 public boolean isUserNameRegistered (final User user) {
538 this.getLoggerBeanLocal().logTrace(MessageFormat.format("isUserNameRegistered: user={0} - CALLED!", user)); //NOI18N
540 // user should not be null
543 throw new NullPointerException("user is null"); //NOI18N
547 Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N
550 query.setParameter("userName", user.getUserName()); //NOI18N
554 User dummy = (User) query.getSingleResult();
557 this.getLoggerBeanLocal().logDebug(MessageFormat.format("isUserNameRegistered: dummy.id={0} found.", dummy.getUserId())); //NOI18N
558 } catch (final NoResultException ex) {
560 this.getLoggerBeanLocal().logDebug(MessageFormat.format("isUserNameRegistered: getSingleResult() returned no result: {0}", ex)); //NOI18N
562 // User name does not exist
564 } catch (final PersistenceException ex) {
565 // Something bad happened
566 this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one email address {0} found.", user.getUserContact().getContactEmailAddress()), ex); //NOI18N
577 public User linkUser (final User user) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException {
579 this.getLoggerBeanLocal().logTrace(MessageFormat.format("linkUser: user={0} - CALLED!", user)); //NOI18N
581 // user should not be null
584 throw new NullPointerException("user is null"); //NOI18N
585 } else if (user.getUserId() instanceof Long) {
587 throw new IllegalArgumentException("user.userId is not null"); //NOI18N
588 } else if (user.getUserContact() == null) {
590 throw new NullPointerException("user.userContact is null"); //NOI18N
591 } else if (user.getUserContact().getContactId() == null) {
593 throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
594 } else if (user.getUserContact().getContactId() < 1) {
595 // Not valid id number
596 throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is not valid", user.getUserContact().getContactId())); //NOI18N
597 } else if (user.getUserAccountStatus() == null) {
599 throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
600 } else if (this.ifUserNameExists(user.getUserName())) {
601 // Name already found
602 throw new UserNameAlreadyRegisteredException(user.getUserName());
603 } else if (this.ifUserExists(user)) {
604 // User does not exist
605 throw new IllegalStateException("User does already exist."); //NOI18N
608 // Try to find the contact
609 Contact foundContact = this.getEntityManager().find(user.getUserContact().getClass(), user.getUserContact().getContactId());
611 // Set detached object in rexcruiter instance
612 user.setUserContact(foundContact);
615 user.setUserCreated(new GregorianCalendar());
618 this.getEntityManager().persist(user);
620 // Flush it to get updated instance back
621 this.getEntityManager().flush();
624 this.getLoggerBeanLocal().logTrace(MessageFormat.format("linkUser: user={0} - EXIT!", user)); //NOI18N
626 // Return updated instanc
631 public User updateUserData (final User user) {
633 this.getLoggerBeanLocal().logTrace(MessageFormat.format("updateUserData: user={0} - CALLED!", user)); //NOI18N
635 // user should not be null
638 throw new NullPointerException("user is null"); //NOI18N
639 } else if (user.getUserId() == null) {
641 throw new NullPointerException("user.userId is null"); //NOI18N
642 } else if (user.getUserId() < 1) {
644 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
645 } else if (user.getUserAccountStatus() == null) {
647 throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
648 } else if (!this.ifUserExists(user)) {
649 // User does not exist
650 throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
653 // Remove contact instance as this is not updated
654 user.setUserContact(null);
657 User foundUser = this.getEntityManager().find(user.getClass(), user.getUserId());
660 assert (foundUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
663 User detachedUser = this.getEntityManager().merge(foundUser);
666 assert (detachedUser instanceof User) : MessageFormat.format("User with id {0} not merged, but should be.", user.getUserId()); //NOI18N
669 detachedUser.copyAll(user);
672 detachedUser.setUserUpdated(new GregorianCalendar());
674 // Return updated instance
679 public PasswordHistory updateUserPassword (final User user) throws UserNotFoundException, UserStatusUnconfirmedException, UserStatusLockedException {
681 this.getLoggerBeanLocal().logTrace(MessageFormat.format("updateUserPassword: user={0} - CALLED!", user)); //NOI18N
683 // user should not be null
686 throw new NullPointerException("user is null"); //NOI18N
687 } else if (user.getUserId() == null) {
689 throw new NullPointerException("user.userId is null"); //NOI18N
690 } else if (user.getUserId() < 1) {
692 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
693 } else if (user.getUserAccountStatus() == null) {
695 throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
696 } else if (!this.ifUserExists(user)) {
697 // User does not exist
698 throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
702 User updatedUser = this.updateUserData(user);
704 // Create history entry
705 PasswordHistory entry = new UserPasswordHistory(user.getUserEncryptedPassword(), updatedUser);
707 // Set created timestamp
708 entry.setUserPasswordHistoryCreated(new GregorianCalendar());
711 this.getEntityManager().persist(entry);
713 // Flush it to get id number back
714 this.getEntityManager().flush();
717 this.getLoggerBeanLocal().logTrace(MessageFormat.format("updateUserPassword: entry.userPasswordHistoryId={0} - EXIT!", entry.getUserPasswordHistoryId())); //NOI18N
724 public User updateUserPersonalData (final User user) {
726 this.getLoggerBeanLocal().logTrace(MessageFormat.format("updateUserPersonalData: user={0} - CALLED!", user)); //NOI18N
728 // user should not be null
731 throw new NullPointerException("user is null"); //NOI18N
732 } else if (user.getUserId() == null) {
734 throw new NullPointerException("user.userId is null"); //NOI18N
735 } else if (user.getUserId() < 1) {
737 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
738 } else if (user.getUserAccountStatus() == null) {
740 throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
741 } else if (!this.ifUserExists(user)) {
742 // User does not exist
743 throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
747 User foundUser = this.getEntityManager().find(user.getClass(), user.getUserId());
750 assert (foundUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
753 User detachedUser = this.getEntityManager().merge(foundUser);
756 assert (detachedUser instanceof User) : MessageFormat.format("User with id {0} not merged, but should be.", user.getUserId()); //NOI18N
759 detachedUser.copyAll(user);
762 detachedUser.setUserUpdated(new GregorianCalendar());
763 detachedUser.getUserContact().setContactUpdated(new GregorianCalendar());
765 // Get contact from it and find it
766 Contact foundContact = this.getEntityManager().find(user.getUserContact().getClass(), user.getUserContact().getContactId());
769 assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", user.getUserContact().getContactId()); //NOI18N
772 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: contact.contactId={0}", foundContact.getContactId())); //NOI18N
774 // Merge contact instance
775 Contact detachedContact = this.getEntityManager().merge(foundContact);
778 detachedContact.copyAll(user.getUserContact());
780 // Set it back in user
781 user.setUserContact(detachedContact);
784 assert (detachedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not merged, but should be.", user.getUserContact().getContactId()); //NOI18N
786 // Get cellphone instance
787 DialableCellphoneNumber cellphone = detachedContact.getContactCellphoneNumber();
789 // Is there a cellphone instance set?
790 if (cellphone instanceof DialableCellphoneNumber) {
792 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: cellphone.phoneId={0} is being updated ...", cellphone.getPhoneId())); //NOI18N
795 DialableCellphoneNumber foundCellphone = this.getEntityManager().find(cellphone.getClass(), cellphone.getPhoneId());
798 assert (foundCellphone instanceof DialableCellphoneNumber) : MessageFormat.format("Cellphone number with id {0} not found but should be.", foundCellphone.getPhoneId()); //NOI18N
800 // Then merge it, too
801 DialableCellphoneNumber detachedCellphone = this.getEntityManager().merge(foundCellphone);
804 assert (detachedCellphone instanceof DialableCellphoneNumber) : MessageFormat.format("Cellphone number with id {0} not found but should be.", detachedCellphone.getPhoneId()); //NOI18N
807 detachedCellphone.copyAll(user.getUserContact().getContactCellphoneNumber());
810 detachedContact.setContactCellphoneNumber(detachedCellphone);
813 // Get cellphone instance
814 DialableFaxNumber fax = detachedContact.getContactFaxNumber();
816 // Is there a fax instance set?
817 if (fax instanceof DialableFaxNumber) {
819 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", fax.getPhoneId())); //NOI18N
822 DialableFaxNumber foundFax = this.getEntityManager().find(fax.getClass(), fax.getPhoneId());
825 assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N
827 // Then merge it, too
828 DialableFaxNumber detachedFax = this.getEntityManager().merge(foundFax);
831 assert (detachedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", detachedFax.getPhoneId()); //NOI18N
834 detachedFax.copyAll(user.getUserContact().getContactFaxNumber());
837 detachedContact.setContactFaxNumber(detachedFax);
840 // Get cellphone instance
841 DialableLandLineNumber landLine = detachedContact.getContactLandLineNumber();
843 // Is there a fax instance set?
844 if (landLine instanceof DialableLandLineNumber) {
846 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLine.getPhoneId())); //NOI18N
849 DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLine.getClass(), landLine.getPhoneId());
852 assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
854 // Then merge it, too
855 DialableLandLineNumber detachedLandLine = this.getEntityManager().merge(foundLandLine);
858 assert (detachedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", detachedLandLine.getPhoneId()); //NOI18N
861 detachedLandLine.copyAll(user.getUserContact().getContactLandLineNumber());
864 detachedContact.setContactLandLineNumber(detachedLandLine);
867 // Return updated user instance