]> git.mxchange.org Git - jjobs-war.git/commitdiff
Introduced updateUserFromFields() which updates a given user instance from all fields
authorRoland Haeder <roland@mxchange.org>
Sat, 5 Mar 2016 17:05:01 +0000 (18:05 +0100)
committerRoland Haeder <roland@mxchange.org>
Sat, 5 Mar 2016 17:05:01 +0000 (18:05 +0100)
src/java/org/mxchange/jjobs/beans/user/UserWebSessionBean.java

index e9990f63683e2a4f0169867661fd56371879b477..434cf74e458655873a26463b895a2dadd2a88366 100644 (file)
@@ -252,12 +252,11 @@ public class UserWebSessionBean implements UserWebSessionController {
                        throw new UserPasswordMismatchException(this.loginController.getLoggedInUser());
                }
 
-               // Create new user instance from existing data
-               User user = this.createUserInstance();
+               // Get user instance
+               User user = this.loginController.getLoggedInUser();
 
-               // Update it from logged-in user (e.g. user and contact id)
-               user.setUserId(this.loginController.getLoggedInUser().getUserId());
-               user.getUserContact().setContactId(this.loginController.getLoggedInUser().getUserContact().getContactId());
+               // Update all fields
+               this.updateUserFromFields(user);
 
                // Send it to the EJB
                this.userBean.updateUserPersonalData(user);
@@ -350,16 +349,19 @@ public class UserWebSessionBean implements UserWebSessionController {
                return Collections.unmodifiableList(this.visibleUserList);
        }
 
-       @Override
-       public User createUserInstance () {
-               // User message
-               //this.getLogger().logTrace("createUserInstance: CALLED!");
-
-               // Required personal data must be set
-               assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
+       /**
+        * Updates given user instance with all (updated) data from this controller
+        * <p>
+        * @param user User instance to to be updated
+        */
+       private void updateUserFromFields (final User user) {
+               // Make sure it is valid
+               if (null == user) {
+                       // Throw NPE
+                       throw new NullPointerException("user is null"); //NOI18N
+               }
 
-               // Create new user instance
-               User user = new LoginUser();
+               // Update all data ...
                user.setUserName(this.getUserName());
                user.setUserProfileMode(this.getUserProfileMode());
                user.setUserCreated(new GregorianCalendar());
@@ -444,9 +446,25 @@ public class UserWebSessionBean implements UserWebSessionController {
 
                // Set contact in user
                user.setUserContact(contact);
+       }
+
+       @Override
+       public User createUserInstance () {
+               // User message
+               //this.getLogger().logTrace("createUserInstance: CALLED!");
+
+               // Required personal data must be set
+               assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
+
+               // Create new user instance
+               User user = new LoginUser();
+
+               // Update all fields
+               this.updateUserFromFields(user);
 
                // Trace message
                //this.getLogger().logTrace(MessageFormat.format("createUserInstance: user={0} - EXIT!", user));
+
                // Return it
                return user;
        }