Stirling-PDF/src/main/java/stirling/software/SPDF/model/User.java

125 lines
2.8 KiB
Java
Raw Normal View History

2023-08-12 03:29:10 +02:00
package stirling.software.SPDF.model;
import java.util.Set;
2023-08-13 02:12:29 +02:00
import java.util.stream.Collectors;
2023-08-12 03:29:10 +02:00
import jakarta.persistence.CascadeType;
2023-08-13 02:12:29 +02:00
import jakarta.persistence.CollectionTable;
2023-08-12 03:29:10 +02:00
import jakarta.persistence.Column;
2023-08-13 02:12:29 +02:00
import jakarta.persistence.ElementCollection;
2023-08-12 03:29:10 +02:00
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
2023-08-15 01:39:13 +02:00
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
2023-08-12 03:29:10 +02:00
import jakarta.persistence.Id;
2023-08-13 02:12:29 +02:00
import jakarta.persistence.MapKeyColumn;
2023-08-12 03:29:10 +02:00
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
2023-08-13 02:12:29 +02:00
import jakarta.persistence.JoinColumn;
import java.util.Map;
import java.util.HashMap;
import java.util.HashSet;
2023-08-12 03:29:10 +02:00
@Entity
@Table(name = "users")
public class User {
2023-08-15 01:39:13 +02:00
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "user_id")
private Long id;
@Column(name = "username", unique = true)
2023-08-12 03:29:10 +02:00
private String username;
@Column(name = "password")
private String password;
2023-08-13 11:53:00 +02:00
@Column(name = "apiKey")
private String apiKey;
2023-08-12 03:29:10 +02:00
@Column(name = "enabled")
private boolean enabled;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "user")
2023-08-13 02:12:29 +02:00
private Set<Authority> authorities = new HashSet<>();
@ElementCollection
@MapKeyColumn(name = "setting_key")
@Column(name = "setting_value")
2023-08-15 01:39:13 +02:00
@CollectionTable(name = "user_settings", joinColumns = @JoinColumn(name = "user_id"))
2023-08-13 02:12:29 +02:00
private Map<String, String> settings = new HashMap<>(); // Key-value pairs of settings.
2023-08-15 01:39:13 +02:00
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
2023-08-13 11:53:00 +02:00
public String getApiKey() {
return apiKey;
}
public void setApiKey(String apiKey) {
this.apiKey = apiKey;
}
2023-08-13 02:12:29 +02:00
public Map<String, String> getSettings() {
return settings;
}
public void setSettings(Map<String, String> settings) {
this.settings = settings;
}
2023-08-12 03:29:10 +02:00
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public Set<Authority> getAuthorities() {
return authorities;
}
public void setAuthorities(Set<Authority> authorities) {
this.authorities = authorities;
}
2023-08-13 02:12:29 +02:00
public void addAuthorities(Set<Authority> authorities) {
this.authorities.addAll(authorities);
}
public void addAuthority(Authority authorities) {
this.authorities.add(authorities);
}
public String getRolesAsString() {
return this.authorities.stream()
.map(Authority::getAuthority)
.collect(Collectors.joining(", "));
}
2023-08-12 03:29:10 +02:00
}