com.xyxy.platform.entity.User.java Source code

Java tutorial

Introduction

Here is the source code for com.xyxy.platform.entity.User.java

Source

/*******************************************************************************
 * Copyright (c) 2005, 2014
 * <p/>
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.xyxy.platform.entity;

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

import javax.persistence.*;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.hibernate.validator.constraints.NotBlank;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.ImmutableList;

@Entity
@Table(name = "t_user")
public class User extends IdEntity {
    private String loginName;//??
    private String name;//??,,loginname??
    private String plainPassword;
    private String password;
    private String salt;
    private String roles;//|??
    private Date registerDate;//|

    private Location location;//

    private Status status;

    private Date updateDate;//|

    private User createUser;//(?)

    private User updateUser;//(?)

    public User() {
    }

    public User(Long id) {
        this.id = id;
    }

    // JPA USER_ID
    @ManyToOne
    @JoinColumn(name = "location_id")
    public Location getLocation() {
        return location;
    }

    public void setLocation(Location location) {
        this.location = location;
    }

    //?, , , ?
    @Enumerated(value = EnumType.ORDINAL)
    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    // JSON??
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    // JSON??
    @ManyToOne
    @JoinColumn(name = "create_user_id")
    public User getCreateUser() {
        return createUser;
    }

    public void setCreateUser(User createUser) {
        this.createUser = createUser;
    }

    @ManyToOne
    @JoinColumn(name = "update_user_id")
    public User getUpdateUser() {
        return updateUser;
    }

    public void setUpdateUser(User updateUser) {
        this.updateUser = updateUser;
    }

    @NotBlank
    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    // ????Restful?.
    @Transient
    @JsonIgnore
    public String getPlainPassword() {
        return plainPassword;
    }

    public void setPlainPassword(String plainPassword) {
        this.plainPassword = plainPassword;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public String getRoles() {
        return roles;
    }

    public void setRoles(String roles) {
        this.roles = roles;
    }

    @Transient
    @JsonIgnore
    public List<String> getRoleList() {
        // ???List.
        return ImmutableList.copyOf(StringUtils.split(roles, ","));
    }

    // JSON??
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getRegisterDate() {
        return registerDate;
    }

    public void setRegisterDate(Date registerDate) {
        this.registerDate = registerDate;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }

    public enum Status {
        ONLINE(""), OFFLINE(""), DISABLED("?");

        private String text;

        Status() {
            this("");
        }

        Status(String text) {
            this.text = text;
        }

        public String getText() {
            return this.text;
        }

        public int getOrdinal() {
            return this.ordinal();
        }
    }
}