2018-12-08 23:53:38 +04:00
|
|
|
|
package ru.ulstu.grant.model;
|
|
|
|
|
|
|
|
|
|
import org.hibernate.validator.constraints.NotBlank;
|
|
|
|
|
import ru.ulstu.core.model.BaseEntity;
|
2018-12-11 15:08:35 +04:00
|
|
|
|
import ru.ulstu.deadline.model.Deadline;
|
2018-12-08 23:53:38 +04:00
|
|
|
|
import ru.ulstu.file.model.FileData;
|
2018-12-11 15:08:35 +04:00
|
|
|
|
import ru.ulstu.project.model.Project;
|
2018-12-08 23:53:38 +04:00
|
|
|
|
|
|
|
|
|
import javax.persistence.*;
|
|
|
|
|
import javax.validation.constraints.NotNull;
|
2018-12-23 02:22:06 +04:00
|
|
|
|
import java.util.*;
|
2018-12-08 23:53:38 +04:00
|
|
|
|
|
|
|
|
|
@Entity
|
2018-12-24 15:20:57 +04:00
|
|
|
|
@Table(name = "grants")
|
2018-12-08 23:53:38 +04:00
|
|
|
|
public class Grant extends BaseEntity {
|
|
|
|
|
public enum GrantStatus {
|
|
|
|
|
APPLICATION("Заявка"),
|
|
|
|
|
ON_COMPETITION("Отправлен на конкурс"),
|
|
|
|
|
SUCCESSFUL_PASSAGE("Успешное прохождение"),
|
|
|
|
|
IN_WORK("В работе"),
|
|
|
|
|
COMPLETED("Завершен"),
|
|
|
|
|
FAILED("Провалены сроки");
|
|
|
|
|
|
|
|
|
|
private String name;
|
|
|
|
|
GrantStatus(String name) {
|
|
|
|
|
this.name = name;
|
|
|
|
|
}
|
|
|
|
|
public String getName() {
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@NotBlank
|
|
|
|
|
private String title;
|
|
|
|
|
|
|
|
|
|
@Enumerated(value = EnumType.STRING)
|
|
|
|
|
private GrantStatus status = GrantStatus.APPLICATION;
|
|
|
|
|
|
2018-12-11 15:08:35 +04:00
|
|
|
|
@OneToMany(cascade = CascadeType.ALL)
|
|
|
|
|
@JoinColumn(name = "grant_id")
|
|
|
|
|
private List<Deadline> deadlines = new ArrayList<>();
|
2018-12-08 23:53:38 +04:00
|
|
|
|
|
|
|
|
|
//Описание гранта
|
|
|
|
|
@NotNull
|
|
|
|
|
private String comment;
|
|
|
|
|
|
|
|
|
|
//Заявка на грант
|
2018-12-11 15:08:35 +04:00
|
|
|
|
@ManyToOne
|
|
|
|
|
@JoinColumn(name = "file_id")
|
2018-12-08 23:53:38 +04:00
|
|
|
|
private FileData application;
|
|
|
|
|
|
2018-12-11 15:08:35 +04:00
|
|
|
|
@ManyToOne(cascade = CascadeType.ALL)
|
2018-12-08 23:53:38 +04:00
|
|
|
|
@JoinColumn(name = "project_id")
|
2018-12-11 15:08:35 +04:00
|
|
|
|
private Project project;
|
2018-12-08 23:53:38 +04:00
|
|
|
|
|
|
|
|
|
public GrantStatus getStatus() {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setStatus(GrantStatus status) {
|
|
|
|
|
this.status = status;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-11 15:08:35 +04:00
|
|
|
|
public List<Deadline> getDeadlines() {
|
|
|
|
|
return deadlines;
|
2018-12-08 23:53:38 +04:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-11 15:08:35 +04:00
|
|
|
|
public void setDeadlines(List<Deadline> deadlines) {
|
|
|
|
|
this.deadlines = deadlines;
|
2018-12-08 23:53:38 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getComment() {
|
|
|
|
|
return comment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setComment(String comment) {
|
|
|
|
|
this.comment = comment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FileData getApplication() {
|
|
|
|
|
return application;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setApplication(FileData application) { this.application = application; }
|
|
|
|
|
|
|
|
|
|
public String getTitle() {
|
|
|
|
|
return title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setTitle(String title) { this.title = title; }
|
|
|
|
|
|
2018-12-11 15:08:35 +04:00
|
|
|
|
public Project getProject() {
|
|
|
|
|
return project;
|
|
|
|
|
}
|
2018-12-08 23:53:38 +04:00
|
|
|
|
|
2018-12-11 15:08:35 +04:00
|
|
|
|
public void setProject(Project project) {
|
|
|
|
|
this.project = project;
|
|
|
|
|
}
|
2018-12-23 02:22:06 +04:00
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
2018-12-08 23:53:38 +04:00
|
|
|
|
}
|