[ce6ad22] | 1 | package parkup.entities;
|
---|
| 2 |
|
---|
| 3 | import javax.persistence.*;
|
---|
| 4 |
|
---|
[9dd526f] | 5 | import org.springframework.security.core.GrantedAuthority;
|
---|
| 6 | import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
---|
| 7 | import org.springframework.security.core.userdetails.UserDetails;
|
---|
| 8 | import parkup.data.Plate;
|
---|
| 9 | import parkup.data.enumarations.UserRole;
|
---|
| 10 |
|
---|
| 11 | import java.util.Collection;
|
---|
| 12 | import java.util.Collections;
|
---|
[ce6ad22] | 13 |
|
---|
| 14 | @Entity
|
---|
| 15 | @Table(name = "guest")
|
---|
[9dd526f] | 16 | public class Guest implements UserDetails {
|
---|
[ce6ad22] | 17 | @Id
|
---|
| 18 | @SequenceGenerator(
|
---|
| 19 | name="guest_sequence_generator",
|
---|
| 20 | sequenceName = "guest_sequence",
|
---|
| 21 | allocationSize = 1,
|
---|
| 22 | initialValue = 400
|
---|
| 23 | )
|
---|
[3753356] | 24 | @GeneratedValue(
|
---|
[ce6ad22] | 25 | strategy = GenerationType.SEQUENCE,
|
---|
| 26 | generator = "guest_sequence_generator"
|
---|
| 27 | )
|
---|
| 28 | @Column(name = "guestId")
|
---|
| 29 | private int guestId;
|
---|
| 30 |
|
---|
| 31 | @OneToOne
|
---|
| 32 | @JoinColumn(name = "tablickaId", nullable = false)
|
---|
[9dd526f] | 33 | private Plate plate;
|
---|
[ce6ad22] | 34 |
|
---|
| 35 | @Column(name = "email")
|
---|
| 36 | private String email;
|
---|
| 37 |
|
---|
| 38 | @Column(name = "mobile")
|
---|
| 39 | private String mobile;
|
---|
| 40 |
|
---|
[3753356] | 41 | @Column(name = "password")
|
---|
| 42 | private String password;
|
---|
| 43 |
|
---|
[9ff45d6] | 44 | @OneToOne
|
---|
| 45 | private ParkingSession session;
|
---|
| 46 |
|
---|
[9dd526f] | 47 | @Enumerated
|
---|
| 48 | private UserRole role;
|
---|
| 49 |
|
---|
[ce6ad22] | 50 |
|
---|
[98f448a] | 51 | public Guest() {this.role=UserRole.ROLE_USER;}
|
---|
[9dd526f] | 52 |
|
---|
[3753356] | 53 | public Guest(int guestId, Plate plate,String password, String email, String mobile) {
|
---|
[ce6ad22] | 54 | this.guestId = guestId;
|
---|
[9dd526f] | 55 | this.plate = plate;
|
---|
[ce6ad22] | 56 | this.email = email;
|
---|
[3753356] | 57 | this.password=password;
|
---|
[ce6ad22] | 58 | this.mobile = mobile;
|
---|
[98f448a] | 59 | this.role=UserRole.ROLE_USER;
|
---|
[ce6ad22] | 60 | }
|
---|
| 61 |
|
---|
[9dd526f] | 62 | public Guest(Plate plate, String email, String mobile) {
|
---|
| 63 | this.plate = plate;
|
---|
[ce6ad22] | 64 | this.email = email;
|
---|
| 65 | this.mobile = mobile;
|
---|
[98f448a] | 66 | this.role=UserRole.ROLE_USER;
|
---|
[ce6ad22] | 67 | }
|
---|
| 68 |
|
---|
| 69 | public int getGuestId() {
|
---|
| 70 | return guestId;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | public void setGuestId(int guestId) {
|
---|
| 74 | this.guestId = guestId;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
[9dd526f] | 77 | public Plate getTablicka() {
|
---|
| 78 | return plate;
|
---|
[ce6ad22] | 79 | }
|
---|
| 80 |
|
---|
[9dd526f] | 81 | public void setTablicka(Plate plate) {
|
---|
| 82 | this.plate = plate;
|
---|
[ce6ad22] | 83 | }
|
---|
| 84 |
|
---|
| 85 | public String getEmail() {
|
---|
| 86 | return email;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | public void setEmail(String email) {
|
---|
| 90 | this.email = email;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
[9dd526f] | 93 | public ParkingSession getSession() {
|
---|
| 94 | return session;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | public void setSession(ParkingSession session) {
|
---|
| 98 | this.session = session;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | public UserRole getRole() {
|
---|
| 102 | return role;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | public void setRole(UserRole role) {
|
---|
| 106 | this.role = role;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
[ce6ad22] | 109 | public String getMobile() {
|
---|
| 110 | return mobile;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | public void setMobile(String mobile) {
|
---|
| 114 | this.mobile = mobile;
|
---|
| 115 | }
|
---|
[9dd526f] | 116 |
|
---|
| 117 | @Override
|
---|
| 118 | public Collection<? extends GrantedAuthority> getAuthorities() {
|
---|
| 119 | SimpleGrantedAuthority authority = new SimpleGrantedAuthority(role.name());
|
---|
| 120 | return Collections.singleton(authority);
|
---|
| 121 | }
|
---|
| 122 |
|
---|
[3753356] | 123 | public Plate getPlate() {
|
---|
| 124 | return plate;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | public void setPlate(Plate plate) {
|
---|
| 128 | this.plate = plate;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | public void setPassword(String password) {
|
---|
| 132 | this.password = password;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
[9dd526f] | 135 | @Override
|
---|
| 136 | public String getPassword() {
|
---|
| 137 | return null;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | @Override
|
---|
| 141 | public String getUsername() {
|
---|
| 142 | return Integer.toString(guestId);
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | @Override
|
---|
| 146 | public boolean isAccountNonExpired() {
|
---|
| 147 | return false;
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | @Override
|
---|
| 151 | public boolean isAccountNonLocked() {
|
---|
| 152 | return false;
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | @Override
|
---|
| 156 | public boolean isCredentialsNonExpired() {
|
---|
| 157 | return false;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | @Override
|
---|
| 161 | public boolean isEnabled() {
|
---|
| 162 | return false;
|
---|
| 163 | }
|
---|
[ce6ad22] | 164 | }
|
---|