source: src/main/java/com/example/autopartz/model/Warehouseman.java@ 676144b

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

Added admin view of pending roles and approve functionality

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[2e46f06]1package com.example.autopartz.model;
2
[ae042f4]3import lombok.Getter;
4import lombok.RequiredArgsConstructor;
5import lombok.Setter;
6import lombok.ToString;
[2e46f06]7import org.hibernate.Hibernate;
[ae042f4]8import org.springframework.security.core.GrantedAuthority;
[2e46f06]9
[ae042f4]10import javax.persistence.Entity;
11import javax.persistence.JoinColumn;
12import javax.persistence.ManyToOne;
[2e46f06]13import java.time.LocalDate;
[ae042f4]14import java.util.Collection;
15import java.util.Collections;
[2e46f06]16import java.util.Objects;
17
18@Getter
19@Setter
20@ToString
21@RequiredArgsConstructor
22@Entity
23public 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}
Note: See TracBrowser for help on using the repository browser.