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.NamedQueries;
33 import javax.persistence.NamedQuery;
34 import javax.persistence.OneToOne;
35 import javax.persistence.Table;
36 import javax.persistence.Temporal;
37 import javax.persistence.TemporalType;
38 import org.mxchange.jcontacts.contact.Contact;
39 import org.mxchange.jcontacts.contact.UserContact;
40 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
43 * A shop customer class.
45 * @author Roland Haeder<roland@mxchange.org>
47 @Entity (name = "users")
52 name = "confirmation_key",
54 columnList = "user_confirm_key"
59 columnList = "user_name"
65 @NamedQuery (name = "AllUserNames", query = "SELECT DISTINCT u.userName FROM users AS u ORDER BY u.userId ASC"),
66 @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"),
67 @NamedQuery (name = "SearchUserName", query = "SELECT u FROM users AS u WHERE LOWER(u.userName) LIKE LOWER(:param)"),
68 @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)"),
69 @NamedQuery (name = "AllPublicUsers", query = "SELECT u FROM users AS u WHERE u.userAccountStatus = :CONFIRMED AND u.userPublicProfile = TRUE")
72 public class LoginUser implements User {
77 private static final long serialVersionUID = 4_328_454_581_751L;
82 @Basic (optional = false)
83 @Column (name = "user_account_status", nullable = false)
84 @Enumerated (value = EnumType.STRING)
85 private UserAccountStatus userAccountStatus;
90 @Column (name = "user_confirm_key", length = 50)
91 private String userConfirmKey;
94 * Id number from "contacts" table
96 @JoinColumn (name = "user_contact_id", nullable = false, updatable = false)
97 @OneToOne (targetEntity = UserContact.class, optional = false, cascade = CascadeType.ALL)
98 private Contact userContact;
101 * "created" timestamp
103 @Basic (optional = false)
104 @Temporal (TemporalType.TIMESTAMP)
105 @Column (name = "user_created", nullable = false)
106 private Calendar userCreated;
111 @Column (name = "user_encrypted_password", nullable = false)
112 private String userEncryptedPassword;
118 @Column (name = "user_id", nullable = false, length = 20, updatable = false)
119 @GeneratedValue (strategy = GenerationType.IDENTITY)
125 @Temporal (TemporalType.TIMESTAMP)
126 @Column (name = "user_locked")
127 private Calendar userLocked;
132 @Column (name = "user_name", nullable = false, length = 20)
133 private String userName;
136 * Whether the user wants a public profile. This means that it can be viewed
137 * from the Internet by everyone (only profile, no personal data, this needs
138 * explicit agreement) and it can be found for sharing addresses with.
140 @Basic (optional = false)
141 @Column (name = "user_public_profile_flag", nullable = false)
142 private Boolean userPublicProfile;
145 * Default constructor
147 public LoginUser () {
148 // Default is not public
149 this.userPublicProfile = Boolean.FALSE;
153 public void copyAll (final User user) {
154 // Copy also contact data
155 this.getUserContact().copyAll(user.getUserContact());
158 this.setUserConfirmKey(user.getUserConfirmKey());
159 this.setUserName(user.getUserName());
160 this.setUserEncryptedPassword(user.getUserEncryptedPassword());
161 this.setUserAccountStatus(user.getUserAccountStatus());
162 this.setUserCreated(user.getUserCreated());
163 this.setUserLocked(user.getUserLocked());
167 public boolean equals (final Object object) {
168 if (object == null) {
171 if (getClass() != object.getClass()) {
175 final User other = (User) object;
177 return ((Objects.equals(this.getUserName(), other.getUserName()))
178 && (Objects.equals(this.getUserId(), other.getUserId())));
182 public UserAccountStatus getUserAccountStatus () {
183 return this.userAccountStatus;
187 public void setUserAccountStatus (final UserAccountStatus userAccountStatus) {
188 this.userAccountStatus = userAccountStatus;
192 public String getUserConfirmKey () {
193 return this.userConfirmKey;
197 public void setUserConfirmKey (final String customerConfirmKey) {
198 this.userConfirmKey = customerConfirmKey;
202 public Contact getUserContact () {
203 return this.userContact;
207 public void setUserContact (final Contact userContact) {
208 this.userContact = userContact;
212 public Calendar getUserCreated () {
213 return this.userCreated;
217 public void setUserCreated (final Calendar userCreated) {
218 this.userCreated = userCreated;
222 public String getUserEncryptedPassword () {
223 return this.userEncryptedPassword;
227 public void setUserEncryptedPassword (final String userEncryptedPassword) {
228 this.userEncryptedPassword = userEncryptedPassword;
232 public Long getUserId () {
237 public void setUserId (final Long userId) {
238 this.userId = userId;
242 public Calendar getUserLocked () {
243 return this.userLocked;
247 public void setUserLocked (final Calendar userLocked) {
248 this.userLocked = userLocked;
252 public String getUserName () {
253 return this.userName;
257 public void setUserName (final String userName) {
258 this.userName = userName;
262 public Boolean getUserPublicProfile () {
263 return this.userPublicProfile;
267 public void setUserPublicProfile (final Boolean userPublicProfile) {
268 this.userPublicProfile = userPublicProfile;
272 public int hashCode () {
274 hash = 83 * hash + Objects.hashCode(this.getUserName());
275 hash = 83 * hash + Objects.hashCode(this.getUserId());