[2e46f06] | 1 | package com.example.autopartz.model;
|
---|
| 2 |
|
---|
[ae042f4] | 3 | import lombok.Getter;
|
---|
| 4 | import lombok.RequiredArgsConstructor;
|
---|
| 5 | import lombok.Setter;
|
---|
| 6 | import lombok.ToString;
|
---|
[2e46f06] | 7 | import org.hibernate.Hibernate;
|
---|
[ae042f4] | 8 | import org.springframework.security.core.GrantedAuthority;
|
---|
[2e46f06] | 9 |
|
---|
[ae042f4] | 10 | import javax.persistence.Entity;
|
---|
| 11 | import javax.persistence.JoinColumn;
|
---|
| 12 | import javax.persistence.ManyToOne;
|
---|
[2e46f06] | 13 | import java.time.LocalDate;
|
---|
[ae042f4] | 14 | import java.util.Collection;
|
---|
| 15 | import java.util.Collections;
|
---|
[2e46f06] | 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;
|
---|
[7d43957] | 25 | public static final LocalDate defaultEmployedFrom = LocalDate.of(2020,1,1);
|
---|
[2e46f06] | 26 | @ManyToOne
|
---|
| 27 | @JoinColumn(name = "id_warehouse")
|
---|
| 28 | Warehouse warehouse;
|
---|
| 29 |
|
---|
[7d43957] | 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 |
|
---|
[2e46f06] | 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;
|
---|
[676144b] | 41 | return id != null && Objects.equals(id, that.id);
|
---|
[2e46f06] | 42 | }
|
---|
| 43 |
|
---|
| 44 | @Override
|
---|
| 45 | public int hashCode() {
|
---|
| 46 | return getClass().hashCode();
|
---|
| 47 | }
|
---|
[ae042f4] | 48 | @Override
|
---|
| 49 | public Collection<? extends GrantedAuthority> getAuthorities() {
|
---|
[676144b] | 50 | if(Objects.equals(employed_from, defaultEmployedFrom))
|
---|
[7d43957] | 51 | return Collections.singletonList(Role.ROLE_PENDING_WAREHOUSEMAN);
|
---|
| 52 | else
|
---|
| 53 | return Collections.singletonList(Role.ROLE_WAREHOUSEMAN);
|
---|
[ae042f4] | 54 | }
|
---|
[2e46f06] | 55 | }
|
---|