2018-12-08 23:53:38 +04:00
|
|
|
package ru.ulstu.grant.model;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
2019-04-04 09:38:18 +04:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2018-12-08 23:53:38 +04:00
|
|
|
import org.hibernate.validator.constraints.NotEmpty;
|
2019-03-18 14:27:54 +04:00
|
|
|
import ru.ulstu.deadline.model.Deadline;
|
2019-04-19 17:49:36 +04:00
|
|
|
import ru.ulstu.paper.model.PaperDto;
|
2018-12-11 15:08:35 +04:00
|
|
|
import ru.ulstu.project.model.ProjectDto;
|
2019-04-04 09:38:18 +04:00
|
|
|
import ru.ulstu.user.model.UserDto;
|
2018-12-08 23:53:38 +04:00
|
|
|
|
2018-12-24 15:20:57 +04:00
|
|
|
import java.util.ArrayList;
|
2018-12-11 15:08:35 +04:00
|
|
|
import java.util.List;
|
2019-04-04 09:38:18 +04:00
|
|
|
import java.util.Set;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
2018-12-08 23:53:38 +04:00
|
|
|
|
|
|
|
public class GrantDto {
|
2019-04-04 09:38:18 +04:00
|
|
|
private final static int MAX_AUTHORS_LENGTH = 60;
|
|
|
|
|
2018-12-22 03:31:43 +04:00
|
|
|
private Integer id;
|
2018-12-08 23:53:38 +04:00
|
|
|
@NotEmpty
|
2018-12-22 03:31:43 +04:00
|
|
|
private String title;
|
|
|
|
private Grant.GrantStatus status;
|
2019-03-18 14:27:54 +04:00
|
|
|
private List<Deadline> deadlines = new ArrayList<>();
|
2018-12-22 03:31:43 +04:00
|
|
|
private String comment;
|
|
|
|
private String applicationFileName;
|
|
|
|
private ProjectDto project;
|
2019-04-04 09:38:18 +04:00
|
|
|
private Set<Integer> authorIds;
|
|
|
|
private Set<UserDto> authors;
|
|
|
|
private Integer leaderId;
|
2019-04-13 23:56:24 +04:00
|
|
|
private boolean wasLeader;
|
2019-04-18 13:09:50 +04:00
|
|
|
private boolean hasAge;
|
|
|
|
private boolean hasDegree;
|
2019-04-19 17:49:36 +04:00
|
|
|
private List<Integer> paperIds = new ArrayList<>();
|
|
|
|
private List<PaperDto> papers = new ArrayList<>();
|
2018-12-08 23:53:38 +04:00
|
|
|
|
2018-12-23 02:22:24 +04:00
|
|
|
public GrantDto() {
|
2019-03-18 14:27:54 +04:00
|
|
|
deadlines.add(new Deadline());
|
2018-12-23 02:22:24 +04:00
|
|
|
}
|
|
|
|
|
2018-12-08 23:53:38 +04:00
|
|
|
@JsonCreator
|
|
|
|
public GrantDto(@JsonProperty("id") Integer id,
|
|
|
|
@JsonProperty("title") String title,
|
|
|
|
@JsonProperty("status") Grant.GrantStatus status,
|
2019-03-18 14:27:54 +04:00
|
|
|
@JsonProperty("deadlines") List<Deadline> deadlines,
|
2018-12-08 23:53:38 +04:00
|
|
|
@JsonProperty("comment") String comment,
|
2019-04-04 09:38:18 +04:00
|
|
|
@JsonProperty("project") ProjectDto project,
|
|
|
|
@JsonProperty("authorIds") Set<Integer> authorIds,
|
|
|
|
@JsonProperty("authors") Set<UserDto> authors,
|
2019-04-13 12:39:53 +04:00
|
|
|
@JsonProperty("leader") Integer leaderId,
|
2019-04-13 23:56:24 +04:00
|
|
|
@JsonProperty("wasLeader") boolean wasLeader,
|
2019-04-18 13:09:50 +04:00
|
|
|
@JsonProperty("hasAge") boolean hasAge,
|
2019-04-19 17:49:36 +04:00
|
|
|
@JsonProperty("hasDegree") boolean hasDegree,
|
|
|
|
@JsonProperty("paperIds") List<Integer> paperIds,
|
|
|
|
@JsonProperty("papers") List<PaperDto> papers) {
|
2018-12-08 23:53:38 +04:00
|
|
|
this.id = id;
|
|
|
|
this.title = title;
|
|
|
|
this.status = status;
|
2018-12-11 15:08:35 +04:00
|
|
|
this.deadlines = deadlines;
|
2018-12-08 23:53:38 +04:00
|
|
|
this.comment = comment;
|
|
|
|
this.applicationFileName = null;
|
2018-12-11 15:08:35 +04:00
|
|
|
this.project = project;
|
2019-04-04 09:38:18 +04:00
|
|
|
this.authors = authors;
|
|
|
|
this.leaderId = leaderId;
|
2019-04-13 23:56:24 +04:00
|
|
|
this.wasLeader = wasLeader;
|
2019-04-18 13:09:50 +04:00
|
|
|
this.hasAge = hasAge;
|
|
|
|
this.hasDegree = hasDegree;
|
2019-04-19 17:49:36 +04:00
|
|
|
this.paperIds = paperIds;
|
|
|
|
this.papers = papers;
|
2018-12-08 23:53:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public GrantDto(Grant grant) {
|
|
|
|
this.id = grant.getId();
|
|
|
|
this.title = grant.getTitle();
|
|
|
|
this.status = grant.getStatus();
|
2019-03-18 14:27:54 +04:00
|
|
|
this.deadlines = grant.getDeadlines();
|
2018-12-08 23:53:38 +04:00
|
|
|
this.comment = grant.getComment();
|
2018-12-11 15:08:35 +04:00
|
|
|
this.project = grant.getProject() == null ? null : new ProjectDto(grant.getProject());
|
2018-12-08 23:53:38 +04:00
|
|
|
this.applicationFileName = grant.getApplication() == null ? null : grant.getApplication().getName();
|
2019-04-04 09:38:18 +04:00
|
|
|
this.authorIds = convert(grant.getAuthors(), user -> user.getId());
|
|
|
|
this.authors = convert(grant.getAuthors(), UserDto::new);
|
|
|
|
this.leaderId = grant.getLeader().getId();
|
2019-04-13 23:56:24 +04:00
|
|
|
this.wasLeader = false;
|
2019-04-18 13:09:50 +04:00
|
|
|
this.hasAge = false;
|
|
|
|
this.hasDegree = false;
|
2019-04-19 17:49:36 +04:00
|
|
|
this.paperIds = convert(grant.getPapers(), paper -> paper.getId());
|
|
|
|
this.papers = convert(grant.getPapers(), PaperDto::new);
|
2018-12-08 23:53:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public Integer getId() {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2019-03-04 10:24:30 +04:00
|
|
|
public void setId(Integer id) {
|
|
|
|
this.id = id;
|
|
|
|
}
|
2018-12-22 03:31:43 +04:00
|
|
|
|
2018-12-08 23:53:38 +04:00
|
|
|
public String getTitle() {
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
2019-03-04 10:24:30 +04:00
|
|
|
public void setTitle(String title) {
|
|
|
|
this.title = title;
|
|
|
|
}
|
2018-12-22 03:31:43 +04:00
|
|
|
|
2018-12-08 23:53:38 +04:00
|
|
|
public Grant.GrantStatus getStatus() {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2018-12-22 03:31:43 +04:00
|
|
|
public void setStatus(Grant.GrantStatus status) {
|
|
|
|
this.status = status;
|
|
|
|
}
|
|
|
|
|
2019-03-18 14:27:54 +04:00
|
|
|
public List<Deadline> getDeadlines() {
|
2018-12-11 15:08:35 +04:00
|
|
|
return deadlines;
|
2018-12-08 23:53:38 +04:00
|
|
|
}
|
|
|
|
|
2019-03-18 14:27:54 +04:00
|
|
|
public void setDeadlines(List<Deadline> deadlines) {
|
2018-12-22 03:31:43 +04:00
|
|
|
this.deadlines = deadlines;
|
|
|
|
}
|
|
|
|
|
2018-12-08 23:53:38 +04:00
|
|
|
public String getComment() {
|
|
|
|
return comment;
|
|
|
|
}
|
|
|
|
|
2019-03-04 10:24:30 +04:00
|
|
|
public void setComment(String comment) {
|
|
|
|
this.comment = comment;
|
|
|
|
}
|
2018-12-22 03:31:43 +04:00
|
|
|
|
2018-12-11 15:08:35 +04:00
|
|
|
public ProjectDto getProject() {
|
|
|
|
return project;
|
2018-12-08 23:53:38 +04:00
|
|
|
}
|
|
|
|
|
2019-03-04 10:24:30 +04:00
|
|
|
public void setProject(ProjectDto project) {
|
|
|
|
this.project = project;
|
|
|
|
}
|
2018-12-22 03:31:43 +04:00
|
|
|
|
2018-12-08 23:53:38 +04:00
|
|
|
public String getApplicationFileName() {
|
|
|
|
return applicationFileName;
|
|
|
|
}
|
2018-12-22 03:31:43 +04:00
|
|
|
|
|
|
|
public void setApplicationFileName(String applicationFileName) {
|
2019-03-04 10:24:30 +04:00
|
|
|
this.applicationFileName = applicationFileName;
|
|
|
|
}
|
2019-04-04 09:38:18 +04:00
|
|
|
|
|
|
|
public Set<Integer> getAuthorIds() {
|
|
|
|
return authorIds;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setAuthorIds(Set<Integer> authorIds) {
|
|
|
|
this.authorIds = authorIds;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Set<UserDto> getAuthors() {
|
|
|
|
return authors;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setAuthors(Set<UserDto> authors) {
|
|
|
|
this.authors = authors;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getAuthorsString() {
|
|
|
|
return StringUtils.abbreviate(authors
|
|
|
|
.stream()
|
|
|
|
.map(author -> author.getLastName())
|
|
|
|
.collect(Collectors.joining(", ")), MAX_AUTHORS_LENGTH);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Integer getLeaderId() {
|
|
|
|
return leaderId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLeaderId(Integer leaderId) {
|
|
|
|
this.leaderId = leaderId;
|
|
|
|
}
|
2019-04-13 12:39:53 +04:00
|
|
|
|
2019-04-13 23:56:24 +04:00
|
|
|
public boolean isWasLeader() {
|
|
|
|
return wasLeader;
|
2019-04-13 12:39:53 +04:00
|
|
|
}
|
|
|
|
|
2019-04-13 23:56:24 +04:00
|
|
|
public void setWasLeader(boolean wasLeader) {
|
|
|
|
this.wasLeader = wasLeader;
|
2019-04-13 12:39:53 +04:00
|
|
|
}
|
|
|
|
|
2019-04-18 13:09:50 +04:00
|
|
|
public boolean isHasAge() {
|
|
|
|
return hasAge;
|
2019-04-13 12:39:53 +04:00
|
|
|
}
|
|
|
|
|
2019-04-18 13:09:50 +04:00
|
|
|
public void setHasAge(boolean hasAge) {
|
|
|
|
this.hasAge = hasAge;
|
2019-04-13 12:39:53 +04:00
|
|
|
}
|
|
|
|
|
2019-04-18 13:09:50 +04:00
|
|
|
public boolean isHasDegree() {
|
|
|
|
return hasDegree;
|
2019-04-13 12:39:53 +04:00
|
|
|
}
|
|
|
|
|
2019-04-18 13:09:50 +04:00
|
|
|
public void setHasDegree(boolean hasDegree) {
|
|
|
|
this.hasDegree = hasDegree;
|
2019-04-13 12:39:53 +04:00
|
|
|
}
|
2019-04-19 17:49:36 +04:00
|
|
|
|
|
|
|
public List<Integer> getPaperIds() {
|
|
|
|
return paperIds;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPaperIds(List<Integer> paperIds) {
|
|
|
|
this.paperIds = paperIds;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<PaperDto> getPapers() {
|
|
|
|
return papers;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPapers(List<PaperDto> papers) {
|
|
|
|
this.papers = papers;
|
|
|
|
}
|
2018-12-08 23:53:38 +04:00
|
|
|
}
|