]> git.mxchange.org Git - juser-core.git/blobdiff - src/org/mxchange/jusercore/model/user/LoginUser.java
Continued:
[juser-core.git] / src / org / mxchange / jusercore / model / user / LoginUser.java
index df3e0203173c341bcc3658b14226bfb66fef3a7b..d6de5bf9a24a69c44f20abb5ddfc61aa31665f14 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 - 2018 Free Software Foundation
+ * Copyright (C) 2016 - 2022 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -39,6 +39,8 @@ import javax.persistence.TemporalType;
 import javax.persistence.Transient;
 import org.mxchange.jcontacts.model.contact.Contact;
 import org.mxchange.jcontacts.model.contact.UserContact;
+import org.mxchange.jcontacts.model.utils.ContactUtils;
+import org.mxchange.jcoreutils.Comparables;
 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
 
@@ -46,7 +48,6 @@ import org.mxchange.jusercore.model.user.status.UserAccountStatus;
  * A generic user entity class
  * <p>
  * @author Roland Häder<roland@mxchange.org>
- * @todo Remove AllUserNames after cleanup of deprecations in EJB/JSF
  */
 @Entity (name = "users")
 @Table (
@@ -54,12 +55,7 @@ import org.mxchange.jusercore.model.user.status.UserAccountStatus;
 )
 @NamedQueries (
                {
-                       @NamedQuery (name = "AllUserNames", query = "SELECT DISTINCT u.userName FROM users AS u ORDER BY u.userId ASC"),
-                       @NamedQuery (name = "SearchUserByName", query = "SELECT u FROM users AS u WHERE LOWER(u.userName) LIKE LOWER(:userName)"),
-                       @NamedQuery (name = "SearchUserByEmailAddress", query = "SELECT u FROM users AS u INNER JOIN contacts AS c ON u.userContact = c WHERE LOWER(c.contactEmailAddress) LIKE LOWER(:emailAddress)"),
-                       @NamedQuery (name = "SearchUserByConfirmKey", query = "SELECT u FROM users AS u WHERE u.userConfirmKey = :confirmKey"),
-                       @NamedQuery (name = "SearchAllUsersExcept", query = "SELECT u FROM users AS u WHERE u != :user ORDER BY u.userId ASC"),
-                       @NamedQuery (name = "AllUsers", query = "SELECT u FROM users AS u ORDER BY u.userId ASC"),
+                       @NamedQuery (name = "AllUsers", query = "SELECT u FROM users AS u ORDER BY u.userId ASC")
                }
 )
 @SuppressWarnings ("PersistenceUnitPresent")
@@ -93,19 +89,26 @@ public class LoginUser implements User {
        private Contact userContact;
 
        /**
-        * "created" timestamp
+        * Encrypted password
         */
        @Basic (optional = false)
-       @Temporal (TemporalType.TIMESTAMP)
-       @Column (name = "user_created", nullable = false, updatable = false)
-       private Date userCreated;
+       @Column (name = "user_encrypted_password", nullable = false)
+       private String userEncryptedPassword;
 
        /**
-        * Encrypted password
+        * When this user entry has been created
         */
        @Basic (optional = false)
-       @Column (name = "user_encrypted_password", nullable = false)
-       private String userEncryptedPassword;
+       @Temporal (TemporalType.TIMESTAMP)
+       @Column (name = "user_entry_created", nullable = false, updatable = false)
+       private Date userEntryCreated;
+
+       /**
+        * When this user entry has been updated
+        */
+       @Temporal (TemporalType.TIMESTAMP)
+       @Column (name = "user_entry_updated", insertable = false)
+       private Date userEntryUpdated;
 
        /**
         * User id
@@ -157,13 +160,6 @@ public class LoginUser implements User {
        @Column (name = "user_profile_mode", nullable = false)
        private ProfileMode userProfileMode;
 
-       /**
-        * When this user has been updated
-        */
-       @Temporal (TemporalType.TIMESTAMP)
-       @Column (name = "user_updated", insertable = false)
-       private Date userUpdated;
-
        /**
         * Default constructor
         */
@@ -178,7 +174,7 @@ public class LoginUser implements User {
         * @param userMustChangePassword Whether user must change password
         * @param userEncryptedPassword  Encrypted password
         * @param userAccountStatus      Account status
-        * @param userContact User's contact data
+        * @param userContact            User's contact data
         */
        public LoginUser (final String userName, final ProfileMode userProfileMode, final Boolean userMustChangePassword, final String userEncryptedPassword, final UserAccountStatus userAccountStatus, final Contact userContact) {
                // Call other constructor first
@@ -225,14 +221,25 @@ public class LoginUser implements User {
                // Checkparameter and return 0 if equal
                if (null == user) {
                        // Should not happen
-                       throw new NullPointerException("user is null"); //NOI18N
+                       throw new NullPointerException("Parameter 'user' is null"); //NOI18N
                } else if (Objects.equals(this, user)) {
                        // Same object
                        return 0;
                }
 
-               // There can only be one user per user name
-               return this.getUserName().compareTo(user.getUserName());
+               // Init comparitors
+               final int comparitors[] = {
+                       // First contact
+                       ContactUtils.compare(this.getUserContact(), user.getUserContact()),
+                       // ... then user name
+                       this.getUserName().compareTo(user.getUserName())
+               };
+
+               // Check all values
+               final int comparison = Comparables.checkAll(comparitors);
+
+               // Return value
+               return comparison;
        }
 
        @Override
@@ -243,11 +250,23 @@ public class LoginUser implements User {
                        return false;
                }
 
-               final User other = (User) object;
+               final User user = (User) object;
 
-               if (!Objects.equals(this.getUserName(), other.getUserName())) {
+               if (!Objects.equals(this.getUserName(), user.getUserName())) {
+                       return false;
+               } else if (!Objects.equals(this.getUserAccountStatus(), user.getUserAccountStatus())) {
                        return false;
-               } else if (!Objects.equals(this.getUserId(), other.getUserId())) {
+               } else if (!Objects.equals(this.getUserConfirmKey(), user.getUserConfirmKey())) {
+                       return false;
+               } else if (!Objects.equals(this.getUserId(), user.getUserId())) {
+                       return false;
+               } else if (!Objects.equals(this.getUserMustChangePassword(), user.getUserMustChangePassword())) {
+                       return false;
+               } else if (!Objects.equals(this.getUserName(), user.getUserName())) {
+                       return false;
+               } else if (!Objects.equals(this.getUserProfileMode(), user.getUserProfileMode())) {
+                       return false;
+               } else if (!Objects.equals(this.getUserContact(), user.getUserContact())) {
                        return false;
                }
 
@@ -284,26 +303,38 @@ public class LoginUser implements User {
                this.userContact = userContact;
        }
 
+       @Override
+       public String getUserEncryptedPassword () {
+               return this.userEncryptedPassword;
+       }
+
+       @Override
+       public void setUserEncryptedPassword (final String userEncryptedPassword) {
+               this.userEncryptedPassword = userEncryptedPassword;
+       }
+
        @Override
        @SuppressWarnings ("ReturnOfDateField")
-       public Date getUserCreated () {
-               return this.userCreated;
+       public Date getUserEntryCreated () {
+               return this.userEntryCreated;
        }
 
        @Override
        @SuppressWarnings ("AssignmentToDateFieldFromParameter")
-       public void setUserCreated (final Date userCreated) {
-               this.userCreated = userCreated;
+       public void setUserEntryCreated (final Date userEntryCreated) {
+               this.userEntryCreated = userEntryCreated;
        }
 
        @Override
-       public String getUserEncryptedPassword () {
-               return this.userEncryptedPassword;
+       @SuppressWarnings ("ReturnOfDateField")
+       public Date getUserEntryUpdated () {
+               return this.userEntryUpdated;
        }
 
        @Override
-       public void setUserEncryptedPassword (final String userEncryptedPassword) {
-               this.userEncryptedPassword = userEncryptedPassword;
+       @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+       public void setUserEntryUpdated (final Date userEntryUpdated) {
+               this.userEntryUpdated = userEntryUpdated;
        }
 
        @Override
@@ -378,23 +409,18 @@ public class LoginUser implements User {
                this.userProfileMode = userProfileMode;
        }
 
-       @Override
-       @SuppressWarnings ("ReturnOfDateField")
-       public Date getUserUpdated () {
-               return this.userUpdated;
-       }
-
-       @Override
-       @SuppressWarnings ("AssignmentToDateFieldFromParameter")
-       public void setUserUpdated (final Date userUpdated) {
-               this.userUpdated = userUpdated;
-       }
-
        @Override
        public int hashCode () {
                int hash = 5;
+
                hash = 83 * hash + Objects.hashCode(this.getUserName());
+               hash = 83 * hash + Objects.hashCode(this.getUserAccountStatus());
+               hash = 83 * hash + Objects.hashCode(this.getUserConfirmKey());
                hash = 83 * hash + Objects.hashCode(this.getUserId());
+               hash = 83 * hash + Objects.hashCode(this.getUserMustChangePassword());
+               hash = 83 * hash + Objects.hashCode(this.getUserProfileMode());
+               hash = 83 * hash + Objects.hashCode(this.getUserContact());
+
                return hash;
        }