2 * Copyright (C) 2016 Roland Haeder
\r
4 * This program is free software: you can redistribute it and/or modify
\r
5 * it under the terms of the GNU General Public License as published by
\r
6 * the Free Software Foundation, either version 3 of the License, or
\r
7 * (at your option) any later version.
\r
9 * This program is distributed in the hope that it will be useful,
\r
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
12 * GNU General Public License for more details.
\r
14 * You should have received a copy of the GNU General Public License
\r
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
17 package org.mxchange.jusercore.model.user;
\r
19 import java.util.Calendar;
\r
20 import java.util.Objects;
\r
21 import javax.persistence.Basic;
\r
22 import javax.persistence.CascadeType;
\r
23 import javax.persistence.Column;
\r
24 import javax.persistence.Entity;
\r
25 import javax.persistence.EnumType;
\r
26 import javax.persistence.Enumerated;
\r
27 import javax.persistence.GeneratedValue;
\r
28 import javax.persistence.GenerationType;
\r
29 import javax.persistence.Id;
\r
30 import javax.persistence.Index;
\r
31 import javax.persistence.JoinColumn;
\r
32 import javax.persistence.Lob;
\r
33 import javax.persistence.NamedQueries;
\r
34 import javax.persistence.NamedQuery;
\r
35 import javax.persistence.OneToOne;
\r
36 import javax.persistence.Table;
\r
37 import javax.persistence.Temporal;
\r
38 import javax.persistence.TemporalType;
\r
39 import org.mxchange.jcontacts.contact.Contact;
\r
40 import org.mxchange.jcontacts.contact.UserContact;
\r
41 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
\r
42 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
\r
45 * A generic user entity class
\r
47 * @author Roland Haeder<roland@mxchange.org>
\r
49 @Entity (name = "users")
\r
54 name = "confirmation_key",
\r
56 columnList = "user_confirm_key"
\r
61 columnList = "user_name"
\r
67 @NamedQuery (name = "AllUserNames", query = "SELECT DISTINCT u.userName FROM users AS u ORDER BY u.userId ASC"),
\r
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"),
\r
69 @NamedQuery (name = "SearchUserByName", query = "SELECT u FROM users AS u WHERE LOWER(u.userName) LIKE LOWER(:param)"),
\r
70 @NamedQuery (name = "SearchUserById", query = "SELECT u FROM users AS u WHERE u.userId = :id"),
\r
71 @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(:param)"),
\r
72 @NamedQuery (name = "SearchAllUsersExcept", query = "SELECT u FROM users AS u WHERE u != :user ORDER BY u.userId ASC"),
\r
73 @NamedQuery (name = "AllUsers", query = "SELECT u FROM users AS u ORDER BY u.userId ASC"),
\r
74 @NamedQuery (name = "AllPublicUsers", query = "SELECT u FROM users AS u WHERE u.userAccountStatus = :status AND u.userProfileMode = :mode ORDER BY u.userId ASC"),
\r
75 @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")
\r
78 @SuppressWarnings ("PersistenceUnitPresent")
\r
79 public class LoginUser implements User {
\r
84 private static final long serialVersionUID = 4_328_454_581_751L;
\r
89 @Basic (optional = false)
\r
90 @Column (name = "user_account_status", nullable = false)
\r
91 @Enumerated (value = EnumType.STRING)
\r
92 private UserAccountStatus userAccountStatus;
\r
97 @Column (name = "user_confirm_key", length = 50)
\r
98 private String userConfirmKey;
\r
101 * Id number from "contacts" table
\r
103 @JoinColumn (name = "user_contact_id", referencedColumnName = "contact_id", nullable = false, updatable = false, unique = true)
\r
104 @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL, optional = false)
\r
105 private Contact userContact;
\r
108 * "created" timestamp
\r
110 @Basic (optional = false)
\r
111 @Temporal (TemporalType.TIMESTAMP)
\r
112 @Column (name = "user_created", nullable = false)
\r
113 private Calendar userCreated;
\r
116 * Encrypted password
\r
118 @Basic (optional = false)
\r
119 @Column (name = "user_encrypted_password", nullable = false)
\r
120 private String userEncryptedPassword;
\r
126 @Column (name = "user_id", nullable = false, length = 20, updatable = false)
\r
127 @GeneratedValue (strategy = GenerationType.IDENTITY)
\r
128 private Long userId;
\r
131 * Last "locked" timestamp
\r
133 @Temporal (TemporalType.TIMESTAMP)
\r
134 @Column (name = "user_last_locked_timestamp")
\r
135 private Calendar userLastLocked;
\r
138 * Last locked reason
\r
141 @Column (name = "user_last_locked_reason")
\r
142 private String userLastLockedReason;
\r
147 @Basic (optional = false)
\r
148 @Column (name = "user_name", nullable = false, length = 20)
\r
149 private String userName;
\r
152 * Profile mode of this user
\r
154 @Basic (optional = false)
\r
155 @Enumerated (EnumType.STRING)
\r
156 @Column (name = "user_profile_mode", nullable = false)
\r
157 private ProfileMode userProfileMode;
\r
160 * When this user has been updated
\r
162 @Temporal (TemporalType.TIMESTAMP)
\r
163 @Column (name = "user_updated")
\r
164 private Calendar userUpdated;
\r
167 * Default constructor
\r
169 public LoginUser () {
\r
170 // Default is invisible
\r
171 this.userProfileMode = ProfileMode.INVISIBLE;
\r
175 public void copyAll (final User user) {
\r
177 if (user.getUserContact() instanceof Contact) {
\r
178 // Copy also contact data
\r
179 this.getUserContact().copyAll(user.getUserContact());
\r
183 this.setUserConfirmKey(user.getUserConfirmKey());
\r
184 this.setUserName(user.getUserName());
\r
185 this.setUserEncryptedPassword(user.getUserEncryptedPassword());
\r
186 this.setUserAccountStatus(user.getUserAccountStatus());
\r
187 this.setUserCreated(user.getUserCreated());
\r
188 this.setUserLastLocked(user.getUserLastLocked());
\r
189 this.setUserUpdated(user.getUserUpdated());
\r
190 this.setUserProfileMode(user.getUserProfileMode());
\r
194 public boolean equals (final Object object) {
\r
195 if (null == object) {
\r
197 } else if (this.getClass() != object.getClass()) {
\r
201 final User other = (User) object;
\r
203 return ((Objects.equals(this.getUserName(), other.getUserName())) &&
\r
204 (Objects.equals(this.getUserId(), other.getUserId())));
\r
208 public UserAccountStatus getUserAccountStatus () {
\r
209 return this.userAccountStatus;
\r
213 public void setUserAccountStatus (final UserAccountStatus userAccountStatus) {
\r
214 this.userAccountStatus = userAccountStatus;
\r
218 public String getUserConfirmKey () {
\r
219 return this.userConfirmKey;
\r
223 public void setUserConfirmKey (final String userConfirmKey) {
\r
224 this.userConfirmKey = userConfirmKey;
\r
228 public Contact getUserContact () {
\r
229 return this.userContact;
\r
233 public void setUserContact (final Contact userContact) {
\r
234 this.userContact = userContact;
\r
238 @SuppressWarnings ("ReturnOfDateField")
\r
239 public Calendar getUserCreated () {
\r
240 return this.userCreated;
\r
244 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
\r
245 public void setUserCreated (final Calendar userCreated) {
\r
246 this.userCreated = userCreated;
\r
250 public String getUserEncryptedPassword () {
\r
251 return this.userEncryptedPassword;
\r
255 public void setUserEncryptedPassword (final String userEncryptedPassword) {
\r
256 this.userEncryptedPassword = userEncryptedPassword;
\r
260 public Long getUserId () {
\r
261 return this.userId;
\r
265 public void setUserId (final Long userId) {
\r
266 this.userId = userId;
\r
270 @SuppressWarnings ("ReturnOfDateField")
\r
271 public Calendar getUserLastLocked () {
\r
272 return this.userLastLocked;
\r
276 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
\r
277 public void setUserLastLocked (final Calendar userLastLocked) {
\r
278 this.userLastLocked = userLastLocked;
\r
282 public String getUserLastLockedReason () {
\r
283 return this.userLastLockedReason;
\r
287 public void setUserLastLockedReason (final String userLastLockedReason) {
\r
288 this.userLastLockedReason = userLastLockedReason;
\r
292 public String getUserName () {
\r
293 return this.userName;
\r
297 public void setUserName (final String userName) {
\r
298 this.userName = userName;
\r
302 public ProfileMode getUserProfileMode () {
\r
303 return this.userProfileMode;
\r
307 public void setUserProfileMode (final ProfileMode userProfileMode) {
\r
308 this.userProfileMode = userProfileMode;
\r
312 @SuppressWarnings ("ReturnOfDateField")
\r
313 public Calendar getUserUpdated () {
\r
314 return this.userUpdated;
\r
318 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
\r
319 public void setUserUpdated (final Calendar userUpdated) {
\r
320 this.userUpdated = userUpdated;
\r
324 public int hashCode () {
\r
326 hash = 83 * hash + Objects.hashCode(this.getUserName());
\r
327 hash = 83 * hash + Objects.hashCode(this.getUserId());
\r