Files
sasiedzi/src/main/java/com/sasiedzi/event/domain/Event.java
T
2024-12-02 19:20:03 +01:00

301 lines
7.5 KiB
Java

package com.sasiedzi.event.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.persistence.*;
import jakarta.validation.constraints.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.HashSet;
import java.util.Set;
/**
* A Event.
*/
@Entity
@Table(name = "event")
@SuppressWarnings("common-java:DuplicatedBlocks")
public class Event implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
@Column(name = "id")
private Long id;
@NotNull
@Column(name = "name", nullable = false)
private String name;
@NotNull
@Column(name = "date", nullable = false)
private LocalDate date;
@Column(name = "players_limit")
private Integer playersLimit;
@Column(name = "cost", precision = 21, scale = 2)
private BigDecimal cost;
// @Lob
@Column(name = "comment")
private String comment;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "event")
@JsonIgnoreProperties(value = { "event", "transactionItems" }, allowSetters = true)
private Set<Registration> registrations = new HashSet<>();
@OneToMany(fetch = FetchType.LAZY, mappedBy = "event")
@JsonIgnoreProperties(value = { "event", "transactionItems" }, allowSetters = true)
private Set<Transaction> transactions = new HashSet<>();
// jhipster-needle-entity-add-field - JHipster will add fields here
public Long getId() {
return this.id;
}
public Event id(Long id) {
this.setId(id);
return this;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return this.name;
}
public Event name(String name) {
this.setName(name);
return this;
}
public void setName(String name) {
this.name = name;
}
public LocalDate getDate() {
return this.date;
}
public Event date(LocalDate date) {
this.setDate(date);
return this;
}
public void setDate(LocalDate date) {
this.date = date;
}
// @Transient
// private Boolean editable;
@JsonProperty("editable")
public Boolean getEditable() {
if (date == null) return false;
LocalDate currentDate = LocalDate.now();
long daysBetween = ChronoUnit.DAYS.between(this.date, currentDate);
return daysBetween <= 7;
}
@Transient
private Long chargeTransactionId;
@JsonProperty("chargeTransactionId")
public Long getChargeTransactionId() {
return chargeTransactionId;
}
public void setChargeTransactionId(Long chargeTransactionId) {
this.chargeTransactionId = chargeTransactionId;
}
// public void setEditable(Boolean editable) {
// this.editable = editable;
// }
@Transient
private Boolean charged;
@JsonProperty("charged")
public Boolean getCharged() {
return charged;
}
public void setCharged(Boolean charged) {
this.charged = charged;
}
@Transient
private Boolean current;
@JsonProperty("current")
public Boolean getCurrent() {
return current;
}
public void setCurrent(Boolean current) {
this.current = current;
}
@JsonProperty("active")
public Boolean getActive() {
if (date == null) return false;
LocalDate currentDate = LocalDate.now();
long daysBetween = ChronoUnit.DAYS.between(this.date, currentDate);
return daysBetween <= 0;
}
// @Transient
// private Boolean deletable;
@JsonProperty("deletable")
public Boolean getDeletable() {
return getEditable();
}
// public void setDeletable(Boolean deletable) {
// this.deletable = deletable;
// }
public Integer getPlayersLimit() {
return this.playersLimit;
}
public Event playersLimit(Integer playersLimit) {
this.setPlayersLimit(playersLimit);
return this;
}
public void setPlayersLimit(Integer playersLimit) {
this.playersLimit = playersLimit;
}
public BigDecimal getCost() {
return this.cost;
}
public Event cost(BigDecimal cost) {
this.setCost(cost);
return this;
}
public void setCost(BigDecimal cost) {
this.cost = cost;
}
public String getComment() {
return this.comment;
}
public Event comment(String comment) {
this.setComment(comment);
return this;
}
public void setComment(String comment) {
this.comment = comment;
}
public Set<Registration> getRegistrations() {
return this.registrations;
}
public void setRegistrations(Set<Registration> registrations) {
if (this.registrations != null) {
this.registrations.forEach(i -> i.setEvent(null));
}
if (registrations != null) {
registrations.forEach(i -> i.setEvent(this));
}
this.registrations = registrations;
}
public Event registrations(Set<Registration> registrations) {
this.setRegistrations(registrations);
return this;
}
public Event addRegistrations(Registration registration) {
this.registrations.add(registration);
registration.setEvent(this);
return this;
}
public Event removeRegistrations(Registration registration) {
this.registrations.remove(registration);
registration.setEvent(null);
return this;
}
public Set<Transaction> getTransactions() {
return this.transactions;
}
public void setTransactions(Set<Transaction> transactions) {
if (this.transactions != null) {
this.transactions.forEach(i -> i.setEvent(null));
}
if (transactions != null) {
transactions.forEach(i -> i.setEvent(this));
}
this.transactions = transactions;
}
public Event transactions(Set<Transaction> transactions) {
this.setTransactions(transactions);
return this;
}
public Event addTransaction(Transaction transaction) {
this.transactions.add(transaction);
transaction.setEvent(this);
return this;
}
public Event removeTransaction(Transaction transaction) {
this.transactions.remove(transaction);
transaction.setEvent(null);
return this;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Event)) {
return false;
}
return getId() != null && getId().equals(((Event) o).getId());
}
@Override
public int hashCode() {
// see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
return getClass().hashCode();
}
// prettier-ignore
@Override
public String toString() {
return "Event{" +
"id=" + getId() +
", name='" + getName() + "'" +
", date='" + getDate() + "'" +
", playersLimit=" + getPlayersLimit() +
", cost=" + getCost() +
", comment='" + getComment() + "'" +
"}";
}
}