[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 |
|
---|
[bc20307] | 31 | @OneToOne(cascade = {CascadeType.ALL})
|
---|
[ce6ad22] | 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 |
|
---|
[bc20307] | 41 | @Column(name="password")
|
---|
[3753356] | 42 | private String password;
|
---|
| 43 |
|
---|
[9ff45d6] | 44 | @OneToOne
|
---|
| 45 | private ParkingSession session;
|
---|
| 46 |
|
---|
[9dd526f] | 47 | @Enumerated
|
---|
| 48 | private UserRole role;
|
---|
| 49 |
|
---|
[ce6ad22] | 50 |
|
---|
[bc20307] | 51 | public Guest() {
|
---|
| 52 | this.role = UserRole.ROLE_USER;
|
---|
| 53 | this.session = null;
|
---|
| 54 | }
|
---|
| 55 | public Guest(Plate plate, String email,String mobile,String password,ParkingSession session){
|
---|
| 56 | this.plate=plate;
|
---|
| 57 | this.email=email;
|
---|
| 58 | this.mobile=mobile;
|
---|
[3753356] | 59 | this.password=password;
|
---|
[bc20307] | 60 | this.session=session;
|
---|
[98f448a] | 61 | this.role=UserRole.ROLE_USER;
|
---|
[ce6ad22] | 62 | }
|
---|
| 63 |
|
---|
[9dd526f] | 64 | public Guest(Plate plate, String email, String mobile) {
|
---|
| 65 | this.plate = plate;
|
---|
[ce6ad22] | 66 | this.email = email;
|
---|
| 67 | this.mobile = mobile;
|
---|
[bc20307] | 68 | this.password = "";
|
---|
[98f448a] | 69 | this.role=UserRole.ROLE_USER;
|
---|
[ce6ad22] | 70 | }
|
---|
| 71 |
|
---|
| 72 | public int getGuestId() {
|
---|
| 73 | return guestId;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | public void setGuestId(int guestId) {
|
---|
| 77 | this.guestId = guestId;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[9dd526f] | 80 | public Plate getTablicka() {
|
---|
| 81 | return plate;
|
---|
[ce6ad22] | 82 | }
|
---|
| 83 |
|
---|
[9dd526f] | 84 | public void setTablicka(Plate plate) {
|
---|
| 85 | this.plate = plate;
|
---|
[ce6ad22] | 86 | }
|
---|
| 87 |
|
---|
| 88 | public String getEmail() {
|
---|
| 89 | return email;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | public void setEmail(String email) {
|
---|
| 93 | this.email = email;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
[9dd526f] | 96 | public ParkingSession getSession() {
|
---|
| 97 | return session;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | public void setSession(ParkingSession session) {
|
---|
| 101 | this.session = session;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | public UserRole getRole() {
|
---|
| 105 | return role;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | public void setRole(UserRole role) {
|
---|
| 109 | this.role = role;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
[ce6ad22] | 112 | public String getMobile() {
|
---|
| 113 | return mobile;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | public void setMobile(String mobile) {
|
---|
| 117 | this.mobile = mobile;
|
---|
| 118 | }
|
---|
[9dd526f] | 119 |
|
---|
| 120 | @Override
|
---|
| 121 | public Collection<? extends GrantedAuthority> getAuthorities() {
|
---|
| 122 | SimpleGrantedAuthority authority = new SimpleGrantedAuthority(role.name());
|
---|
| 123 | return Collections.singleton(authority);
|
---|
| 124 | }
|
---|
| 125 |
|
---|
[3753356] | 126 | public Plate getPlate() {
|
---|
| 127 | return plate;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | public void setPlate(Plate plate) {
|
---|
| 131 | this.plate = plate;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | public void setPassword(String password) {
|
---|
| 135 | this.password = password;
|
---|
| 136 | }
|
---|
| 137 |
|
---|
[9dd526f] | 138 | @Override
|
---|
| 139 | public String getPassword() {
|
---|
[bc20307] | 140 | return this.password;
|
---|
[9dd526f] | 141 | }
|
---|
| 142 |
|
---|
| 143 | @Override
|
---|
| 144 | public String getUsername() {
|
---|
| 145 | return Integer.toString(guestId);
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | @Override
|
---|
| 149 | public boolean isAccountNonExpired() {
|
---|
[bc20307] | 150 | return true;
|
---|
[9dd526f] | 151 | }
|
---|
| 152 |
|
---|
| 153 | @Override
|
---|
| 154 | public boolean isAccountNonLocked() {
|
---|
[bc20307] | 155 | return true;
|
---|
[9dd526f] | 156 | }
|
---|
| 157 |
|
---|
| 158 | @Override
|
---|
| 159 | public boolean isCredentialsNonExpired() {
|
---|
[bc20307] | 160 | return true;
|
---|
[9dd526f] | 161 | }
|
---|
| 162 |
|
---|
| 163 | @Override
|
---|
| 164 | public boolean isEnabled() {
|
---|
[bc20307] | 165 | return true;
|
---|
[9dd526f] | 166 | }
|
---|
[ce6ad22] | 167 | }
|
---|