From 91e2bfb768f313324c0b64169ea9118759a14176 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 10 Jun 2016 12:03:45 +0200 Subject: [PATCH] New "feature" controller introduced: (please cherry-pick this) - no more tons of separate and same-looking methods, just one central and very flexible method isFeatureEnabled() - renamed all context parameters - added features "imprint", "terms" and "privacy" MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../PizzaAdminContactWebRequestBean.java | 11 +++ .../contact/PizzaContactWebSessionBean.java | 42 +++++++++++- .../PizzaContactWebSessionController.java | 24 +++++++ .../PizzaEmailChangeWebSessionBean.java | 10 +++ ...PizzaFeaturesWebApplicationController.java | 39 +++++++++++ .../login/PizzaUserLoginWebSessionBean.java | 5 -- .../PizzaUserLoginWebSessionController.java | 8 +-- .../PizzaUserRegisterWebSessionBean.java | 48 ++++++------- ...PizzaUserRegisterWebSessionController.java | 14 ---- .../beans/user/PizzaUserWebSessionBean.java | 31 +++------ .../generic/gender_selection_box.tpl | 2 +- web/WEB-INF/templates/guest/guest_base.tpl | 4 +- web/WEB-INF/templates/guest/guest_footer.tpl | 32 +++++---- web/WEB-INF/templates/guest/guest_menu.tpl | 14 ++-- .../register/guest_form_register_page1.tpl | 4 +- .../register/guest_form_register_single.tpl | 4 +- .../templates/login/user/user_menu.tpl | 26 ++++--- web/WEB-INF/web.xml | 68 ++++++++++++++++--- web/admin/user/admin_user_export.xhtml | 2 +- web/admin/user/admin_user_show.xhtml | 2 +- web/customer/empty_basket.xhtml | 6 +- web/guest/user/login.xhtml | 23 ++++--- web/guest/user/lost_passwd.xhtml | 4 +- web/guest/user/register.xhtml | 34 ++++++---- web/guest/user/register_page2.xhtml | 6 +- web/guest/user/user_list.xhtml | 37 +++++----- web/imprint.xhtml | 4 +- web/privacy.xhtml | 4 +- web/terms.xhtml | 4 +- web/user/login_change_email_address.xhtml | 64 +++++++++-------- web/user/login_change_password.xhtml | 28 +++++--- web/user/login_change_personal_data.xhtml | 40 ++++++----- web/user/login_contact_data_saved.xhtml | 11 ++- 33 files changed, 418 insertions(+), 237 deletions(-) create mode 100644 src/java/org/mxchange/pizzaapplication/beans/features/PizzaFeaturesWebApplicationController.java diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java index 8d1552c4..492105b4 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java @@ -596,6 +596,17 @@ public class PizzaAdminContactWebRequestBean extends BasePizzaController impleme this.contactId = contactId; } + @Override + public String getControllerType () { + return "admin"; //NOI18N + } + + @Override + @Deprecated + public void setControllerType (final String controllerType) { + throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N + } + @Override public Country getCountry () { return this.country; diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java index 5d6be6d9..eb3df7bd 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java @@ -230,6 +230,9 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P @Override public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) { + // Trace message + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("contactController.afterAdminAddedContact(): event={0} - CALLED!", event)); //NOI18N + // The event must be valid if (null == event) { // Throw NPE @@ -255,6 +258,20 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P @Override public void afterAdminAddedCustomer (@Observes final AdminAddedCustomerEvent event) { // The event must be valid + + // Call other method + this.selectableContacts.add(event.getAddedContact()); + + // Trace message + //* NOISY-DEBUG: */ System.out.println("contactController.afterAdminAddedContact(): EXIT!"); //NOI18N + } + + @Override + public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) { + // Trace message + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("contactController.afterAdminAddedUserEvent(): event={0} - CALLED!", event)); //NOI18N + + // event should not be null if (null == event) { // Throw NPE throw new NullPointerException("event is null"); //NOI18N @@ -274,6 +291,9 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P // Call other method this.contactList.add(event.getAddedCustomer().getCustomerContact()); + + // Trace message + //* NOISY-DEBUG: */ System.out.println("contactController.afterAdminAddedUserEvent(): EXIT!"); //NOI18N } @Override @@ -300,13 +320,13 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P this.clear(); // Trace message - //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminAddedUserEvent: EXIT!"); //NOI18N + //* NOISY-DEBUG: */ System.out.println("contactController.afterAdminAddedUserEvent(): EXIT!"); //NOI18N } @Override public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) { // Trace message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("contactController.afterAdminUpdatedContactDataEvent(): event={0} - CALLED!", event)); //NOI18N // event should not be null if (null == event) { @@ -347,6 +367,9 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P // Add email address to list this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress()); + + // Trace message + //* NOISY-DEBUG: */ System.out.println("contactController.afterAdminUpdatedContactDataEvent(): EXIT!"); //NOI18N } @Override @@ -374,7 +397,6 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P // Debug message //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: registeredContact={0}", registeredContact)); //NOI18N - // Copy all data from registered->user this.copyContact(registeredContact); @@ -429,6 +451,9 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P // Add contact to list this.contactList.add(contact); + + // Trace message + //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterAdminUpdatedContactDataEvent: EXIT!"); //NOI18N } @Override @@ -662,6 +687,17 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P this.comment = comment; } + @Override + public String getControllerType () { + return "general"; //NOI18N + } + + @Override + @Deprecated + public void setControllerType (final String controllerType) { + throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N + } + @Override public Country getCountry () { return this.country; diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionController.java index ddb6a55f..fd767813 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionController.java @@ -430,6 +430,22 @@ public interface PizzaContactWebSessionController extends Serializable { */ void setZipCode (final Integer zipCode); + /** + * Getter for controller type + *

+ * @return controller type + */ + String getControllerType (); + + /** + * Setter for controller type + *

+ * @param controllerType Controller type + * @deprecated Don't use this method. + */ + @Deprecated + void setControllerType (final String controllerType); + /** * Checks whether contact instance's email address is used *

@@ -468,4 +484,12 @@ public interface PizzaContactWebSessionController extends Serializable { */ String doChangePersonalContactData (); + /** + * Returns a list of all selectable contacts for user creation. Contacts + * from already existing users are excluded in this list. + *

+ * @return A list of all selectable contacts + */ + List selectableContacts (); + } diff --git a/src/java/org/mxchange/pizzaapplication/beans/email_address/PizzaEmailChangeWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/email_address/PizzaEmailChangeWebSessionBean.java index a783581a..a72fbd55 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/email_address/PizzaEmailChangeWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/email_address/PizzaEmailChangeWebSessionBean.java @@ -34,6 +34,7 @@ import org.mxchange.jusercore.model.email_address.EmailAddressChange; import org.mxchange.jusercore.model.email_address.EmailChangeSessionBeanRemote; import org.mxchange.jusercore.model.user.User; import org.mxchange.pizzaapplication.beans.BasePizzaController; +import org.mxchange.pizzaapplication.beans.features.PizzaFeaturesWebApplicationController; import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController; /** @@ -70,6 +71,12 @@ public class PizzaEmailChangeWebSessionBean extends BasePizzaController implemen */ private final EmailChangeSessionBeanRemote emailBean; + /** + * Features controller + */ + @Inject + private PizzaFeaturesWebApplicationController featureController; + /** * Login bean (controller) */ @@ -112,6 +119,9 @@ public class PizzaEmailChangeWebSessionBean extends BasePizzaController implemen // Password not matching this.showFacesMessage("login_change_email_address_form:currentPassword", new UserPasswordMismatchException(this.loginController.getLoggedInUser())); //NOI18N return ""; //NOI18N + } else if (!this.featureController.isFeatureEnabled("edit_user_data")) { //NOI18N + // Editing is not allowed + throw new IllegalStateException("User tried to edit personal data"); //NOI18N } // Get user instance diff --git a/src/java/org/mxchange/pizzaapplication/beans/features/PizzaFeaturesWebApplicationController.java b/src/java/org/mxchange/pizzaapplication/beans/features/PizzaFeaturesWebApplicationController.java new file mode 100644 index 00000000..05892d05 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/features/PizzaFeaturesWebApplicationController.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2016 Cho-Time GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.features; + +import java.io.Serializable; +import javax.ejb.Local; + +/** + * An interface for country beans + *

+ * @author Roland Haeder + */ +@Local +public interface PizzaFeaturesWebApplicationController extends Serializable { + + /** + * Checks if given feature is enabled. + *

+ * @param feature Feature to be checked + *

+ * @return Whether given feature is enabled + */ + boolean isFeatureEnabled (final String feature); + +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionBean.java index d11bf289..f3df1d72 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionBean.java @@ -220,11 +220,6 @@ public class PizzaUserLoginWebSessionBean extends BasePizzaController implements return UserUtils.ifPasswordMatches(container, this.getLoggedInUser()); } - @Override - public boolean isGuest () { - return (!this.isUserLoggedIn()); - } - @Override public boolean isInvisible () { // Check on login diff --git a/src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionController.java index f7ff6415..6164051a 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionController.java @@ -68,13 +68,6 @@ public interface PizzaUserLoginWebSessionController extends Serializable { */ boolean isUserLoggedIn (); - /** - * Is this truly a guest? - *

- * @return Whether the user is truly a guest - */ - boolean isGuest (); - /** * Whether the currently logged-in user is invisible *

@@ -103,4 +96,5 @@ public interface PizzaUserLoginWebSessionController extends Serializable { * @return If current password matches */ boolean ifCurrentPasswordMatches (); + } diff --git a/src/java/org/mxchange/pizzaapplication/beans/register/PizzaUserRegisterWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/register/PizzaUserRegisterWebSessionBean.java index 72cf1eb5..748ad89e 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/register/PizzaUserRegisterWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/register/PizzaUserRegisterWebSessionBean.java @@ -20,7 +20,6 @@ import java.text.MessageFormat; import javax.enterprise.context.SessionScoped; import javax.enterprise.event.Event; import javax.enterprise.inject.Any; -import javax.faces.context.FacesContext; import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; import javax.inject.Named; @@ -41,6 +40,7 @@ import org.mxchange.jusercore.model.user.UserUtils; import org.mxchange.jusercore.model.user.status.UserAccountStatus; import org.mxchange.pizzaapplication.beans.BasePizzaController; import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController; +import org.mxchange.pizzaapplication.beans.features.PizzaFeaturesWebApplicationController; import org.mxchange.pizzaapplication.beans.user.PizzaAdminUserWebRequestController; import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController; @@ -70,6 +70,12 @@ public class PizzaUserRegisterWebSessionBean extends BasePizzaController impleme @Inject private PizzaContactWebSessionController contactController; + /** + * Features controller + */ + @Inject + private PizzaFeaturesWebApplicationController featureController; + /** * Reemote register session bean */ @@ -106,6 +112,12 @@ public class PizzaUserRegisterWebSessionBean extends BasePizzaController impleme @Override public String doFinishRegistration () { + // Is registration enabled? + if (!this.featureController.isFeatureEnabled("user_registration")) { //NOI18N + // Is not enabled + throw new FaceletException("Registration is disabled."); //NOI18N + } + // Get user instance User user = this.userController.createUserInstance(); @@ -116,7 +128,7 @@ public class PizzaUserRegisterWebSessionBean extends BasePizzaController impleme } else if (!this.userController.isRequiredPersonalDataSet()) { // Not all required fields are set throw new FaceletException("Not all required fields are set."); //NOI18N - } else if ((this.userController.isUserNameRequired()) && (this.userController.isUserNameRegistered(user))) { + } else if ((this.featureController.isFeatureEnabled("user_name_required")) && (this.userController.isUserNameRegistered(user))) { //NOI18N // User name is already used throw new FaceletException(new UserNameAlreadyRegisteredException(user)); } else if (this.contactController.isEmailAddressRegistered(user.getUserContact())) { @@ -174,6 +186,12 @@ public class PizzaUserRegisterWebSessionBean extends BasePizzaController impleme @Override public String doRegisterMultiPage1 () { + // Is registration enabled? + if (!this.featureController.isFeatureEnabled("user_registration")) { //NOI18N + // Is not enabled + throw new FaceletException("Registration is disabled."); //NOI18N + } + // Get user instance User user = this.userController.createUserInstance(); @@ -181,7 +199,7 @@ public class PizzaUserRegisterWebSessionBean extends BasePizzaController impleme if (null == user) { // user must be set throw new NullPointerException("user is null after createUserInstance() was called"); //NOI18N - } else if ((this.userController.isUserNameRequired()) && (this.userController.isUserNameRegistered(user))) { + } else if ((this.featureController.isFeatureEnabled("user_name_required")) && (this.userController.isUserNameRegistered(user))) { //NOI18N // User name is already used throw new FaceletException(new UserNameAlreadyRegisteredException(user)); } else if (!this.contactController.isSameEmailAddressEntered()) { @@ -206,28 +224,4 @@ public class PizzaUserRegisterWebSessionBean extends BasePizzaController impleme return "register_page2"; //NOI18N } - @Override - public boolean isMultiplePageEnabled () { - // Get context parameter - String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_multi_register_page"); //NOI18N - - // Is it set? - boolean isEnabled = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N - - // Return value - return isEnabled; - } - - @Override - public boolean isResendConfirmationLinkEnabled () { - // Get context parameter - String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_resend_confirm_link_enabled"); //NOI18N - - // Is it set? - boolean isEnabled = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N - - // Return value - return isEnabled; - } - } diff --git a/src/java/org/mxchange/pizzaapplication/beans/register/PizzaUserRegisterWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/register/PizzaUserRegisterWebSessionController.java index fdd0d7bc..21e10684 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/register/PizzaUserRegisterWebSessionController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/register/PizzaUserRegisterWebSessionController.java @@ -42,18 +42,4 @@ public interface PizzaUserRegisterWebSessionController extends Serializable { */ String doRegisterMultiPage1 (); - /** - * Checks wether multi-page or single-page registration is active - *

- * @return Whether multi (true) or single page (false) is active - */ - boolean isMultiplePageEnabled (); - - /** - * Checks whether the "resend confirmation link" feature is enabled - *

- * @return Whether "resend confirmation link" is enabled - */ - boolean isResendConfirmationLinkEnabled (); - } diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java index e6f7f012..9f105bc4 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java @@ -53,9 +53,9 @@ import org.mxchange.jusercore.model.user.UserUtils; import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; import org.mxchange.pizzaapplication.beans.BasePizzaController; import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController; +import org.mxchange.pizzaapplication.beans.features.PizzaFeaturesWebApplicationController; import org.mxchange.pizzaapplication.beans.localization.PizzaLocalizationSessionController; import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController; -import org.mxchange.pizzaapplication.beans.register.PizzaUserRegisterWebSessionController; /** * A user bean (controller) @@ -83,28 +83,16 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz private PizzaContactWebSessionController contactController; /** - * Localization controller - */ - @Inject - private PizzaLocalizationSessionController localizationController; - - /** - * Login bean (controller) + * Features controller */ @Inject - private PizzaUserLoginWebSessionController loginController; + private PizzaFeaturesWebApplicationController featureController; /** - * Registration controller + * Localization controller */ @Inject - private PizzaUserRegisterWebSessionController - registerController; - - /** - * A list of all selectable contacts - */ - private List selectableContacts; + private PizzaLocalizationSessionController localizationController; /** * Event being fired when user updated personal data @@ -456,7 +444,7 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz user.setUserProfileMode(this.getUserProfileMode()); // Is multiple registration page - if (!this.registerController.isMultiplePageEnabled()) { + if ((createContactData) || (!this.featureController.isFeatureEnabled("user_register_multiple_page"))) { //NOI18N // Create contact instance Contact contact = this.contactController.createContactInstance(); @@ -512,7 +500,10 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz throw new FaceletException("Not all required fields are set."); //NOI18N } else if (!this.loginController.ifCurrentPasswordMatches()) { // Password not matching - throw new FaceletException(new UserPasswordMismatchException(this.loginController.getLoggedInUser())); + throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); + } else if (!this.featureController.isFeatureEnabled("edit_user_data")) { + // Editing is not allowed + throw new IllegalStateException("User tried to edit personal data"); //NOI18N } // Get user instance @@ -716,7 +707,7 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz @Override public boolean isRequiredPersonalDataSet () { - if (this.registerController.isMultiplePageEnabled()) { + if (this.featureController.isFeatureEnabled("user_register_multiple_page")) { //NOI18N // Multiple registration page return this.contactController.isRequiredPersonalDataSet(); } else { diff --git a/web/WEB-INF/templates/generic/gender_selection_box.tpl b/web/WEB-INF/templates/generic/gender_selection_box.tpl index 6134e37c..dfa9efcb 100644 --- a/web/WEB-INF/templates/generic/gender_selection_box.tpl +++ b/web/WEB-INF/templates/generic/gender_selection_box.tpl @@ -6,7 +6,7 @@ xmlns:ui="http://xmlns.jcp.org/jsf/facelets"> - + diff --git a/web/WEB-INF/templates/guest/guest_base.tpl b/web/WEB-INF/templates/guest/guest_base.tpl index 426b3b81..77ae70e9 100644 --- a/web/WEB-INF/templates/guest/guest_base.tpl +++ b/web/WEB-INF/templates/guest/guest_base.tpl @@ -9,7 +9,9 @@ - + + +