[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 | )
|
---|
| 24 | @GeneratedValue( //za postgres treba sequence da se namesti i ime na generator mi ga davamo kako od gore sto e
|
---|
| 25 | strategy = GenerationType.SEQUENCE,
|
---|
| 26 | generator = "guest_sequence_generator"
|
---|
| 27 | )
|
---|
| 28 | @Column(name = "guestId")
|
---|
| 29 | private int guestId;
|
---|
| 30 |
|
---|
| 31 | //dali ova treba vaka?
|
---|
| 32 | @OneToOne
|
---|
| 33 | @JoinColumn(name = "tablickaId", nullable = false)
|
---|
[9dd526f] | 34 | private Plate plate;
|
---|
[ce6ad22] | 35 |
|
---|
| 36 | @Column(name = "email")
|
---|
| 37 | private String email;
|
---|
| 38 |
|
---|
| 39 | @Column(name = "mobile")
|
---|
| 40 | private String mobile;
|
---|
| 41 |
|
---|
[9ff45d6] | 42 | @OneToOne
|
---|
| 43 | private ParkingSession session;
|
---|
| 44 |
|
---|
[9dd526f] | 45 | @Enumerated
|
---|
| 46 | private UserRole role;
|
---|
| 47 |
|
---|
[ce6ad22] | 48 |
|
---|
[98f448a] | 49 | public Guest() {this.role=UserRole.ROLE_USER;}
|
---|
[9dd526f] | 50 |
|
---|
| 51 | public Guest(int guestId, Plate plate, String email, String mobile) {
|
---|
[ce6ad22] | 52 | this.guestId = guestId;
|
---|
[9dd526f] | 53 | this.plate = plate;
|
---|
[ce6ad22] | 54 | this.email = email;
|
---|
| 55 | this.mobile = mobile;
|
---|
[98f448a] | 56 | this.role=UserRole.ROLE_USER;
|
---|
[ce6ad22] | 57 | }
|
---|
| 58 |
|
---|
[9dd526f] | 59 | public Guest(Plate plate, String email, String mobile) {
|
---|
| 60 | this.plate = plate;
|
---|
[ce6ad22] | 61 | this.email = email;
|
---|
| 62 | this.mobile = mobile;
|
---|
[98f448a] | 63 | this.role=UserRole.ROLE_USER;
|
---|
[ce6ad22] | 64 | }
|
---|
| 65 |
|
---|
| 66 | public int getGuestId() {
|
---|
| 67 | return guestId;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | public void setGuestId(int guestId) {
|
---|
| 71 | this.guestId = guestId;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
[9dd526f] | 74 | public Plate getTablicka() {
|
---|
| 75 | return plate;
|
---|
[ce6ad22] | 76 | }
|
---|
| 77 |
|
---|
[9dd526f] | 78 | public void setTablicka(Plate plate) {
|
---|
| 79 | this.plate = plate;
|
---|
[ce6ad22] | 80 | }
|
---|
| 81 |
|
---|
| 82 | public String getEmail() {
|
---|
| 83 | return email;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | public void setEmail(String email) {
|
---|
| 87 | this.email = email;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
[9dd526f] | 90 | public ParkingSession getSession() {
|
---|
| 91 | return session;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | public void setSession(ParkingSession session) {
|
---|
| 95 | this.session = session;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | public UserRole getRole() {
|
---|
| 99 | return role;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | public void setRole(UserRole role) {
|
---|
| 103 | this.role = role;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[ce6ad22] | 106 | public String getMobile() {
|
---|
| 107 | return mobile;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | public void setMobile(String mobile) {
|
---|
| 111 | this.mobile = mobile;
|
---|
| 112 | }
|
---|
[9dd526f] | 113 |
|
---|
| 114 | @Override
|
---|
| 115 | public Collection<? extends GrantedAuthority> getAuthorities() {
|
---|
| 116 | SimpleGrantedAuthority authority = new SimpleGrantedAuthority(role.name());
|
---|
| 117 | return Collections.singleton(authority);
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | @Override
|
---|
| 121 | public String getPassword() {
|
---|
| 122 | return null;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | @Override
|
---|
| 126 | public String getUsername() {
|
---|
| 127 | return Integer.toString(guestId);
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | @Override
|
---|
| 131 | public boolean isAccountNonExpired() {
|
---|
| 132 | return false;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | @Override
|
---|
| 136 | public boolean isAccountNonLocked() {
|
---|
| 137 | return false;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | @Override
|
---|
| 141 | public boolean isCredentialsNonExpired() {
|
---|
| 142 | return false;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | @Override
|
---|
| 146 | public boolean isEnabled() {
|
---|
| 147 | return false;
|
---|
| 148 | }
|
---|
[ce6ad22] | 149 | }
|
---|