[ce6ad22] | 1 | package parkup.entities;
|
---|
| 2 |
|
---|
| 3 | import java.util.ArrayList;
|
---|
[97fbc67] | 4 | import java.util.Collection;
|
---|
| 5 | import java.util.Collections;
|
---|
[ce6ad22] | 6 | import java.util.List;
|
---|
| 7 | import javax.persistence.*;
|
---|
| 8 |
|
---|
[97fbc67] | 9 | import org.springframework.security.core.GrantedAuthority;
|
---|
| 10 | import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
---|
| 11 | import org.springframework.security.core.userdetails.UserDetails;
|
---|
[9dd526f] | 12 | import parkup.data.Plate;
|
---|
| 13 | import parkup.data.enumarations.UserRole;
|
---|
[ce6ad22] | 14 |
|
---|
| 15 | @Entity
|
---|
[9dd526f] | 16 | @Table(name = "registeredUser")
|
---|
| 17 | public class RegisteredUser implements UserDetails {
|
---|
[ce6ad22] | 18 | @Id
|
---|
| 19 | @SequenceGenerator(
|
---|
[9dd526f] | 20 | name="registeredUser_sequence_generator",
|
---|
| 21 | sequenceName = "registeredUser_sequence",
|
---|
[ce6ad22] | 22 | allocationSize = 1,
|
---|
| 23 | initialValue = 300
|
---|
| 24 | )
|
---|
| 25 | @GeneratedValue( //za postgres treba sequence da se namesti i ime na generator mi ga davamo kako od gore sto e
|
---|
| 26 | strategy = GenerationType.SEQUENCE,
|
---|
[9dd526f] | 27 | generator = "registeredUser_sequence_generator"
|
---|
[ce6ad22] | 28 | )
|
---|
| 29 | @Column(name = "regParkId")
|
---|
| 30 | private int regParkId;
|
---|
| 31 |
|
---|
[74fb0dc] | 32 | @Column(name = "firstName")
|
---|
| 33 | private String firstName;
|
---|
[ce6ad22] | 34 |
|
---|
[74fb0dc] | 35 | @Column(name = "lastName")
|
---|
| 36 | private String lastName;
|
---|
[ce6ad22] | 37 |
|
---|
| 38 | @Column(name = "password")
|
---|
| 39 | private String password;
|
---|
| 40 |
|
---|
[97fbc67] | 41 | @OneToMany(cascade ={CascadeType.ALL})
|
---|
[9dd526f] | 42 | @Column(name = "regPlates")
|
---|
| 43 | private List<Plate> plates;
|
---|
[ce6ad22] | 44 |
|
---|
| 45 | @Column(name = "email")
|
---|
| 46 | private String email;
|
---|
| 47 |
|
---|
| 48 | @Column(name = "mobile")
|
---|
| 49 | private String mobile;
|
---|
| 50 |
|
---|
[9dd526f] | 51 | @Enumerated
|
---|
[ce6ad22] | 52 | @Column(name = "role")
|
---|
[9dd526f] | 53 | private UserRole role;
|
---|
[ce6ad22] | 54 |
|
---|
[9ff45d6] | 55 | @OneToOne
|
---|
| 56 | private ParkingSession session;
|
---|
| 57 |
|
---|
[97fbc67] | 58 | private boolean locked;
|
---|
| 59 |
|
---|
| 60 | private boolean enabled;
|
---|
[ce6ad22] | 61 |
|
---|
[9dd526f] | 62 | public RegisteredUser() {
|
---|
| 63 | this.plates = new ArrayList<Plate>();
|
---|
[98f448a] | 64 | this.role = UserRole.ROLE_REG_USER;
|
---|
[bc20307] | 65 | this.session=null;
|
---|
[ce6ad22] | 66 | }
|
---|
| 67 |
|
---|
[74fb0dc] | 68 | public RegisteredUser(int regParkId, String firstName, String lastName, String password, List<Plate> plates, String email, String mobile) {
|
---|
[ce6ad22] | 69 | this.regParkId = regParkId;
|
---|
[74fb0dc] | 70 | this.firstName = firstName;
|
---|
| 71 | this.lastName = lastName;
|
---|
[ce6ad22] | 72 | this.password = password;
|
---|
[9dd526f] | 73 | this.plates = plates;
|
---|
[ce6ad22] | 74 | this.email = email;
|
---|
| 75 | this.mobile = mobile;
|
---|
[98f448a] | 76 | this.role = UserRole.ROLE_REG_USER;
|
---|
[9ff45d6] | 77 | session=null;
|
---|
[ce6ad22] | 78 | }
|
---|
| 79 |
|
---|
[74fb0dc] | 80 | public RegisteredUser(String firstName, String lastName, String password, List<Plate> plates, String email, String mobile) {
|
---|
| 81 | this.firstName = firstName;
|
---|
| 82 | this.lastName = lastName;
|
---|
[ce6ad22] | 83 | this.password = password;
|
---|
[9dd526f] | 84 | this.plates = plates;
|
---|
[ce6ad22] | 85 | this.email = email;
|
---|
| 86 | this.mobile = mobile;
|
---|
[98f448a] | 87 | this.role = UserRole.ROLE_REG_USER;
|
---|
[9ff45d6] | 88 | session=null;
|
---|
[97fbc67] | 89 | }
|
---|
| 90 |
|
---|
[74fb0dc] | 91 | public RegisteredUser(String firstName, String lastName, String email, String password, String mobile) {
|
---|
| 92 | this.firstName = firstName;
|
---|
| 93 | this.lastName = lastName;
|
---|
[97fbc67] | 94 | this.password = password;
|
---|
| 95 | this.email = email;
|
---|
| 96 | this.mobile = mobile;
|
---|
[98f448a] | 97 | this.role = UserRole.ROLE_REG_USER;
|
---|
[9ff45d6] | 98 | session=null;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | public ParkingSession getSession() {
|
---|
| 102 | return session;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | public void setSession(ParkingSession session) {
|
---|
| 106 | this.session = session;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | public boolean isLocked() {
|
---|
| 110 | return locked;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | public void setLocked(boolean locked) {
|
---|
| 114 | this.locked = locked;
|
---|
[ce6ad22] | 115 | }
|
---|
| 116 |
|
---|
[9ff45d6] | 117 | public void setEnabled(boolean enabled) {
|
---|
| 118 | this.enabled = enabled;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 |
|
---|
[ce6ad22] | 122 | public int getRegParkId() {
|
---|
| 123 | return regParkId;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | public void setRegParkId(int regParkId) {
|
---|
| 127 | this.regParkId = regParkId;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
[74fb0dc] | 130 | public String getFirstName() {
|
---|
| 131 | return firstName;
|
---|
[ce6ad22] | 132 | }
|
---|
| 133 |
|
---|
[74fb0dc] | 134 | public void setFirstName(String name) {
|
---|
| 135 | this.firstName = name;
|
---|
[ce6ad22] | 136 | }
|
---|
| 137 |
|
---|
[74fb0dc] | 138 | public String getLastName() {
|
---|
| 139 | return lastName;
|
---|
[ce6ad22] | 140 | }
|
---|
| 141 |
|
---|
[74fb0dc] | 142 | public void setLastName(String surname) {
|
---|
| 143 | this.lastName = surname;
|
---|
[ce6ad22] | 144 | }
|
---|
| 145 |
|
---|
[9dd526f] | 146 | public List<Plate> getPlates() {
|
---|
| 147 | return plates;
|
---|
[ce6ad22] | 148 | }
|
---|
| 149 |
|
---|
[9dd526f] | 150 | public void setPlates(List<Plate> plates) {
|
---|
| 151 | this.plates = plates;
|
---|
[ce6ad22] | 152 | }
|
---|
| 153 |
|
---|
| 154 | public String getEmail() {
|
---|
| 155 | return email;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | public void setEmail(String email) {
|
---|
| 159 | this.email = email;
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | public String getMobile() {
|
---|
| 163 | return mobile;
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | public void setMobile(String mobile) {
|
---|
| 167 | this.mobile = mobile;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
[9dd526f] | 170 | public UserRole getRole() {return role;}
|
---|
[ce6ad22] | 171 |
|
---|
[9dd526f] | 172 | public void setRole(UserRole role) {this.role = role;}
|
---|
[97fbc67] | 173 |
|
---|
| 174 | @Override
|
---|
| 175 | public Collection<? extends GrantedAuthority> getAuthorities() {
|
---|
[9dd526f] | 176 | SimpleGrantedAuthority authority = new SimpleGrantedAuthority(role.getAuthority());
|
---|
[97fbc67] | 177 | return Collections.singleton(authority);
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | public String getPassword() {
|
---|
| 181 | return password;
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | public void setPassword(String password) {
|
---|
| 185 | this.password = password;
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | @Override
|
---|
| 189 | public String getUsername() {
|
---|
| 190 | return email;
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | @Override
|
---|
| 194 | public boolean isAccountNonExpired() {
|
---|
| 195 | return true;
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | @Override
|
---|
| 199 | public boolean isAccountNonLocked() {
|
---|
| 200 | return !locked;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | @Override
|
---|
| 204 | public boolean isCredentialsNonExpired() {
|
---|
| 205 | return true;
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 | @Override
|
---|
| 209 | public boolean isEnabled() {
|
---|
| 210 | return enabled;
|
---|
| 211 | }
|
---|
[ce6ad22] | 212 | }
|
---|
| 213 |
|
---|