From 0c4341ada8cd115b8d31f37d3b68d2c120295525 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 25 Aug 2016 15:47:34 +0200 Subject: [PATCH] Please cherry-pick: - renamed event observer methods to have suffix "Event" in it - added observer method afterUserResendConfirmationLinkEvent() for logging user activity MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../contact/JobsContactWebSessionBean.java | 4 +-- .../JobsContactWebSessionController.java | 4 +-- .../JobsLocalizationSessionBean.java | 5 +-- .../JobsLocalizationSessionController.java | 2 +- .../JobsResendLinkWebSessionBean.java | 35 ++++++++++++++++--- .../beans/user/JobsUserWebSessionBean.java | 6 ++-- .../user/JobsUserWebSessionController.java | 6 ++-- .../JobsUserActivityWebApplicationBean.java | 28 +++++++++++++-- ...sUserActivityWebApplicationController.java | 1 + 9 files changed, 69 insertions(+), 22 deletions(-) diff --git a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java index 1f4ee396..6108f6d2 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java @@ -485,7 +485,7 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job } @Override - public void afterUserConfirmedAccountEvent (@Observes final UserConfirmedAccountEvent event) { + public void afterUserConfirmedAccountEventEvent (@Observes final UserConfirmedAccountEvent event) { // event should not be null if (null == event) { // Throw NPE @@ -506,7 +506,7 @@ public class JobsContactWebSessionBean extends BaseJobsController implements Job } @Override - public void afterUserLogin (@Observes final UserLoggedInEvent event) { + public void afterUserLoginEvent (@Observes final UserLoggedInEvent event) { // event should not be null if (null == event) { // Throw NPE diff --git a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionController.java b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionController.java index 70e20315..7a98cc31 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionController.java +++ b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionController.java @@ -93,7 +93,7 @@ public interface JobsContactWebSessionController extends Serializable { *

* @param event Event being fired */ - void afterUserConfirmedAccountEvent (final UserConfirmedAccountEvent event); + void afterUserConfirmedAccountEventEvent (final UserConfirmedAccountEvent event); /** * Event observer when a list with unused mobile numbers is being created @@ -156,7 +156,7 @@ public interface JobsContactWebSessionController extends Serializable { *

* @param event Event instance */ - void afterUserLogin (final UserLoggedInEvent event); + void afterUserLoginEvent (final UserLoggedInEvent event); /** * Creates an instance from all properties diff --git a/src/java/org/mxchange/jjobs/beans/localization/JobsLocalizationSessionBean.java b/src/java/org/mxchange/jjobs/beans/localization/JobsLocalizationSessionBean.java index 38888164..c6eb7c4e 100644 --- a/src/java/org/mxchange/jjobs/beans/localization/JobsLocalizationSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/localization/JobsLocalizationSessionBean.java @@ -49,10 +49,7 @@ public class JobsLocalizationSessionBean extends BaseJobsController implements J private Locale locale; @Override - public void afterUserLogin (@Observes final UserLoggedInEvent event) { - // Trace message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("LandingLocalizationSessionBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N - + public void afterUserLoginEvent (@Observes final UserLoggedInEvent event) { // event should not be null if (null == event) { // Throw NPE diff --git a/src/java/org/mxchange/jjobs/beans/localization/JobsLocalizationSessionController.java b/src/java/org/mxchange/jjobs/beans/localization/JobsLocalizationSessionController.java index d29f4db9..37612465 100644 --- a/src/java/org/mxchange/jjobs/beans/localization/JobsLocalizationSessionController.java +++ b/src/java/org/mxchange/jjobs/beans/localization/JobsLocalizationSessionController.java @@ -32,7 +32,7 @@ public interface JobsLocalizationSessionController extends Serializable { *

* @param event Event instance */ - void afterUserLogin (final UserLoggedInEvent event); + void afterUserLoginEvent (final UserLoggedInEvent event); /** * Getter for locale diff --git a/src/java/org/mxchange/jjobs/beans/resendlink/JobsResendLinkWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/resendlink/JobsResendLinkWebSessionBean.java index d5d17002..2b1d0ceb 100644 --- a/src/java/org/mxchange/jjobs/beans/resendlink/JobsResendLinkWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/resendlink/JobsResendLinkWebSessionBean.java @@ -17,6 +17,8 @@ package org.mxchange.jjobs.beans.resendlink; import javax.enterprise.context.SessionScoped; +import javax.enterprise.event.Event; +import javax.enterprise.inject.Any; import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; import javax.inject.Named; @@ -27,7 +29,12 @@ import org.mxchange.jcoreee.utils.FacesUtils; import org.mxchange.jjobs.beans.BaseJobsController; import org.mxchange.jjobs.beans.localization.JobsLocalizationSessionController; import org.mxchange.jjobs.beans.user.JobsUserWebSessionController; +import org.mxchange.jusercore.events.resendlink.ResendLinkUserAccountEvent; +import org.mxchange.jusercore.events.resendlink.UserResendLinkAccountEvent; import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException; +import org.mxchange.jusercore.exceptions.UserNotFoundException; +import org.mxchange.jusercore.exceptions.UserStatusConfirmedException; +import org.mxchange.jusercore.exceptions.UserStatusLockedException; import org.mxchange.jusercore.model.user.User; import org.mxchange.jusercore.model.user.status.UserAccountStatus; @@ -67,6 +74,13 @@ public class JobsResendLinkWebSessionBean extends BaseJobsController implements @Inject private JobsUserWebSessionController userController; + /** + * Event being fired after confirmation link is being sent + */ + @Inject + @Any + private Event userResendLinkEvent; + /** * Default constructor */ @@ -127,11 +141,24 @@ public class JobsResendLinkWebSessionBean extends BaseJobsController implements throw new NullPointerException("user.userConfirmKey is null"); //NOI18N } - // Get base URL - String baseUrl = FacesUtils.generateBaseUrl(); + try { + // Get base URL + String baseUrl = FacesUtils.generateBaseUrl(); + + // Call EJB and return redirect target + this.emailBean.resendConfirmationLink(user, this.localizationController.getLocale(), baseUrl); + } catch (final UserNotFoundException ex) { + // User not found + this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_NOT_FOUND"); //NOI18N + return ""; //NOI18N + } catch (final UserStatusLockedException | UserStatusConfirmedException ex) { + // Output message, this should not happen as the confirmation key is being removed + this.showFacesMessage("form_resend_link:resendEmailAddress", ex); //NOI18N + return ""; //NOI18N + } - // Call EJB and return redirect target - this.emailBean.resendConfirmationLink(user, this.localizationController.getLocale(), baseUrl); + // Fire event + this.userResendLinkEvent.fire(new ResendLinkUserAccountEvent(user)); // Clear this bean this.clear(); diff --git a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java index b7897b2d..84dcdc21 100644 --- a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java @@ -331,7 +331,7 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs } @Override - public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) { + public void afterUserConfirmedAccountEvent (@Observes final UserConfirmedAccountEvent event) { // event should not be null if (null == event) { // Throw NPE @@ -352,7 +352,7 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs } @Override - public void afterUserLogin (@Observes final UserLoggedInEvent event) { + public void afterUserLoginEvent (@Observes final UserLoggedInEvent event) { // event should not be null if (null == event) { // Throw NPE @@ -403,7 +403,7 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs } @Override - public void afterUserUpdatedPersonalData (@Observes final UpdatedUserPersonalDataEvent event) { + public void afterUserUpdatedPersonalDataEvent (@Observes final UpdatedUserPersonalDataEvent event) { // Check parameter if (null == event) { // Throw NPE diff --git a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionController.java b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionController.java index 13c57204..0ecb8096 100644 --- a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionController.java +++ b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionController.java @@ -86,7 +86,7 @@ public interface JobsUserWebSessionController extends Serializable { *

* @param event Event being fired */ - void afterUserConfirmedAccount (final UserConfirmedAccountEvent event); + void afterUserConfirmedAccountEvent (final UserConfirmedAccountEvent event); /** * Method being call after user's password has been updated (and history @@ -101,7 +101,7 @@ public interface JobsUserWebSessionController extends Serializable { *

* @param event Event being fired */ - void afterUserUpdatedPersonalData (final UpdatedUserPersonalDataEvent event); + void afterUserUpdatedPersonalDataEvent (final UpdatedUserPersonalDataEvent event); /** * Event observer for new user registrations @@ -115,7 +115,7 @@ public interface JobsUserWebSessionController extends Serializable { *

* @param event Event instance */ - void afterUserLogin (final UserLoggedInEvent event); + void afterUserLoginEvent (final UserLoggedInEvent event); /** * All users diff --git a/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java b/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java index 66958f2c..6062b056 100644 --- a/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java @@ -34,6 +34,7 @@ import org.mxchange.jjobs.beans.BaseJobsController; 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.resendlink.UserResendLinkAccountEvent; import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent; import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent; @@ -278,7 +279,7 @@ public class JobsUserActivityWebApplicationBean extends BaseJobsController imple } @Override - public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) { + public void afterUserConfirmedAccountEvent (@Observes final UserConfirmedAccountEvent event) { // event should not be null if (null == event) { // Throw NPE @@ -299,7 +300,7 @@ public class JobsUserActivityWebApplicationBean extends BaseJobsController imple } @Override - public void afterUserLogin (@Observes final UserLoggedInEvent event) { + public void afterUserLoginEvent (@Observes final UserLoggedInEvent event) { // event should not be null if (null == event) { // Throw NPE @@ -319,6 +320,27 @@ public class JobsUserActivityWebApplicationBean extends BaseJobsController imple this.addUserActivity(event.getLoggedInUser(), "USER_LOGGED_IN"); //NOI18N } + @Override + public void afterUserResendConfirmationLinkEvent (@Observes final UserResendLinkAccountEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getResendLinkUser()== null) { + // Throw NPE again + throw new NullPointerException("event.resendLinkUser is null"); //NOI18N + } else if (event.getResendLinkUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.resendLinkUser.userId is null"); //NOI18N + } else if (event.getResendLinkUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getResendLinkUser(), event.getResendLinkUser().getUserId())); //NOI18N + } + + // Copy all data to this bean + this.addUserActivity(event.getResendLinkUser(), "USER_RESEND_CONFIRMATION_LINK"); //NOI18N + } + @Override public void afterUserUpdatedPasswordEvent (@Observes final UpdatedUserPasswordEvent event) { // Check parameter @@ -341,7 +363,7 @@ public class JobsUserActivityWebApplicationBean extends BaseJobsController imple } @Override - public void afterUserUpdatedPersonalData (@Observes final UpdatedUserPersonalDataEvent event) { + public void afterUserUpdatedPersonalDataEvent (@Observes final UpdatedUserPersonalDataEvent event) { // Check parameter if (null == event) { // Throw NPE diff --git a/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationController.java b/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationController.java index a738ba9b..c576b632 100644 --- a/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationController.java +++ b/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationController.java @@ -22,6 +22,7 @@ import javax.ejb.Local; 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.resendlink.UserResendLinkAccountEvent; import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent; import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent; -- 2.39.5