source: src/main/java/com/example/autopartz/model/Warehouseman.java@ 7d43957

main
Last change on this file since 7d43957 was 7d43957, checked in by andrejtodorovski <82031894+andrejtodorovski@…>, 18 months ago

Added functionalities

  • Property mode set to 100644
File size: 1.7 KB
Line 
1package com.example.autopartz.model;
2
3import lombok.Getter;
4import lombok.RequiredArgsConstructor;
5import lombok.Setter;
6import lombok.ToString;
7import org.hibernate.Hibernate;
8import org.springframework.security.core.GrantedAuthority;
9
10import javax.persistence.Entity;
11import javax.persistence.JoinColumn;
12import javax.persistence.ManyToOne;
13import java.time.LocalDate;
14import java.util.Collection;
15import java.util.Collections;
16import java.util.Objects;
17
18@Getter
19@Setter
20@ToString
21@RequiredArgsConstructor
22@Entity
23public 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_user != null && Objects.equals(ID_user, that.ID_user);
42 }
43
44 @Override
45 public int hashCode() {
46 return getClass().hashCode();
47 }
48 @Override
49 public Collection<? extends GrantedAuthority> getAuthorities() {
50 if(employed_from==defaultEmployedFrom)
51 return Collections.singletonList(Role.ROLE_PENDING_WAREHOUSEMAN);
52 else
53 return Collections.singletonList(Role.ROLE_WAREHOUSEMAN);
54 }
55}
Note: See TracBrowser for help on using the repository browser.