]> git.mxchange.org Git - addressbook-war.git/blobdiff - src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java
Continued with admin area:
[addressbook-war.git] / src / java / org / mxchange / addressbook / beans / user / AddressbookUserWebSessionBean.java
index e6806af6ac109e2ad55a339b7606dd5b3488e28c..4c2d87d93016161ccc5ee7050779ada2c44e2d71 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
@@ -183,6 +182,11 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC
         */
        private String street;
 
+       /**
+        * User instance
+        */
+       private User user;
+
        /**
         * Remote user bean
         */
@@ -281,7 +285,7 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC
                this.addUserNameEmailAddress(registeredUser);
 
                // Clear all data
-               this.clearData();
+               this.clear();
 
                // Set user id again
                this.setUserId(registeredUser.getUserId());
@@ -344,12 +348,11 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC
                User user = new LoginUser();
                user.setUserName(this.getUserName());
                user.setUserProfileMode(this.getUserProfileMode());
-               user.setUserCreated(new GregorianCalendar());
 
                // 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 +406,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,7 +424,6 @@ 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
@@ -444,12 +446,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;
        }
 
@@ -643,6 +645,16 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC
                this.street = street;
        }
 
+       @Override
+       public User getUser () {
+               return this.user;
+       }
+
+       @Override
+       public void setUser (final User user) {
+               this.user = user;
+       }
+
        @Override
        public Long getUserId () {
                return this.userId;
@@ -730,32 +742,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 +777,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 +798,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 +811,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 +853,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);
@@ -864,6 +882,9 @@ public class AddressbookUserWebSessionBean implements AddressbookUserWebSessionC
                this.setUserName(null);
                this.setUserPassword(null);
                this.setUserPasswordRepeat(null);
+
+               // - user instance
+               this.setUser(null);
        }
 
        /**
@@ -896,7 +917,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());
                }