]> git.mxchange.org Git - jjobs-war.git/commitdiff
Rewitten a bit: (please cherry-pick)
authorRoland Häder <roland@mxchange.org>
Thu, 11 Aug 2016 12:04:52 +0000 (14:04 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 19 Aug 2016 20:56:11 +0000 (22:56 +0200)
- updateList and uniqlyAddUser did both the same, now only updateList() is left

Signed-off-by: Roland Häder <roland@haeder.net>
Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java

index b38a4236ea2964e819f7eae586ee8c29b0c6c833..331f5c53d87f83b64ba933b2a1f555422d07db47 100644 (file)
@@ -43,6 +43,7 @@ import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
+import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
 import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent;
 import org.mxchange.jusercore.events.user.password_change.UpdatedUserPasswordEvent;
 import org.mxchange.jusercore.events.user.unlocked.AdminUnlockedUserEvent;
@@ -196,14 +197,38 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs
                        throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
                }
 
-               // Add user uniquely
-               this.uniqueAddUser(event.getAddedUser());
+               // Update user list
+               this.updateList(event.getAddedUser());
 
                // Clear all data
                this.clear();
 
                // Set user id again
                this.setUserId(event.getAddedUser().getUserId());
+       }
+
+       @Override
+       public void afterAdminLinkedUserEvent (@Observes final AdminLinkedUserEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getLinkedUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.linkedUser is null"); //NOI18N
+               } else if (event.getLinkedUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.linkedUser.userId is null"); //NOI18N
+               } else if (event.getLinkedUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserId())); //NOI18N
+               }
+
+               // Update user list
+               this.updateList(event.getLinkedUser());
+
+               // Clear all data
+               this.clear();
 
                // Trace message
                //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminAddedUserEvent: EXIT!"); //NOI18N
@@ -226,8 +251,8 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs
                        throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLockedUser(), event.getLockedUser().getUserId())); //NOI18N
                }
 
-               // Add user uniquely
-               this.uniqueAddUser(event.getLockedUser());
+               // Update user list
+               this.updateList(event.getLockedUser());
        }
 
        @Override
@@ -247,8 +272,8 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs
                        throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUnlockedUser(), event.getUnlockedUser().getUserId())); //NOI18N
                }
 
-               // Add user uniquely
-               this.uniqueAddUser(event.getUnlockedUser());
+               // Update user list
+               this.updateList(event.getUnlockedUser());
        }
 
        @Override
@@ -271,7 +296,7 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs
                        throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedUser(), event.getUpdatedUser().getUserId())); //NOI18N
                }
 
-               // Update list
+               // Update user list
                this.updateList(event.getUpdatedUser());
 
                // Clear all data
@@ -313,8 +338,8 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs
                // Clear all data
                this.clear();
 
-               // Add user uniquely
-               this.uniqueAddUser(registeredUser);
+               // Update user list
+               this.updateList(registeredUser);
 
                // Add user name
                this.addUserName(registeredUser);
@@ -352,8 +377,8 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs
                        throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
                }
 
-               // Add user uniquely
-               this.uniqueAddUser(event.getConfirmedUser());
+               // Update user list
+               this.updateList(event.getConfirmedUser());
        }
 
        @Override
@@ -406,7 +431,7 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs
                        throw new IllegalArgumentException(MessageFormat.format("event.passwordHistory.userPasswordHistoryId={0} is in valid", event.getPasswordHistory().getUserPasswordHistoryId())); //NOI18N
                }
 
-               // All fine, so update list
+               // Update user list
                this.updateList(event.getPasswordHistory().getUserPasswordHistoryUser());
        }
 
@@ -427,7 +452,7 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs
                        throw new IllegalArgumentException(MessageFormat.format("event.updatedUser.userId={0} is in valid", event.getUpdatedUser().getUserId())); //NOI18N
                }
 
-               // All fine, so update list
+               // Update user list
                this.updateList(event.getUpdatedUser());
        }
 
@@ -933,6 +958,9 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs
                if (null == user) {
                        // Throw NPE
                        throw new NullPointerException("user is null"); //NOI18N
+               } else if (user.getUserContact() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("user.userContact is null"); //NOI18N
                } else if (user.getUserId() == null) {
                        // ... again NPE
                        throw new NullPointerException("user.userId is null"); //NOI18N
@@ -941,23 +969,23 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs
                        throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
                }
 
-               // Get iterator
+               // Get iterator from list
                Iterator<User> iterator = this.userList.iterator();
 
-               // Look whole list
+               // "Walk" through all entries
                while (iterator.hasNext()) {
                        // Get next element
                        User next = iterator.next();
 
-                       // Is the same user id?
+                       // Is user id number the same?
                        if (Objects.equals(user.getUserId(), next.getUserId())) {
-                               // Found it, so remove it
+                               // Found entry, so remove it and abort
                                this.userList.remove(next);
                                break;
                        }
                }
 
-               // Re-add item
+               // Re-add user
                this.userList.add(user);
        }