From: Roland Häder Date: Fri, 7 Jul 2017 22:49:34 +0000 (+0200) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4fd88397c0ca7c391ba4fbf6e0af8de87a813461;p=jfinancials-war.git Please cherry-pick: - "cached" beanHelper.contact locally so such "expensive" calls are reduced - and the instance has not changed between two calls anyway Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jfinancials/beans/user/FinancialsAdminUserWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/user/FinancialsAdminUserWebRequestBean.java index 02ed9888..8235523d 100644 --- a/src/java/org/mxchange/jfinancials/beans/user/FinancialsAdminUserWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/user/FinancialsAdminUserWebRequestBean.java @@ -203,6 +203,9 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsController @Override public String addUser () { + // Get contact from bean helper to "cache" it locally + Contact contact = this.beanHelper.getContact(); + // As the form cannot validate the data (required="true"), check it here if (this.getUserName() == null) { // Throw NPE @@ -210,7 +213,7 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsController } else if (this.getUserName().isEmpty()) { // Is empty throw new IllegalArgumentException("userName is null"); //NOI18N - } else if (this.beanHelper.getContact() == null) { + } else if (contact == null) { // No contact instance set, so test required fields: gender, first name and family name if (this.contactController.getPersonalTitle() == null) { // Throw NPE again @@ -224,7 +227,7 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsController } else if (this.adminContactController.getFamilyName() == null) { // ... and again throw new NullPointerException("contactController.familyName is null"); //NOI18N - } else if (this.contactController.getFamilyName().isEmpty()) { + } else if (this.adminContactController.getFamilyName().isEmpty()) { // ... and again throw new IllegalArgumentException("contactController.familyName is empty"); //NOI18N } else if (this.adminContactController.getEmailAddress() == null) { @@ -238,27 +241,29 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsController // Create new user instance User user = new LoginUser(); - // Set user name, CONFIRMED and INVISIBLE user.setUserName(this.getUserName()); user.setUserMustChangePassword(this.getUserMustChangePassword()); user.setUserAccountStatus(UserAccountStatus.CONFIRMED); user.setUserProfileMode(ProfileMode.INVISIBLE); + // Copy user locale + user.setUserLocale(this.localizationController.getLocale()); + // Init instance - Contact contact; + Contact userContact; // Is a contact instance in helper set? - if (this.beanHelper.getContact() instanceof Contact) { + if (contact instanceof Contact) { // Then use it for contact linking - contact = this.beanHelper.getContact(); + userContact = contact; } else { // Create contact instance - contact = this.contactController.createContactInstance(); + userContact = this.contactController.createContactInstance(); } // Set contact in user - user.setUserContact(contact); + user.setUserContact(userContact); // Init variable for password String password = null; @@ -268,7 +273,7 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsController if (this.userController.isUserNameRegistered(user)) { // User name is already used throw new FaceletException(new UserNameAlreadyRegisteredException(user)); - } else if ((this.beanHelper.getContact() == null) && (this.contactController.isEmailAddressRegistered(user.getUserContact()))) { + } else if ((contact == null) && (this.contactController.isEmailAddressRegistered(user.getUserContact()))) { // Email address is already used this.showFacesMessage("admin_add_user:emailAddress", "ERROR_EMAIL_ADDRESS_ALREADY_USED"); //NOI18N @@ -298,15 +303,12 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsController try { // Now, that all is set, call EJB - if (this.beanHelper.getContact() instanceof Contact) { + if (contact instanceof Contact) { // Link contact with this user User updatedUser = this.adminUserBean.linkUser(user); // Fire event this.userLinkedEvent.fire(new AdminLinkedUserEvent(updatedUser)); - - // Remove contact instance - this.beanHelper.setContact(null); } else { // Add new contact User updatedUser = this.adminUserBean.addUser(user);