package ru.ulstu.grant.model; import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; import ru.ulstu.project.model.Project; import javax.persistence.*; import javax.validation.constraints.NotNull; import java.util.*; @Entity @Table(name = "grants") 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; @OneToMany(cascade = CascadeType.ALL) @JoinColumn(name = "grant_id") private List deadlines = new ArrayList<>(); //Описание гранта @NotNull private String comment; //Заявка на грант @ManyToOne @JoinColumn(name = "file_id") private FileData application; @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "project_id") private Project project; public GrantStatus getStatus() { return status; } public void setStatus(GrantStatus status) { this.status = status; } public List getDeadlines() { return deadlines; } public void setDeadlines(List deadlines) { this.deadlines = deadlines; } 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; } public Project getProject() { return project; } public void setProject(Project project) { this.project = project; } public Optional getNextDeadline() { return deadlines .stream() .filter(deadline -> deadline.getDate() != null) .sorted(Comparator.comparing(Deadline::getDate)) .filter(d -> d.getDate().after(new Date())) .findFirst(); } }