com.github.mrstampy.gameboot.usersession.data.entity.User.java Source code

Java tutorial

Introduction

Here is the source code for com.github.mrstampy.gameboot.usersession.data.entity.User.java

Source

/*
 *              ______                        ____              __ 
 *             / ____/___ _____ ___  ___     / __ )____  ____  / /_
 *            / / __/ __ `/ __ `__ \/ _ \   / __  / __ \/ __ \/ __/
 *           / /_/ / /_/ / / / / / /  __/  / /_/ / /_/ / /_/ / /_  
 *           \____/\__,_/_/ /_/ /_/\___/  /_____/\____/\____/\__/  
 *                                                 
 *                                 .-'\
 *                              .-'  `/\
 *                           .-'      `/\
 *                           \         `/\
 *                            \         `/\
 *                             \    _-   `/\       _.--.
 *                              \    _-   `/`-..--\     )
 *                               \    _-   `,','  /    ,')
 *                                `-_   -   ` -- ~   ,','
 *                                 `-              ,','
 *                                  \,--.    ____==-~
 *                                   \   \_-~\
 *                                    `_-~_.-'
 *                                     \-~
 * 
 *                       http://mrstampy.github.io/gameboot/
 *
 * Copyright (C) 2015, 2016 Burton Alexander
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 * 
 */
package com.github.mrstampy.gameboot.usersession.data.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.hibernate.envers.Audited;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.github.mrstampy.gameboot.data.entity.AbstractGameBootEntity;

/**
 * The Class User.
 */
@Entity
@Table
@Audited
public class User extends AbstractGameBootEntity {

    @Column(unique = true, nullable = false, length = 50)
    private String userName;

    @Column(nullable = false)
    @JsonIgnore
    private String passwordHash;

    @Column
    private String firstName;

    @Column
    private String lastName;

    @Column
    private String email;

    @Column
    @Temporal(TemporalType.DATE)
    @JsonFormat(shape = Shape.STRING, pattern = "yyyy/MM/dd")
    private Date dob;

    @OneToMany(fetch = FetchType.LAZY)
    private List<User> friends;

    @OneToMany(fetch = FetchType.LAZY)
    private List<User> blocked;

    @Column(length = 2)
    private String countryCode;

    @Column(length = 2)
    private String languageCode;

    /**
     * The Enum UserState.
     */
    public enum UserState {

        /** The active. */
        ACTIVE,
        /** The inactive. */
        INACTIVE,
        /** The deleted. */
        DELETED
    }

    @Column(nullable = false)
    @Enumerated(EnumType.STRING)
    private UserState state;

    /**
     * Gets the user name.
     *
     * @return the user name
     */
    public String getUserName() {
        return userName;
    }

    /**
     * Sets the user name.
     *
     * @param userName
     *          the new user name
     */
    public void setUserName(String userName) {
        this.userName = userName;
    }

    /**
     * Gets the password hash.
     *
     * @return the password hash
     */
    public String getPasswordHash() {
        return passwordHash;
    }

    /**
     * Sets the password hash.
     *
     * @param passwordHash
     *          the new password hash
     */
    public void setPasswordHash(String passwordHash) {
        this.passwordHash = passwordHash;
    }

    /**
     * Gets the first name.
     *
     * @return the first name
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     * Sets the first name.
     *
     * @param firstName
     *          the new first name
     */
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    /**
     * Gets the last name.
     *
     * @return the last name
     */
    public String getLastName() {
        return lastName;
    }

    /**
     * Sets the last name.
     *
     * @param lastName
     *          the new last name
     */
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    /**
     * Gets the email.
     *
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * Sets the email.
     *
     * @param email
     *          the new email
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * Gets the dob.
     *
     * @return the dob
     */
    public Date getDob() {
        return dob;
    }

    /**
     * Sets the dob.
     *
     * @param dob
     *          the new dob
     */
    public void setDob(Date dob) {
        this.dob = dob;
    }

    /**
     * Gets the state.
     *
     * @return the state
     */
    public UserState getState() {
        return state;
    }

    /**
     * Sets the state.
     *
     * @param state
     *          the new state
     */
    public void setState(UserState state) {
        this.state = state;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        ToStringBuilder tsb = new ToStringBuilder(this);

        //@formatter:off
        tsb.append(getUserName()).append(getFirstName()).append(getLastName()).append(getState()).append(getDob())
                .append(getEmail());
        //@formatter:on

        return tsb.toString();
    }

    /**
     * Gets the friends.
     *
     * @return the friends
     */
    public List<User> getFriends() {
        return friends;
    }

    /**
     * Sets the friends.
     *
     * @param friends
     *          the new friends
     */
    public void setFriends(List<User> friends) {
        this.friends = friends;
    }

    /**
     * Gets the blocked.
     *
     * @return the blocked
     */
    public List<User> getBlocked() {
        return blocked;
    }

    /**
     * Sets the blocked.
     *
     * @param blocked
     *          the new blocked
     */
    public void setBlocked(List<User> blocked) {
        this.blocked = blocked;
    }

    /**
     * Gets the country code.
     *
     * @return the country code
     */
    public String getCountryCode() {
        return countryCode;
    }

    /**
     * Sets the country code.
     *
     * @param countryCode
     *          the new country code
     */
    public void setCountryCode(String countryCode) {
        this.countryCode = countryCode;
    }

    /**
     * Gets the language code.
     *
     * @return the language code
     */
    public String getLanguageCode() {
        return languageCode;
    }

    /**
     * Sets the language code.
     *
     * @param languageCode
     *          the new language code
     */
    public void setLanguageCode(String languageCode) {
        this.languageCode = languageCode;
    }
}