]> git.mxchange.org Git - addressbook-war.git/blobdiff - src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java
moved user instance to admin controller as this is the right one for this purpose
[addressbook-war.git] / src / java / org / mxchange / addressbook / beans / user / AddressbookUserWebSessionBean.java
index e6806af6ac109e2ad55a339b7606dd5b3488e28c..12d19b022d438bb6e8d22ca83192b77cbe590e79 100644 (file)
@@ -19,7 +19,6 @@ package org.mxchange.addressbook.beans.user;
 import java.text.MessageFormat;
 import java.util.Collections;
 import java.util.Date;
-import java.util.GregorianCalendar;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Objects;
@@ -32,6 +31,7 @@ import javax.inject.Named;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
+import org.mxchange.addressbook.beans.login.AddressbookUserLoginWebSessionController;
 import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jcontacts.contact.UserContact;
 import org.mxchange.jcontacts.contact.gender.Gender;
@@ -42,7 +42,7 @@ import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
-import org.mxchange.jphone.phonenumbers.smsprovider.SmsProvider;
+import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
 import org.mxchange.jusercore.exceptions.UserNotFoundException;
@@ -50,7 +50,6 @@ import org.mxchange.jusercore.model.user.LoginUser;
 import org.mxchange.jusercore.model.user.User;
 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
-import org.mxchange.addressbook.beans.login.AddressbookUserLoginWebSessionController;
 
 /**
  * A user bean (controller)
@@ -75,7 +74,7 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC
        /**
         * Cellphone number's carrier
         */
-       private SmsProvider cellphoneCarrier;
+       private MobileProvider cellphoneCarrier;
 
        /**
         * Cellphone number
@@ -257,19 +256,19 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC
                if (null == event) {
                        // Throw NPE
                        throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getUser() == null) {
+               } else if (event.getRegisteredUser() == null) {
                        // Throw NPE again
                        throw new NullPointerException("event.user is null"); //NOI18N
-               } else if (event.getUser().getUserId() == null) {
+               } else if (event.getRegisteredUser().getUserId() == null) {
                        // userId is null
                        throw new NullPointerException("event.user.userId is null"); //NOI18N
-               } else if (event.getUser().getUserId() < 1) {
+               } else if (event.getRegisteredUser().getUserId() < 1) {
                        // Not avalid id
-                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUser(), event.getUser().getUserId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
                }
 
                // Get user instance
-               User registeredUser = event.getUser();
+               User registeredUser = event.getRegisteredUser();
 
                // Debug message
                System.out.println(MessageFormat.format("UserWebBean:afterRegistration: registeredUser={0}", registeredUser)); //NOI18N
@@ -281,13 +280,13 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC
                this.addUserNameEmailAddress(registeredUser);
 
                // Clear all data
-               this.clearData();
+               this.clear();
 
                // Set user id again
                this.setUserId(registeredUser.getUserId());
 
                // Is the account public?
-               if (registeredUser.getUserProfileMode().equals(ProfileMode.PUBLIC)) {
+               if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
                        // Also add it to this list
                        this.visibleUserList.add(registeredUser);
                }
@@ -305,22 +304,22 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC
                if (null == event) {
                        // Throw NPE
                        throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getUser() == null) {
+               } else if (event.getLoggedInUser() == null) {
                        // Throw NPE again
                        throw new NullPointerException("event.user is null"); //NOI18N
-               } else if (event.getUser().getUserId() == null) {
+               } else if (event.getLoggedInUser().getUserId() == null) {
                        // userId is null
                        throw new NullPointerException("event.user.userId is null"); //NOI18N
-               } else if (event.getUser().getUserId() < 1) {
+               } else if (event.getLoggedInUser().getUserId() < 1) {
                        // Not avalid id
-                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUser(), event.getUser().getUserId())); //NOI18N
+                       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.getUser());
+               this.copyUser(event.getLoggedInUser());
 
                // Trace message
                System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: this.visibleUserList.size()={0} - EXIT!", this.visibleUserList.size())); //NOI18N
@@ -341,15 +340,16 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC
                assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
 
                // Create new user instance
-               User user = new LoginUser();
-               user.setUserName(this.getUserName());
-               user.setUserProfileMode(this.getUserProfileMode());
-               user.setUserCreated(new GregorianCalendar());
+               User localUser = new LoginUser();
+
+               // Update all data ...
+               localUser.setUserName(this.getUserName());
+               localUser.setUserProfileMode(this.getUserProfileMode());
 
                // Generate phone number
-               DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber(), new GregorianCalendar());
-               DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber(), new GregorianCalendar());
-               DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber(), new GregorianCalendar());
+               DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
+               DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
+               DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
 
                // Create new contact
                Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
@@ -403,7 +403,7 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC
                }
 
                // Is the provider set?
-               if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof SmsProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
+               if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
                        // Is the number set?
                        if (cellphone.getPhoneNumber() == null) {
                                // Is null
@@ -421,16 +421,16 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC
                contact.setContactComment(this.getComment());
 
                // Created timestamp and ownContact
-               contact.setContactCreated(new GregorianCalendar());
                contact.setContactOwnContact(Boolean.TRUE);
 
                // Set contact in user
-               user.setUserContact(contact);
+               localUser.setUserContact(contact);
 
                // Trace message
                //this.getLogger().logTrace(MessageFormat.format("createUserInstance: user={0} - EXIT!", user));
+
                // Return it
-               return user;
+               return localUser;
        }
 
        @Override
@@ -444,12 +444,12 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC
        }
 
        @Override
-       public SmsProvider getCellphoneCarrier () {
+       public MobileProvider getCellphoneCarrier () {
                return this.cellphoneCarrier;
        }
 
        @Override
-       public void setCellphoneCarrier (final SmsProvider cellphoneCarrier) {
+       public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
                this.cellphoneCarrier = cellphoneCarrier;
        }
 
@@ -730,32 +730,32 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC
        }
 
        @Override
-       public boolean isRequiredPersonalDataSet () {
-               return ((this.getUserName() != null) &&
-                               (this.getUserProfileMode() != null) &&
+       public boolean isRequiredChangePersonalDataSet () {
+               return ((this.getUserProfileMode() != null) &&
                                (this.getGender() != null) &&
                                (this.getFirstName() != null) &&
                                (this.getFamilyName() != null) &&
                                (this.getStreet() != null) &&
                                (this.getHouseNumber() != null) &&
                                (this.getZipCode() != null) &&
-                               (this.getCity() != null) &&
-                               (this.getEmailAddress() != null) &&
-                               (this.getEmailAddressRepeat() != null) &&
-                               (this.getUserPassword() != null) &&
-                               (this.getUserPasswordRepeat() != null));
+                               (this.getCity() != null));
        }
 
        @Override
-       public boolean isRequiredChangePersonalDataSet () {
-               return ((this.getUserProfileMode() != null) &&
+       public boolean isRequiredPersonalDataSet () {
+               return ((this.getUserName() != null) &&
+                               (this.getUserProfileMode() != null) &&
                                (this.getGender() != null) &&
                                (this.getFirstName() != null) &&
                                (this.getFamilyName() != null) &&
                                (this.getStreet() != null) &&
                                (this.getHouseNumber() != null) &&
                                (this.getZipCode() != null) &&
-                               (this.getCity() != null));
+                               (this.getCity() != null) &&
+                               (this.getEmailAddress() != null) &&
+                               (this.getEmailAddressRepeat() != null) &&
+                               (this.getUserPassword() != null) &&
+                               (this.getUserPasswordRepeat() != null));
        }
 
        @Override
@@ -765,7 +765,7 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC
 
        @Override
        public boolean isSamePasswordEntered () {
-               return (Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat()));
+               return ((!this.getUserPassword().isEmpty()) && (Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat())));
        }
 
        @Override
@@ -786,7 +786,10 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC
        @Override
        public User lookupUserById (final Long userId) throws UserNotFoundException {
                // Init variable
-               User user = null;
+               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();) {
@@ -796,19 +799,22 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC
                        // Is the user id found?
                        if (Objects.equals(next.getUserId(), userId)) {
                                // Copy to other variable
-                               user = next;
+                               localUser = next;
                                break;
                        }
                }
 
                // Is it still null?
-               if (null == user) {
+               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 user;
+               return localUser;
        }
 
        /**
@@ -835,9 +841,9 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC
        }
 
        /**
-        * Clears all data in this bean
+        * Clears this bean
         */
-       private void clearData () {
+       private void clear () {
                // Clear all data
                // - personal data
                this.setUserId(null);
@@ -896,7 +902,7 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC
                        this.setPhoneAreaCode(phone.getPhoneAreaCode());
                        this.setPhoneNumber(phone.getPhoneNumber());
                }
-               if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof SmsProvider)) {
+               if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) {
                        this.setCellphoneCarrier(cellphone.getCellphoneProvider());
                        this.setCellphoneNumber(cellphone.getPhoneNumber());
                }