301 lines
7.7 KiB
Java
301 lines
7.7 KiB
Java
package ru.ulstu.paper.model;
|
||
|
||
import org.hibernate.annotations.Fetch;
|
||
import org.hibernate.annotations.FetchMode;
|
||
import org.hibernate.validator.constraints.NotBlank;
|
||
import ru.ulstu.conference.model.Conference;
|
||
import ru.ulstu.core.model.BaseEntity;
|
||
import ru.ulstu.core.model.UserContainer;
|
||
import ru.ulstu.deadline.model.Deadline;
|
||
import ru.ulstu.file.model.FileData;
|
||
import ru.ulstu.grant.model.Grant;
|
||
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.EnumType;
|
||
import javax.persistence.Enumerated;
|
||
import javax.persistence.FetchType;
|
||
import javax.persistence.JoinColumn;
|
||
import javax.persistence.ManyToMany;
|
||
import javax.persistence.OneToMany;
|
||
import javax.persistence.OrderBy;
|
||
import javax.persistence.Temporal;
|
||
import javax.persistence.TemporalType;
|
||
import java.util.ArrayList;
|
||
import java.util.Comparator;
|
||
import java.util.Date;
|
||
import java.util.HashSet;
|
||
import java.util.List;
|
||
import java.util.Objects;
|
||
import java.util.Optional;
|
||
import java.util.Set;
|
||
|
||
@Entity
|
||
public class Paper extends BaseEntity implements UserContainer {
|
||
public enum PaperStatus {
|
||
ATTENTION("Обратить внимание"),
|
||
ON_PREPARATION("На подготовке"),
|
||
ON_REVIEW("Отправлена на проверку"),
|
||
ACCEPTED("Принята"),
|
||
NOT_ACCEPTED("Не принята"),
|
||
COMPLETED("Завершена (опубликована)"),
|
||
DRAFT("Черновик"),
|
||
FAILED("Провалены сроки");
|
||
|
||
private String statusName;
|
||
|
||
PaperStatus(String name) {
|
||
this.statusName = name;
|
||
}
|
||
|
||
public String getStatusName() {
|
||
return statusName;
|
||
}
|
||
}
|
||
|
||
public enum PaperType {
|
||
OTHER("Прочая публикация"),
|
||
VAK("ВАК"),
|
||
SCOPUS("Scopus"),
|
||
WEB_OF_SCIENCE("Web Of Science");
|
||
|
||
private String typeName;
|
||
|
||
PaperType(String name) {
|
||
this.typeName = name;
|
||
}
|
||
|
||
public String getTypeName() {
|
||
return typeName;
|
||
}
|
||
}
|
||
|
||
@NotBlank
|
||
private String title;
|
||
|
||
@Enumerated(value = EnumType.STRING)
|
||
private PaperStatus status = PaperStatus.DRAFT;
|
||
|
||
@Enumerated(value = EnumType.STRING)
|
||
private PaperType type = PaperType.OTHER;
|
||
|
||
@Column(name = "create_date")
|
||
@Temporal(TemporalType.TIMESTAMP)
|
||
private Date createDate = new Date();
|
||
|
||
@Column(name = "update_date")
|
||
@Temporal(TemporalType.TIMESTAMP)
|
||
private Date updateDate = new Date();
|
||
|
||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||
@JoinColumn(name = "paper_id", unique = true)
|
||
@Fetch(FetchMode.SUBSELECT)
|
||
@OrderBy("date")
|
||
private List<Deadline> deadlines = new ArrayList<>();
|
||
|
||
private String comment;
|
||
|
||
private String url;
|
||
|
||
private Boolean locked = false;
|
||
|
||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||
@JoinColumn(name = "paper_id")
|
||
private List<Event> events = new ArrayList<>();
|
||
|
||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||
@JoinColumn(name = "paper_id", unique = true)
|
||
@Fetch(FetchMode.SUBSELECT)
|
||
private List<FileData> files = new ArrayList<>();
|
||
|
||
@ManyToMany(fetch = FetchType.EAGER)
|
||
private Set<User> authors = new HashSet<>();
|
||
|
||
@Column(name = "latex_text")
|
||
private String latexText;
|
||
|
||
@ManyToMany(mappedBy = "papers")
|
||
private List<Conference> conferences;
|
||
|
||
@ManyToMany(mappedBy = "papers")
|
||
private List<Grant> grants;
|
||
|
||
public PaperStatus getStatus() {
|
||
return status;
|
||
}
|
||
|
||
public void setStatus(PaperStatus status) {
|
||
this.status = status;
|
||
}
|
||
|
||
public PaperType getType() {
|
||
return type;
|
||
}
|
||
|
||
public void setType(PaperType type) {
|
||
this.type = type;
|
||
}
|
||
|
||
public Date getCreateDate() {
|
||
return createDate;
|
||
}
|
||
|
||
public void setCreateDate(Date createDate) {
|
||
this.createDate = createDate;
|
||
}
|
||
|
||
public Date getUpdateDate() {
|
||
return updateDate;
|
||
}
|
||
|
||
public void setUpdateDate(Date updateDate) {
|
||
this.updateDate = updateDate;
|
||
}
|
||
|
||
public List<Deadline> getDeadlines() {
|
||
return deadlines;
|
||
}
|
||
|
||
public void setDeadlines(List<Deadline> deadlines) {
|
||
this.deadlines = deadlines;
|
||
}
|
||
|
||
public String getComment() {
|
||
return comment;
|
||
}
|
||
|
||
public void setComment(String comment) {
|
||
this.comment = comment;
|
||
}
|
||
|
||
public Boolean getLocked() {
|
||
return locked;
|
||
}
|
||
|
||
public void setLocked(Boolean locked) {
|
||
this.locked = locked;
|
||
}
|
||
|
||
public List<FileData> getFiles() {
|
||
return files;
|
||
}
|
||
|
||
public void setFiles(List<FileData> files) {
|
||
this.files = files;
|
||
}
|
||
|
||
public String getTitle() {
|
||
return title;
|
||
}
|
||
|
||
public void setTitle(String title) {
|
||
this.title = title;
|
||
}
|
||
|
||
public Set<User> getAuthors() {
|
||
return authors;
|
||
}
|
||
|
||
public void setAuthors(Set<User> authors) {
|
||
this.authors = authors;
|
||
}
|
||
|
||
public List<Event> getEvents() {
|
||
return events;
|
||
}
|
||
|
||
public void setEvents(List<Event> events) {
|
||
this.events = events;
|
||
}
|
||
|
||
public String getUrl() {
|
||
return url;
|
||
}
|
||
|
||
public void setUrl(String url) {
|
||
this.url = url;
|
||
}
|
||
|
||
public String getLatexText() {
|
||
return latexText;
|
||
}
|
||
|
||
public void setLatexText(String latexText) {
|
||
this.latexText = latexText;
|
||
}
|
||
|
||
public List<Conference> getConferences() {
|
||
return conferences;
|
||
}
|
||
|
||
public void setConferences(List<Conference> conferences) {
|
||
this.conferences = conferences;
|
||
}
|
||
|
||
public List<Grant> getGrants() {
|
||
return grants;
|
||
}
|
||
|
||
public void setGrants(List<Grant> grants) {
|
||
this.grants = grants;
|
||
}
|
||
|
||
@Override
|
||
public Set<User> getUsers() {
|
||
return getAuthors();
|
||
}
|
||
|
||
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();
|
||
}
|
||
|
||
public boolean lastDeadlineFailed() {
|
||
return !deadlines
|
||
.stream()
|
||
.filter(deadline -> deadline.getDate() != null)
|
||
.filter(d -> d.getDate().after(new Date()))
|
||
.findAny()
|
||
.isPresent();
|
||
}
|
||
|
||
@Override
|
||
public boolean equals(Object o) {
|
||
if (this == o) {
|
||
return true;
|
||
}
|
||
if (o == null || getClass() != o.getClass()) {
|
||
return false;
|
||
}
|
||
if (!super.equals(o)) {
|
||
return false;
|
||
}
|
||
Paper paper = (Paper) o;
|
||
return Objects.equals(title, paper.title) &&
|
||
status == paper.status &&
|
||
type == paper.type &&
|
||
Objects.equals(deadlines, paper.deadlines) &&
|
||
Objects.equals(comment, paper.comment) &&
|
||
Objects.equals(url, paper.url) &&
|
||
Objects.equals(locked, paper.locked) &&
|
||
Objects.equals(events, paper.events) &&
|
||
Objects.equals(files, paper.files) &&
|
||
Objects.equals(authors, paper.authors) &&
|
||
Objects.equals(latexText, paper.latexText) &&
|
||
Objects.equals(conferences, paper.conferences) &&
|
||
Objects.equals(grants, paper.grants);
|
||
}
|
||
|
||
@Override
|
||
public int hashCode() {
|
||
return Objects.hash(super.hashCode(), title, status, type, createDate, updateDate, deadlines, comment, url, locked, events, files, authors, latexText, conferences, grants);
|
||
}
|
||
}
|