]> git.mxchange.org Git - jjobs-war.git/blobdiff - src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java
Removed all clear() methods in request-scoped beans as it makes no sense to clear...
[jjobs-war.git] / src / java / org / mxchange / jjobs / beans / user / JobsUserWebSessionBean.java
index b82e653a34a854a4656d7401b110003ce2a4e2fb..ce980b3fcb72b96ee3f5730d6a8d7cf5534e1f6f 100644 (file)
@@ -18,7 +18,6 @@ package org.mxchange.jjobs.beans.user;
 
 import java.text.MessageFormat;
 import java.util.Collections;
-import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Objects;
@@ -32,17 +31,11 @@ import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import org.mxchange.jcontacts.contact.Contact;
-import org.mxchange.jcontacts.contact.UserContact;
-import org.mxchange.jcontacts.contact.gender.Gender;
-import org.mxchange.jcountry.data.Country;
+import org.mxchange.jjobs.beans.contact.JobsContactWebSessionController;
 import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
-import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
 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.mobileprovider.MobileProvider;
 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
 import org.mxchange.jusercore.exceptions.UserNotFoundException;
@@ -67,84 +60,10 @@ public class JobsUserWebSessionBean implements JobsUserWebSessionController {
        private static final long serialVersionUID = 542_145_347_916L;
 
        /**
-        * Birth day
+        * General contact controller
         */
-       private Date birthday;
-
-       /**
-        * Cellphone number's carrier
-        */
-       private MobileProvider cellphoneCarrier;
-
-       /**
-        * Cellphone number
-        */
-       private Long cellphoneNumber;
-
-       /**
-        * City
-        */
-       private String city;
-
-       /**
-        * Optional comments
-        */
-       private String comment;
-
-       /**
-        * Country instance
-        */
-       private Country country;
-
-       /**
-        * Email address
-        */
-       private String emailAddress;
-
-       /**
-        * Email address list
-        */
-       private List<String> emailAddressList;
-
-       /**
-        * Email address repeated
-        */
-       private String emailAddressRepeat;
-
-       /**
-        * Family name
-        */
-       private String familyName;
-
-       /**
-        * Fax number's area code
-        */
-       private Integer faxAreaCode;
-
-       /**
-        * Country instance for fax number
-        */
-       private Country faxCountry;
-
-       /**
-        * Fax number
-        */
-       private Long faxNumber;
-
-       /**
-        * First name
-        */
-       private String firstName;
-
-       /**
-        * Gender instance
-        */
-       private Gender gender;
-
-       /**
-        * House number
-        */
-       private Short houseNumber;
+       @Inject
+       private JobsContactWebSessionController contactController;
 
        /**
         * Login bean (controller)
@@ -152,26 +71,6 @@ public class JobsUserWebSessionBean implements JobsUserWebSessionController {
        @Inject
        private JobsUserLoginWebSessionController loginController;
 
-       /**
-        * Phone number area code
-        */
-       private Integer phoneAreaCode;
-
-       /**
-        * Country instance for phone number
-        */
-       private Country phoneCountry;
-
-       /**
-        * Phone number
-        */
-       private Long phoneNumber;
-
-       /**
-        * Street
-        */
-       private String street;
-
        /**
         * Remote user bean
         */
@@ -212,18 +111,10 @@ public class JobsUserWebSessionBean implements JobsUserWebSessionController {
         */
        private List<User> visibleUserList;
 
-       /**
-        * ZIP code
-        */
-       private Integer zipCode;
-
        /**
         * Default constructor
         */
        public JobsUserWebSessionBean () {
-               // Set gender to UNKNOWN
-               this.gender = Gender.UNKNOWN;
-
                // Try it
                try {
                        // Get initial context
@@ -336,89 +227,14 @@ public class JobsUserWebSessionBean implements JobsUserWebSessionController {
                localUser.setUserName(this.getUserName());
                localUser.setUserProfileMode(this.getUserProfileMode());
 
-               // Generate phone number
-               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());
-               contact.setContactStreet(this.getStreet());
-               contact.setContactHouseNumber(this.getHouseNumber());
-               contact.setContactZipCode(this.getZipCode());
-               contact.setContactCity(this.getCity());
-               contact.setContactCountry(this.getCountry());
-               contact.setContactEmailAddress(this.getEmailAddress());
-
-               // Don't set null or wrong references
-               if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
-                       // Now the number must be given
-                       if (phone.getPhoneAreaCode() == null) {
-                               // Is null
-                               throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
-                       } else if (phone.getPhoneAreaCode() < 1) {
-                               // Abort here
-                               throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
-                       } else if (phone.getPhoneNumber() == null) {
-                               // Is null
-                               throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
-                       } else if (phone.getPhoneNumber() < 1) {
-                               // Abort here
-                               throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
-                       }
-
-                       // Set phone number
-                       contact.setContactLandLineNumber(phone);
-               }
-
-               // Don't set null or wrong references
-               if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
-                       // Now the number must be given
-                       if (fax.getPhoneAreaCode() == null) {
-                               // Is null
-                               throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
-                       } else if (fax.getPhoneAreaCode() < 1) {
-                               // Abort here
-                               throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
-                       } else if (fax.getPhoneNumber() == null) {
-                               // Is null
-                               throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
-                       } else if (fax.getPhoneNumber() < 1) {
-                               // Abort here
-                               throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
-                       }
-
-                       // Set fax number
-                       contact.setContactFaxNumber(fax);
-               }
-
-               // Is the provider set?
-               if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
-                       // Is the number set?
-                       if (cellphone.getPhoneNumber() == null) {
-                               // Is null
-                               throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
-                       } else if (cellphone.getPhoneNumber() < 1) {
-                               // Abort here
-                               throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
-                       }
-
-                       // Set cellphone number
-                       contact.setContactCellphoneNumber(cellphone);
-               }
-
-               contact.setContactBirthday(this.getBirthday());
-               contact.setContactComment(this.getComment());
-
-               // Created timestamp and ownContact
-               contact.setContactOwnContact(Boolean.TRUE);
+               // Create contact instance
+               Contact contact = this.contactController.createContactInstance();
 
                // Set contact in user
                localUser.setUserContact(contact);
 
                // Trace message
                //this.getLogger().logTrace(MessageFormat.format("createUserInstance: user={0} - EXIT!", user));
-
                // Return it
                return localUser;
        }
@@ -440,6 +256,9 @@ public class JobsUserWebSessionBean implements JobsUserWebSessionController {
                // Get user instance
                User user = this.loginController.getLoggedInUser();
 
+               // Copy contact data to contact instance
+               this.contactController.updateContactDataFromController(user.getUserContact());
+
                // It should be there, so run some tests on it
                assert (user instanceof User) : "Instance loginController.loggedInUser is null";
                assert (user.getUserId() instanceof Long) : "Instance loginController.loggedInUser.userId is null";
@@ -450,240 +269,12 @@ public class JobsUserWebSessionBean implements JobsUserWebSessionController {
 
                // Update all fields
                user.setUserProfileMode(this.getUserProfileMode());
-               user.getUserContact().setContactGender(this.getGender());
-               user.getUserContact().setContactFirstName(this.getFirstName());
-               user.getUserContact().setContactFamilyName(this.getFamilyName());
-               user.getUserContact().setContactStreet(this.getStreet());
-               user.getUserContact().setContactHouseNumber(this.getHouseNumber());
-               user.getUserContact().setContactZipCode(this.getZipCode());
-               user.getUserContact().setContactCity(this.getCity());
-               user.getUserContact().setContactCountry(this.getCountry());
-
-               // Is there a phone number?
-               if (user.getUserContact().getContactLandLineNumber() instanceof DialableLandLineNumber) {
-                       // Debug message
-                       System.out.println(MessageFormat.format("UserWebBean:doChangePersonalData: phoneId={0}", user.getUserContact().getContactLandLineNumber().getPhoneId())); //NOI18N
-
-                       // Yes, then update as well
-                       user.getUserContact().getContactLandLineNumber().setPhoneAreaCode(this.getPhoneAreaCode());
-                       user.getUserContact().getContactLandLineNumber().setPhoneNumber(this.getPhoneNumber());
-               }
-
-               // Is there a fax number?
-               if (user.getUserContact().getContactFaxNumber() instanceof DialableFaxNumber) {
-                       // Debug message
-                       System.out.println(MessageFormat.format("UserWebBean:doChangePersonalData: faxId={0}", user.getUserContact().getContactFaxNumber().getPhoneId())); //NOI18N
-
-                       // Yes, then update as well
-                       user.getUserContact().getContactFaxNumber().setPhoneAreaCode(this.getFaxAreaCode());
-                       user.getUserContact().getContactFaxNumber().setPhoneNumber(this.getFaxNumber());
-               }
-
-               // Is there a cellphone number?
-               if (user.getUserContact().getContactCellphoneNumber() instanceof DialableCellphoneNumber) {
-                       // Debug message
-                       System.out.println(MessageFormat.format("UserWebBean:doChangePersonalData: cellPhoneId={0}", user.getUserContact().getContactCellphoneNumber().getPhoneId())); //NOI18N
-
-                       // Yes, then update as well
-                       user.getUserContact().getContactCellphoneNumber().setCellphoneProvider(this.getCellphoneCarrier());
-                       user.getUserContact().getContactCellphoneNumber().setPhoneNumber(this.getCellphoneNumber());
-               }
 
                // Send it to the EJB
                this.userBean.updateUserPersonalData(user);
 
                // All fine
-               return "login_data_saved"; //NOI18N
-       }
-
-       @Override
-       public Date getBirthday () {
-               return this.birthday;
-       }
-
-       @Override
-       public void setBirthday (final Date birthday) {
-               this.birthday = birthday;
-       }
-
-       @Override
-       public MobileProvider getCellphoneCarrier () {
-               return this.cellphoneCarrier;
-       }
-
-       @Override
-       public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
-               this.cellphoneCarrier = cellphoneCarrier;
-       }
-
-       @Override
-       public Long getCellphoneNumber () {
-               return this.cellphoneNumber;
-       }
-
-       @Override
-       public void setCellphoneNumber (Long cellphoneNumber) {
-               this.cellphoneNumber = cellphoneNumber;
-       }
-
-       @Override
-       public String getCity () {
-               return this.city;
-       }
-
-       @Override
-       public void setCity (final String city) {
-               this.city = city;
-       }
-
-       @Override
-       public String getComment () {
-               return this.comment;
-       }
-
-       @Override
-       public void setComment (final String comment) {
-               this.comment = comment;
-       }
-
-       @Override
-       public Country getCountry () {
-               return this.country;
-       }
-
-       @Override
-       public void setCountry (final Country country) {
-               this.country = country;
-       }
-
-       @Override
-       public String getEmailAddress () {
-               return this.emailAddress;
-       }
-
-       @Override
-       public void setEmailAddress (final String emailAddress) {
-               this.emailAddress = emailAddress;
-       }
-
-       @Override
-       public String getEmailAddressRepeat () {
-               return this.emailAddressRepeat;
-       }
-
-       @Override
-       public void setEmailAddressRepeat (final String emailAddressRepeat) {
-               this.emailAddressRepeat = emailAddressRepeat;
-       }
-
-       @Override
-       public String getFamilyName () {
-               return this.familyName;
-       }
-
-       @Override
-       public void setFamilyName (final String familyName) {
-               this.familyName = familyName;
-       }
-
-       @Override
-       public Integer getFaxAreaCode () {
-               return this.faxAreaCode;
-       }
-
-       @Override
-       public void setFaxAreaCode (final Integer faxAreaCode) {
-               this.faxAreaCode = faxAreaCode;
-       }
-
-       @Override
-       public Country getFaxCountry () {
-               return this.faxCountry;
-       }
-
-       @Override
-       public void setFaxCountry (final Country faxCountry) {
-               this.faxCountry = faxCountry;
-       }
-
-       @Override
-       public Long getFaxNumber () {
-               return this.faxNumber;
-       }
-
-       @Override
-       public void setFaxNumber (final Long faxNumber) {
-               this.faxNumber = faxNumber;
-       }
-
-       @Override
-       public String getFirstName () {
-               return this.firstName;
-       }
-
-       @Override
-       public void setFirstName (final String firstName) {
-               this.firstName = firstName;
-       }
-
-       @Override
-       public Gender getGender () {
-               return this.gender;
-       }
-
-       @Override
-       public void setGender (final Gender gender) {
-               this.gender = gender;
-       }
-
-       @Override
-       public Short getHouseNumber () {
-               return this.houseNumber;
-       }
-
-       @Override
-       public void setHouseNumber (final Short houseNumber) {
-               this.houseNumber = houseNumber;
-       }
-
-       @Override
-       public Integer getPhoneAreaCode () {
-               return this.phoneAreaCode;
-       }
-
-       @Override
-       public void setPhoneAreaCode (final Integer phoneAreaCode) {
-               this.phoneAreaCode = phoneAreaCode;
-       }
-
-       @Override
-       public Country getPhoneCountry () {
-               return this.phoneCountry;
-       }
-
-       @Override
-       public void setPhoneCountry (final Country phoneCountry) {
-               this.phoneCountry = phoneCountry;
-       }
-
-       @Override
-       public Long getPhoneNumber () {
-               return this.phoneNumber;
-       }
-
-       @Override
-       public void setPhoneNumber (final Long phoneNumber) {
-               this.phoneNumber = phoneNumber;
-       }
-
-       @Override
-       public String getStreet () {
-               return this.street;
-       }
-
-       @Override
-       public void setStreet (final String street) {
-               this.street = street;
+               return "user_data_saved"; //NOI18N
        }
 
        @Override
@@ -736,16 +327,6 @@ public class JobsUserWebSessionBean implements JobsUserWebSessionController {
                this.userProfileMode = userProfileMode;
        }
 
-       @Override
-       public Integer getZipCode () {
-               return this.zipCode;
-       }
-
-       @Override
-       public void setZipCode (final Integer zipCode) {
-               this.zipCode = zipCode;
-       }
-
        /**
         * Post-initialization of this class
         */
@@ -754,9 +335,6 @@ public class JobsUserWebSessionBean implements JobsUserWebSessionController {
                // Get full user name list for reducing EJB calls
                this.userNameList = this.userBean.getUserNameList();
 
-               // Get full email address list for reducing EJB calls
-               this.emailAddressList = this.userBean.getEmailAddressList();
-
                // Is the user logged-in?
                if (this.loginController.isUserLoggedIn()) {
                        // Is logged-in, so load also users visible to memebers
@@ -767,45 +345,21 @@ public class JobsUserWebSessionBean implements JobsUserWebSessionController {
                }
        }
 
-       @Override
-       public boolean isEmailAddressRegistered (final User user) {
-               return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(user.getUserContact().getContactEmailAddress())));
-       }
-
        @Override
        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.contactController.isRequiredChangePersonalDataSet()));
        }
 
        @Override
        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.getEmailAddress() != null) &&
-                               (this.getEmailAddressRepeat() != null) &&
+                               (this.contactController.isRequiredPersonalDataSet()) &&
                                (this.getUserPassword() != null) &&
                                (this.getUserPasswordRepeat() != null));
        }
 
-       @Override
-       public boolean isSameEmailAddressEntered () {
-               return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
-       }
-
        @Override
        public boolean isSamePasswordEntered () {
                return ((!this.getUserPassword().isEmpty()) && (Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat())));
@@ -871,7 +425,7 @@ public class JobsUserWebSessionBean implements JobsUserWebSessionController {
                if (this.userNameList.contains(user.getUserName())) {
                        // Abort here
                        throw new IllegalArgumentException(MessageFormat.format("User name {0} already added.", user.getUserName())); //NOI18N
-               } else if (this.emailAddressList.contains(user.getUserContact().getContactEmailAddress())) {
+               } else if (this.contactController.isEmailAddressRegistered(user.getUserContact())) {
                        // Already added
                        throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", user.getUserContact().getContactEmailAddress())); //NOI18N
                }
@@ -880,7 +434,7 @@ public class JobsUserWebSessionBean implements JobsUserWebSessionController {
                this.userNameList.add(user.getUserName());
 
                // Add email addres
-               this.emailAddressList.add(user.getUserContact().getContactEmailAddress());
+               this.contactController.addEmailAddress(user.getUserContact().getContactEmailAddress());
        }
 
        /**
@@ -890,26 +444,9 @@ public class JobsUserWebSessionBean implements JobsUserWebSessionController {
                // Clear all data
                // - personal data
                this.setUserId(null);
-               this.setGender(Gender.UNKNOWN);
                this.setUserProfileMode(null);
-               this.setFirstName(null);
-               this.setFamilyName(null);
-               this.setStreet(null);
-               this.setHouseNumber(null);
-               this.setZipCode(null);
-               this.setCity(null);
-               this.setCountry(null);
-
-               // - contact data
-               this.setEmailAddress(null);
-               this.setEmailAddressRepeat(null);
-               this.setPhoneAreaCode(null);
-               this.setCellphoneCarrier(null);
-               this.setFaxAreaCode(null);
 
                // - other data
-               this.setBirthday(null);
-               this.setComment(null);
                this.setUserName(null);
                this.setUserPassword(null);
                this.setUserPasswordRepeat(null);
@@ -925,39 +462,10 @@ public class JobsUserWebSessionBean implements JobsUserWebSessionController {
                // - base data
                this.setUserId(user.getUserId());
                this.setUserProfileMode(user.getUserProfileMode());
-               this.setGender(user.getUserContact().getContactGender());
-               this.setFirstName(user.getUserContact().getContactFirstName());
-               this.setFamilyName(user.getUserContact().getContactFamilyName());
-               this.setStreet(user.getUserContact().getContactStreet());
-               this.setHouseNumber(user.getUserContact().getContactHouseNumber());
-               this.setZipCode(user.getUserContact().getContactZipCode());
-               this.setCity(user.getUserContact().getContactCity());
-               this.setCountry(user.getUserContact().getContactCountry());
 
                // Get cellphone, phone and fax instance
                DialableCellphoneNumber cellphone = user.getUserContact().getContactCellphoneNumber();
                DialableFaxNumber fax = user.getUserContact().getContactFaxNumber();
                DialableLandLineNumber phone = user.getUserContact().getContactLandLineNumber();
-
-               // - contact data
-               if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
-                       this.setPhoneCountry(phone.getPhoneCountry());
-                       this.setPhoneAreaCode(phone.getPhoneAreaCode());
-                       this.setPhoneNumber(phone.getPhoneNumber());
-               }
-               if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) {
-                       this.setCellphoneCarrier(cellphone.getCellphoneProvider());
-                       this.setCellphoneNumber(cellphone.getPhoneNumber());
-               }
-               if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
-                       this.setFaxCountry(fax.getPhoneCountry());
-                       this.setFaxAreaCode(fax.getPhoneAreaCode());
-                       this.setFaxNumber(fax.getPhoneNumber());
-               }
-               this.setEmailAddress(user.getUserContact().getContactEmailAddress());
-
-               // -- other data
-               this.setBirthday(user.getUserContact().getContactBirthday());
-               this.setComment(user.getUserContact().getContactComment());
        }
 }