]> git.mxchange.org Git - jjobs-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Fri, 7 Jul 2017 22:49:34 +0000 (00:49 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 7 Jul 2017 22:51:00 +0000 (00:51 +0200)
- "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 <roland@mxchange.org>
src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java

index bba299c5b08a8d4642346d7a779b8ffc3b94fc53..28bcde2c915bfd738570fec571fca3353938bd17 100644 (file)
@@ -203,6 +203,9 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J
 
        @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 JobsAdminUserWebRequestBean extends BaseJobsController implements J
                } 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
@@ -246,19 +249,19 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J
                user.setUserProfileMode(ProfileMode.INVISIBLE);
 
                // 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 +271,7 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J
                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 +301,12 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J
 
                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);