1 | package com.example.autopartz.model;
|
---|
2 |
|
---|
3 | import lombok.Getter;
|
---|
4 | import lombok.RequiredArgsConstructor;
|
---|
5 | import lombok.Setter;
|
---|
6 | import lombok.ToString;
|
---|
7 | import org.hibernate.Hibernate;
|
---|
8 | import org.springframework.security.core.GrantedAuthority;
|
---|
9 |
|
---|
10 | import javax.persistence.Entity;
|
---|
11 | import javax.persistence.JoinColumn;
|
---|
12 | import javax.persistence.ManyToOne;
|
---|
13 | import java.time.LocalDate;
|
---|
14 | import java.util.Collection;
|
---|
15 | import java.util.Collections;
|
---|
16 | import java.util.Objects;
|
---|
17 |
|
---|
18 | @Getter
|
---|
19 | @Setter
|
---|
20 | @ToString
|
---|
21 | @RequiredArgsConstructor
|
---|
22 | @Entity
|
---|
23 | public class Warehouseman extends User{
|
---|
24 | LocalDate employed_from;
|
---|
25 | public static final LocalDate defaultEmployedFrom = LocalDate.of(2020,1,1);
|
---|
26 | @ManyToOne
|
---|
27 | @JoinColumn(name = "id_warehouse")
|
---|
28 | Warehouse warehouse;
|
---|
29 |
|
---|
30 | public Warehouseman(String username, String name, String email, String password, String number, Warehouse warehouse) {
|
---|
31 | super(username, name, email, password, number);
|
---|
32 | this.employed_from=defaultEmployedFrom;
|
---|
33 | this.warehouse= warehouse;
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | public boolean equals(Object o) {
|
---|
38 | if (this == o) return true;
|
---|
39 | if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
|
---|
40 | Warehouseman that = (Warehouseman) o;
|
---|
41 | return id != null && Objects.equals(id, that.id);
|
---|
42 | }
|
---|
43 |
|
---|
44 | @Override
|
---|
45 | public int hashCode() {
|
---|
46 | return getClass().hashCode();
|
---|
47 | }
|
---|
48 | @Override
|
---|
49 | public Collection<? extends GrantedAuthority> getAuthorities() {
|
---|
50 | if(Objects.equals(employed_from, defaultEmployedFrom))
|
---|
51 | return Collections.singletonList(Role.ROLE_PENDING_WAREHOUSEMAN);
|
---|
52 | else
|
---|
53 | return Collections.singletonList(Role.ROLE_WAREHOUSEMAN);
|
---|
54 | }
|
---|
55 | }
|
---|