From: Roland Haeder Date: Sat, 5 Mar 2016 17:05:01 +0000 (+0100) Subject: Introduced updateUserFromFields() which updates a given user instance from all fields X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=85390aaa83377fd29e3c14c70916deb874ed6052;p=jjobs-war.git Introduced updateUserFromFields() which updates a given user instance from all fields --- diff --git a/src/java/org/mxchange/jjobs/beans/user/UserWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/user/UserWebSessionBean.java index e9990f63..434cf74e 100644 --- a/src/java/org/mxchange/jjobs/beans/user/UserWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/UserWebSessionBean.java @@ -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 + *

+ * @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; }