From d03b690935e5f286f048505091f4fa37368cf7b6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 11 Aug 2016 14:04:52 +0200 Subject: [PATCH] Rewitten a bit: (please cherry-pick) - updateList and uniqlyAddUser did both the same, now only updateList() is left MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder Signed-off-by: Roland Häder --- .../beans/user/JobsUserWebSessionBean.java | 64 +++++++++++++------ 1 file changed, 46 insertions(+), 18 deletions(-) diff --git a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java index b38a4236..331f5c53 100644 --- a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java @@ -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 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); } -- 2.39.5