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