From 6b7bfcc5c145d0467db956b598e4ed73c4007c76 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 9 Jul 2017 12:53:03 +0200 Subject: [PATCH] Please cherry-pick: - renamed bean to userConfirmationLinkController - always handle returned (mostly updated/managed) entities, then the updated data is being handled MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../JobsAdminContactWebRequestBean.java | 27 ++-- .../phone/JobsAdminPhoneWebRequestBean.java | 17 ++- .../JobsUserProfileWebRequestBean.java | 136 +----------------- .../JobsConfirmationLinkWebRequestBean.java | 56 ++++++-- .../JobsResendLinkWebSessionBean.java | 13 +- web/guest/user/user_confirm_account.xhtml | 8 +- 6 files changed, 79 insertions(+), 178 deletions(-) diff --git a/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java index fce1821c..cdb33bb6 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java @@ -33,9 +33,9 @@ import javax.naming.NamingException; import org.mxchange.jcontacts.contact.AdminContactSessionBeanRemote; import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jcontacts.contact.ContactSessionBeanRemote; +import org.mxchange.jcontacts.contact.ContactUtils; import org.mxchange.jcontacts.contact.UserContact; import org.mxchange.jcontacts.contact.title.PersonalTitle; -import org.mxchange.jcontacts.contact.ContactUtils; import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent; import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent; import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent; @@ -66,6 +66,10 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement * Serial number */ private static final long serialVersionUID = 542_145_347_916L; + /** + * Academic academicTitle + */ + private String academicTitle; /** * An event fired when the administrator has added a new contact @@ -226,10 +230,6 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement */ private String street; - /** - * Academic academicTitle - */ - private String academicTitle; /** * An event fired when the administrator has updated contact data @@ -541,6 +541,14 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement // Return it return number; } + @Override + public String getAcademicTitle () { + return this.academicTitle; + } + @Override + public void setAcademicTitle (final String academicTitle) { + this.academicTitle = academicTitle; + } @Override @SuppressWarnings ("ReturnOfDateField") @@ -785,15 +793,6 @@ public class JobsAdminContactWebRequestBean extends BaseJobsController implement this.street = street; } - @Override - public String getAcademicTitle () { - return this.academicTitle; - } - - @Override - public void setAcademicTitle (final String academicTitle) { - this.academicTitle = academicTitle; - } @Override public Integer getZipCode () { diff --git a/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java index bf7295f1..79fd4612 100644 --- a/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java @@ -96,15 +96,6 @@ public abstract class JobsAdminPhoneWebRequestBean extends BaseJobsController im */ private DialableFaxNumber faxNumber; - /** - * land-line number - */ - private DialableLandLineNumber landLineNumber; - - /** - * mobile number - */ - private DialableMobileNumber mobileNumber; /** * Event being fired when an administrator has deleted fax number @@ -119,6 +110,10 @@ public abstract class JobsAdminPhoneWebRequestBean extends BaseJobsController im @Inject @Any private Event faxNumberUpdatedEvent; + /** + * land-line number + */ + private DialableLandLineNumber landLineNumber; /** * Event being fired when an administrator has deleted land-line number @@ -133,6 +128,10 @@ public abstract class JobsAdminPhoneWebRequestBean extends BaseJobsController im @Inject @Any private Event landLineNumberUpdatedEvent; + /** + * mobile number + */ + private DialableMobileNumber mobileNumber; /** * Event being fired when an administrator has deleted mobile number diff --git a/src/java/org/mxchange/jjobs/beans/profile/JobsUserProfileWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/profile/JobsUserProfileWebRequestBean.java index 2ff1883a..f78c697d 100644 --- a/src/java/org/mxchange/jjobs/beans/profile/JobsUserProfileWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/profile/JobsUserProfileWebRequestBean.java @@ -17,19 +17,14 @@ package org.mxchange.jjobs.beans.profile; import java.text.MessageFormat; -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; import javax.annotation.PostConstruct; import javax.enterprise.context.RequestScoped; -import javax.faces.application.FacesMessage; -import javax.faces.context.FacesContext; import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jjobs.beans.BaseJobsController; -import org.mxchange.jjobs.beans.user.login.JobsUserLoginWebSessionController; import org.mxchange.jjobs.beans.user.JobsUserWebSessionController; +import org.mxchange.jjobs.beans.user.login.JobsUserLoginWebSessionController; import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.model.user.User; import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; @@ -41,7 +36,7 @@ import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; */ @Named (value = "profileController") @RequestScoped -public abstract class JobsUserProfileWebRequestBean extends BaseJobsController implements JobsUserProfileWebRequestController { +public class JobsUserProfileWebRequestBean extends BaseJobsController implements JobsUserProfileWebRequestController { /** * Serial number @@ -135,131 +130,4 @@ public abstract class JobsUserProfileWebRequestBean extends BaseJobsController i (this.userLoginController.isUserLoggedIn()) && (profileMode.equals(ProfileMode.MEMBERS))); } - /** - * Returns given property key or throws an exception if not found. - *

- * @param parameterKey Property key - *

- * @return Property value - *

- * @throws NullPointerException If given key is not found - * @throws NumberFormatException If no number is given in context parameter - */ - protected int getIntegerContextParameter (final String parameterKey) throws NullPointerException, NumberFormatException { - // Get context parameter - Integer contextValue = Integer.parseInt(this.getStringContextParameter(parameterKey)); - // Return it - return contextValue; - } - - /** - * Returns given property key or throws an exception if not found. - *

- * @param parameterKey Property key - *

- * @return Property value - *

- * @throws NullPointerException If given key is not found - */ - protected String getStringContextParameter (final String parameterKey) throws NullPointerException { - // Get context parameter - String contextValue = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(parameterKey); - // Is it null? - if (null == contextValue) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("parameterKey={0} is not set.", parameterKey)); //NOI18N - } - // Return it - return contextValue; - } - - /** - * Checks whether debug mode is enabled for given controller - *

- * @param controllerName Name of controller - *

- * @return Whether debug mode is enabled - */ - protected boolean isDebugModeEnabled (final String controllerName) { - // Parameters should be valid - if (null == controllerName) { - // Throw NPE - throw new NullPointerException("controllerName is null"); //NOI18N - } else if (controllerName.isEmpty()) { - // Is empty - throw new IllegalArgumentException("controllerName is empty"); //NOI18N - } - // Try to get context parameter - String contextParameter = this.getStringContextParameter(String.format("is_debug_%s_enabled", controllerName)); //NOI18N - // Is it set and true? - boolean isEnabled = Boolean.parseBoolean(contextParameter) == Boolean.TRUE; - // Return it - return isEnabled; - } - - /** - * Loads resource bundle for given locale. This must be implemented per - * project so all projects can still customize their methods. Calling - * ResourceBundleloadBundle() in this class means that also the bundle files - * must be present here. - *

- * @param locale Locale from e.g. FacesContext - *

- * @return Initialized and loaded resource bundle - */ - protected abstract ResourceBundle loadResourceBundle (final Locale locale); - - /** - * Shows a faces message for given causing exception. The message from the - * exception is being inserted into the message. - *

- * @param clientId Client id to send message to - * @param cause Causing exception - */ - protected void showFacesMessage (final String clientId, final Throwable cause) { - // Get context and add message - this.showFacesMessage(clientId, cause.getMessage()); - } - - /** - * Shows a faces message with given message (i18n) key. - *

- * @param clientId Client id to send message to - * @param i18nKey Message key - *

- * @throws NullPointerException If clientId or i18nKey is null - * @throws IllegalArgumentException If clientId or i18nKey is empty - */ - protected void showFacesMessage (final String clientId, final String i18nKey) throws NullPointerException, IllegalArgumentException { - // Both parameter must be valid - if (null == clientId) { - // Throw NPE - throw new NullPointerException("clientId is null"); //NOI18N - } else if (clientId.isEmpty()) { - // Is empty - throw new IllegalArgumentException("clientId is null"); //NOI18N - } else if (null == i18nKey) { - // Throw NPE - throw new NullPointerException("i18nKey is null"); //NOI18N - } else if (i18nKey.isEmpty()) { - // Is empty - throw new IllegalArgumentException("i18nKey is null"); //NOI18N - } - // Get current locale - Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); - // Get bundle bundle - ResourceBundle bundle = this.loadResourceBundle(locale); - // Default is i18nKey - String message = MessageFormat.format("!{0}!", i18nKey); //NOI18N - // Try it - try { - // Get message - message = bundle.getString(i18nKey); - } catch (final MissingResourceException ex) { - // Did not find it, ignored - } - // Get context and add message - FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(message)); - } - } diff --git a/src/java/org/mxchange/jjobs/beans/user/confirmlink/JobsConfirmationLinkWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/user/confirmlink/JobsConfirmationLinkWebRequestBean.java index daa10924..7a8c0d1e 100644 --- a/src/java/org/mxchange/jjobs/beans/user/confirmlink/JobsConfirmationLinkWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/confirmlink/JobsConfirmationLinkWebRequestBean.java @@ -47,7 +47,7 @@ import org.mxchange.jusercore.model.user.status.UserAccountStatus; *

* @author Roland Häder */ -@Named ("confirmationLinkController") +@Named ("userConfirmationLinkController") @RequestScoped public class JobsConfirmationLinkWebRequestBean extends BaseJobsController implements JobsConfirmationLinkWebRequestController { @@ -123,6 +123,9 @@ public class JobsConfirmationLinkWebRequestBean extends BaseJobsController imple @Override public void maybeConfirmUserAccount () { + // Trace message + System.out.println(MessageFormat.format("{0}.maybeConfirmAccount: CALLED!", this.getClass().getSimpleName())); //NOI18N + // Is the confirmation key set? if (this.getConfirmationKey() == null) { // May be null if not set @@ -135,6 +138,9 @@ public class JobsConfirmationLinkWebRequestBean extends BaseJobsController imple // Now try to find the user in user list, first get the whole list List users = this.userController.allUsers(); + // Debug message + System.out.println(MessageFormat.format("{0}.maybeConfirmAccount: users.size()={1}", this.getClass().getSimpleName(), users.size())); //NOI18N + // Get iterator from it Iterator iterator = users.iterator(); @@ -146,41 +152,49 @@ public class JobsConfirmationLinkWebRequestBean extends BaseJobsController imple // Get next user User next = iterator.next(); + // Debug message + System.out.println(MessageFormat.format("{0}.maybeConfirmAccount: this.confirmationKey={1},next.confirmationKey={2}", this.getClass().getSimpleName(), this.getConfirmationKey(), next.getUserConfirmKey())); //NOI18N + // Same confirmation key? if (Objects.equals(this.getConfirmationKey(), next.getUserConfirmKey())) { + // Debug message + System.out.println(MessageFormat.format("{0}.maybeConfirmAccount: next={1} - Aborting ...", this.getClass().getSimpleName(), next)); //NOI18N + // Found it, then set it and abort loop user = next; break; } } + // Debug message + System.out.println(MessageFormat.format("{0}.maybeConfirmAccount: user={1}", this.getClass().getSimpleName(), user)); //NOI18N + // Is the user instance null? if ((null == user) || (user.getUserAccountStatus() != UserAccountStatus.UNCONFIRMED)) { // Then clear this bean and the helper this.beanHelper.setUser(null); } else { - // Set user ... - this.beanHelper.setUser(user); - - // ... and copy it to the controller - this.beanHelper.copyUserToController(); - // Try to confirm it - this.confirmUserAccount(); + this.confirmUserAccount(user); } + + // Trace message + System.out.println(MessageFormat.format("{0}.maybeConfirmAccount: EXIT!", this.getClass().getSimpleName())); //NOI18N } /** * Tries to confirm the currently set user instance (in helper). + *

+ * @param user User instance */ - private void confirmUserAccount () { - // Get user instance - User user = this.beanHelper.getUser(); + private void confirmUserAccount (final User user) { + // Trace message + System.out.println(MessageFormat.format("{0}.confirmUserAccount: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N // Should be set if (null == user) { // Throw NPE - throw new NullPointerException("user is null"); + throw new NullPointerException("user is null"); //NOI18N } else if (user.getUserId() == null) { // Abort here throw new NullPointerException("user.userId is null"); //NOI18N @@ -196,6 +210,9 @@ public class JobsConfirmationLinkWebRequestBean extends BaseJobsController imple } else if (user.getUserConfirmKey() == null) { // Throw NPE throw new NullPointerException("user.userConfirmKey is null"); //NOI18N + } else if (user.getUserConfirmKey().isEmpty()) { + // Is empty string + throw new IllegalArgumentException("user.userConfirmKey is empty"); //NOI18N } // Updated user instance @@ -205,8 +222,14 @@ public class JobsConfirmationLinkWebRequestBean extends BaseJobsController imple // Get base URL String baseUrl = FacesUtils.generateBaseUrl(); + // Debug message + System.out.println(MessageFormat.format("{0}.confirmUserAccount: baseUrl={1}", this.getClass().getSimpleName(), baseUrl)); //NOI18N + // Confirm account updatedUser = this.userBean.confirmAccount(user, baseUrl); + + // Debug message + System.out.println(MessageFormat.format("{0}.confirmUserAccount: updatedUser={1} - Returned from EJB", this.getClass().getSimpleName(), updatedUser)); //NOI18N } catch (final UserStatusConfirmedException | UserStatusLockedException ex) { // Something unexpected happened throw new FaceletException(MessageFormat.format("Cannot confirm user account {0}", user.getUserName()), ex); //NOI18N @@ -215,8 +238,17 @@ public class JobsConfirmationLinkWebRequestBean extends BaseJobsController imple // Fire event that the user has confirmed account this.userConfirmedEvent.fire(new UserConfirmedAccountEvent(updatedUser)); + // Debug message + System.out.println(MessageFormat.format("{0}.confirmUserAccount: updatedUser={1}", this.getClass().getSimpleName(), updatedUser)); //NOI18N + // Set it again in helper this.beanHelper.setUser(updatedUser); + + // ... and copy it to the controller + this.beanHelper.copyUserToController(); + + // Trace message + System.out.println(MessageFormat.format("{0}.confirmUserAccount: EXIT!", this.getClass().getSimpleName())); //NOI18N } } diff --git a/src/java/org/mxchange/jjobs/beans/user/resendlink/JobsResendLinkWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/user/resendlink/JobsResendLinkWebSessionBean.java index 3cba8dcd..530698c7 100644 --- a/src/java/org/mxchange/jjobs/beans/user/resendlink/JobsResendLinkWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/resendlink/JobsResendLinkWebSessionBean.java @@ -36,8 +36,8 @@ 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.resendlink.ResendLinkSessionBeanRemote; import org.mxchange.jusercore.model.user.User; +import org.mxchange.jusercore.model.user.resendlink.ResendLinkSessionBeanRemote; import org.mxchange.jusercore.model.user.status.UserAccountStatus; /** @@ -134,12 +134,15 @@ public class JobsResendLinkWebSessionBean extends BaseJobsController implements throw new NullPointerException("user.userConfirmKey is null"); //NOI18N } + // Init managed user instance + User managedUser; + try { // Get base URL String baseUrl = FacesUtils.generateBaseUrl(); // Call EJB and return redirect target - this.resendLinkBean.resendConfirmationLink(user, this.localizationController.getLocale(), baseUrl); + managedUser = this.resendLinkBean.resendConfirmationLink(user, this.localizationController.getLocale(), baseUrl); } catch (final UserNotFoundException ex) { // User not found this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_NOT_FOUND"); //NOI18N @@ -150,12 +153,12 @@ public class JobsResendLinkWebSessionBean extends BaseJobsController implements return ""; //NOI18N } - // Fire event - this.userResendLinkEvent.fire(new UserResendLinkAccountEvent(user)); - // Clear this bean this.clear(); + // Fire event + this.userResendLinkEvent.fire(new UserResendLinkAccountEvent(managedUser)); + // Return redirect target return "user_resend_done"; //NOI18N } diff --git a/web/guest/user/user_confirm_account.xhtml b/web/guest/user/user_confirm_account.xhtml index aeb797b4..a49b6eaa 100644 --- a/web/guest/user/user_confirm_account.xhtml +++ b/web/guest/user/user_confirm_account.xhtml @@ -10,8 +10,8 @@ - - + + @@ -24,7 +24,7 @@ - +

@@ -47,7 +47,7 @@ - + -- 2.39.5