From: Roland Häder Date: Tue, 3 May 2016 08:29:18 +0000 (+0200) Subject: Cleanups: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5be3f91081016da812711b2509c66fba9e133877;p=jfinancials-war.git Cleanups: - hasUsers/allUsers was redundant - moved isContactFound to admin user controller to avoid redundant lists, too Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/addressbook/beans/helper/AddressbookAdminWebRequestController.java b/src/java/org/mxchange/addressbook/beans/helper/AddressbookAdminWebRequestController.java index fb9cea97..fd0cfc10 100644 --- a/src/java/org/mxchange/addressbook/beans/helper/AddressbookAdminWebRequestController.java +++ b/src/java/org/mxchange/addressbook/beans/helper/AddressbookAdminWebRequestController.java @@ -46,6 +46,16 @@ public interface AddressbookAdminWebRequestController extends Serializable { */ void copyUserToController (); + /** + * Returns a message key depending on if this contact is a user and/or a + * contact. If this contact is unused, a default key is returned. + *

+ * @param contact Contact instance to check + *

+ * @return Message key + */ + String getContactUsageMessageKey (final Contact contact); + /** * Getter for contact instance *

diff --git a/src/java/org/mxchange/addressbook/beans/helper/AddressbookAdminWebRequestHelper.java b/src/java/org/mxchange/addressbook/beans/helper/AddressbookAdminWebRequestHelper.java index 6dbb3d90..b345b136 100644 --- a/src/java/org/mxchange/addressbook/beans/helper/AddressbookAdminWebRequestHelper.java +++ b/src/java/org/mxchange/addressbook/beans/helper/AddressbookAdminWebRequestHelper.java @@ -40,13 +40,13 @@ public class AddressbookAdminWebRequestHelper implements AddressbookAdminWebRequ private static final long serialVersionUID = 17_258_793_567_145_701L; /** - * Admin contact controller + * Administrative contact controller */ @Inject private AddressbookAdminContactWebRequestController adminContactController; /** - * Admin user controller + * Administrative user controller */ @Inject private AddressbookAdminUserWebRequestController adminUserController; @@ -70,7 +70,7 @@ public class AddressbookAdminWebRequestHelper implements AddressbookAdminWebRequ @Override public void copyContactToController () { // Log message - System.out.println("AdminHelper::copyContactToController - CALLED!"); //NOI18N + //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyContactToController - CALLED!"); //NOI18N // Validate user instance if (this.getContact() == null) { @@ -88,28 +88,31 @@ public class AddressbookAdminWebRequestHelper implements AddressbookAdminWebRequ this.adminContactController.copyContactToController(this.getContact()); // Log message - System.out.println("AdminHelper::copyContactToController - EXIT!"); //NOI18N + //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyContactToController - EXIT!"); //NOI18N } @Override public void copyUserToController () { + // Log message + //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyUserToController - CALLED!"); //NOI18N + // Validate user instance if (this.getUser() == null) { // Throw NPE - throw new NullPointerException("this.user is null"); + throw new NullPointerException("this.user is null"); //NOI18N } else if (this.getUser().getUserId() == null) { // Throw NPE again - throw new NullPointerException("this.user.userId is null"); + throw new NullPointerException("this.user.userId is null"); //NOI18N } else if (this.getUser().getUserId() < 1) { // Not valid - throw new IllegalStateException(MessageFormat.format("this.user.userId={0} is not valid.", this.getUser().getUserId())); + throw new IllegalStateException(MessageFormat.format("this.user.userId={0} is not valid.", this.getUser().getUserId())); //NOI18N } // Set all fields: user this.adminUserController.setUserName(this.getUser().getUserName()); // Log message - System.out.println("AdminHelper::copyUserToController - EXIT!"); //NOI18N + //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyUserToController - EXIT!"); //NOI18N } @Override @@ -122,6 +125,36 @@ public class AddressbookAdminWebRequestHelper implements AddressbookAdminWebRequ this.contact = contact; } + @Override + public String getContactUsageMessageKey (final Contact contact) { + // The contact must be valid + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // Throw again ... + throw new NullPointerException("contact.contactId is null"); //NOI18N + } else if (contact.getContactId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N + } + + // Default key is "unused" + String messageKey = "CONTACT_IS_UNUSED"; //NOI18N + + // Check user/customer + boolean isUserContact = this.adminUserController.isContactFound(contact); + + // Check user first + if (isUserContact) { + // Only user + messageKey = "CONTACT_IS_USER"; //NOI18N + } + + // Return message key + return messageKey; + } + @Override public User getUser () { return this.user; diff --git a/src/java/org/mxchange/addressbook/beans/profile/AddressbookUserProfileWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/profile/AddressbookUserProfileWebRequestBean.java index abedbba9..32dc4faf 100644 --- a/src/java/org/mxchange/addressbook/beans/profile/AddressbookUserProfileWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/profile/AddressbookUserProfileWebRequestBean.java @@ -22,7 +22,7 @@ import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; import javax.inject.Named; import org.mxchange.addressbook.beans.login.AddressbookUserLoginWebSessionController; -import org.mxchange.addressbook.beans.user.AddressbookUserWebSessionController; +import org.mxchange.addressbook.beans.user.AddressbookAdminUserWebRequestController; import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.model.user.User; import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; @@ -42,16 +42,16 @@ public class AddressbookUserProfileWebRequestBean implements AddressbookUserProf private static final long serialVersionUID = 187_687_145_286_710L; /** - * Login controller + * User controller */ @Inject - private AddressbookUserLoginWebSessionController loginController; + private AddressbookAdminUserWebRequestController adminUserController; /** - * User controller + * Login controller */ @Inject - private AddressbookUserWebSessionController userController; + private AddressbookUserLoginWebSessionController loginController; @Override public boolean isProfileLinkVisibleById (final Long userId) { @@ -60,7 +60,7 @@ public class AddressbookUserProfileWebRequestBean implements AddressbookUserProf try { // Try to get it - u = this.userController.lookupUserById(userId); + u = this.adminUserController.lookupUserById(userId); } catch (final UserNotFoundException ex) { // Throw again throw new FaceletException(ex); diff --git a/src/java/org/mxchange/addressbook/beans/register/AddressbookUserRegisterWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/register/AddressbookUserRegisterWebSessionBean.java index f6926f33..4a763495 100644 --- a/src/java/org/mxchange/addressbook/beans/register/AddressbookUserRegisterWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/register/AddressbookUserRegisterWebSessionBean.java @@ -111,7 +111,7 @@ public class AddressbookUserRegisterWebSessionBean implements AddressbookUserReg } 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.isUserNameRegistered(user)) { + } else if (this.adminUserController.isUserNameRegistered(user)) { // User name is already used throw new FaceletException(new UserNameAlreadyRegisteredException(user)); } else if (this.contactController.isEmailAddressRegistered(user.getUserContact())) { diff --git a/src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestController.java b/src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestController.java index 42bbe24f..7278e730 100644 --- a/src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestController.java +++ b/src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestController.java @@ -19,6 +19,8 @@ package org.mxchange.addressbook.beans.user; import java.io.Serializable; import java.util.List; import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jusercore.events.login.UserLoggedInEvent; +import org.mxchange.jusercore.events.registration.UserRegisteredEvent; import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent; import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.model.user.User; @@ -30,6 +32,20 @@ import org.mxchange.jusercore.model.user.User; */ public interface AddressbookAdminUserWebRequestController extends Serializable { + /** + * Event observer for new user registrations + *

+ * @param event User registration event + */ + void afterRegistrationEvent (final UserRegisteredEvent event); + + /** + * Event observer for logged-in user + *

+ * @param event Event instance + */ + void afterUserLogin (final UserLoggedInEvent event); + /** * Listens to fired event when user updated personal data *

diff --git a/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java index a51c7ab8..3ef2fc19 100644 --- a/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java @@ -17,9 +17,6 @@ package org.mxchange.addressbook.beans.user; import java.text.MessageFormat; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; import java.util.Objects; import javax.annotation.PostConstruct; import javax.enterprise.context.SessionScoped; @@ -42,7 +39,6 @@ import org.mxchange.jusercore.events.login.UserLoggedInEvent; import org.mxchange.jusercore.events.registration.UserRegisteredEvent; import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent; import org.mxchange.jusercore.events.user.update.UserUpdatedPersonalDataEvent; -import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.exceptions.UserPasswordMismatchException; import org.mxchange.jusercore.model.user.LoginUser; import org.mxchange.jusercore.model.user.User; @@ -97,11 +93,6 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC */ private String userName; - /** - * User name list - */ - private List userNameList; - /** * User password (unencrypted from web form) */ @@ -117,11 +108,6 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC */ private ProfileMode userProfileMode; - /** - * A list of all public user profiles - */ - private List visibleUserList; - /** * Default constructor */ @@ -168,21 +154,12 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC // Copy all data from registered->user this.copyUser(registeredUser); - // Add user name and email address - this.addUserNameEmailAddress(registeredUser); - // Clear all data this.clear(); // Set user id again this.setUserId(registeredUser.getUserId()); - // Is the account public? - if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) { - // Also add it to this list - this.visibleUserList.add(registeredUser); - } - // Trace message System.out.println("UserWebBean:afterRegistration: EXIT!"); //NOI18N } @@ -207,20 +184,10 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N } - // Re-initialize list - this.visibleUserList = this.userBean.allMemberPublicVisibleUsers(); - // Copy all data to this bean this.copyUser(event.getLoggedInUser()); // Trace message - System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: this.visibleUserList.size()={0} - EXIT!", this.visibleUserList.size())); //NOI18N - } - - @Override - public List allVisibleUsers () { - // Return it - return Collections.unmodifiableList(this.visibleUserList); } @Override @@ -346,17 +313,6 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC */ @PostConstruct public void init () { - // Get full user name list for reducing EJB calls - this.userNameList = this.userBean.getUserNameList(); - - // Is the user logged-in? - if (this.loginController.isUserLoggedIn()) { - // Is logged-in, so load also users visible to memebers - this.visibleUserList = this.userBean.allMemberPublicVisibleUsers(); - } else { - // Initialize user list - this.visibleUserList = this.userBean.allPublicUsers(); - } } @Override @@ -385,73 +341,6 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC return ((this.getUserId() == null) || (this.getUserId() == 0)); } - @Override - public boolean isUserNameRegistered (final User user) { - return ((this.userNameList instanceof List) && (this.userNameList.contains(user.getUserName()))); - } - - @Override - public boolean isVisibleUserFound () { - return ((this.visibleUserList instanceof List) && (this.visibleUserList.size() > 0)); - } - - @Override - public User lookupUserById (final Long userId) throws UserNotFoundException { - // Init variable - User localUser = null; - - // Clear this bean - this.clear(); - - // Try to lookup it in visible user list - for (final Iterator iterator = this.visibleUserList.iterator(); iterator.hasNext();) { - // Get next user - User next = iterator.next(); - - // Is the user id found? - if (Objects.equals(next.getUserId(), userId)) { - // Copy to other variable - localUser = next; - break; - } - } - - // Is it still null? - if (null == localUser) { - // Not visible for the current user - throw new UserNotFoundException(userId); - } - - // Copy all data to this bean - this.copyUser(localUser); - - // Return it - return localUser; - } - - /** - * Adds user's name and email address to bean's internal list. It also - * updates the public user list if the user has decided to ha } - *

- * @param user User instance - */ - private void addUserNameEmailAddress (final User user) { - // Make sure the entry is not added yet - if (this.userNameList.contains(user.getUserName())) { - // Abort here - throw new IllegalArgumentException(MessageFormat.format("User name {0} already added.", user.getUserName())); //NOI18N - } else if (this.contactController.isEmailAddressRegistered(user.getUserContact())) { - // Already added - throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", user.getUserContact().getContactEmailAddress())); //NOI18N - } - - // Add user name - this.userNameList.add(user.getUserName()); - - // Add email addres - this.contactController.addEmailAddress(user.getUserContact().getContactEmailAddress()); - } - /** * Clears this bean */ diff --git a/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionController.java b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionController.java index 414e8cee..3024ea2c 100644 --- a/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionController.java +++ b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionController.java @@ -17,10 +17,8 @@ package org.mxchange.addressbook.beans.user; import java.io.Serializable; -import java.util.List; import org.mxchange.jusercore.events.login.UserLoggedInEvent; import org.mxchange.jusercore.events.registration.UserRegisteredEvent; -import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.model.user.User; import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; @@ -36,18 +34,6 @@ public interface AddressbookUserWebSessionController extends Serializable { */ public static final Integer MINIMUM_PASSWORD_LENGTH = 5; - /** - * Tries to lookup user by given id number. If the user is not found or the - * account status is not CONFIRMED proper exceptions are thrown. - *

- * @param userId User id - *

- * @return User instance - *

- * @throws UserNotFoundException If the user is not found - */ - User lookupUserById (final Long userId) throws UserNotFoundException; - /** * Event observer for new user registrations *

@@ -62,13 +48,6 @@ public interface AddressbookUserWebSessionController extends Serializable { */ void afterUserLogin (final UserLoggedInEvent event); - /** - * All public user profiles - *

- * @return A list of all public user profiles - */ - List allVisibleUsers (); - /** * Creates an instance from all properties *

@@ -167,23 +146,6 @@ public interface AddressbookUserWebSessionController extends Serializable { */ boolean isSamePasswordEntered (); - /** - * Checks whether given user instance's name is used - *

- * @param user User instance's name to check - *

- * @return Whether it is already used - */ - boolean isUserNameRegistered (final User user); - - /** - * Checks whether a public user account is registered. This means that at - * least one user profile has its flag "public user profile" enabled. - *

- * @return Whether at least one user has a public profile - */ - boolean isVisibleUserFound (); - /** * Checks if the user id is empty *