2 * Copyright (C) 2015 Roland Haeder
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.Calendar;
20 import java.util.Objects;
21 import javax.persistence.Basic;
22 import javax.persistence.CascadeType;
23 import javax.persistence.Column;
24 import javax.persistence.Entity;
25 import javax.persistence.EnumType;
26 import javax.persistence.Enumerated;
27 import javax.persistence.GeneratedValue;
28 import javax.persistence.GenerationType;
29 import javax.persistence.Id;
30 import javax.persistence.Index;
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 org.mxchange.jcontacts.contact.Contact;
40 import org.mxchange.jcontacts.contact.UserContact;
41 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
42 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
45 * A generic user entity class
47 * @author Roland Haeder<roland@mxchange.org>
49 @Entity (name = "users")
54 name = "confirmation_key",
56 columnList = "user_confirm_key"
61 columnList = "user_name"
67 @NamedQuery (name = "AllUserNames", query = "SELECT DISTINCT u.userName FROM users AS u ORDER BY u.userId ASC"),
68 @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"),
69 @NamedQuery (name = "SearchUserName", query = "SELECT u FROM users AS u WHERE LOWER(u.userName) LIKE LOWER(:param)"),
70 @NamedQuery (name = "SearchUserId", query = "SELECT u FROM users AS u WHERE u.userId = :id"),
71 @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)"),
72 @NamedQuery (name = "SearchAllUsersExcept", query = "SELECT u FROM users AS u WHERE u != :user ORDER BY u.userId ASC"),
73 @NamedQuery (name = "AllPublicUsers", query = "SELECT u FROM users AS u WHERE u.userAccountStatus = :status AND u.userProfileMode = :mode ORDER BY u.userId ASC"),
74 @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")
77 public class LoginUser implements User {
82 private static final long serialVersionUID = 4_328_454_581_751L;
87 @Basic (optional = false)
88 @Column (name = "user_account_status", nullable = false)
89 @Enumerated (value = EnumType.STRING)
90 private UserAccountStatus userAccountStatus;
95 @Column (name = "user_confirm_key", length = 50)
96 private String userConfirmKey;
99 * Id number from "contacts" table
101 @JoinColumn (name = "user_contact_id", nullable = false, updatable = false)
102 @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL, optional = false)
103 private Contact userContact;
106 * "created" timestamp
108 @Basic (optional = false)
109 @Temporal (TemporalType.TIMESTAMP)
110 @Column (name = "user_created", nullable = false)
111 private Calendar userCreated;
116 @Column (name = "user_encrypted_password", nullable = false)
117 private String userEncryptedPassword;
123 @Column (name = "user_id", nullable = false, length = 20, updatable = false)
124 @GeneratedValue (strategy = GenerationType.IDENTITY)
128 * Last "locked" timestamp
130 @Temporal (TemporalType.TIMESTAMP)
131 @Column (name = "user_last_locked")
132 private Calendar userLastLocked;
138 @Column (name = "user_last_locked_reason")
139 private String lastLockedReason;
144 @Column (name = "user_name", nullable = false, length = 20)
145 private String userName;
148 * When this user has been updated
150 @Temporal (TemporalType.TIMESTAMP)
151 @Column (name = "user_updated")
152 private Calendar userUpdated;
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 * Default constructor
165 public LoginUser () {
166 // Default is invisible
167 this.userProfileMode = ProfileMode.INVISIBLE;
171 public void copyAll (final User user) {
172 // Copy also contact data
173 this.getUserContact().copyAll(user.getUserContact());
176 this.setUserConfirmKey(user.getUserConfirmKey());
177 this.setUserName(user.getUserName());
178 this.setUserEncryptedPassword(user.getUserEncryptedPassword());
179 this.setUserAccountStatus(user.getUserAccountStatus());
180 this.setUserCreated(user.getUserCreated());
181 this.setUserLastLocked(user.getUserLastLocked());
185 public boolean equals (final Object object) {
186 if (object == null) {
189 if (getClass() != object.getClass()) {
193 final User other = (User) object;
195 return ((Objects.equals(this.getUserName(), other.getUserName()))
196 && (Objects.equals(this.getUserId(), other.getUserId())));
200 public String getLastLockedReason () {
201 return this.lastLockedReason;
205 public void setLastLockedReason (final String lastLockedReason) {
206 this.lastLockedReason = lastLockedReason;
210 public UserAccountStatus getUserAccountStatus () {
211 return this.userAccountStatus;
215 public void setUserAccountStatus (final UserAccountStatus userAccountStatus) {
216 this.userAccountStatus = userAccountStatus;
220 public String getUserConfirmKey () {
221 return this.userConfirmKey;
225 public void setUserConfirmKey (final String userConfirmKey) {
226 this.userConfirmKey = userConfirmKey;
230 public Contact getUserContact () {
231 return this.userContact;
235 public void setUserContact (final Contact userContact) {
236 this.userContact = userContact;
240 public Calendar getUserCreated () {
241 return this.userCreated;
245 public void setUserCreated (final Calendar userCreated) {
246 this.userCreated = userCreated;
250 public String getUserEncryptedPassword () {
251 return this.userEncryptedPassword;
255 public void setUserEncryptedPassword (final String userEncryptedPassword) {
256 this.userEncryptedPassword = userEncryptedPassword;
260 public Long getUserId () {
265 public void setUserId (final Long userId) {
266 this.userId = userId;
270 public Calendar getUserLastLocked () {
271 return this.userLastLocked;
275 public void setUserLastLocked (final Calendar userLastLocked) {
276 this.userLastLocked = userLastLocked;
280 public String getUserName () {
281 return this.userName;
285 public void setUserName (final String userName) {
286 this.userName = userName;
290 public ProfileMode getUserProfileMode () {
291 return this.userProfileMode;
295 public void setUserProfileMode (final ProfileMode userProfileMode) {
296 this.userProfileMode = userProfileMode;
300 public Calendar getUserUpdated () {
301 return this.userUpdated;
305 public void setUserUpdated (final Calendar userUpdated) {
306 this.userUpdated = userUpdated;
310 public int hashCode () {
312 hash = 83 * hash + Objects.hashCode(this.getUserName());
313 hash = 83 * hash + Objects.hashCode(this.getUserId());