Preference.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package fr.triplea.demovote.model;
  2. import java.time.LocalDateTime;
  3. import java.time.format.DateTimeFormatter;
  4. import java.util.Locale;
  5. import org.hibernate.annotations.CreationTimestamp;
  6. import org.hibernate.annotations.UpdateTimestamp;
  7. import org.springframework.util.StringUtils;
  8. import com.fasterxml.jackson.annotation.JsonFormat;
  9. import jakarta.persistence.Column;
  10. import jakarta.persistence.Entity;
  11. import jakarta.persistence.GeneratedValue;
  12. import jakarta.persistence.GenerationType;
  13. import jakarta.persistence.Id;
  14. import jakarta.persistence.JoinColumn;
  15. import jakarta.persistence.ManyToOne;
  16. import jakarta.persistence.Table;
  17. import jakarta.persistence.Temporal;
  18. import jakarta.persistence.TemporalType;
  19. import jakarta.persistence.Transient;
  20. @Entity(name = "vote.preferences")
  21. @Table(name = "preferences")
  22. public class Preference
  23. {
  24. @Temporal(TemporalType.TIMESTAMP)
  25. @CreationTimestamp
  26. @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="dd/MM/yyyy HH:mm:ss", timezone="Europe/Paris")
  27. private LocalDateTime dateCreation;
  28. @Temporal(TemporalType.TIMESTAMP)
  29. @UpdateTimestamp
  30. @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="dd/MM/yyyy HH:mm:ss", timezone="Europe/Paris")
  31. private LocalDateTime dateModification;
  32. @Id
  33. @GeneratedValue(strategy = GenerationType.IDENTITY)
  34. @Column(name = "numero_preference", nullable = false)
  35. private Integer numeroPreference;
  36. @ManyToOne
  37. @JoinColumn(name="numero_participant", referencedColumnName="numero_participant")
  38. private Participant participant;
  39. private Integer numeroTraitement;
  40. @Column(length = 4000, nullable = false)
  41. private String valeurs;
  42. public Preference() { super(); }
  43. @Transient
  44. DateTimeFormatter df = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss", Locale.FRANCE);
  45. public void setDateCreation(LocalDateTime d) { this.dateCreation = d; }
  46. public void setDateCreation(String s) { this.dateCreation = LocalDateTime.parse(s, df); }
  47. public LocalDateTime getDateCreation() { return this.dateCreation; }
  48. public void setDateModification(LocalDateTime d) { this.dateModification = d; }
  49. public void setDateModification(String s) { this.dateModification = LocalDateTime.parse(s, df); }
  50. public LocalDateTime getDateModification() { return this.dateModification; }
  51. public void setNumeroPreference(Integer numeroPreference) { this.numeroPreference = numeroPreference; }
  52. public Integer getNumeroPreference() { return this.numeroPreference; }
  53. public void setParticipant(Participant p) { this.participant = p; }
  54. public Participant getParticipant() { return this.participant; }
  55. public void setNumeroTraitement(int t) { this.numeroTraitement = Integer.valueOf(t); }
  56. public Integer getNumeroTraitement() { return this.numeroTraitement; }
  57. public void setValeurs(String str) { if (str != null) { this.valeurs = StringUtils.truncate(str, 4000); } }
  58. public String getValeurs() { return this.valeurs; }
  59. @Override
  60. public int hashCode()
  61. {
  62. final int prime = 42;
  63. int result = 1;
  64. result = (prime * result) + ((getNumeroPreference() == null) ? 0 : getNumeroPreference().hashCode());
  65. result = (prime * result) + ((getParticipant() == null) ? 0 : getParticipant().hashCode());
  66. result = (prime * result) + ((getNumeroTraitement() == null) ? 0 : getNumeroTraitement().hashCode());
  67. result = (prime * result) + ((getValeurs() == null) ? 0 : getValeurs().hashCode());
  68. return result;
  69. }
  70. @Override
  71. public boolean equals(final Object obj)
  72. {
  73. if (this == obj) { return true; }
  74. if (obj == null) { return false; }
  75. if (getClass() != obj.getClass()) { return false; }
  76. final Preference p = (Preference) obj;
  77. if (getNumeroPreference() == null) { if (p.getNumeroPreference() == null) { return false; } } else if (!getNumeroPreference().equals(p.getNumeroPreference())) { return false; }
  78. if (getParticipant() == null) { if (p.getParticipant() == null) { return false; } } else if (!getParticipant().equals(p.getParticipant())) { return false; }
  79. if (getNumeroTraitement() == null) { if (p.getNumeroTraitement() == null) { return false; } } else if (!getNumeroTraitement().equals(p.getNumeroTraitement())) { return false; }
  80. return true;
  81. }
  82. @Override
  83. public String toString()
  84. {
  85. final StringBuilder builder = new StringBuilder();
  86. builder.append("Preference [id=")
  87. .append(numeroPreference)
  88. .append(", participant=").append(participant)
  89. .append(", numeroTraitement=").append(numeroTraitement)
  90. .append(", valeurs=").append(valeurs)
  91. .append(", créé=").append(dateCreation)
  92. .append(", modifié=").append(dateModification)
  93. .append("]");
  94. return builder.toString();
  95. }
  96. }