source: sources/app/src/main/java/parkup/entities/Worker.java@ 98f448a

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

parkingZone and parkingSession services fix

  • Property mode set to 100644
File size: 5.6 KB
RevLine 
[ce6ad22]1package parkup.entities;
2
[97fbc67]3import org.springframework.security.core.GrantedAuthority;
[9dd526f]4import org.springframework.security.core.authority.SimpleGrantedAuthority;
[97fbc67]5import org.springframework.security.core.userdetails.UserDetails;
[9ff45d6]6import parkup.data.enumarations.EmployeeStatus;
[9dd526f]7import parkup.data.enumarations.UserRole;
[ce6ad22]8
9import javax.persistence.*;
10import java.util.ArrayList;
[97fbc67]11import java.util.Collection;
[9dd526f]12import java.util.Collections;
[ce6ad22]13import java.util.List;
14
15@Entity
[9dd526f]16@Table(name = "worker")
17public class Worker implements UserDetails {
[ce6ad22]18 @Id
19 @SequenceGenerator(
[9dd526f]20 name="worker_sequence_generator",
21 sequenceName = "worker_sequence",
[ce6ad22]22 allocationSize = 1,
23 initialValue = 200
24 )
25 @GeneratedValue( //za postgres treba sequence da se namesti i ime na generator mi ga davamo kako od gore sto e
26 strategy = GenerationType.SEQUENCE,
[9dd526f]27 generator = "worker_sequence_generator"
[ce6ad22]28 )
[9dd526f]29 @Column(name = "workerId")
30 private int workerId;
[ce6ad22]31
[97fbc67]32 @Override
33 public String toString() {
34 return "Vraboten{" +
35 "firstName='" + firstName + '\'' +
36 ", lastName='" + lastName + '\'' +
37 ", parkingZones=" + parkingZones +
38 ", locked=" + locked +
39 ", enabled=" + enabled +
40 '}';
41 }
42
[ce6ad22]43 @Column(name = "firstName")
44 private String firstName;
45
46 @Column(name = "lastName")
47 private String lastName;
48
49 @Column(name = "email")
50 private String email;
51
52 @Column(name = "password")
53 private String password;
54
55 @Column(name = "mobile")
56 private String mobile;
57
[9dd526f]58 @Enumerated
[ce6ad22]59 @Column(name = "role")
[9dd526f]60 private UserRole role;
[ce6ad22]61
[98f448a]62 @ManyToMany
[ce6ad22]63 private List<ParkingZone> parkingZones;
64
65 @Column(name = "status")
[9ff45d6]66 private EmployeeStatus status;
67
68 public void setLocked(boolean locked) {
69 this.locked = locked;
70 }
[ce6ad22]71
[97fbc67]72 @Column(name="locked")
73 private boolean locked;
74
75 @Column(name = "enabled")
76 private boolean enabled;
77
[ce6ad22]78
[9dd526f]79 public Worker() {
[98f448a]80 this.role = UserRole.ROLE_WORKER;
[ce6ad22]81 this.parkingZones = new ArrayList<ParkingZone>();
[9ff45d6]82 this.enabled = true;
83 this.status = EmployeeStatus.NOT_WORKING;
[ce6ad22]84 }
85
[9dd526f]86 public Worker(int workerId, String firstName, String lastName, String email, String password, String mobile, List<ParkingZone> parkingZones) {
87 this.workerId = workerId;
[ce6ad22]88 this.firstName = firstName;
89 this.lastName = lastName;
90 this.email = email;
91 this.password = password;
92 this.mobile = mobile;
93 this.parkingZones = parkingZones;
[98f448a]94 this.role = UserRole.ROLE_WORKER;
[9ff45d6]95 this.enabled = true;
96 this.status = EmployeeStatus.NOT_WORKING;
[ce6ad22]97 }
98
[9dd526f]99 public Worker(String firstName, String lastName, String email, String password, String mobile, List<ParkingZone> parkingZones) {
[ce6ad22]100 this.firstName = firstName;
101 this.lastName = lastName;
102 this.email = email;
103 this.password = password;
104 this.mobile = mobile;
105 this.parkingZones = parkingZones;
[98f448a]106 this.role = UserRole.ROLE_WORKER;
[9ff45d6]107 this.enabled = true;
108 this.status = EmployeeStatus.NOT_WORKING;
[ce6ad22]109 }
110
[9dd526f]111 public Worker(String firstName, String lastName, String email, String password, String mobile) {
[97fbc67]112 this.firstName=firstName;
113 this.lastName=lastName;
114 this.email=email;
115 this.password=password;
116 this.mobile=mobile;
117 this.parkingZones=new ArrayList<>();
[98f448a]118 this.role = UserRole.ROLE_WORKER;
[9ff45d6]119 this.enabled=true;
120 this.status = EmployeeStatus.NOT_WORKING;
[97fbc67]121 }
122
[9dd526f]123 public int getWorkerId() {
124 return workerId;
[ce6ad22]125 }
126
[9dd526f]127 public void setWorkerId(int workerId) {
128 this.workerId = workerId;
[ce6ad22]129 }
130
131 public String getFirstName() {
132 return firstName;
133 }
134
135 public void setFirstName(String firstName) {
136 this.firstName = firstName;
137 }
138
139 public String getLastName() {
140 return lastName;
141 }
142
143 public void setLastName(String lastName) {
144 this.lastName = lastName;
145 }
146
147 public String getEmail() {
148 return email;
149 }
150
151 public void setEmail(String email) {
152 this.email = email;
153 }
154
[97fbc67]155 @Override
156 public Collection<? extends GrantedAuthority> getAuthorities() {
[9dd526f]157 SimpleGrantedAuthority authority = new SimpleGrantedAuthority(role.getAuthority());
158 return Collections.singleton(authority);
[97fbc67]159 }
160
[ce6ad22]161 public String getPassword() {
162 return password;
163 }
164
[97fbc67]165 @Override
166 public String getUsername() {
167 return email;
168 }
169
170 @Override
171 public boolean isAccountNonExpired() {
172 return true;
173 }
174
175 @Override
176 public boolean isAccountNonLocked() {
177 return !locked;
178 }
179
180 public void lockVraboten(){
181 this.locked = !locked;
182 }
183
184 @Override
185 public boolean isCredentialsNonExpired() {
186 return true;
187 }
188
189 @Override
190 public boolean isEnabled() {
191 return enabled;
192 }
193
[ce6ad22]194 public void setPassword(String password) {
195 this.password = password;
196 }
197
198 public String getMobile() {
199 return mobile;
200 }
201
202 public void setMobile(String mobile) {
203 this.mobile = mobile;
204 }
205
[9dd526f]206 public UserRole getRole() {return role;}
[ce6ad22]207
[9dd526f]208 public void setRole(UserRole role) {this.role = role;}
[ce6ad22]209
210 public List<ParkingZone> getParkingZones() {return parkingZones;}
211
212 public void setParkingZones(List<ParkingZone> parkingZones) {this.parkingZones = parkingZones;}
213
[9ff45d6]214 public EmployeeStatus getStatus() {return status;}
[ce6ad22]215
[9ff45d6]216 public void setStatus(EmployeeStatus status) {this.status = status;}
[ce6ad22]217
[97fbc67]218 public boolean isAccount() {return enabled;}
[ce6ad22]219
[97fbc67]220 public void setAccount(boolean account) {this.enabled = account;}
[ce6ad22]221}
Note: See TracBrowser for help on using the repository browser.