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;
|
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 12:39:53 +04:00
|
|
|
private boolean leader;
|
|
|
|
private boolean birthDate;
|
|
|
|
private boolean degree;
|
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,
|
|
|
|
@JsonProperty("leader") boolean leader,
|
|
|
|
@JsonProperty("birthDate") boolean birthDate,
|
|
|
|
@JsonProperty("degree") boolean degree) {
|
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 12:39:53 +04:00
|
|
|
this.leader = leader;
|
|
|
|
this.birthDate = birthDate;
|
|
|
|
this.degree = degree;
|
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 12:39:53 +04:00
|
|
|
this.leader = false;
|
|
|
|
this.birthDate = false;
|
|
|
|
this.degree = false;
|
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
|
|
|
|
|
|
|
public boolean isLeader() {
|
|
|
|
return leader;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLeader(boolean leader) {
|
|
|
|
this.leader = leader;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isBirthDate() {
|
|
|
|
return birthDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setBirthDate(boolean birthDate) {
|
|
|
|
this.birthDate = birthDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isDegree() {
|
|
|
|
return degree;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDegree(boolean degree) {
|
|
|
|
this.degree = degree;
|
|
|
|
}
|
2018-12-08 23:53:38 +04:00
|
|
|
}
|