2 * Copyright (C) 2016, 2017 Roland Häder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jusercore.model.user;
19 import java.util.Date;
20 import java.util.Locale;
21 import java.util.Objects;
22 import javax.persistence.Basic;
23 import javax.persistence.CascadeType;
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.EnumType;
27 import javax.persistence.Enumerated;
28 import javax.persistence.GeneratedValue;
29 import javax.persistence.GenerationType;
30 import javax.persistence.Id;
31 import javax.persistence.JoinColumn;
32 import javax.persistence.Lob;
33 import javax.persistence.NamedQueries;
34 import javax.persistence.NamedQuery;
35 import javax.persistence.OneToOne;
36 import javax.persistence.Table;
37 import javax.persistence.Temporal;
38 import javax.persistence.TemporalType;
39 import javax.persistence.Transient;
40 import org.mxchange.jcontacts.model.contact.Contact;
41 import org.mxchange.jcontacts.model.contact.UserContact;
42 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
43 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
46 * A generic user entity class
48 * @author Roland Häder<roland@mxchange.org>
50 @Entity (name = "users")
56 @NamedQuery (name = "AllUserNames", query = "SELECT DISTINCT u.userName FROM users AS u ORDER BY u.userId ASC"),
57 @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"),
58 @NamedQuery (name = "SearchUserByName", query = "SELECT u FROM users AS u WHERE LOWER(u.userName) LIKE LOWER(:userName)"),
59 @NamedQuery (name = "SearchUserById", query = "SELECT u FROM users AS u WHERE u.userId = :id"),
60 @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)"),
61 @NamedQuery (name = "SearchUserByConfirmKey", query = "SELECT u FROM users AS u WHERE u.userConfirmKey = :confirmKey"),
62 @NamedQuery (name = "SearchAllUsersExcept", query = "SELECT u FROM users AS u WHERE u != :user ORDER BY u.userId ASC"),
63 @NamedQuery (name = "AllUsers", query = "SELECT u FROM users AS u ORDER BY u.userId ASC"),
64 @NamedQuery (name = "AllPublicUsers", query = "SELECT u FROM users AS u WHERE u.userAccountStatus = :status AND u.userProfileMode = :mode ORDER BY u.userId ASC"),
65 @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")
68 @SuppressWarnings ("PersistenceUnitPresent")
69 public class LoginUser implements User {
75 private static final long serialVersionUID = 4_328_454_581_751L;
80 @Basic (optional = false)
81 @Column (name = "user_account_status", nullable = false)
82 @Enumerated (value = EnumType.STRING)
83 private UserAccountStatus userAccountStatus;
88 @Column (name = "user_confirm_key", unique = true)
89 private String userConfirmKey;
92 * Id number from "contacts" table
94 @JoinColumn (name = "user_contact_id", referencedColumnName = "contact_id", nullable = false, updatable = false, unique = true)
95 @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL, optional = false)
96 private Contact userContact;
101 @Basic (optional = false)
102 @Temporal (TemporalType.TIMESTAMP)
103 @Column (name = "user_created", nullable = false, updatable = false)
104 private Date userCreated;
109 @Basic (optional = false)
110 @Column (name = "user_encrypted_password", nullable = false)
111 private String userEncryptedPassword;
117 @Column (name = "user_id", nullable = false, updatable = false)
118 @GeneratedValue (strategy = GenerationType.IDENTITY)
122 * Last "locked" timestamp
124 @Temporal (TemporalType.TIMESTAMP)
125 @Column (name = "user_last_locked_timestamp")
126 private Date userLastLocked;
132 @Column (name = "user_last_locked_reason")
133 private String userLastLockedReason;
138 @Column (name = "user_locale")
139 private Locale userLocale;
142 * Whether the user must change password after login
144 @Column (name = "user_must_change_password")
145 private Boolean userMustChangePassword;
150 @Basic (optional = false)
151 @Column (name = "user_name", nullable = false, length = 30, unique = true)
152 private String userName;
155 * Profile mode of this user
157 @Basic (optional = false)
158 @Enumerated (EnumType.STRING)
159 @Column (name = "user_profile_mode", nullable = false)
160 private ProfileMode userProfileMode;
163 * When this user has been updated
165 @Temporal (TemporalType.TIMESTAMP)
166 @Column (name = "user_updated", insertable = false)
167 private Date userUpdated;
170 * Default constructor
172 public LoginUser () {
173 // Default is invisible
174 this.userProfileMode = ProfileMode.INVISIBLE;
178 public boolean equals (final Object object) {
179 if (null == object) {
181 } else if (this.getClass() != object.getClass()) {
185 final User other = (User) object;
187 if (!Objects.equals(this.getUserName(), other.getUserName())) {
189 } else if (!Objects.equals(this.getUserId(), other.getUserId())) {
197 public UserAccountStatus getUserAccountStatus () {
198 return this.userAccountStatus;
202 public void setUserAccountStatus (final UserAccountStatus userAccountStatus) {
203 this.userAccountStatus = userAccountStatus;
207 public String getUserConfirmKey () {
208 return this.userConfirmKey;
212 public void setUserConfirmKey (final String userConfirmKey) {
213 this.userConfirmKey = userConfirmKey;
217 public Contact getUserContact () {
218 return this.userContact;
222 public void setUserContact (final Contact userContact) {
223 this.userContact = userContact;
227 @SuppressWarnings ("ReturnOfDateField")
228 public Date getUserCreated () {
229 return this.userCreated;
233 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
234 public void setUserCreated (final Date userCreated) {
235 this.userCreated = userCreated;
239 public String getUserEncryptedPassword () {
240 return this.userEncryptedPassword;
244 public void setUserEncryptedPassword (final String userEncryptedPassword) {
245 this.userEncryptedPassword = userEncryptedPassword;
249 public Long getUserId () {
254 public void setUserId (final Long userId) {
255 this.userId = userId;
259 @SuppressWarnings ("ReturnOfDateField")
260 public Date getUserLastLocked () {
261 return this.userLastLocked;
265 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
266 public void setUserLastLocked (final Date userLastLocked) {
267 this.userLastLocked = userLastLocked;
271 public String getUserLastLockedReason () {
272 return this.userLastLockedReason;
276 public void setUserLastLockedReason (final String userLastLockedReason) {
277 this.userLastLockedReason = userLastLockedReason;
281 public Locale getUserLocale () {
282 return this.userLocale;
286 public void setUserLocale (final Locale userLocale) {
287 this.userLocale = userLocale;
291 public Boolean getUserMustChangePassword () {
292 return this.userMustChangePassword;
296 public void setUserMustChangePassword (final Boolean userMustChangePassword) {
297 this.userMustChangePassword = userMustChangePassword;
301 public String getUserName () {
302 return this.userName;
306 public void setUserName (final String userName) {
307 this.userName = userName;
311 public ProfileMode getUserProfileMode () {
312 return this.userProfileMode;
316 public void setUserProfileMode (final ProfileMode userProfileMode) {
317 this.userProfileMode = userProfileMode;
321 @SuppressWarnings ("ReturnOfDateField")
322 public Date getUserUpdated () {
323 return this.userUpdated;
327 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
328 public void setUserUpdated (final Date userUpdated) {
329 this.userUpdated = userUpdated;
333 public int hashCode () {
335 hash = 83 * hash + Objects.hashCode(this.getUserName());
336 hash = 83 * hash + Objects.hashCode(this.getUserId());