com.formkiq.server.domain.User Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of formkiq-server Show documentation
Show all versions of formkiq-server Show documentation
Server-side integration for the FormKiQ ios application
package com.formkiq.server.domain;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import com.formkiq.server.domain.type.UserRole;
import com.formkiq.server.domain.type.UserStatus;
/**
* User domain.
*
*/
@Entity
@Table(name = "users")
public class User implements UserDetails {
/** serialVersionUID. */
private static final long serialVersionUID = -7371006788796125701L;
/** password column length. */
private static final int FL_PASSWORD = 255;
/** email column length. */
private static final int FL_EMAIL = 255;
/** user status column length. */
private static final int FL_USER_STATUS = 10;
/** Security Token Column Length. */
private static final int FL_RESET_TOKEN = 255;
/** identifier column. */
@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
@Column(name = "user_id", unique = true, columnDefinition = "uuid")
private String userid;
/** email column. */
@NotNull
@Column(name = "email", length = FL_EMAIL, nullable = false)
private String email;
/** password column. */
@Column(name = "password", length = FL_PASSWORD, nullable = true)
private String password;
/** status column. */
@NotNull
@Enumerated(EnumType.STRING)
@Column(name = "status", length = FL_USER_STATUS, nullable = false)
private UserStatus status;
/** role column. */
@NotNull
@Enumerated(EnumType.STRING)
@Column(name = "role", length = FL_USER_STATUS, nullable = false)
private UserRole role;
/** reset token column. */
@Column(name = "reset_token", length = FL_RESET_TOKEN,
nullable = true)
private String resetToken;
/** Reset Token Inserted Date column. */
@Column(name = "reset_inserted_date", nullable = true)
private Date resetInsertedDate;
/** inserted column. */
@NotNull
@Column(name = "inserted_date", nullable = false)
private Date insertedDate;
/** updated column. */
@NotNull
@Column(name = "updated_date", nullable = false)
private Date updatedDate;
/**
* default constructor.
*/
public User() {
}
/**
* constructor.
* @param emailStr String
* @param pass String
* @param userStatus UserStatus
* @param userRole UserRole
*/
public User(final String emailStr,
final String pass, final UserStatus userStatus,
final UserRole userRole) {
this();
this.email = emailStr;
this.password = pass;
this.status = userStatus;
this.role = userRole;
}
/**
* @return {@link String}
*/
public String getEmail() {
return this.email;
}
/**
* @return {@link String}
*/
public String getUserid() {
return this.userid;
}
/**
* @return {@link String}
*/
@Override
public String getPassword() {
return this.password;
}
/**
* @return UserStatus
*/
public UserStatus getStatus() {
return this.status;
}
/**
* @param emailStr String
*/
public void setEmail(final String emailStr) {
this.email = emailStr;
}
/**
* @param user String
*/
public void setUserid(final String user) {
this.userid = user;
}
/**
* @param pass String
*/
public void setPassword(final String pass) {
this.password = pass;
}
/**
* @param userStatus UserStatus
*/
public void setStatus(final UserStatus userStatus) {
this.status = userStatus;
}
@Override
public String toString() {
return String.format("User[user_id=%s, email='%s', password='%s', "
+ "status='%s', role='%s']",
this.userid, this.email, this.password,
this.status, this.role);
}
/**
* @return UserRole
*/
public UserRole getRole() {
return this.role;
}
/**
* @param userRole UserRole
*/
public void setRole(final UserRole userRole) {
this.role = userRole;
}
@Override
public Collection< ? extends GrantedAuthority> getAuthorities() {
GrantedAuthority ga = new SimpleGrantedAuthority(getRole().name());
return Arrays.asList(ga);
}
@Override
public String getUsername() {
return getEmail();
}
@Override
public boolean isAccountNonExpired() {
return isEnabled();
}
@Override
public boolean isAccountNonLocked() {
return isEnabled();
}
@Override
public boolean isCredentialsNonExpired() {
return isEnabled();
}
@Override
public boolean isEnabled() {
return UserStatus.ACTIVE.equals(this.status);
}
/**
* @return {@link String}
*/
public String getResetToken() {
return this.resetToken;
}
/**
* @param token String
*/
public void setResetToken(final String token) {
this.resetToken = token;
}
/**
* @return Date
*/
public Date getResetInsertedDate() {
return this.resetInsertedDate != null
? (Date) this.resetInsertedDate.clone() : null;
}
/**
* @param date Date
*/
public void setResetInsertedDate(final Date date) {
this.resetInsertedDate = date != null ? (Date) date.clone() : null;
}
/**
* @return Date
*/
public Date getInsertedDate() {
return this.insertedDate != null ? (Date) this.insertedDate.clone()
: null;
}
/**
* @param date Date
*/
public void setInsertedDate(final Date date) {
this.insertedDate = date != null ? (Date) date.clone() : null;
}
/**
* @return Date
*/
public Date getUpdatedDate() {
return this.updatedDate != null ? (Date) this.updatedDate.clone()
: null;
}
/**
* @param date Date
*/
public void setUpdatedDate(final Date date) {
this.updatedDate = date != null ? (Date) date.clone() : null;
}
}