package kr.wisestone.owl.domain;
|
|
import kr.wisestone.owl.domain.enumType.SocialType;
|
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.userdetails.UserDetails;
|
import javax.persistence.*;
|
import java.io.Serializable;
|
import java.security.Principal;
|
import java.util.*;
|
|
@Entity
|
public class User extends BaseEntity implements UserDetails, Principal, Serializable {
|
|
private static final long serialVersionUID = 1L;
|
|
public static final String USER_STATUS_ACTIVE = "01"; // 사용자 활성
|
public static final String USER_STATUS_DEL = "02"; // 사용자 탈퇴
|
public static final String DEFAULT_PROFILE = "assets/images/default_profile.png"; // 기본 프로필
|
public static final String DEFAULT_RESERVATION_NOTIFY_TIME = "09:00"; // 기본 이메일 알림 예정 시간
|
public static final String DEFAULT_LANGUAGE = "ko"; // 기본 언어
|
|
public static final String INSERT_TYPE_NORMAL = "N"; // 추가 타입(일반)
|
public static final String INSERT_TYPE_API = "A"; // 추가 타입(API)
|
|
@Id
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
private Long id;
|
private String name;
|
private String account;
|
private String password;
|
private String status;
|
private String phone;
|
private String profile;
|
private String awsKey;
|
@Enumerated(EnumType.STRING)
|
private SocialType socialType;
|
private Long lastWorkspaceId;
|
private Long lastProjectId;
|
private Date lastLoginDate;
|
private String reservationNotifyTime; // 이메일 알림 시간 예정
|
private String language;
|
private String licensekey;
|
private String insertType = User.INSERT_TYPE_NORMAL;
|
|
@OneToMany(mappedBy = "user", cascade = {CascadeType.ALL}, orphanRemoval = true)
|
private Set<SystemRoleUser> systemRoleUsers = new HashSet<>();
|
|
@OneToMany(mappedBy = "user", cascade = {CascadeType.ALL}, orphanRemoval = true)
|
private Set<ProjectRoleUser> projectRoleUsers = new HashSet<>();
|
|
@OneToMany(mappedBy = "user", cascade = {CascadeType.ALL}, orphanRemoval = true)
|
private Set<IssueUser> issueUsers = new HashSet<>();
|
|
@OneToMany(mappedBy = "user", cascade = {CascadeType.ALL}, orphanRemoval = true)
|
private Set<UserLikeIssue> userLikeIssues = new HashSet<>();
|
|
@OneToMany(mappedBy = "user", cascade = {CascadeType.ALL}, orphanRemoval = true)
|
private Set<UserWorkspace> userWorkspaces = new HashSet<>();
|
|
@OneToMany(mappedBy = "user", cascade = {CascadeType.ALL}, orphanRemoval = true)
|
private Set<IssueSearch> issueSearches = new HashSet<>();
|
|
@OneToMany(mappedBy = "user", cascade = {CascadeType.ALL}, orphanRemoval = true)
|
private Set<IssueTableConfig> issueTableConfigs = new HashSet<>();
|
|
@ManyToOne(targetEntity = UserLevel.class, fetch = FetchType.LAZY)
|
@JoinColumn(name="level_id")
|
private UserLevel userLevel;
|
|
@OneToMany(mappedBy = "user", cascade = {CascadeType.ALL}, orphanRemoval = true)
|
private Set<ApiToken> apiTokens = new HashSet<>();
|
|
public User() {
|
}
|
|
public User(Long id, String name, String account) {
|
this.id = id;
|
this.name = name;
|
this.account = account;
|
}
|
|
public UserLevel getUserLevel() {
|
return userLevel;
|
}
|
|
public void setUserLevel(UserLevel userLevel) {
|
this.userLevel = userLevel;
|
}
|
|
|
public Long getId() {
|
return id;
|
}
|
|
public void setId(Long id) {
|
this.id = id;
|
}
|
|
public String getAccount() {
|
return account;
|
}
|
|
public void setAccount(String account) {
|
this.account = account;
|
}
|
|
public String getPassword() {
|
return password;
|
}
|
|
public void setPassword(String password) {
|
this.password = password;
|
}
|
|
public String getName() {
|
return name;
|
}
|
|
public void setName(String name) {
|
this.name = name;
|
}
|
|
public String getProfile() {
|
return profile;
|
}
|
|
public void setProfile(String profile) {
|
this.profile = profile;
|
}
|
|
public String getStatus() {
|
return status;
|
}
|
|
public void setStatus(String status) {
|
this.status = status;
|
}
|
|
public SocialType getSocialType() {
|
return socialType;
|
}
|
|
public void setSocialType(SocialType socialType) {
|
this.socialType = socialType;
|
}
|
|
public String getPhone() {
|
return phone;
|
}
|
|
public void setPhone(String phone) {
|
this.phone = phone;
|
}
|
|
public Long getLastWorkspaceId() {
|
return lastWorkspaceId;
|
}
|
|
public Long getLastProjectId() {return lastProjectId; }
|
|
public void setLastProjectId(Long lastProjectId) {
|
this.lastProjectId = lastProjectId;
|
}
|
|
public String getAwsKey() {
|
return awsKey;
|
}
|
|
public void setAwsKey(String awsKey) {
|
this.awsKey = awsKey;
|
}
|
|
public void setLastWorkspaceId(Long lastWorkspaceId) {
|
this.lastWorkspaceId = lastWorkspaceId;
|
}
|
|
public Set<SystemRoleUser> getSystemRoleUsers() {
|
return systemRoleUsers;
|
}
|
|
public Set<IssueSearch> getIssueSearches() {
|
return issueSearches;
|
}
|
|
public void setIssueSearches(Set<IssueSearch> issueSearches) {
|
this.issueSearches = issueSearches;
|
}
|
|
public void setSystemRoleUsers(Set<SystemRoleUser> systemRoleUsers) {
|
this.systemRoleUsers = systemRoleUsers;
|
}
|
|
public void addSystemRole(SystemRole systemRole) {
|
if (this.systemRoleUsers == null) {
|
this.systemRoleUsers = new HashSet<>();
|
}
|
SystemRoleUser systemRoleUser = new SystemRoleUser(systemRole, this);
|
|
this.systemRoleUsers.add(systemRoleUser);
|
}
|
|
public Set<ProjectRoleUser> getProjectRoleUsers() {
|
return projectRoleUsers;
|
}
|
|
public void setProjectRoleUsers(Set<ProjectRoleUser> projectRoleUsers) {
|
this.projectRoleUsers = projectRoleUsers;
|
}
|
|
public String getInsertType() {
|
return insertType;
|
}
|
|
public void setInsertType(String insertType) {
|
this.insertType = insertType;
|
}
|
|
public void addProjectRole(ProjectRole projectRole) {
|
if (this.projectRoleUsers == null) {
|
this.projectRoleUsers = new HashSet<>();
|
}
|
ProjectRoleUser projectRoleUser = new ProjectRoleUser(projectRole, this);
|
|
this.projectRoleUsers.add(projectRoleUser);
|
}
|
|
public void removeProjectRole(ProjectRole projectRole) {
|
Iterator<ProjectRoleUser> iterator = this.projectRoleUsers.iterator();
|
|
while (iterator.hasNext()) {
|
ProjectRoleUser projectRoleUser = iterator.next();
|
if (projectRole.getId().equals(projectRoleUser.getProjectRole().getId())) {
|
this.projectRoleUsers.remove(projectRoleUser);
|
break;
|
}
|
}
|
}
|
|
public Set<IssueUser> getIssueUsers() {
|
return issueUsers;
|
}
|
|
public void setIssueUsers(Set<IssueUser> issueUsers) {
|
this.issueUsers = issueUsers;
|
}
|
|
public void addIssue(Issue issue) {
|
if (this.issueUsers == null) {
|
this.issueUsers = new HashSet<>();
|
}
|
IssueUser issueUser = new IssueUser(issue, this);
|
|
this.issueUsers.add(issueUser);
|
}
|
|
public void removeIssue(Issue issue) {
|
Iterator<IssueUser> iterator = this.issueUsers.iterator();
|
|
while (iterator.hasNext()) {
|
IssueUser issueUser = iterator.next();
|
if (issue.getId().equals(issueUser.getIssue().getId())) {
|
this.issueUsers.remove(issueUser);
|
break;
|
}
|
}
|
}
|
|
public Set<UserWorkspace> getUserWorkspaces() {
|
return userWorkspaces;
|
}
|
|
public void setUserWorkspaces(Set<UserWorkspace> userWorkspaces) {
|
this.userWorkspaces = userWorkspaces;
|
}
|
|
public Set<UserLikeIssue> getUserLikeIssues() {
|
return userLikeIssues;
|
}
|
|
public void setUserLikeIssues(Set<UserLikeIssue> userLikeIssues) {
|
this.userLikeIssues = userLikeIssues;
|
}
|
|
public String getReservationNotifyTime() {
|
return reservationNotifyTime;
|
}
|
|
public void setReservationNotifyTime(String reservationNotifyTime) {
|
this.reservationNotifyTime = reservationNotifyTime;
|
}
|
|
public Set<IssueTableConfig> getIssueTableConfigs() {
|
return issueTableConfigs;
|
}
|
|
public void setIssueTableConfigs(Set<IssueTableConfig> issueTableConfigs) {
|
this.issueTableConfigs = issueTableConfigs;
|
}
|
|
public String getLanguage() {
|
return language;
|
}
|
|
public void setLanguage(String language) {
|
this.language = language;
|
}
|
|
|
public Integer getPermission() {
|
return this.userLevel.getPermission();
|
}
|
|
// wyu - TEST
|
// public void setPermission(Integer permission) {
|
// this.userLevel.setPermission(permission);
|
// }
|
|
public String getLicensekey() {
|
return licensekey;
|
}
|
|
public void setLicensekey(String licensekey) {
|
this.licensekey = licensekey;
|
}
|
|
public Set<ApiToken> getApiTokens() {
|
return apiTokens;
|
}
|
|
public void setApiTokens(Set<ApiToken> apiTokens) {
|
this.apiTokens = apiTokens;
|
}
|
|
@Override
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
// TODO Auto-generated method stub
|
return null;
|
}
|
|
@Override
|
public String getUsername() {
|
return this.account;
|
}
|
|
@Override
|
public boolean isAccountNonExpired() {
|
return true;
|
}
|
|
@Override
|
public boolean isAccountNonLocked() {
|
return true;
|
}
|
|
@Override
|
public boolean isCredentialsNonExpired() {
|
return true;
|
}
|
|
@Override
|
public boolean isEnabled() {
|
return true;
|
}
|
|
@Override
|
public int hashCode() {
|
final int prime = 31;
|
int result = 1;
|
result = prime * result + ((this.account == null) ? 0 : this.account.hashCode());
|
result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
|
return result;
|
}
|
|
@Override
|
public boolean equals(Object obj) {
|
if (this == obj) {
|
return true;
|
}
|
if (obj == null) {
|
return false;
|
}
|
if (getClass() != obj.getClass()) {
|
return false;
|
}
|
User other = (User) obj;
|
if (this.account == null) {
|
if (other.account != null) {
|
return false;
|
}
|
}
|
else if (!this.account.equals(other.account)) {
|
return false;
|
}
|
if (this.id == null) {
|
if (other.id != null) {
|
return false;
|
}
|
}
|
else if (!this.id.equals(other.id)) {
|
return false;
|
}
|
return true;
|
}
|
|
public void setLastLoginDate(Date date) { this.lastLoginDate = date; }
|
public Date getLastLoginDate() { return this.lastLoginDate; }
|
|
/*@Override
|
public String toString() {
|
return CommonUtil.decryptAES128(this.account);
|
}*/
|
}
|