]> git.mxchange.org Git - jjobs-ejb.git/blob - src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java
used new setter instead of "hard-coded"
[jjobs-ejb.git] / src / java / org / mxchange / jusercore / model / user / JobsUserSessionBean.java
1 /*
2  * Copyright (C) 2016 Roland Haeder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.jusercore.model.user;
18
19 import java.text.MessageFormat;
20 import java.util.GregorianCalendar;
21 import java.util.List;
22 import javax.ejb.EJB;
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.jjobs.database.BaseJobsDatabaseBean;
31 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
32 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
33 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
34 import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
35 import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
36 import org.mxchange.jusercore.exceptions.UserNotFoundException;
37 import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote;
38 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
39 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
40
41 /**
42  * A user EJB
43  * <p>
44  * @author Roland Haeder<roland@mxchange.org>
45  */
46 @Stateless (name = "user", description = "A bean handling the user data")
47 public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSessionBeanRemote {
48
49         /**
50          * Serial number
51          */
52         private static final long serialVersionUID = 542_145_347_916L;
53
54         /**
55          * Registration EJB
56          */
57         @EJB
58         private UserRegistrationSessionBeanRemote registerBean;
59
60         /**
61          * Default constructor
62          */
63         public JobsUserSessionBean () {
64         }
65
66         @Override
67         public User addUser (final User user) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException {
68                 // Trace message
69                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("addUser: user={0} - CALLED!", user)); //NOI18N
70
71                 // user should not be null
72                 if (null == user) {
73                         // Abort here
74                         throw new NullPointerException("user is null"); //NOI18N
75                 } else if (user.getUserId() != null) {
76                         // Not allowed here
77                         throw new IllegalStateException(MessageFormat.format("user.userId must be null, is: {0}", user.getUserId())); //NOI18N
78                 }
79
80                 // Check if user is registered
81                 if (this.registerBean.isUserNameRegistered(user)) {
82                         // Abort here
83                         throw new UserNameAlreadyRegisteredException(user);
84                 } else if (this.registerBean.isEmailAddressRegistered(user)) {
85                         // Abort here
86                         throw new EmailAddressAlreadyRegisteredException(user);
87                 }
88
89                 // Set created timestamp
90                 user.setUserCreated(new GregorianCalendar());
91                 user.getUserContact().setContactCreated(new GregorianCalendar());
92
93                 // Update cellphone, land-line and fax instance
94                 this.setAllContactPhoneEntriesCreated(user.getUserContact());
95
96                         // Persist it
97                 this.getEntityManager().persist(user);
98
99                 // Flush to get id back
100                 this.getEntityManager().flush();
101
102                 // Trace message
103                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("addUser: user={0},user.id={1} - EXIT!", user, user.getUserId())); //NOI18N
104
105                 // Return it
106                 return user;
107         }
108
109         @Override
110         @SuppressWarnings ("unchecked")
111         public List<User> allMemberPublicVisibleUsers () {
112                 // Trace message
113                 this.getLoggerBeanLocal().logTrace("allMemberPublicVisibleUsers: CALLED!"); //NOI18N
114
115                 // Get named query
116                 Query query = this.getEntityManager().createNamedQuery("AllMemberPublicUsers", List.class); //NOI18N
117
118                 // Set parameters
119                 query.setParameter("status", UserAccountStatus.CONFIRMED); //NOI18N
120                 query.setParameter("members", ProfileMode.MEMBERS); //NOI18N
121                 query.setParameter("public", ProfileMode.PUBLIC); //NOI18N
122
123                 // Get result
124                 List<User> users = query.getResultList();
125
126                 // Trace message
127                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("allMemberPublicVisibleUsers: users.size()={0} - EXIT!", users.size())); //NOI18N
128
129                 // Return full list
130                 return users;
131         }
132
133         @Override
134         @SuppressWarnings ("unchecked")
135         public List<User> allPublicUsers () {
136                 // Trace message
137                 this.getLoggerBeanLocal().logTrace("allPublicUsers: CALLED!"); //NOI18N
138
139                 // Get named query
140                 Query query = this.getEntityManager().createNamedQuery("AllPublicUsers", List.class); //NOI18N
141
142                 // Set parameters
143                 query.setParameter("status", UserAccountStatus.CONFIRMED); //NOI18N
144                 query.setParameter("mode", ProfileMode.PUBLIC); //NOI18N
145
146                 // Get result
147                 List<User> users = query.getResultList();
148
149                 // Trace message
150                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("allPublicUsers: users.size()={0} - EXIT!", users.size())); //NOI18N
151
152                 // Return full list
153                 return users;
154         }
155
156         @Override
157         @SuppressWarnings ("unchecked")
158         public List<User> allUsers () {
159                 // Trace message
160                 this.getLoggerBeanLocal().logTrace("allUsers: CALLED!"); //NOI18N
161
162                 // Get named query
163                 Query query = this.getEntityManager().createNamedQuery("AllUsers", List.class); //NOI18N
164
165                 // Get result
166                 List<User> users = query.getResultList();
167
168                 // Trace message
169                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("allUsers: users.size()={0} - EXIT!", users.size())); //NOI18N
170
171                 // Return full list
172                 return users;
173         }
174
175         @Override
176         public User fillUserData (final User user) {
177                 // Trace message
178                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("fillUserData: user={0} - CALLED!", user)); //NOI18N
179
180                 // user should not be null
181                 if (null == user) {
182                         // Abort here
183                         throw new NullPointerException("user is null"); //NOI18N
184                 }
185
186                 // Try to locate it
187                 Query query = this.getEntityManager().createNamedQuery("SearchUserName", LoginUser.class); //NOI18N
188
189                 // Set parameter
190                 query.setParameter("param", user.getUserName()); //NOI18N
191
192                 // Initialize variable
193                 User foundUser = null;
194
195                 // Try it
196                 try {
197                         // Try to get single result
198                         foundUser = (User) query.getSingleResult();
199                 } catch (final NoResultException ex) {
200                         // Log it
201                         this.getLoggerBeanLocal().logException(ex);
202                 }
203
204                 // Trace message
205                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("fillUserData: foundUser={0} - EXIT!", foundUser)); //NOI18N
206
207                 // Return prepared instance
208                 return foundUser;
209         }
210
211         @Override
212         public User findUserById (final Long userId) throws UserNotFoundException {
213                 // Is the parameter valid?
214                 if (null == userId) {
215                         // Throw NPE
216                         throw new NullPointerException("userId is null"); //NOI18N
217                 } else if (userId < 1) {
218                         // Not valid
219                         throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N
220                 } else if (!this.ifUserIdExists(userId)) {
221                         // Does not exist
222                         throw new UserNotFoundException(userId);
223                 }
224
225                 // Create query instance
226                 Query query = this.getEntityManager().createNamedQuery("SearchUserId", LoginUser.class); //NOI18N
227
228                 // Set user id
229                 query.setParameter("id", userId); //NOI18N
230
231                 // Fetch the result, it should be there by now
232                 User user = (User) query.getSingleResult();
233
234                 // Should be there
235                 assert(user instanceof User) : "user is null"; //NOI18N
236
237                 // Return found user
238                 return user;
239         }
240
241         @Override
242         @SuppressWarnings ("unchecked")
243         public List<String> getEmailAddressList () {
244                 // Get query
245                 Query query = this.getEntityManager().createNamedQuery("AllEmailAddresses", String.class); //NOI18N
246
247                 // Get result list
248                 List<String> emailAddressList = query.getResultList();
249
250                 // Return it
251                 return emailAddressList;
252         }
253
254         @Override
255         @SuppressWarnings ("unchecked")
256         public List<String> getUserNameList () {
257                 // Get query
258                 Query query = this.getEntityManager().createNamedQuery("AllUserNames", String.class); //NOI18N
259
260                 // Get result list
261                 List<String> userNameList = query.getResultList();
262
263                 // Return it
264                 return userNameList;
265         }
266
267         @Override
268         public boolean ifUserExists (final User user) {
269                 // Trace message
270                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("ifUserExists: user={0} - CALLED!", user)); //NOI18N
271
272                 // userId should not be null
273                 if (null == user) {
274                         // Abort here
275                         throw new NullPointerException("user is null"); //NOI18N
276                 } else if (user.getUserId() == null) {
277                         // Abort here
278                         throw new NullPointerException("user.userId is null"); //NOI18N
279                 } else if (user.getUserId() < 1) {
280                         // Invalid number
281                         throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", user.getUserId())); //NOI18N
282                 }
283
284                 // Generate query
285                 Query query = this.getEntityManager().createNamedQuery("SearchUserId", LoginUser.class); //NOI18N
286
287                 // Set parameter
288                 query.setParameter("id", user.getUserId()); //NOI18N
289
290                 // Try this
291                 try {
292                         User dummy = (User) query.getSingleResult();
293
294                         // Debug message
295                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserExists: dummy.id={0} found.", dummy.getUserId())); //NOI18N
296                 } catch (final NoResultException ex) {
297                         // Log it
298                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserExists: getSingleResult() returned no result: {0}", ex)); //NOI18N
299
300                         // User name does not exist
301                         return false;
302                 } catch (final PersistenceException ex) {
303                         // Something bad happened
304                         this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one user {0} found.", user, ex)); //NOI18N
305
306                         // Throw again
307                         throw ex;
308                 }
309
310                 // Trace message
311                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("ifUserExists: Found user {0} - EXIT!", user)); //NOI18N
312
313                 // Found it
314                 return true;
315         }
316
317         @Override
318         public boolean ifUserIdExists (final Long userId) {
319                 // Trace message
320                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("ifUserIdExists: userId={0} - CALLED!", userId)); //NOI18N
321
322                 // userId should not be null
323                 if (null == userId) {
324                         // Abort here
325                         throw new NullPointerException("userId is null"); //NOI18N
326                 } else if (userId < 1) {
327                         // Invalid number
328                         throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", userId)); //NOI18N
329                 }
330
331                 // Generate query
332                 Query query = this.getEntityManager().createNamedQuery("SearchUserId", LoginUser.class); //NOI18N
333
334                 // Set parameter
335                 query.setParameter("id", userId); //NOI18N
336
337                 // Try this
338                 try {
339                         User dummy = (User) query.getSingleResult();
340
341                         // Debug message
342                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserIdExists: dummy.id={0} found.", dummy.getUserId())); //NOI18N
343                 } catch (final NoResultException ex) {
344                         // Log it
345                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserIdExists: getSingleResult() returned no result: {0}", ex)); //NOI18N
346
347                         // User name does not exist
348                         return false;
349                 } catch (final PersistenceException ex) {
350                         // Something bad happened
351                         this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one user id {0} found.", userId, ex)); //NOI18N
352
353                         // Throw again
354                         throw ex;
355                 }
356
357                 // Trace message
358                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("ifUserIdExists: Found user id {0} - EXIT!", userId)); //NOI18N
359
360                 // Found it
361                 return true;
362         }
363
364         @Override
365         public boolean ifUserNameExists (final String userName) {
366                 // Trace message
367                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("ifUserNameExists: userName={0} - CALLED!", userName)); //NOI18N
368
369                 // userId should not be null
370                 if (null == userName) {
371                         // Abort here
372                         throw new NullPointerException("userName is null"); //NOI18N
373                 } else if (userName.isEmpty()) {
374                         // Abort here
375                         throw new NullPointerException("userName is empty"); //NOI18N
376                 }
377
378                 // Generate query
379                 Query query = this.getEntityManager().createNamedQuery("SearchUserName", LoginUser.class); //NOI18N
380
381                 // Set parameter
382                 query.setParameter("param", userName); //NOI18N
383
384                 // Try this
385                 try {
386                         User dummy = (User) query.getSingleResult();
387
388                         // Debug message
389                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserNameExists: dummy.id={0} found.", dummy.getUserId())); //NOI18N
390                 } catch (final NoResultException ex) {
391                         // Log it
392                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserNameExists: getSingleResult() returned no result: {0}", ex)); //NOI18N
393
394                         // User name does not exist
395                         return false;
396                 }
397
398                 // Trace message
399                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("ifUserNameExists: Found user name {0} - EXIT!", userName)); //NOI18N
400
401                 // Found it
402                 return true;
403         }
404
405         @Override
406         public boolean isEmailAddressReqistered (final User user) {
407                 // Trace message
408                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("isEmailAddressReqistered: user={0} - CALLED!", user)); //NOI18N
409
410                 // user should not be null
411                 if (null == user) {
412                         // Abort here
413                         throw new NullPointerException("user is null"); //NOI18N
414                 }
415
416                 // Generate query
417                 Query query = this.getEntityManager().createNamedQuery("SearchEmailAddress", LoginUser.class); //NOI18N
418
419                 // Set parameter
420                 query.setParameter("param", user.getUserContact().getContactEmailAddress()); //NOI18N
421
422                 // Search for it
423                 try {
424                         User dummy = (User) query.getSingleResult();
425
426                         // Debug message
427                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("isEmailAddressReqistered: dummy.id={0} found.", dummy.getUserId())); //NOI18N
428                 } catch (final NoResultException ex) {
429                         // Log it
430                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("isEmailAddressReqistered: getSingleResult() returned no result: {0}", ex)); //NOI18N
431
432                         // Email address does not exist
433                         return false;
434                 } catch (final PersistenceException ex) {
435                         // Something bad happened
436                         this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one email address {0} found.", user.getUserContact().getContactEmailAddress()), ex); //NOI18N
437
438                         // Throw again
439                         throw ex;
440                 }
441
442                 // Found it
443                 return true;
444         }
445
446         @Override
447         public boolean isUserNameReqistered (final User user) {
448                 // Trace message
449                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("isUserNameReqistered: user={0} - CALLED!", user)); //NOI18N
450
451                 // user should not be null
452                 if (null == user) {
453                         // Abort here
454                         throw new NullPointerException("user is null"); //NOI18N
455                 }
456
457                 // Generate query
458                 Query query = this.getEntityManager().createNamedQuery("SearchUserName", LoginUser.class); //NOI18N
459
460                 // Set parameter
461                 query.setParameter("param", user.getUserName()); //NOI18N
462
463                 // Try this
464                 try {
465                         User dummy = (User) query.getSingleResult();
466
467                         // Debug message
468                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("isUserNameReqistered: dummy.id={0} found.", dummy.getUserId())); //NOI18N
469                 } catch (final NoResultException ex) {
470                         // Log it
471                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("isUserNameReqistered: getSingleResult() returned no result: {0}", ex)); //NOI18N
472
473                         // User name does not exist
474                         return false;
475                 } catch (final PersistenceException ex) {
476                         // Something bad happened
477                         this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one email address {0} found.", user.getUserContact().getContactEmailAddress()), ex); //NOI18N
478
479                         // Throw again
480                         throw ex;
481                 }
482
483                 // Found it
484                 return true;
485         }
486
487         @Override
488         public User linkUser (User user) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException {
489                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
490         }
491
492         @Override
493         public User updateUserData (final User user) {
494                 // Trace message
495                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("updateUserData: user={0} - CALLED!", user)); //NOI18N
496
497                 // user should not be null
498                 if (null == user) {
499                         // Abort here
500                         throw new NullPointerException("user is null"); //NOI18N
501                 } else if (user.getUserId() == null) {
502                         // Throw NPE again
503                         throw new NullPointerException("user.userId is null"); //NOI18N
504                 } else if (user.getUserId() < 1) {
505                         // Not valid
506                         throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
507                 } else if (user.getUserAccountStatus() == null) {
508                         // Throw NPE again
509                         throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
510                 } else if (!this.ifUserExists(user)) {
511                         // User does not exist
512                         throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
513                 }
514
515                 // Remove contact instance as this is not updatedf
516                 user.setUserContact(null);
517
518                 // Find the instance
519                 User foundUser = this.getEntityManager().find(user.getClass(), user.getUserId());
520
521                 // Should be found!
522                 assert (foundUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
523
524                 // Merge user
525                 User detachedUser = this.getEntityManager().merge(foundUser);
526
527                 // Should be found!
528                 assert (detachedUser instanceof User) : MessageFormat.format("User with id {0} not merged, but should be.", user.getUserId()); //NOI18N
529
530                 // Copy all data
531                 detachedUser.copyAll(user);
532
533                 // Set as updated
534                 detachedUser.setUserUpdated(new GregorianCalendar());
535
536                 // Return updated instance
537                 return detachedUser;
538         }
539
540         @Override
541         public User updateUserPersonalData (final User user) {
542                 // Trace message
543                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("updateUserPersonalData: user={0} - CALLED!", user)); //NOI18N
544
545                 // user should not be null
546                 if (null == user) {
547                         // Abort here
548                         throw new NullPointerException("user is null"); //NOI18N
549                 } else if (user.getUserId() == null) {
550                         // Throw NPE again
551                         throw new NullPointerException("user.userId is null"); //NOI18N
552                 } else if (user.getUserId() < 1) {
553                         // Not valid
554                         throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
555                 } else if (user.getUserAccountStatus() == null) {
556                         // Throw NPE again
557                         throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
558                 } else if (!this.ifUserExists(user)) {
559                         // User does not exist
560                         throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
561                 }
562
563                 // Find the instance
564                 User foundUser = this.getEntityManager().find(user.getClass(), user.getUserId());
565
566                 // Should be found!
567                 assert (foundUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
568
569                 // Merge user
570                 User detachedUser = this.getEntityManager().merge(foundUser);
571
572                 // Should be found!
573                 assert (detachedUser instanceof User) : MessageFormat.format("User with id {0} not merged, but should be.", user.getUserId()); //NOI18N
574
575                 // Copy all data
576                 detachedUser.copyAll(user);
577
578                 // Set as updated
579                 detachedUser.setUserUpdated(new GregorianCalendar());
580                 detachedUser.getUserContact().setContactUpdated(new GregorianCalendar());
581
582                 // Get contact from it and find it
583                 Contact foundContact = this.getEntityManager().find(user.getUserContact().getClass(), user.getUserContact().getContactId());
584
585                 // Should be found
586                 assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", user.getUserContact().getContactId()); //NOI18N
587
588                 // Debug message
589                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: contact.contactId={0}", foundContact.getContactId())); //NOI18N
590
591                 // Merge contact instance
592                 Contact detachedContact = this.getEntityManager().merge(foundContact);
593
594                 // Copy all
595                 detachedContact.copyAll(user.getUserContact());
596
597                 // Set it back in user
598                 user.setUserContact(detachedContact);
599
600                 // Should be found!
601                 assert (detachedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not merged, but should be.", user.getUserContact().getContactId()); //NOI18N
602
603                 // Get cellphone instance
604                 DialableCellphoneNumber cellphone = detachedContact.getContactCellphoneNumber();
605
606                 // Is there a  cellphone instance set?
607                 if (cellphone instanceof DialableCellphoneNumber) {
608                         // Debug message
609                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: cellphone.phoneId={0} is being updated ...", cellphone.getPhoneId())); //NOI18N
610
611                         // Then find it, too
612                         DialableCellphoneNumber foundCellphone = this.getEntityManager().find(cellphone.getClass(), cellphone.getPhoneId());
613
614                         // Should be there
615                         assert (foundCellphone instanceof DialableCellphoneNumber) : MessageFormat.format("Cellphone number with id {0} not found but should be.", foundCellphone.getPhoneId()); //NOI18N
616
617                         // Then merge it, too
618                         DialableCellphoneNumber detachedCellphone = this.getEntityManager().merge(foundCellphone);
619
620                         // Should be there
621                         assert (detachedCellphone instanceof DialableCellphoneNumber) : MessageFormat.format("Cellphone number with id {0} not found but should be.", detachedCellphone.getPhoneId()); //NOI18N
622
623                         // Copy all
624                         detachedCellphone.copyAll(user.getUserContact().getContactCellphoneNumber());
625
626                         // Set it back
627                         detachedContact.setContactCellphoneNumber(detachedCellphone);
628                 }
629
630                 // Get cellphone instance
631                 DialableFaxNumber fax = detachedContact.getContactFaxNumber();
632
633                 // Is there a  fax instance set?
634                 if (fax instanceof DialableFaxNumber) {
635                         // Debug message
636                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", fax.getPhoneId())); //NOI18N
637
638                         // Then find it, too
639                         DialableFaxNumber foundFax = this.getEntityManager().find(fax.getClass(), fax.getPhoneId());
640
641                         // Should be there
642                         assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N
643
644                         // Then merge it, too
645                         DialableFaxNumber detachedFax = this.getEntityManager().merge(foundFax);
646
647                         // Should be there
648                         assert (detachedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", detachedFax.getPhoneId()); //NOI18N
649
650                         // Copy all
651                         detachedFax.copyAll(user.getUserContact().getContactFaxNumber());
652
653                         // Set it back
654                         detachedContact.setContactFaxNumber(detachedFax);
655                 }
656
657                 // Get cellphone instance
658                 DialableLandLineNumber landLine = detachedContact.getContactLandLineNumber();
659
660                 // Is there a  fax instance set?
661                 if (landLine instanceof DialableLandLineNumber) {
662                         // Debug message
663                         this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLine.getPhoneId())); //NOI18N
664
665                         // Then find it, too
666                         DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLine.getClass(), landLine.getPhoneId());
667
668                         // Should be there
669                         assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
670
671                         // Then merge it, too
672                         DialableLandLineNumber detachedLandLine = this.getEntityManager().merge(foundLandLine);
673
674                         // Should be there
675                         assert (detachedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", detachedLandLine.getPhoneId()); //NOI18N
676
677                         // Copy all
678                         detachedLandLine.copyAll(user.getUserContact().getContactLandLineNumber());
679
680                         // Set it back
681                         detachedContact.setContactLandLineNumber(detachedLandLine);
682                 }
683
684                 // Return updated user instance
685                 return detachedUser;
686         }
687
688 }