203 lines
5.7 KiB
Java
203 lines
5.7 KiB
Java
package ru.ulstu.project.model;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
import org.hibernate.validator.constraints.NotEmpty;
|
|
import org.thymeleaf.util.StringUtils;
|
|
import ru.ulstu.deadline.model.Deadline;
|
|
import ru.ulstu.file.model.FileDataDto;
|
|
import ru.ulstu.grant.model.GrantDto;
|
|
import ru.ulstu.name.NameContainer;
|
|
import ru.ulstu.user.model.User;
|
|
import ru.ulstu.user.model.UserDto;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
import java.util.stream.Collectors;
|
|
|
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
|
|
|
public class ProjectDto extends NameContainer {
|
|
private Integer id;
|
|
|
|
@NotEmpty
|
|
private String title;
|
|
private Project.ProjectStatus status;
|
|
private String description;
|
|
private List<Deadline> deadlines = new ArrayList<>();
|
|
private GrantDto grant;
|
|
private String repository;
|
|
private List<FileDataDto> files = new ArrayList<>();
|
|
private List<Integer> removedDeadlineIds = new ArrayList<>();
|
|
private Set<Integer> executorIds;
|
|
private List<UserDto> executors;
|
|
private List<Integer> grantIds;
|
|
private List<GrantDto> grants;
|
|
|
|
private final static int MAX_EXECUTORS_LENGTH = 40;
|
|
|
|
public ProjectDto() {
|
|
}
|
|
|
|
public ProjectDto(String title) {
|
|
this.title = title;
|
|
}
|
|
|
|
@JsonCreator
|
|
public ProjectDto(@JsonProperty("id") Integer id,
|
|
@JsonProperty("title") String title,
|
|
@JsonProperty("status") Project.ProjectStatus status,
|
|
@JsonProperty("description") String description,
|
|
@JsonProperty("grant") GrantDto grant,
|
|
@JsonProperty("repository") String repository,
|
|
@JsonProperty("files") List<FileDataDto> files,
|
|
@JsonProperty("deadlines") List<Deadline> deadlines,
|
|
@JsonProperty("executorIds") Set<Integer> executorIds,
|
|
@JsonProperty("executors") List<UserDto> executors,
|
|
@JsonProperty("grantIds") List<Integer> grantIds,
|
|
@JsonProperty("grants") List<GrantDto> grants) {
|
|
this.id = id;
|
|
this.title = title;
|
|
this.status = status;
|
|
this.description = description;
|
|
this.grant = grant;
|
|
this.repository = repository;
|
|
this.deadlines = deadlines;
|
|
this.files = files;
|
|
this.executorIds = executorIds;
|
|
this.executors = executors;
|
|
this.grantIds = grantIds;
|
|
this.grants = grants;
|
|
}
|
|
|
|
|
|
public ProjectDto(Project project) {
|
|
Set<User> users = new HashSet<User>(project.getExecutors());
|
|
this.id = project.getId();
|
|
this.title = project.getTitle();
|
|
this.status = project.getStatus();
|
|
this.description = project.getDescription();
|
|
this.files = convert(project.getFiles(), FileDataDto::new);
|
|
this.grant = project.getGrant() == null ? null : new GrantDto(project.getGrant());
|
|
this.repository = project.getRepository();
|
|
this.deadlines = project.getDeadlines();
|
|
this.executorIds = convert(users, user -> user.getId());
|
|
this.executors = convert(project.getExecutors(), UserDto::new);
|
|
this.grantIds = convert(project.getGrants(), grant -> grant.getId());
|
|
this.grants = convert(project.getGrants(), GrantDto::new);
|
|
}
|
|
|
|
public Integer getId() {
|
|
return id;
|
|
}
|
|
|
|
public void setId(Integer id) {
|
|
this.id = id;
|
|
}
|
|
|
|
public String getTitle() {
|
|
return title;
|
|
}
|
|
|
|
public void setTitle(String title) {
|
|
this.title = title;
|
|
}
|
|
|
|
public Project.ProjectStatus getStatus() {
|
|
return status;
|
|
}
|
|
|
|
public void setStatus(Project.ProjectStatus status) {
|
|
this.status = status;
|
|
}
|
|
|
|
public String getDescription() {
|
|
return description;
|
|
}
|
|
|
|
public void setDescription(String description) {
|
|
this.description = description;
|
|
}
|
|
|
|
public GrantDto getGrant() {
|
|
return grant;
|
|
}
|
|
|
|
public void setGrant(GrantDto grant) {
|
|
this.grant = grant;
|
|
}
|
|
|
|
public String getRepository() {
|
|
return repository;
|
|
}
|
|
|
|
public void setRepository(String repository) {
|
|
this.repository = repository;
|
|
}
|
|
|
|
public List<Deadline> getDeadlines() {
|
|
return deadlines;
|
|
}
|
|
|
|
public void setDeadlines(List<Deadline> deadlines) {
|
|
this.deadlines = deadlines;
|
|
}
|
|
|
|
public List<FileDataDto> getFiles() {
|
|
return files;
|
|
}
|
|
|
|
public void setFiles(List<FileDataDto> files) {
|
|
this.files = files;
|
|
}
|
|
|
|
public List<Integer> getRemovedDeadlineIds() {
|
|
return removedDeadlineIds;
|
|
}
|
|
|
|
public void setRemovedDeadlineIds(List<Integer> removedDeadlineIds) {
|
|
this.removedDeadlineIds = removedDeadlineIds;
|
|
}
|
|
|
|
public Set<Integer> getExecutorIds() {
|
|
return executorIds;
|
|
}
|
|
|
|
public void setExecutorIds(Set<Integer> executorIds) {
|
|
this.executorIds = executorIds;
|
|
}
|
|
|
|
public List<UserDto> getExecutors() {
|
|
return executors;
|
|
}
|
|
|
|
public void setExecutors(List<UserDto> executors) {
|
|
this.executors = executors;
|
|
}
|
|
|
|
public String getExecutorsString() {
|
|
return StringUtils.abbreviate(executors
|
|
.stream()
|
|
.map(executor -> executor.getLastName())
|
|
.collect(Collectors.joining(", ")), MAX_EXECUTORS_LENGTH);
|
|
}
|
|
|
|
public List<Integer> getGrantIds() {
|
|
return grantIds;
|
|
}
|
|
|
|
public void setGrantIds(List<Integer> grantIds) {
|
|
this.grantIds = grantIds;
|
|
}
|
|
|
|
public List<GrantDto> getGrants() {
|
|
return grants;
|
|
}
|
|
|
|
public void setGrants(List<GrantDto> grants) {
|
|
this.grants = grants;
|
|
}
|
|
}
|