]> git.mxchange.org Git - juser-login-core.git/blobdiff - src/org/mxchange/jusercore/model/user/LoginUser.java
updated more fields
[juser-login-core.git] / src / org / mxchange / jusercore / model / user / LoginUser.java
index c6162dc8cb40aa083fc90c21bdc6f2208f680dcd..36f4dd37f77feef3881f84751e49c732b4ebc4b0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Roland Haeder
+ * Copyright (C) 2016 Roland Haeder
  *
  * 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
@@ -29,6 +29,7 @@ import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.Index;
 import javax.persistence.JoinColumn;
+import javax.persistence.Lob;
 import javax.persistence.NamedQueries;
 import javax.persistence.NamedQuery;
 import javax.persistence.OneToOne;
@@ -37,10 +38,11 @@ import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
 import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jcontacts.contact.UserContact;
+import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
 
 /**
- * A shop customer class.
+ * A generic user entity class
  * <p>
  * @author Roland Haeder<roland@mxchange.org>
  */
@@ -63,12 +65,17 @@ 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 = "AllEmailAddresses", query = "SELECT DISTINCT c.contactEmailAddress FROM contacts AS c ORDER BY c.contactId ASC"),
+                       @NamedQuery (name = "AllEmailAddresses", query = "SELECT DISTINCT c.contactEmailAddress FROM contacts AS c INNER JOIN users AS u ON u.userContact = c ORDER BY c.contactId ASC"),
                        @NamedQuery (name = "SearchUserName", query = "SELECT u FROM users AS u WHERE LOWER(u.userName) LIKE LOWER(:param)"),
+                       @NamedQuery (name = "SearchUserId", query = "SELECT u FROM users AS u WHERE u.userId = :id"),
                        @NamedQuery (name = "SearchEmailAddress", query = "SELECT u FROM users AS u INNER JOIN contacts AS c ON u.userContact = c WHERE LOWER(c.contactEmailAddress) LIKE LOWER(:param)"),
-                       @NamedQuery (name = "AllPublicUsers", query = "SELECT u FROM users AS u WHERE u.userAccountStatus = :CONFIRMED AND u.userPublicProfile = TRUE")
+                       @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 = "AllPublicUsers", query = "SELECT u FROM users AS u WHERE u.userAccountStatus = :status AND u.userProfileMode = :mode ORDER BY u.userId ASC"),
+                       @NamedQuery (name = "AllMemberPublicUsers", query = "SELECT u FROM users AS u WHERE u.userAccountStatus = :status AND u.userProfileMode IN (:public, :members) ORDER BY u.userId ASC")
                }
 )
+@SuppressWarnings ("PersistenceUnitPresent")
 public class LoginUser implements User {
 
        /**
@@ -93,8 +100,8 @@ public class LoginUser implements User {
        /**
         * Id number from "contacts" table
         */
-       @JoinColumn (name = "user_contact_id", nullable = false, updatable = false)
-       @OneToOne (targetEntity = UserContact.class, optional = false, cascade = CascadeType.ALL)
+       @JoinColumn (name = "user_contact_id", referencedColumnName = "contact_id", nullable = false, updatable = false, unique = true)
+       @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL, optional = false)
        private Contact userContact;
 
        /**
@@ -108,6 +115,7 @@ public class LoginUser implements User {
        /**
         * Encrypted password
         */
+       @Basic (optional = false)
        @Column (name = "user_encrypted_password", nullable = false)
        private String userEncryptedPassword;
 
@@ -120,39 +128,56 @@ public class LoginUser implements User {
        private Long userId;
 
        /**
-        * "locked" timestamp
+        * Last "locked" timestamp
         */
        @Temporal (TemporalType.TIMESTAMP)
-       @Column (name = "user_locked")
-       private Calendar userLocked;
+       @Column (name = "user_last_locked_timestamp")
+       private Calendar userLastLocked;
+
+       /**
+        * Last locked reason
+        */
+       @Lob
+       @Column (name = "user_last_locked_reason")
+       private String userLastLockedReason;
 
        /**
         * User name
         */
+       @Basic (optional = false)
        @Column (name = "user_name", nullable = false, length = 20)
        private String userName;
 
        /**
-        * Whether the user wants a public profile. This means that it can be viewed
-        * from the Internet by everyone (only profile, no personal data, this needs
-        * explicit agreement) and it can be found for sharing addresses with.
+        * Profile mode of this user
         */
        @Basic (optional = false)
-       @Column (name = "user_public_profile_flag", nullable = false)
-       private Boolean userPublicProfile;
+       @Enumerated (EnumType.STRING)
+       @Column (name = "user_profile_mode", nullable = false)
+       private ProfileMode userProfileMode;
+
+       /**
+        * When this user has been updated
+        */
+       @Temporal (TemporalType.TIMESTAMP)
+       @Column (name = "user_updated")
+       private Calendar userUpdated;
 
        /**
         * Default constructor
         */
        public LoginUser () {
-               // Default is not public
-               this.userPublicProfile = Boolean.FALSE;
+               // Default is invisible
+               this.userProfileMode = ProfileMode.INVISIBLE;
        }
 
        @Override
        public void copyAll (final User user) {
-               // Copy also contact data
-               this.getUserContact().copyAll(user.getUserContact());
+               // Is contact set?
+               if (user.getUserContact() instanceof Contact) {
+                       // Copy also contact data
+                       this.getUserContact().copyAll(user.getUserContact());
+               }
 
                // Copy other data
                this.setUserConfirmKey(user.getUserConfirmKey());
@@ -160,22 +185,23 @@ public class LoginUser implements User {
                this.setUserEncryptedPassword(user.getUserEncryptedPassword());
                this.setUserAccountStatus(user.getUserAccountStatus());
                this.setUserCreated(user.getUserCreated());
-               this.setUserLocked(user.getUserLocked());
+               this.setUserLastLocked(user.getUserLastLocked());
+               this.setUserUpdated(user.getUserUpdated());
+               this.setUserProfileMode(user.getUserProfileMode());
        }
 
        @Override
        public boolean equals (final Object object) {
-               if (object == null) {
+               if (null == object) {
                        return false;
-               }
-               if (getClass() != object.getClass()) {
+               } else if (this.getClass() != object.getClass()) {
                        return false;
                }
 
                final User other = (User) object;
 
-               return ((Objects.equals(this.getUserName(), other.getUserName()))
-                               && (Objects.equals(this.getUserId(), other.getUserId())));
+               return ((Objects.equals(this.getUserName(), other.getUserName())) &&
+                               (Objects.equals(this.getUserId(), other.getUserId())));
        }
 
        @Override
@@ -194,8 +220,8 @@ public class LoginUser implements User {
        }
 
        @Override
-       public void setUserConfirmKey (final String customerConfirmKey) {
-               this.userConfirmKey = customerConfirmKey;
+       public void setUserConfirmKey (final String userConfirmKey) {
+               this.userConfirmKey = userConfirmKey;
        }
 
        @Override
@@ -209,11 +235,13 @@ public class LoginUser implements User {
        }
 
        @Override
+       @SuppressWarnings ("ReturnOfDateField")
        public Calendar getUserCreated () {
                return this.userCreated;
        }
 
        @Override
+       @SuppressWarnings ("AssignmentToDateFieldFromParameter")
        public void setUserCreated (final Calendar userCreated) {
                this.userCreated = userCreated;
        }
@@ -239,13 +267,25 @@ public class LoginUser implements User {
        }
 
        @Override
-       public Calendar getUserLocked () {
-               return this.userLocked;
+       @SuppressWarnings ("ReturnOfDateField")
+       public Calendar getUserLastLocked () {
+               return this.userLastLocked;
+       }
+
+       @Override
+       @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+       public void setUserLastLocked (final Calendar userLastLocked) {
+               this.userLastLocked = userLastLocked;
+       }
+
+       @Override
+       public String getUserLastLockedReason () {
+               return this.userLastLockedReason;
        }
 
        @Override
-       public void setUserLocked (final Calendar userLocked) {
-               this.userLocked = userLocked;
+       public void setUserLastLockedReason (final String userLastLockedReason) {
+               this.userLastLockedReason = userLastLockedReason;
        }
 
        @Override
@@ -259,13 +299,25 @@ public class LoginUser implements User {
        }
 
        @Override
-       public Boolean getUserPublicProfile () {
-               return this.userPublicProfile;
+       public ProfileMode getUserProfileMode () {
+               return this.userProfileMode;
+       }
+
+       @Override
+       public void setUserProfileMode (final ProfileMode userProfileMode) {
+               this.userProfileMode = userProfileMode;
+       }
+
+       @Override
+       @SuppressWarnings ("ReturnOfDateField")
+       public Calendar getUserUpdated () {
+               return this.userUpdated;
        }
 
        @Override
-       public void setUserPublicProfile (final Boolean userPublicProfile) {
-               this.userPublicProfile = userPublicProfile;
+       @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+       public void setUserUpdated (final Calendar userUpdated) {
+               this.userUpdated = userUpdated;
        }
 
        @Override
@@ -275,4 +327,5 @@ public class LoginUser implements User {
                hash = 83 * hash + Objects.hashCode(this.getUserId());
                return hash;
        }
+
 }