source: sources/app/src/main/java/parkup/entities/Administrator.java@ b519b38

Last change on this file since b519b38 was 98f448a, checked in by andrejTavchioski <andrej.tavchioski@…>, 2 years ago

parkingZone and parkingSession services fix

  • Property mode set to 100644
File size: 4.2 KB
Line 
1package parkup.entities;
2
3import org.springframework.security.core.GrantedAuthority;
4import org.springframework.security.core.authority.SimpleGrantedAuthority;
5import org.springframework.security.core.userdetails.UserDetails;
6import parkup.data.enumarations.UserRole;
7
8import javax.persistence.*;
9import java.util.Collection;
10import java.util.Collections;
11
12@Entity
13@Table(name = "administrator")
14public class Administrator implements UserDetails {
15 @Id
16 @SequenceGenerator(
17 name="administrator_sequence_generator",
18 sequenceName = "administrator_sequence",
19 allocationSize = 1,
20 initialValue = 100
21 )
22 @GeneratedValue( //za postgres treba sequence da se namesti i ime na generator mi ga davamo kako od gore sto e
23 strategy = GenerationType.SEQUENCE,
24 generator = "administrator_sequence_generator"
25 )
26 @Column(name = "administratorId")
27 private int administratorId;
28
29 @Column(name = "firstName")
30 private String firstName;
31
32 @Column(name = "lastName")
33 private String lastName;
34
35 @Column(name = "email")
36 private String email;
37
38 @Column(name = "password")
39 private String password;
40
41 @Column(name = "mobile")
42 private String mobile;
43
44 @Enumerated
45 @Column(name = "role")
46 private UserRole role;
47
48 private boolean locked;
49
50 private boolean enabled;
51
52 public Administrator(){
53 this.role = UserRole.ROLE_ADMIN;
54 this.enabled=true;
55 }
56
57 public Administrator(int administratorId, String firstName, String lastName, String email, String password, String mobile) {
58 this.administratorId = administratorId;
59 this.firstName = firstName;
60 this.lastName = lastName;
61 this.email = email;
62 this.password = password;
63 this.mobile = mobile;
64 this.enabled=true;
65 this.role = UserRole.ROLE_ADMIN;
66 }
67
68 public Administrator(String firstName, String lastName, String email, String password, String mobile) {
69 this.firstName = firstName;
70 this.lastName = lastName;
71 this.email = email;
72 this.password = password;
73 this.mobile = mobile;
74 this.role = UserRole.ROLE_ADMIN;
75 this.enabled=true;
76 }
77
78 public Administrator(String firstName, String lastName, String email, String password) {
79 this.firstName = firstName;
80 this.lastName = lastName;
81 this.email = email;
82 this.password = password;
83 this.mobile = mobile;
84 this.role = UserRole.ROLE_ADMIN;
85 this.enabled=true;
86 }
87
88 public int getAdministratorId() {
89 return administratorId;
90 }
91
92 public void setAdministratorId(int administratorId) {
93 this.administratorId = administratorId;
94 }
95
96 public String getFirstName() {
97 return firstName;
98 }
99
100 public void setFirstName(String firstName) {
101 this.firstName = firstName;
102 }
103
104 public String getLastName() {
105 return lastName;
106 }
107
108 public void setLastName(String lastName) {
109 this.lastName = lastName;
110 }
111
112 public String getEmail() {
113 return email;
114 }
115
116 public void setEmail(String email) {
117 this.email = email;
118 }
119
120 public void setPassword(String password) {
121 this.password = password;
122 }
123
124 public String getMobile() {
125 return mobile;
126 }
127
128 public void setMobile(String mobile) {
129 this.mobile = mobile;
130 }
131
132 public UserRole getRole() {return role;}
133
134 public void setRole(UserRole role) {this.role = role;}
135
136 @Override
137 public Collection<? extends GrantedAuthority> getAuthorities() {
138 SimpleGrantedAuthority authority = new SimpleGrantedAuthority(role.getAuthority());
139 return Collections.singleton(authority);
140 }
141
142 @Override
143 public String getPassword() {
144 return password;
145 }
146
147 @Override
148 public String getUsername() {
149 return email;
150 }
151
152 @Override
153 public boolean isAccountNonExpired() {
154 return true;
155 }
156
157 @Override
158 public boolean isAccountNonLocked() {
159 return !locked;
160 }
161
162 @Override
163 public boolean isCredentialsNonExpired() {
164 return true;
165 }
166
167 @Override
168 public boolean isEnabled() {
169 return enabled;
170 }
171}
Note: See TracBrowser for help on using the repository browser.