1 | package finki.diplomska.tripplanner.models;
|
---|
2 |
|
---|
3 | import com.fasterxml.jackson.annotation.JsonIgnore;
|
---|
4 | import com.fasterxml.jackson.annotation.JsonManagedReference;
|
---|
5 | import lombok.AllArgsConstructor;
|
---|
6 | import lombok.Getter;
|
---|
7 | import lombok.Setter;
|
---|
8 | import org.springframework.security.core.GrantedAuthority;
|
---|
9 | import org.springframework.security.core.userdetails.UserDetails;
|
---|
10 |
|
---|
11 | import javax.persistence.*;
|
---|
12 | import javax.validation.constraints.Email;
|
---|
13 | import javax.validation.constraints.NotBlank;
|
---|
14 | import java.util.ArrayList;
|
---|
15 | import java.util.Collection;
|
---|
16 | import java.util.Date;
|
---|
17 | import java.util.List;
|
---|
18 |
|
---|
19 | @Entity
|
---|
20 | @Table(name = "users")
|
---|
21 | @AllArgsConstructor
|
---|
22 | @Getter
|
---|
23 | @Setter
|
---|
24 | public class User implements UserDetails {
|
---|
25 |
|
---|
26 | @Id
|
---|
27 | @GeneratedValue(strategy = GenerationType.IDENTITY)
|
---|
28 | private Long id;
|
---|
29 |
|
---|
30 | @Email(message = "Username needs to be an email")
|
---|
31 | @NotBlank(message = "username is required")
|
---|
32 | @Column(unique = true)
|
---|
33 | private String username;
|
---|
34 | @NotBlank(message = "Please enter your full name")
|
---|
35 | private String fullName;
|
---|
36 | @NotBlank(message = "Password field is required")
|
---|
37 | private String password;
|
---|
38 | @Transient
|
---|
39 | private String confirmPassword;
|
---|
40 | private Date create_At;
|
---|
41 | private Date update_At;
|
---|
42 |
|
---|
43 | //OneToMany with Planners
|
---|
44 | @OneToMany(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER, mappedBy = "user", orphanRemoval = true)
|
---|
45 | @JsonIgnore
|
---|
46 | private List<Planner> planners = new ArrayList<>();
|
---|
47 |
|
---|
48 | @OneToMany(cascade = CascadeType.REFRESH, mappedBy = "user", orphanRemoval = true)
|
---|
49 | @JsonIgnore
|
---|
50 | private List<Location> locationList = new ArrayList<>();;
|
---|
51 |
|
---|
52 | public User() {
|
---|
53 | }
|
---|
54 |
|
---|
55 | public User(String username, String fullName, String password, String confirmPassword) {
|
---|
56 | this.username = username;
|
---|
57 | this.fullName = fullName;
|
---|
58 | this.password = password;
|
---|
59 | this.confirmPassword = confirmPassword;
|
---|
60 | }
|
---|
61 |
|
---|
62 | @PrePersist
|
---|
63 | protected void onCreate(){
|
---|
64 | this.create_At = new Date();
|
---|
65 | }
|
---|
66 | @PreUpdate
|
---|
67 | protected void onUpdate(){
|
---|
68 | this.update_At = new Date();
|
---|
69 | }
|
---|
70 |
|
---|
71 | @Override
|
---|
72 | @JsonIgnore
|
---|
73 | public Collection<? extends GrantedAuthority> getAuthorities() {
|
---|
74 | return null;
|
---|
75 | }
|
---|
76 |
|
---|
77 | @Override
|
---|
78 | @JsonIgnore
|
---|
79 | public boolean isAccountNonExpired() {
|
---|
80 | return true;
|
---|
81 | }
|
---|
82 |
|
---|
83 | @Override
|
---|
84 | @JsonIgnore
|
---|
85 | public boolean isAccountNonLocked() {
|
---|
86 | return true;
|
---|
87 | }
|
---|
88 |
|
---|
89 | @Override
|
---|
90 | @JsonIgnore
|
---|
91 | public boolean isCredentialsNonExpired() {
|
---|
92 | return true;
|
---|
93 | }
|
---|
94 |
|
---|
95 | @Override
|
---|
96 | @JsonIgnore
|
---|
97 | public boolean isEnabled() {
|
---|
98 | return true;
|
---|
99 | }
|
---|
100 | }
|
---|