move classes, add deadline to entities, fix db changelogs
This commit is contained in:
parent
590cd16abe
commit
d71a8d2c83
41
src/main/java/ru/ulstu/deadline/model/Deadline.java
Normal file
41
src/main/java/ru/ulstu/deadline/model/Deadline.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package ru.ulstu.deadline.model;
|
||||||
|
|
||||||
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Deadline extends BaseEntity {
|
||||||
|
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Temporal(value = TemporalType.TIMESTAMP)
|
||||||
|
private Date date;
|
||||||
|
|
||||||
|
public Deadline() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Deadline(Date deadlineDate, String description) {
|
||||||
|
this.date = deadlineDate;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDate() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDate(Date date) {
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
}
|
41
src/main/java/ru/ulstu/deadline/model/DeadlineDto.java
Normal file
41
src/main/java/ru/ulstu/deadline/model/DeadlineDto.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package ru.ulstu.deadline.model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class DeadlineDto {
|
||||||
|
private final Integer id;
|
||||||
|
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
private final Date date;
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public DeadlineDto(@JsonProperty("id") Integer id,
|
||||||
|
@JsonProperty("description") String description,
|
||||||
|
@JsonProperty("date") Date date) {
|
||||||
|
this.id = id;
|
||||||
|
this.description = description;
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeadlineDto(Deadline deadline) {
|
||||||
|
this.id = deadline.getId();
|
||||||
|
this.description = deadline.getDescription();
|
||||||
|
this.date = deadline.getDate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDate() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package ru.ulstu.deadline.repository;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
|
||||||
|
public interface DeadlineRepository extends JpaRepository<Deadline, Integer> {
|
||||||
|
|
||||||
|
}
|
45
src/main/java/ru/ulstu/deadline/service/DeadlineService.java
Normal file
45
src/main/java/ru/ulstu/deadline/service/DeadlineService.java
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package ru.ulstu.deadline.service;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.deadline.model.DeadlineDto;
|
||||||
|
import ru.ulstu.deadline.repository.DeadlineRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class DeadlineService {
|
||||||
|
private final DeadlineRepository deadlineRepository;
|
||||||
|
|
||||||
|
public DeadlineService(DeadlineRepository deadlineRepository) {
|
||||||
|
this.deadlineRepository = deadlineRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Deadline> saveOrCreate(List<DeadlineDto> deadlines) {
|
||||||
|
return deadlines.stream().map(deadlineDto -> {
|
||||||
|
return deadlineDto.getId() != null ? update(deadlineDto) : create(deadlineDto);
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Deadline update(DeadlineDto deadlineDto) {
|
||||||
|
Deadline deadline = deadlineRepository.findOne(deadlineDto.getId());
|
||||||
|
deadlineRepository.save(copyFromDto(deadline, deadlineDto));
|
||||||
|
return deadline;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Deadline create(DeadlineDto deadlineDto) {
|
||||||
|
Deadline newDeadline = copyFromDto(new Deadline(), deadlineDto);
|
||||||
|
newDeadline = deadlineRepository.save(newDeadline);
|
||||||
|
return newDeadline;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Deadline copyFromDto(Deadline deadline, DeadlineDto deadlineDto) {
|
||||||
|
deadline.setDate(deadlineDto.getDate());
|
||||||
|
deadline.setDescription(deadlineDto.getDescription());
|
||||||
|
return deadline;
|
||||||
|
}
|
||||||
|
}
|
@ -1,21 +0,0 @@
|
|||||||
package ru.ulstu.grant.model;
|
|
||||||
|
|
||||||
import org.hibernate.validator.constraints.NotBlank;
|
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
|
||||||
import ru.ulstu.file.model.FileData;
|
|
||||||
|
|
||||||
import javax.persistence.*;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
public class Deadline extends BaseEntity {
|
|
||||||
|
|
||||||
@ManyToOne
|
|
||||||
@JoinColumn(name = "grant_id")
|
|
||||||
private Integer grantId;
|
|
||||||
|
|
||||||
public Integer getGrantId() { return grantId;}
|
|
||||||
public void setGrantId(Integer grantId) { this.grantId = grantId; }
|
|
||||||
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
package ru.ulstu.grant.model;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import org.hibernate.validator.constraints.NotEmpty;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class DeadlineDto {
|
|
||||||
private final Integer id;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private final Integer grantId;
|
|
||||||
|
|
||||||
@JsonCreator
|
|
||||||
public DeadlineDto(@JsonProperty("id") Integer id,
|
|
||||||
@JsonProperty("grantId") Integer grantId){
|
|
||||||
this.id = id;
|
|
||||||
this.grantId = grantId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DeadlineDto(Deadline deadline) {
|
|
||||||
this.id = deadline.getId();
|
|
||||||
this.grantId = deadline.getGrantId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getGrantId() { return grantId; }
|
|
||||||
}
|
|
@ -3,13 +3,17 @@ package ru.ulstu.grant.model;
|
|||||||
import org.hibernate.validator.constraints.NotBlank;
|
import org.hibernate.validator.constraints.NotBlank;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
import ru.ulstu.core.model.UserContainer;
|
import ru.ulstu.core.model.UserContainer;
|
||||||
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.file.model.FileData;
|
import ru.ulstu.file.model.FileData;
|
||||||
|
import ru.ulstu.project.model.Project;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@ -39,21 +43,22 @@ public class Grant extends BaseEntity {
|
|||||||
@Enumerated(value = EnumType.STRING)
|
@Enumerated(value = EnumType.STRING)
|
||||||
private GrantStatus status = GrantStatus.APPLICATION;
|
private GrantStatus status = GrantStatus.APPLICATION;
|
||||||
|
|
||||||
@Column(name = "deadline_date")
|
@OneToMany(cascade = CascadeType.ALL)
|
||||||
@NotNull
|
@JoinColumn(name = "grant_id")
|
||||||
private Date deadlineDate;
|
private List<Deadline> deadlines = new ArrayList<>();
|
||||||
|
|
||||||
//Описание гранта
|
//Описание гранта
|
||||||
@NotNull
|
@NotNull
|
||||||
private String comment;
|
private String comment;
|
||||||
|
|
||||||
//Заявка на грант
|
//Заявка на грант
|
||||||
@NotNull
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "file_id")
|
||||||
private FileData application;
|
private FileData application;
|
||||||
|
|
||||||
@OneToOne
|
@ManyToOne(cascade = CascadeType.ALL)
|
||||||
@JoinColumn(name = "project_id")
|
@JoinColumn(name = "project_id")
|
||||||
private Integer projectId;
|
private Project project;
|
||||||
|
|
||||||
public GrantStatus getStatus() {
|
public GrantStatus getStatus() {
|
||||||
return status;
|
return status;
|
||||||
@ -63,12 +68,12 @@ public class Grant extends BaseEntity {
|
|||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getDeadlineDate() {
|
public List<Deadline> getDeadlines() {
|
||||||
return deadlineDate;
|
return deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDeadlineDate(Date deadlineDate) {
|
public void setDeadlines(List<Deadline> deadlines) {
|
||||||
this.deadlineDate = deadlineDate;
|
this.deadlines = deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getComment() {
|
public String getComment() {
|
||||||
@ -91,8 +96,11 @@ public class Grant extends BaseEntity {
|
|||||||
|
|
||||||
public void setTitle(String title) { this.title = title; }
|
public void setTitle(String title) { this.title = title; }
|
||||||
|
|
||||||
public Integer getProjectId() { return projectId;}
|
public Project getProject() {
|
||||||
|
return project;
|
||||||
public void setProjectId(Integer project_id) { this.projectId = projectId; }
|
}
|
||||||
|
|
||||||
|
public void setProject(Project project) {
|
||||||
|
this.project = project;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,10 @@ package ru.ulstu.grant.model;
|
|||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import org.hibernate.validator.constraints.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import ru.ulstu.file.model.FileData;
|
import ru.ulstu.deadline.model.DeadlineDto;
|
||||||
import ru.ulstu.user.model.UserDto;
|
import ru.ulstu.project.model.ProjectDto;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import java.util.List;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
@ -18,35 +15,34 @@ public class GrantDto {
|
|||||||
@NotEmpty
|
@NotEmpty
|
||||||
private final String title;
|
private final String title;
|
||||||
private final Grant.GrantStatus status;
|
private final Grant.GrantStatus status;
|
||||||
@NotNull
|
private final List<DeadlineDto> deadlines;
|
||||||
private final Date deadlineDate;
|
|
||||||
private final String comment;
|
private final String comment;
|
||||||
private final String applicationFileName;
|
private final String applicationFileName;
|
||||||
private final Integer projectId;
|
private final ProjectDto project;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public GrantDto(@JsonProperty("id") Integer id,
|
public GrantDto(@JsonProperty("id") Integer id,
|
||||||
@JsonProperty("title") String title,
|
@JsonProperty("title") String title,
|
||||||
@JsonProperty("status") Grant.GrantStatus status,
|
@JsonProperty("status") Grant.GrantStatus status,
|
||||||
@JsonProperty("deadlineDate") Date deadlineDate,
|
@JsonProperty("deadlines") List<DeadlineDto> deadlines,
|
||||||
@JsonProperty("comment") String comment,
|
@JsonProperty("comment") String comment,
|
||||||
@JsonProperty("projectId") Integer projectId){
|
@JsonProperty("project") ProjectDto project) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.deadlineDate = deadlineDate;
|
this.deadlines = deadlines;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
this.applicationFileName = null;
|
this.applicationFileName = null;
|
||||||
this.projectId = projectId;
|
this.project = project;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GrantDto(Grant grant) {
|
public GrantDto(Grant grant) {
|
||||||
this.id = grant.getId();
|
this.id = grant.getId();
|
||||||
this.title = grant.getTitle();
|
this.title = grant.getTitle();
|
||||||
this.status = grant.getStatus();
|
this.status = grant.getStatus();
|
||||||
this.deadlineDate = grant.getDeadlineDate();
|
this.deadlines = convert(grant.getDeadlines(), DeadlineDto::new);
|
||||||
this.comment = grant.getComment();
|
this.comment = grant.getComment();
|
||||||
this.projectId = grant.getProjectId();
|
this.project = grant.getProject() == null ? null : new ProjectDto(grant.getProject());
|
||||||
this.applicationFileName = grant.getApplication() == null ? null : grant.getApplication().getName();
|
this.applicationFileName = grant.getApplication() == null ? null : grant.getApplication().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,16 +58,16 @@ public class GrantDto {
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getDeadlineDate() {
|
public List<DeadlineDto> getDeadlines() {
|
||||||
return deadlineDate;
|
return deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getComment() {
|
public String getComment() {
|
||||||
return comment;
|
return comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getProjectId() {
|
public ProjectDto getProject() {
|
||||||
return projectId;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getApplicationFileName() {
|
public String getApplicationFileName() {
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
package ru.ulstu.grant.model;
|
|
||||||
|
|
||||||
import org.hibernate.validator.constraints.NotBlank;
|
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
|
||||||
import ru.ulstu.file.model.FileData;
|
|
||||||
|
|
||||||
import javax.persistence.*;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
public class Project extends BaseEntity {
|
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
private String title;
|
|
||||||
|
|
||||||
public String getTitle() {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTitle(String title) { this.title = title; }
|
|
||||||
}
|
|
@ -3,9 +3,11 @@ package ru.ulstu.paper.model;
|
|||||||
import org.hibernate.validator.constraints.NotBlank;
|
import org.hibernate.validator.constraints.NotBlank;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
import ru.ulstu.core.model.UserContainer;
|
import ru.ulstu.core.model.UserContainer;
|
||||||
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.file.model.FileData;
|
import ru.ulstu.file.model.FileData;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.EnumType;
|
import javax.persistence.EnumType;
|
||||||
@ -14,10 +16,14 @@ import javax.persistence.FetchType;
|
|||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.ManyToMany;
|
import javax.persistence.ManyToMany;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
|
import javax.persistence.OneToMany;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@ -52,9 +58,9 @@ public class Paper extends BaseEntity implements UserContainer {
|
|||||||
@Column(name = "update_date")
|
@Column(name = "update_date")
|
||||||
private Date updateDate = new Date();
|
private Date updateDate = new Date();
|
||||||
|
|
||||||
@Column(name = "deadline_date")
|
@OneToMany(cascade = CascadeType.ALL)
|
||||||
@NotNull
|
@JoinColumn(name = "paper_id")
|
||||||
private Date deadlineDate;
|
private List<Deadline> deadlines = new ArrayList<>();
|
||||||
|
|
||||||
private String comment;
|
private String comment;
|
||||||
|
|
||||||
@ -91,12 +97,12 @@ public class Paper extends BaseEntity implements UserContainer {
|
|||||||
this.updateDate = updateDate;
|
this.updateDate = updateDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getDeadlineDate() {
|
public List<Deadline> getDeadlines() {
|
||||||
return deadlineDate;
|
return deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDeadlineDate(Date deadlineDate) {
|
public void setDeadlines(List<Deadline> deadlines) {
|
||||||
this.deadlineDate = deadlineDate;
|
this.deadlines = deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getComment() {
|
public String getComment() {
|
||||||
@ -143,4 +149,12 @@ public class Paper extends BaseEntity implements UserContainer {
|
|||||||
public Set<User> getUsers() {
|
public Set<User> getUsers() {
|
||||||
return getAuthors();
|
return getAuthors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<Deadline> getNextDeadline() {
|
||||||
|
return deadlines
|
||||||
|
.stream()
|
||||||
|
.sorted(Comparator.comparing(Deadline::getDate))
|
||||||
|
.filter(d -> d.getDate().after(new Date()))
|
||||||
|
.findFirst();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,12 @@ package ru.ulstu.paper.model;
|
|||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import org.hibernate.validator.constraints.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
|
import ru.ulstu.deadline.model.DeadlineDto;
|
||||||
import ru.ulstu.user.model.UserDto;
|
import ru.ulstu.user.model.UserDto;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -19,8 +21,7 @@ public class PaperDto {
|
|||||||
private final Paper.PaperStatus status;
|
private final Paper.PaperStatus status;
|
||||||
private final Date createDate;
|
private final Date createDate;
|
||||||
private final Date updateDate;
|
private final Date updateDate;
|
||||||
@NotNull
|
private final List<DeadlineDto> deadlines;
|
||||||
private final Date deadlineDate;
|
|
||||||
private final String comment;
|
private final String comment;
|
||||||
private final Boolean locked;
|
private final Boolean locked;
|
||||||
private final String tmpFileName;
|
private final String tmpFileName;
|
||||||
@ -35,7 +36,7 @@ public class PaperDto {
|
|||||||
@JsonProperty("status") Paper.PaperStatus status,
|
@JsonProperty("status") Paper.PaperStatus status,
|
||||||
@JsonProperty("createDate") Date createDate,
|
@JsonProperty("createDate") Date createDate,
|
||||||
@JsonProperty("updateDate") Date updateDate,
|
@JsonProperty("updateDate") Date updateDate,
|
||||||
@JsonProperty("deadlineDate") Date deadlineDate,
|
@JsonProperty("deadlines") List<DeadlineDto> deadlines,
|
||||||
@JsonProperty("comment") String comment,
|
@JsonProperty("comment") String comment,
|
||||||
@JsonProperty("locked") Boolean locked,
|
@JsonProperty("locked") Boolean locked,
|
||||||
@JsonProperty("tmpFileName") String tmpFileName,
|
@JsonProperty("tmpFileName") String tmpFileName,
|
||||||
@ -45,7 +46,7 @@ public class PaperDto {
|
|||||||
this.status = status;
|
this.status = status;
|
||||||
this.createDate = createDate;
|
this.createDate = createDate;
|
||||||
this.updateDate = updateDate;
|
this.updateDate = updateDate;
|
||||||
this.deadlineDate = deadlineDate;
|
this.deadlines = deadlines;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
this.locked = locked;
|
this.locked = locked;
|
||||||
this.tmpFileName = tmpFileName;
|
this.tmpFileName = tmpFileName;
|
||||||
@ -61,7 +62,7 @@ public class PaperDto {
|
|||||||
this.status = paper.getStatus();
|
this.status = paper.getStatus();
|
||||||
this.createDate = paper.getCreateDate();
|
this.createDate = paper.getCreateDate();
|
||||||
this.updateDate = paper.getUpdateDate();
|
this.updateDate = paper.getUpdateDate();
|
||||||
this.deadlineDate = paper.getDeadlineDate();
|
this.deadlines = convert(paper.getDeadlines(), DeadlineDto::new);
|
||||||
this.comment = paper.getComment();
|
this.comment = paper.getComment();
|
||||||
this.locked = paper.getLocked();
|
this.locked = paper.getLocked();
|
||||||
this.tmpFileName = null;
|
this.tmpFileName = null;
|
||||||
@ -91,8 +92,8 @@ public class PaperDto {
|
|||||||
return updateDate;
|
return updateDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getDeadlineDate() {
|
public List<DeadlineDto> getDeadlines() {
|
||||||
return deadlineDate;
|
return deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getComment() {
|
public String getComment() {
|
||||||
|
@ -29,16 +29,16 @@ public class PaperNotificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean needToSendDeadlineNotification(Paper paper, Date compareDate, boolean isDeadlineBeforeWeek) {
|
private boolean needToSendDeadlineNotification(Paper paper, Date compareDate, boolean isDeadlineBeforeWeek) {
|
||||||
return (paper.getDeadlineDate() != null)
|
return (paper.getNextDeadline().isPresent())
|
||||||
&& (compareDate.after(paper.getDeadlineDate()) && isDeadlineBeforeWeek
|
&& (compareDate.after(paper.getNextDeadline().get().getDate()) && isDeadlineBeforeWeek
|
||||||
|| compareDate.before(paper.getDeadlineDate()) && !isDeadlineBeforeWeek)
|
|| compareDate.before(paper.getNextDeadline().get().getDate()) && !isDeadlineBeforeWeek)
|
||||||
&& paper.getDeadlineDate().after(new Date());
|
&& paper.getNextDeadline().get().getDate().after(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendMessageDeadline(Paper paper) {
|
private void sendMessageDeadline(Paper paper) {
|
||||||
paper.getAuthors().forEach(user -> {
|
paper.getAuthors().forEach(user -> {
|
||||||
mailService.sendEmail(user.getEmail(), "Приближается срок сдачи статьи",
|
mailService.sendEmail(user.getEmail(), "Приближается срок сдачи статьи",
|
||||||
"Срок сдачи статьи " + paper.getTitle() + " " + paper.getDeadlineDate().toString());
|
"Срок сдачи статьи " + paper.getTitle() + " " + paper.getNextDeadline().get().getDate().toString());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@ package ru.ulstu.paper.service;
|
|||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.deadline.service.DeadlineService;
|
||||||
import ru.ulstu.file.service.FileService;
|
import ru.ulstu.file.service.FileService;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
import ru.ulstu.paper.model.PaperDto;
|
import ru.ulstu.paper.model.PaperDto;
|
||||||
@ -27,17 +29,19 @@ public class PaperService {
|
|||||||
private final PaperNotificationService paperNotificationService;
|
private final PaperNotificationService paperNotificationService;
|
||||||
private final PaperRepository paperRepository;
|
private final PaperRepository paperRepository;
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
private final DeadlineService deadlineService;
|
||||||
private final FileService fileService;
|
private final FileService fileService;
|
||||||
|
|
||||||
|
|
||||||
public PaperService(PaperRepository paperRepository,
|
public PaperService(PaperRepository paperRepository,
|
||||||
FileService fileService,
|
FileService fileService,
|
||||||
PaperNotificationService paperNotificationService,
|
PaperNotificationService paperNotificationService,
|
||||||
UserService userService) {
|
UserService userService,
|
||||||
|
DeadlineService deadlineService) {
|
||||||
this.paperRepository = paperRepository;
|
this.paperRepository = paperRepository;
|
||||||
this.fileService = fileService;
|
this.fileService = fileService;
|
||||||
this.paperNotificationService = paperNotificationService;
|
this.paperNotificationService = paperNotificationService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
|
this.deadlineService = deadlineService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Paper> findAll() {
|
public List<Paper> findAll() {
|
||||||
@ -71,7 +75,7 @@ public class PaperService {
|
|||||||
paper.setStatus(paperDto.getStatus() == null ? DRAFT : paperDto.getStatus());
|
paper.setStatus(paperDto.getStatus() == null ? DRAFT : paperDto.getStatus());
|
||||||
paper.setTitle(paperDto.getTitle());
|
paper.setTitle(paperDto.getTitle());
|
||||||
paper.setUpdateDate(new Date());
|
paper.setUpdateDate(new Date());
|
||||||
paper.setDeadlineDate(paperDto.getDeadlineDate());
|
paper.setDeadlines(deadlineService.saveOrCreate(paperDto.getDeadlines()));
|
||||||
if (paperDto.getTmpFileName() != null) {
|
if (paperDto.getTmpFileName() != null) {
|
||||||
paper.setFileData(fileService.createFileFromTmp(paperDto.getTmpFileName()));
|
paper.setFileData(fileService.createFileFromTmp(paperDto.getTmpFileName()));
|
||||||
}
|
}
|
||||||
@ -115,7 +119,7 @@ public class PaperService {
|
|||||||
Paper paper = new Paper();
|
Paper paper = new Paper();
|
||||||
paper.setTitle(title);
|
paper.setTitle(title);
|
||||||
paper.getAuthors().add(user);
|
paper.getAuthors().add(user);
|
||||||
paper.setDeadlineDate(deadlineDate);
|
paper.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн"));
|
||||||
paper.setCreateDate(new Date());
|
paper.setCreateDate(new Date());
|
||||||
paper.setUpdateDate(new Date());
|
paper.setUpdateDate(new Date());
|
||||||
paper.setStatus(DRAFT);
|
paper.setStatus(DRAFT);
|
||||||
@ -133,11 +137,11 @@ public class PaperService {
|
|||||||
public void closeFailedPapers() {
|
public void closeFailedPapers() {
|
||||||
List<Paper> papers = paperRepository.findAll()
|
List<Paper> papers = paperRepository.findAll()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(paper -> paper.getDeadlineDate() != null
|
.filter(paper -> paper.getNextDeadline().isPresent()
|
||||||
&& (paper.getStatus() == ON_PREPARATION
|
&& (paper.getStatus() == ON_PREPARATION
|
||||||
|| paper.getStatus() == DRAFT
|
|| paper.getStatus() == DRAFT
|
||||||
|| paper.getStatus() == ATTENTION)
|
|| paper.getStatus() == ATTENTION)
|
||||||
&& paper.getDeadlineDate().before(new Date()))
|
&& paper.getNextDeadline().get().getDate().before(new Date()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
papers.forEach(paper -> {
|
papers.forEach(paper -> {
|
||||||
Paper.PaperStatus oldStatus = paper.getStatus();
|
Paper.PaperStatus oldStatus = paper.getStatus();
|
||||||
|
39
src/main/java/ru/ulstu/project/model/Project.java
Normal file
39
src/main/java/ru/ulstu/project/model/Project.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package ru.ulstu.project.model;
|
||||||
|
|
||||||
|
import org.hibernate.validator.constraints.NotBlank;
|
||||||
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
|
||||||
|
import javax.persistence.CascadeType;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.OneToMany;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Project extends BaseEntity {
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@OneToMany(cascade = CascadeType.ALL)
|
||||||
|
@JoinColumn(name = "project_id")
|
||||||
|
private List<Deadline> deadlines = new ArrayList<>();
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Deadline> getDeadlines() {
|
||||||
|
return deadlines;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeadlines(List<Deadline> deadlines) {
|
||||||
|
this.deadlines = deadlines;
|
||||||
|
}
|
||||||
|
}
|
@ -1,27 +1,35 @@
|
|||||||
package ru.ulstu.grant.model;
|
package ru.ulstu.project.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import org.hibernate.validator.constraints.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
|
import ru.ulstu.deadline.model.DeadlineDto;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import java.util.List;
|
||||||
import java.util.Date;
|
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
public class ProjectDto {
|
public class ProjectDto {
|
||||||
private final Integer id;
|
private final Integer id;
|
||||||
|
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
private final String title;
|
private final String title;
|
||||||
|
|
||||||
|
private final List<DeadlineDto> deadlines;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public ProjectDto(@JsonProperty("id") Integer id,
|
public ProjectDto(@JsonProperty("id") Integer id,
|
||||||
@JsonProperty("title") String title){
|
@JsonProperty("title") String title,
|
||||||
|
@JsonProperty("deadlines") List<DeadlineDto> deadlines) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
|
this.deadlines = deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProjectDto(Project project) {
|
public ProjectDto(Project project) {
|
||||||
this.id = project.getId();
|
this.id = project.getId();
|
||||||
this.title = project.getTitle();
|
this.title = project.getTitle();
|
||||||
|
this.deadlines = convert(project.getDeadlines(), DeadlineDto::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
@ -3,6 +3,18 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||||
<changeSet author="tanya" id="20181208_000000-1">
|
<changeSet author="tanya" id="20181208_000000-1">
|
||||||
|
<createTable tableName="project">
|
||||||
|
<column name="id" type="integer">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="title" type="varchar(255)"/>
|
||||||
|
<column name="version" type="integer"/>
|
||||||
|
</createTable>
|
||||||
|
<addPrimaryKey columnNames="id" constraintName="pk_project" tableName="project"/>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
|
|
||||||
|
<changeSet author="tanya" id="20181208_000000-2">
|
||||||
<createTable tableName="grant">
|
<createTable tableName="grant">
|
||||||
<column name="id" type="integer">
|
<column name="id" type="integer">
|
||||||
<constraints nullable="false"/>
|
<constraints nullable="false"/>
|
||||||
@ -12,34 +24,42 @@
|
|||||||
<column name="deadline_date" type="timestamp"/>
|
<column name="deadline_date" type="timestamp"/>
|
||||||
<column name="comment" type="varchar(255)"/>
|
<column name="comment" type="varchar(255)"/>
|
||||||
<column name="project_id" type="integer"/>
|
<column name="project_id" type="integer"/>
|
||||||
|
<column name="file_id" type="integer"/>
|
||||||
<column name="applicationFileName" type="varchar(255)">
|
<column name="applicationFileName" type="varchar(255)">
|
||||||
<constraints nullable="true"/>
|
<constraints nullable="true"/>
|
||||||
</column>
|
</column>
|
||||||
|
<column name="version" type="integer"/>
|
||||||
</createTable>
|
</createTable>
|
||||||
<addPrimaryKey columnNames="id" constraintName="pk_grant" tableName="grant"/>
|
<addPrimaryKey columnNames="id" constraintName="pk_grant" tableName="grant"/>
|
||||||
<addForeignKeyConstraint baseTableName="grant" baseColumnNames="project_id"
|
<addForeignKeyConstraint baseTableName="grant" baseColumnNames="project_id"
|
||||||
constraintName="fk_project_project_id" referencedTableName="project"
|
constraintName="fk_grant_project_id" referencedTableName="project"
|
||||||
|
referencedColumnNames="id"/>
|
||||||
|
<addForeignKeyConstraint baseTableName="grant" baseColumnNames="file_id"
|
||||||
|
constraintName="fk_grant_file_id" referencedTableName="file"
|
||||||
referencedColumnNames="id"/>
|
referencedColumnNames="id"/>
|
||||||
</changeSet>
|
</changeSet>
|
||||||
<changeSet author="tanya" id="20181208_000000-2">
|
|
||||||
<createTable tableName="project">
|
<changeSet author="orion" id="20181211_000000-3">
|
||||||
<column name="id" type="integer">
|
|
||||||
<constraints nullable="false"/>
|
|
||||||
</column>
|
|
||||||
<column name="title" type="varchar(255)"/>
|
|
||||||
</createTable>
|
|
||||||
<addPrimaryKey columnNames="id" constraintName="pk_project" tableName="project"/>
|
|
||||||
</changeSet>
|
|
||||||
<changeSet author="tanya" id="20181208_000000-3">
|
|
||||||
<createTable tableName="deadline">
|
<createTable tableName="deadline">
|
||||||
<column name="id" type="integer">
|
<column name="id" type="integer">
|
||||||
<constraints nullable="false"/>
|
<constraints nullable="false"/>
|
||||||
</column>
|
</column>
|
||||||
|
<column name="date" type="timestamp"/>
|
||||||
|
<column name="description" type="varchar(255)"/>
|
||||||
|
<column name="project_id" type="integer"/>
|
||||||
<column name="grant_id" type="integer"/>
|
<column name="grant_id" type="integer"/>
|
||||||
|
<column name="paper_id" type="integer"/>
|
||||||
|
<column name="version" type="integer"/>
|
||||||
</createTable>
|
</createTable>
|
||||||
<addPrimaryKey columnNames="id" constraintName="pk_deadline" tableName="deadline"/>
|
<addPrimaryKey columnNames="id" constraintName="pk_deadline" tableName="deadline"/>
|
||||||
|
<addForeignKeyConstraint baseTableName="deadline" baseColumnNames="project_id"
|
||||||
|
constraintName="fk_deadline_project_id" referencedTableName="project"
|
||||||
|
referencedColumnNames="id"/>
|
||||||
<addForeignKeyConstraint baseTableName="deadline" baseColumnNames="grant_id"
|
<addForeignKeyConstraint baseTableName="deadline" baseColumnNames="grant_id"
|
||||||
constraintName="fk_grant_grant_id" referencedTableName="grant"
|
constraintName="fk_deadline_grant_id" referencedTableName="grant"
|
||||||
|
referencedColumnNames="id"/>
|
||||||
|
<addForeignKeyConstraint baseTableName="deadline" baseColumnNames="paper_id"
|
||||||
|
constraintName="fk_deadline_paper_id" referencedTableName="paper"
|
||||||
referencedColumnNames="id"/>
|
referencedColumnNames="id"/>
|
||||||
</changeSet>
|
</changeSet>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
|
@ -16,4 +16,5 @@
|
|||||||
<include file="db/changelog-20181031_000000-schema.xml"/>
|
<include file="db/changelog-20181031_000000-schema.xml"/>
|
||||||
<include file="db/changelog-20181108_000000-data.xml"/>
|
<include file="db/changelog-20181108_000000-data.xml"/>
|
||||||
<include file="db/changelog-20181111_000000-schema.xml"/>
|
<include file="db/changelog-20181111_000000-schema.xml"/>
|
||||||
|
<include file="db/changelog-20181208_000000-schema.xml"/>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
@ -13,7 +13,7 @@
|
|||||||
Вам нужно поработать над статьей "<a th:href="@{|${baseUrl}/papers/paper?id=${paper.id}|}"><span th:text="${paper.title}">Title</span></a>".
|
Вам нужно поработать над статьей "<a th:href="@{|${baseUrl}/papers/paper?id=${paper.id}|}"><span th:text="${paper.title}">Title</span></a>".
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Срок исполнения: <span th:text="${#dates.format(paper.deadlineDate, 'dd.MM.yyyy HH:mm')}"></span>.
|
Срок исполнения: <span th:text="${#dates.format(paper.nextDeadline.get().date, 'dd.MM.yyyy HH:mm')}"></span>.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Regards,
|
Regards,
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
Приближается срок сдачи статьи "<span th:text="${paper.title}">Title</span>".
|
Приближается срок сдачи статьи "<span th:text="${paper.title}">Title</span>".
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Срок исполнения: <span th:text="${#dates.format(paper.deadlineDate, 'dd.MM.yyyy HH:mm')}"></span>.
|
Срок исполнения: <span th:text="${#dates.format(paper.nextDeadline.get().date, 'dd.MM.yyyy HH:mm')}"></span>.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Regards,
|
Regards,
|
||||||
|
Loading…
Reference in New Issue
Block a user