Guest User

Untitled

a guest
Jan 13th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.74 KB | None | 0 0
  1. package pl.sylogic.bacca.data.model;
  2.  
  3. import pl.sylogic.bacca.data.model.fieldLength.FieldLength;
  4. import pl.sylogic.common.model.IFetchField;
  5. import pl.sylogic.common.model.IField;
  6.  
  7. import javax.persistence.*;
  8.  
  9. import java.util.Date;
  10. import java.util.HashSet;
  11. import java.util.Set;
  12.  
  13. @SuppressWarnings("serial")
  14. @Entity
  15. @Table(name = "eb_user")
  16. public class User implements java.io.Serializable, pl.sylogic.security.User {
  17. private Long id;
  18.  
  19. private String firstName; // Imię
  20. private String lastName; // Nazwisko
  21.  
  22. private String email; // Adres e-mail
  23. private String cellphone; // Numer telefonu komórkowego
  24. private String phone; // Numer telefonu stacjonarnego
  25.  
  26. private String password; // Hasło
  27. private String salt; // Sól do hash'owania hasła
  28.  
  29. private Date creationDate; // Data utworzennia
  30. private Boolean active; // Czy użytkownik jest aktywny
  31. private Boolean deleted; //czy użytkownik jest zablokowany
  32.  
  33. private Boolean confirmed; // Czy użytkownik potwierdził swój e-mail
  34. private Date confirmationDate; // Data potwierdzenia
  35.  
  36. private BrokerageEmployee brokerageEmployee;
  37. private Student student;
  38.  
  39. private Set<Role> roles = new HashSet<Role>(); // Zbiór roli jakie użytkownik ma w systemie
  40.  
  41.  
  42. public User() {
  43. }
  44.  
  45. @Id
  46. @SequenceGenerator(
  47. name = "SEQ_STORE",
  48. sequenceName = "user_id_seq",
  49. allocationSize = 1,
  50. initialValue = 1
  51. )
  52. @GeneratedValue(
  53. strategy = GenerationType.SEQUENCE,
  54. generator = "SEQ_STORE"
  55. )
  56. @Column(name = "id", nullable = false, precision = 22, scale = 0)
  57. public Long getId() {
  58. return this.id;
  59. }
  60.  
  61. public void setId(Long id) {
  62. this.id = id;
  63. }
  64.  
  65. @Column(name = "first_name", nullable = false, length = FieldLength.FIRST_NAME)
  66. public String getFirstName() {
  67. return this.firstName;
  68. }
  69.  
  70. public void setFirstName(String firstName) {
  71. this.firstName = firstName;
  72. }
  73.  
  74. @Column(name = "last_name", nullable = false, length = FieldLength.SUR_NAME)
  75. public String getLastName() {
  76. return this.lastName;
  77. }
  78.  
  79. public void setLastName(String lastName) {
  80. this.lastName = lastName;
  81. }
  82.  
  83. @Column(name = "email", unique = true, nullable = false, length = FieldLength.EMAIL)
  84. public String getEmail() {
  85. return this.email;
  86. }
  87.  
  88. public void setEmail(String email) {
  89. this.email = email;
  90. }
  91.  
  92. @Override
  93. @Column(name = "password", nullable = false, length = FieldLength.PASSWORD)
  94. public String getPassword() {
  95. return this.password;
  96. }
  97.  
  98. public void setPassword(String password) {
  99. this.password = password;
  100. }
  101.  
  102. @Column(name = "salt", nullable = false, length = FieldLength.SALT)
  103. public String getSalt() {
  104. return this.salt;
  105. }
  106.  
  107. public void setSalt(String salt) {
  108. this.salt = salt;
  109. }
  110.  
  111. @Column(name = "cellphone", length = FieldLength.CELLPHONE)
  112. public String getCellphone() {
  113. return this.cellphone;
  114. }
  115.  
  116. public void setCellphone(String cellphone) {
  117. this.cellphone = cellphone;
  118. }
  119.  
  120. @Column(name = "phone", length = FieldLength.PHONE)
  121. public String getPhone() {
  122. return this.phone;
  123. }
  124.  
  125. public void setPhone(String phone) {
  126. this.phone = phone;
  127. }
  128.  
  129. @Override
  130. @Column(name = "is_active", nullable = false, length = 1)
  131. public Boolean isActive() {
  132. return this.active;
  133. }
  134.  
  135. public void setActive(Boolean isActive) {
  136. this.active = isActive;
  137. }
  138.  
  139. @Column(name = "is_deleted", nullable = false, length = 1)
  140. public Boolean isDeleted() {
  141. return deleted;
  142. }
  143.  
  144. public void setDeleted(Boolean deleted) {
  145. this.deleted = deleted;
  146. }
  147.  
  148.  
  149.  
  150. @Column(name = "is_confirmed", length = 1)
  151. public Boolean getConfirmed() {
  152. return this.confirmed;
  153. }
  154.  
  155. public void setConfirmed(Boolean isConfirmed) {
  156. this.confirmed = isConfirmed;
  157. }
  158.  
  159. @Temporal(TemporalType.DATE)
  160. @Column(name = "creation_date", nullable = false)
  161. public Date getCreationDate() {
  162. return this.creationDate;
  163. }
  164.  
  165. public void setCreationDate(Date creationDate) {
  166. this.creationDate = creationDate;
  167. }
  168.  
  169. @Temporal(TemporalType.DATE)
  170. @Column(name = "confirmation_date")
  171. public Date getConfirmationDate() {
  172. return this.confirmationDate;
  173. }
  174.  
  175. public void setConfirmationDate(Date confirmationDate) {
  176. this.confirmationDate = confirmationDate;
  177. }
  178.  
  179. @Override
  180. @Transient
  181. public String getLogin() {
  182. return getEmail();
  183. }
  184.  
  185. public void setLogin(String login) {
  186. setEmail(login);
  187. }
  188.  
  189. @OneToOne(fetch = FetchType.LAZY, mappedBy = "user", cascade=CascadeType.ALL )
  190. public BrokerageEmployee getBrokerageEmployee() {
  191. return brokerageEmployee;
  192. }
  193.  
  194. public void setBrokerageEmployee(BrokerageEmployee brokerageEmployee) {
  195. this.brokerageEmployee = brokerageEmployee;
  196. }
  197.  
  198. @OneToOne(fetch = FetchType.LAZY, mappedBy = "user_id", cascade=CascadeType.ALL )
  199. public Student getStudent() {
  200. return student;
  201. }
  202.  
  203. public void setStudent(Student student) {
  204. this.student = student;
  205. }
  206.  
  207. @Override
  208. @ManyToMany(fetch = FetchType.LAZY)
  209. @JoinTable(
  210. name = "user2role",
  211. joinColumns = {
  212. @JoinColumn(name = "id", nullable = false, updatable = false)
  213. },
  214. inverseJoinColumns = {
  215. @JoinColumn(name = "id", nullable = false, updatable = false)
  216. }
  217. )
  218. public Set<Role> getRoles() {
  219. return this.roles;
  220. }
  221.  
  222. public void setRoles(Set<Role> roles) {
  223. this.roles = roles;
  224. }
  225.  
  226. public boolean hasRole(Role.Roles role) {
  227. for(Role r : roles) {
  228. if(role.getRoleName().equals(r.getName()))
  229. return true;
  230. }
  231.  
  232. return false;
  233. }
  234.  
  235.  
  236. @Override
  237. public boolean equals(Object o) {
  238. if (this == o) return true;
  239. if (o == null || getClass() != o.getClass()) return false;
  240.  
  241. User user = (User) o;
  242.  
  243. if (active != null ? !active.equals(user.active) : user.active != null) return false;
  244. if (cellphone != null ? !cellphone.equals(user.cellphone) : user.cellphone != null) return false;
  245. if (confirmationDate != null ? !confirmationDate.equals(user.confirmationDate) : user.confirmationDate != null)
  246. return false;
  247. if (confirmed != null ? !confirmed.equals(user.confirmed) : user.confirmed != null) return false;
  248. if (creationDate != null ? !creationDate.equals(user.creationDate) : user.creationDate != null) return false;
  249. if (email != null ? !email.equals(user.email) : user.email != null) return false;
  250. if (firstName != null ? !firstName.equals(user.firstName) : user.firstName != null) return false;
  251. if (phone != null ? !phone.equals(user.phone) : user.phone != null) return false;
  252. if (salt != null ? !salt.equals(user.salt) : user.salt != null) return false;
  253. if (lastName != null ? !lastName.equals(user.lastName) : user.lastName != null) return false;
  254. if (id != null ? !id.equals(user.id) : user.id != null) return false;
  255.  
  256. return true;
  257. }
  258.  
  259. @Override
  260. public int hashCode() {
  261. int result = id != null ? id.hashCode() : 0;
  262. result = 31 * result + (firstName != null ? firstName.hashCode() : 0);
  263. result = 31 * result + (lastName != null ? lastName.hashCode() : 0);
  264. result = 31 * result + (email != null ? email.hashCode() : 0);
  265. result = 31 * result + (cellphone != null ? cellphone.hashCode() : 0);
  266. result = 31 * result + (phone != null ? phone.hashCode() : 0);
  267. result = 31 * result + (salt != null ? salt.hashCode() : 0);
  268. result = 31 * result + (creationDate != null ? creationDate.hashCode() : 0);
  269. result = 31 * result + (active != null ? active.hashCode() : 0);
  270. result = 31 * result + (confirmed != null ? confirmed.hashCode() : 0);
  271. result = 31 * result + (confirmationDate != null ? confirmationDate.hashCode() : 0);
  272. return result;
  273. }
  274.  
  275. @Override
  276. public String toString() {
  277. final StringBuffer sb = new StringBuffer();
  278. sb.append("User");
  279. sb.append("{userId=").append(id);
  280. sb.append(", firstName='").append(firstName).append('\'');
  281. sb.append(", surName='").append(lastName).append('\'');
  282. sb.append(", email='").append(email).append('\'');
  283. sb.append(", cellphone='").append(cellphone).append('\'');
  284. sb.append(", phone='").append(phone).append('\'');
  285. sb.append(", creationDate=").append(creationDate);
  286. sb.append(", active=").append(active);
  287. sb.append(", salt='").append(salt).append('\'');
  288. sb.append(", confirmed=").append(confirmed);
  289. sb.append(", confirmationDate=").append(confirmationDate);
  290. sb.append('}');
  291. return sb.toString();
  292. }
  293.  
  294.  
  295.  
  296. /**
  297. * Enum polami z relacji
  298. *
  299. */
  300. public enum FetchField implements IFetchField {
  301. BROKERAGE_EMPLOYEE ("brokerageEmployee"),
  302. ROLES ("roles");
  303.  
  304. private final String fieldName;
  305.  
  306. FetchField(String fieldName) {
  307. this.fieldName = fieldName;
  308. }
  309.  
  310. @Override
  311. public String toString() {
  312. return this.fieldName;
  313. }
  314. }
  315.  
  316. /**
  317. * Enum z polami zwykłymi
  318. *
  319. */
  320. public enum Field implements IField {
  321. IS_ACTIVE ("active"),
  322. IS_DELETED ("deleted"),
  323. IS_CONFIRMED ("confirmed"),
  324. CONFIRMATION_DATE ("confirmationDate"),
  325. CREATION_DATE ("creationDate"),
  326. USER_ID ("userId"),
  327. PASSWORD ("password"),
  328. EMAIL ("email"),
  329. CELLPHONE ("cellphone"),
  330. PHONE ("phone"),
  331. SALT ("salt"),
  332. FIRSTNAME ("firstName"),
  333. LOGIN ("login"),
  334. SURNAME ("surName");
  335.  
  336. private final String fieldName;
  337.  
  338. Field(String fieldName) {
  339. this.fieldName = fieldName;
  340. }
  341.  
  342. @Override
  343. public String toString() {
  344. return this.fieldName;
  345. }
  346. }
  347.  
  348. /**
  349. * Metoda pobierająca pole klasy, które reprezentuje ID.
  350. * Wykorzystywane przez GenericHibernateDaoImpl przy pobieraniu po Id.
  351. *
  352. * @see pl.sylogic.common.model.dao.GenericHibernateDaoImpl
  353. * @return IField
  354. */
  355. public static IField getIdField() {
  356. return Field.USER_ID;
  357. }
  358. }
Add Comment
Please, Sign In to add comment