Newer
Older
CosmosServer / src / main / java / com / example / cosmos_serversb / entities / User.java
package com.example.cosmos_serversb.entities;

import java.util.HashSet;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonView;
import lombok.Data;
import com.example.cosmos_serversb.views.UsersView;
import org.hibernate.validator.constraints.Length;

public class User {
    /**
    * USER用のクラス
    *
    * @param uId string //LONGに変更
    * @param uri String
    * @param name String
    * @param iconUri String iconの保存先
    * @param login Boolean トークンが存在するか否か
    * @param groups Set<Group> 所属するグループ
    * @param tokens Set<Token> 所持するトークン
    * @param firstToken String 初期トークン
    * 
    * TODO: Tokenのデータベース接続
    */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonProperty("token")
    public String firstToken;//初期トークン
    @JsonView(UsersView.putUsersView.class)
    public String uId;
    @JsonView(UsersView.putUsersView.class)
    public String uri;
    @JsonView(UsersView.getUsersView.class)
    public String name;
    @JsonView(UsersView.getUsersView.class)
    @Length(max = 2047)
    public String iconUri;
    @JsonIgnore
    public boolean login = true;
    @JsonIgnore
    public Set<Group> groups = new HashSet<>();
    @JsonIgnore
    public Set<Token> tokens = new HashSet<>();
    //public Set<String> tokens = new HashSet<>();

    public User() {

    }
    public User(String name, String uId, String uri, String iconUri,String token) {
        setuId(uId);
        setUri(uri);
        setName(name);
        setIconUri(iconUri);
        setFirstToken(token);
        //addToken(this.dummyToken);
        this.login = true;
    }

    public String getuId() {
        return uId;
    }

    public void setuId(String uId) {
        this.uId = uId;
    }

    public String getFirstToken() {
        return firstToken;
    }

    public void setFirstToken(String firstToken) {
        this.firstToken = firstToken;
    }
    public Set<Token> getTokens() {
        return tokens;
    }

    public void setTokens(Set<Token> tokens) {
        this.tokens = tokens;
    }

    public String getUri() {
        return uri;
    }

    public void setUri(String uri) {



        this.uri = uri;
    }

    public String getName() {
        return name;
    }

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

    public String getIconUri() {
        return iconUri;
    }

    public void setIconUri(String iconUri) {
        this.iconUri = iconUri;
    }

    public void setLogin(boolean login) {
        this.login = login;
    }

    public boolean isLogin() {
        return login;
    }

    public void setGroups(Set<Group> groups) {
        this.groups = groups;
    }

    public Set<Group> getGroups() {
        return groups;
    }

    public void addGroups(Group group){
        groups.add(group);
    }

    public void exitGroup(Group group){
        this.groups.remove(group);
    }

    public boolean equals(User user) {
        return uId.equals(user.getuId());
    }
}