ng-tracker/src/main/java/ru/ulstu/grant/model/GrantDto.java

194 lines
5.2 KiB
Java
Raw Normal View History

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;
import org.hibernate.validator.constraints.NotEmpty;
2019-03-18 14:27:54 +04:00
import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.project.model.ProjectDto;
2019-04-04 09:38:18 +04:00
import ru.ulstu.user.model.UserDto;
2018-12-24 15:20:57 +04:00
import java.util.ArrayList;
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;
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;
@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;
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
}
@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,
@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,
@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,
@JsonProperty("hasDegree") boolean hasDegree) {
this.id = id;
this.title = title;
this.status = status;
this.deadlines = deadlines;
this.comment = comment;
this.applicationFileName = null;
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;
}
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();
this.comment = grant.getComment();
this.project = grant.getProject() == null ? null : new ProjectDto(grant.getProject());
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;
}
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
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
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() {
return deadlines;
}
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;
}
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
public ProjectDto getProject() {
return project;
}
2019-03-04 10:24:30 +04:00
public void setProject(ProjectDto project) {
this.project = project;
}
2018-12-22 03:31:43 +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 23:56:24 +04:00
public boolean isWasLeader() {
return wasLeader;
}
2019-04-13 23:56:24 +04:00
public void setWasLeader(boolean wasLeader) {
this.wasLeader = wasLeader;
}
2019-04-18 13:09:50 +04:00
public boolean isHasAge() {
return hasAge;
}
2019-04-18 13:09:50 +04:00
public void setHasAge(boolean hasAge) {
this.hasAge = hasAge;
}
2019-04-18 13:09:50 +04:00
public boolean isHasDegree() {
return hasDegree;
}
2019-04-18 13:09:50 +04:00
public void setHasDegree(boolean hasDegree) {
this.hasDegree = hasDegree;
}
}