Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pl.sylogic.bacca.data.model;
- import pl.sylogic.bacca.data.model.fieldLength.FieldLength;
- import pl.sylogic.common.model.IFetchField;
- import pl.sylogic.common.model.IField;
- import javax.persistence.*;
- import java.util.Date;
- import java.util.HashSet;
- import java.util.Set;
- @SuppressWarnings("serial")
- @Entity
- @Table(name = "eb_user")
- public class User implements java.io.Serializable, pl.sylogic.security.User {
- private Long id;
- private String firstName; // Imię
- private String lastName; // Nazwisko
- private String email; // Adres e-mail
- private String cellphone; // Numer telefonu komórkowego
- private String phone; // Numer telefonu stacjonarnego
- private String password; // Hasło
- private String salt; // Sól do hash'owania hasła
- private Date creationDate; // Data utworzennia
- private Boolean active; // Czy użytkownik jest aktywny
- private Boolean deleted; //czy użytkownik jest zablokowany
- private Boolean confirmed; // Czy użytkownik potwierdził swój e-mail
- private Date confirmationDate; // Data potwierdzenia
- private BrokerageEmployee brokerageEmployee;
- private Student student;
- private Set<Role> roles = new HashSet<Role>(); // Zbiór roli jakie użytkownik ma w systemie
- public User() {
- }
- @Id
- @SequenceGenerator(
- name = "SEQ_STORE",
- sequenceName = "user_id_seq",
- allocationSize = 1,
- initialValue = 1
- )
- @GeneratedValue(
- strategy = GenerationType.SEQUENCE,
- generator = "SEQ_STORE"
- )
- @Column(name = "id", nullable = false, precision = 22, scale = 0)
- public Long getId() {
- return this.id;
- }
- public void setId(Long id) {
- this.id = id;
- }
- @Column(name = "first_name", nullable = false, length = FieldLength.FIRST_NAME)
- public String getFirstName() {
- return this.firstName;
- }
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
- @Column(name = "last_name", nullable = false, length = FieldLength.SUR_NAME)
- public String getLastName() {
- return this.lastName;
- }
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
- @Column(name = "email", unique = true, nullable = false, length = FieldLength.EMAIL)
- public String getEmail() {
- return this.email;
- }
- public void setEmail(String email) {
- this.email = email;
- }
- @Override
- @Column(name = "password", nullable = false, length = FieldLength.PASSWORD)
- public String getPassword() {
- return this.password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- @Column(name = "salt", nullable = false, length = FieldLength.SALT)
- public String getSalt() {
- return this.salt;
- }
- public void setSalt(String salt) {
- this.salt = salt;
- }
- @Column(name = "cellphone", length = FieldLength.CELLPHONE)
- public String getCellphone() {
- return this.cellphone;
- }
- public void setCellphone(String cellphone) {
- this.cellphone = cellphone;
- }
- @Column(name = "phone", length = FieldLength.PHONE)
- public String getPhone() {
- return this.phone;
- }
- public void setPhone(String phone) {
- this.phone = phone;
- }
- @Override
- @Column(name = "is_active", nullable = false, length = 1)
- public Boolean isActive() {
- return this.active;
- }
- public void setActive(Boolean isActive) {
- this.active = isActive;
- }
- @Column(name = "is_deleted", nullable = false, length = 1)
- public Boolean isDeleted() {
- return deleted;
- }
- public void setDeleted(Boolean deleted) {
- this.deleted = deleted;
- }
- @Column(name = "is_confirmed", length = 1)
- public Boolean getConfirmed() {
- return this.confirmed;
- }
- public void setConfirmed(Boolean isConfirmed) {
- this.confirmed = isConfirmed;
- }
- @Temporal(TemporalType.DATE)
- @Column(name = "creation_date", nullable = false)
- public Date getCreationDate() {
- return this.creationDate;
- }
- public void setCreationDate(Date creationDate) {
- this.creationDate = creationDate;
- }
- @Temporal(TemporalType.DATE)
- @Column(name = "confirmation_date")
- public Date getConfirmationDate() {
- return this.confirmationDate;
- }
- public void setConfirmationDate(Date confirmationDate) {
- this.confirmationDate = confirmationDate;
- }
- @Override
- @Transient
- public String getLogin() {
- return getEmail();
- }
- public void setLogin(String login) {
- setEmail(login);
- }
- @OneToOne(fetch = FetchType.LAZY, mappedBy = "user", cascade=CascadeType.ALL )
- public BrokerageEmployee getBrokerageEmployee() {
- return brokerageEmployee;
- }
- public void setBrokerageEmployee(BrokerageEmployee brokerageEmployee) {
- this.brokerageEmployee = brokerageEmployee;
- }
- @OneToOne(fetch = FetchType.LAZY, mappedBy = "user_id", cascade=CascadeType.ALL )
- public Student getStudent() {
- return student;
- }
- public void setStudent(Student student) {
- this.student = student;
- }
- @Override
- @ManyToMany(fetch = FetchType.LAZY)
- @JoinTable(
- name = "user2role",
- joinColumns = {
- @JoinColumn(name = "id", nullable = false, updatable = false)
- },
- inverseJoinColumns = {
- @JoinColumn(name = "id", nullable = false, updatable = false)
- }
- )
- public Set<Role> getRoles() {
- return this.roles;
- }
- public void setRoles(Set<Role> roles) {
- this.roles = roles;
- }
- public boolean hasRole(Role.Roles role) {
- for(Role r : roles) {
- if(role.getRoleName().equals(r.getName()))
- return true;
- }
- return false;
- }
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- User user = (User) o;
- if (active != null ? !active.equals(user.active) : user.active != null) return false;
- if (cellphone != null ? !cellphone.equals(user.cellphone) : user.cellphone != null) return false;
- if (confirmationDate != null ? !confirmationDate.equals(user.confirmationDate) : user.confirmationDate != null)
- return false;
- if (confirmed != null ? !confirmed.equals(user.confirmed) : user.confirmed != null) return false;
- if (creationDate != null ? !creationDate.equals(user.creationDate) : user.creationDate != null) return false;
- if (email != null ? !email.equals(user.email) : user.email != null) return false;
- if (firstName != null ? !firstName.equals(user.firstName) : user.firstName != null) return false;
- if (phone != null ? !phone.equals(user.phone) : user.phone != null) return false;
- if (salt != null ? !salt.equals(user.salt) : user.salt != null) return false;
- if (lastName != null ? !lastName.equals(user.lastName) : user.lastName != null) return false;
- if (id != null ? !id.equals(user.id) : user.id != null) return false;
- return true;
- }
- @Override
- public int hashCode() {
- int result = id != null ? id.hashCode() : 0;
- result = 31 * result + (firstName != null ? firstName.hashCode() : 0);
- result = 31 * result + (lastName != null ? lastName.hashCode() : 0);
- result = 31 * result + (email != null ? email.hashCode() : 0);
- result = 31 * result + (cellphone != null ? cellphone.hashCode() : 0);
- result = 31 * result + (phone != null ? phone.hashCode() : 0);
- result = 31 * result + (salt != null ? salt.hashCode() : 0);
- result = 31 * result + (creationDate != null ? creationDate.hashCode() : 0);
- result = 31 * result + (active != null ? active.hashCode() : 0);
- result = 31 * result + (confirmed != null ? confirmed.hashCode() : 0);
- result = 31 * result + (confirmationDate != null ? confirmationDate.hashCode() : 0);
- return result;
- }
- @Override
- public String toString() {
- final StringBuffer sb = new StringBuffer();
- sb.append("User");
- sb.append("{userId=").append(id);
- sb.append(", firstName='").append(firstName).append('\'');
- sb.append(", surName='").append(lastName).append('\'');
- sb.append(", email='").append(email).append('\'');
- sb.append(", cellphone='").append(cellphone).append('\'');
- sb.append(", phone='").append(phone).append('\'');
- sb.append(", creationDate=").append(creationDate);
- sb.append(", active=").append(active);
- sb.append(", salt='").append(salt).append('\'');
- sb.append(", confirmed=").append(confirmed);
- sb.append(", confirmationDate=").append(confirmationDate);
- sb.append('}');
- return sb.toString();
- }
- /**
- * Enum polami z relacji
- *
- */
- public enum FetchField implements IFetchField {
- BROKERAGE_EMPLOYEE ("brokerageEmployee"),
- ROLES ("roles");
- private final String fieldName;
- FetchField(String fieldName) {
- this.fieldName = fieldName;
- }
- @Override
- public String toString() {
- return this.fieldName;
- }
- }
- /**
- * Enum z polami zwykłymi
- *
- */
- public enum Field implements IField {
- IS_ACTIVE ("active"),
- IS_DELETED ("deleted"),
- IS_CONFIRMED ("confirmed"),
- CONFIRMATION_DATE ("confirmationDate"),
- CREATION_DATE ("creationDate"),
- USER_ID ("userId"),
- PASSWORD ("password"),
- EMAIL ("email"),
- CELLPHONE ("cellphone"),
- PHONE ("phone"),
- SALT ("salt"),
- FIRSTNAME ("firstName"),
- LOGIN ("login"),
- SURNAME ("surName");
- private final String fieldName;
- Field(String fieldName) {
- this.fieldName = fieldName;
- }
- @Override
- public String toString() {
- return this.fieldName;
- }
- }
- /**
- * Metoda pobierająca pole klasy, które reprezentuje ID.
- * Wykorzystywane przez GenericHibernateDaoImpl przy pobieraniu po Id.
- *
- * @see pl.sylogic.common.model.dao.GenericHibernateDaoImpl
- * @return IField
- */
- public static IField getIdField() {
- return Field.USER_ID;
- }
- }
Add Comment
Please, Sign In to add comment