167 lines
4.2 KiB
Java
167 lines
4.2 KiB
Java
package ru.ulstu.conference.model;
|
|
|
|
import org.hibernate.annotations.Fetch;
|
|
import org.hibernate.annotations.FetchMode;
|
|
import org.hibernate.validator.constraints.NotBlank;
|
|
import org.springframework.format.annotation.DateTimeFormat;
|
|
import ru.ulstu.core.model.BaseEntity;
|
|
import ru.ulstu.core.model.EventSource;
|
|
import ru.ulstu.deadline.model.Deadline;
|
|
import ru.ulstu.paper.model.Paper;
|
|
import ru.ulstu.timeline.model.Event;
|
|
import ru.ulstu.user.model.User;
|
|
|
|
import javax.persistence.CascadeType;
|
|
import javax.persistence.Column;
|
|
import javax.persistence.Entity;
|
|
import javax.persistence.FetchType;
|
|
import javax.persistence.JoinColumn;
|
|
import javax.persistence.JoinTable;
|
|
import javax.persistence.ManyToMany;
|
|
import javax.persistence.OneToMany;
|
|
import javax.persistence.OrderBy;
|
|
import javax.persistence.Table;
|
|
import javax.persistence.Temporal;
|
|
import javax.persistence.TemporalType;
|
|
import java.util.ArrayList;
|
|
import java.util.Comparator;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
|
|
@Entity
|
|
@Table(name = "conference")
|
|
public class Conference extends BaseEntity implements EventSource {
|
|
|
|
@NotBlank
|
|
private String title;
|
|
|
|
private String description;
|
|
|
|
private String url;
|
|
|
|
private int ping = 0;
|
|
|
|
@Column(name = "begin_date")
|
|
@Temporal(TemporalType.TIMESTAMP)
|
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
|
private Date beginDate = new Date();
|
|
|
|
@Column(name = "end_date")
|
|
@Temporal(TemporalType.TIMESTAMP)
|
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
|
private Date endDate = new Date();
|
|
|
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
|
@JoinColumn(name = "conference_id", unique = true)
|
|
@Fetch(FetchMode.SUBSELECT)
|
|
@OrderBy("date")
|
|
private List<Deadline> deadlines = new ArrayList<>();
|
|
|
|
@ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
|
|
@JoinTable(name = "paper_conference",
|
|
joinColumns = {@JoinColumn(name = "conference_id")},
|
|
inverseJoinColumns = {@JoinColumn(name = "paper_id")})
|
|
@Fetch(FetchMode.SUBSELECT)
|
|
private List<Paper> papers = new ArrayList<>();
|
|
|
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
|
@JoinColumn(name = "conference_id", unique = true)
|
|
@Fetch(FetchMode.SUBSELECT)
|
|
private List<ConferenceUser> users = new ArrayList<>();
|
|
|
|
public String getTitle() {
|
|
return title;
|
|
}
|
|
|
|
@Override
|
|
public List<User> getRecipients() {
|
|
List<User> list = new ArrayList<>();
|
|
|
|
getUsers().forEach(conferenceUser -> list.add(conferenceUser.getUser()));
|
|
return list;
|
|
}
|
|
|
|
@Override
|
|
public void addObjectToEvent(Event event) {
|
|
event.setConference(this);
|
|
}
|
|
|
|
public void setTitle(String title) {
|
|
this.title = title;
|
|
}
|
|
|
|
public String getDescription() {
|
|
return description;
|
|
}
|
|
|
|
public void setDescription(String description) {
|
|
this.description = description;
|
|
}
|
|
|
|
public String getUrl() {
|
|
return url;
|
|
}
|
|
|
|
public void setUrl(String url) {
|
|
this.url = url;
|
|
}
|
|
|
|
public int getPing() {
|
|
return ping;
|
|
}
|
|
|
|
public void setPing(int ping) {
|
|
this.ping = ping;
|
|
}
|
|
|
|
public Date getBeginDate() {
|
|
return beginDate;
|
|
}
|
|
|
|
public void setBeginDate(Date beginDate) {
|
|
this.beginDate = beginDate;
|
|
}
|
|
|
|
public Date getEndDate() {
|
|
return endDate;
|
|
}
|
|
|
|
public void setEndDate(Date endDate) {
|
|
this.endDate = endDate;
|
|
}
|
|
|
|
public List<Deadline> getDeadlines() {
|
|
return deadlines;
|
|
}
|
|
|
|
public void setDeadlines(List<Deadline> deadlines) {
|
|
this.deadlines = deadlines;
|
|
}
|
|
|
|
public List<Paper> getPapers() {
|
|
return papers;
|
|
}
|
|
|
|
public void setPapers(List<Paper> papers) {
|
|
this.papers = papers;
|
|
}
|
|
|
|
public List<ConferenceUser> getUsers() {
|
|
return users;
|
|
}
|
|
|
|
public void setUsers(List<ConferenceUser> users) {
|
|
this.users = users;
|
|
}
|
|
|
|
public Optional<Deadline> getNextDeadline() {
|
|
return deadlines
|
|
.stream()
|
|
.filter(deadline -> deadline.getDate() != null)
|
|
.sorted(Comparator.comparing(Deadline::getDate))
|
|
.filter(d -> d.getDate().after(new Date()))
|
|
.findFirst();
|
|
}
|
|
}
|