fr.mael.microrss.domain.User.java Source code

Java tutorial

Introduction

Here is the source code for fr.mael.microrss.domain.User.java

Source

/*
   Copyright  2013 Mael Le Guvel
   This work is free. You can redistribute it and/or modify it under the
   terms of the Do What The Fuck You Want To Public License, Version 2,
   as published by Sam Hocevar. See the COPYING file for more details.
*/
package fr.mael.microrss.domain;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * User generated by hbm2java
 */
@Entity
@Table(name = "user", uniqueConstraints = @UniqueConstraint(columnNames = "username"))
public class User extends BaseDomain implements java.io.Serializable, UserDetails {

    private String username;
    private String password;
    private String roles;
    private String email;
    private String salt;
    private Set<UserFeed> userFeeds = new HashSet<UserFeed>(0);
    private Set<UserArticle> userArticles = new HashSet<UserArticle>(0);
    private Set<Category> categories = new HashSet<Category>(0);
    private UserConfig userConfig;

    public User() {
    }

    public User(String username, String password, String email) {
        this.username = username;
        this.password = password;
        this.email = email;
    }

    public User(String username, String password, String roles, String email, String salt, Set userFeeds,
            Set userArticles, Set categories) {
        this.username = username;
        this.password = password;
        this.roles = roles;
        this.email = email;
        this.salt = salt;
        this.userFeeds = userFeeds;
        this.userArticles = userArticles;
        this.categories = categories;
    }

    @Column(name = "username", unique = true, nullable = false, length = 45)
    public String getUsername() {
        return this.username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Column(name = "password", nullable = false)
    public String getPassword() {
        return this.password;
    }

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

    @Column(name = "roles")
    public String getRoles() {
        return this.roles;
    }

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

    @Column(name = "email", nullable = false)
    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Column(name = "salt")
    public String getSalt() {
        return this.salt;
    }

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

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
    public Set<UserFeed> getUserFeeds() {
        return this.userFeeds;
    }

    public void setUserFeeds(Set<UserFeed> userFeeds) {
        this.userFeeds = userFeeds;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
    public Set<UserArticle> getUserArticles() {
        return this.userArticles;
    }

    public void setUserArticles(Set<UserArticle> userArticles) {
        this.userArticles = userArticles;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
    public Set<Category> getCategories() {
        return this.categories;
    }

    public void setCategories(Set<Category> categories) {
        this.categories = categories;
    }

    @Override
    @Transient
    public Collection<? extends GrantedAuthority> getAuthorities() {
        List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
        if (roles == null || "".equals(roles)) {
            return authorities;
        }
        for (final String role : roles.split(",")) {
            authorities.add(new Role(role));
        }
        return authorities;
    }

    @Override
    @Transient
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    @Transient
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    @Transient
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    @Transient
    public boolean isEnabled() {
        return true;
    }

    @OneToOne(mappedBy = "user", fetch = FetchType.LAZY)
    public UserConfig getUserConfig() {
        return userConfig;
    }

    public void setUserConfig(UserConfig userConfig) {
        this.userConfig = userConfig;
    }

}