]> git.mxchange.org Git - jfinancials-war.git/commitdiff
Cleanups:
authorRoland Häder <roland@mxchange.org>
Tue, 3 May 2016 08:29:18 +0000 (10:29 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 4 May 2016 18:56:32 +0000 (20:56 +0200)
- hasUsers/allUsers was redundant
- moved isContactFound to admin user controller to avoid redundant lists, too

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/addressbook/beans/helper/AddressbookAdminWebRequestController.java
src/java/org/mxchange/addressbook/beans/helper/AddressbookAdminWebRequestHelper.java
src/java/org/mxchange/addressbook/beans/profile/AddressbookUserProfileWebRequestBean.java
src/java/org/mxchange/addressbook/beans/register/AddressbookUserRegisterWebSessionBean.java
src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestController.java
src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java
src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionController.java

index fb9cea974b2ccfcced452fb2707b3620460e1a24..fd0cfc1037280dc2334f0ce326b5cdb142c218fd 100644 (file)
@@ -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.
+        * <p>
+        * @param contact Contact instance to check
+        * <p>
+        * @return Message key
+        */
+       String getContactUsageMessageKey (final Contact contact);
+
        /**
         * Getter for contact instance
         * <p>
index 6dbb3d90f8c764452fc1397a0a81edf73961c82b..b345b1367b5f3b74526429913d065bc98c321d26 100644 (file)
@@ -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;
index abedbba9e0ede5726cf15cabb0f17e10487dd02a..32dc4fafe2f6752dc7dca42d0f433c4c9c2ea6e2 100644 (file)
@@ -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);
index f6926f33a5177e66e5b072b484e963e1d8c20e09..4a763495946c6802d7aec4b537d9c45463f28f6d 100644 (file)
@@ -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())) {
index 42bbe24f6970dd3ed28b2446f7f49d0bf061f063..7278e7301217f8f855b18472f96c4cb59a60d8a7 100644 (file)
@@ -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
+        * <p>
+        * @param event User registration event
+        */
+       void afterRegistrationEvent (final UserRegisteredEvent event);
+
+       /**
+        * Event observer for logged-in user
+        * <p>
+        * @param event Event instance
+        */
+       void afterUserLogin (final UserLoggedInEvent event);
+
        /**
         * Listens to fired event when user updated personal data
         * <p>
index a51c7ab83a5d5d37b3cddc4ef90c7363e6e75213..3ef2fc19342ffcb57d40eedfd6df0defdbea2d06 100644 (file)
@@ -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<String> 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<User> 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<User> 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<User> 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   }
-        * <p>
-        * @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
         */
index 414e8ceea4a28933edfc0640dfac23795633a5bc..3024ea2c2c2f6f06ba6b3a2f0388c1368f41ba5e 100644 (file)
 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.
-        * <p>
-        * @param userId User id
-        * <p>
-        * @return User instance
-        * <p>
-        * @throws UserNotFoundException If the user is not found
-        */
-       User lookupUserById (final Long userId) throws UserNotFoundException;
-
        /**
         * Event observer for new user registrations
         * <p>
@@ -62,13 +48,6 @@ public interface AddressbookUserWebSessionController extends Serializable {
         */
        void afterUserLogin (final UserLoggedInEvent event);
 
-       /**
-        * All public user profiles
-        * <p>
-        * @return A list of all public user profiles
-        */
-       List<User> allVisibleUsers ();
-
        /**
         * Creates an instance from all properties
         * <p>
@@ -167,23 +146,6 @@ public interface AddressbookUserWebSessionController extends Serializable {
         */
        boolean isSamePasswordEntered ();
 
-       /**
-        * Checks whether given user instance's name is used
-        * <p>
-        * @param user User instance's name to check
-        * <p>
-        * @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.
-        * <p>
-        * @return Whether at least one user has a public profile
-        */
-       boolean isVisibleUserFound ();
-
        /**
         * Checks if the user id is empty
         * <p>