#38 add variable "files"
This commit is contained in:
parent
a352f561fa
commit
2ebd61016d
@ -1,5 +1,7 @@
|
|||||||
package ru.ulstu.grant.model;
|
package ru.ulstu.grant.model;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.Fetch;
|
||||||
|
import org.hibernate.annotations.FetchMode;
|
||||||
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;
|
||||||
@ -66,10 +68,11 @@ public class Grant extends BaseEntity implements UserContainer {
|
|||||||
|
|
||||||
private String comment;
|
private String comment;
|
||||||
|
|
||||||
//Заявка на грант
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
@ManyToOne
|
@JoinColumn(name = "grant_id", unique = true)
|
||||||
@JoinColumn(name = "file_id")
|
@Fetch(FetchMode.SUBSELECT)
|
||||||
private FileData application;
|
private List<FileData> files = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
@ManyToOne(cascade = CascadeType.ALL)
|
@ManyToOne(cascade = CascadeType.ALL)
|
||||||
@JoinColumn(name = "project_id")
|
@JoinColumn(name = "project_id")
|
||||||
@ -113,12 +116,12 @@ public class Grant extends BaseEntity implements UserContainer {
|
|||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileData getApplication() {
|
public List<FileData> getFiles() {
|
||||||
return application;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setApplication(FileData application) {
|
public void setFiles(List<FileData> files) {
|
||||||
this.application = application;
|
this.files = files;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
|
@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.hibernate.validator.constraints.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.file.model.FileDataDto;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
import ru.ulstu.project.model.ProjectDto;
|
import ru.ulstu.project.model.ProjectDto;
|
||||||
import ru.ulstu.user.model.UserDto;
|
import ru.ulstu.user.model.UserDto;
|
||||||
@ -25,7 +26,7 @@ public class GrantDto {
|
|||||||
private Grant.GrantStatus status;
|
private Grant.GrantStatus status;
|
||||||
private List<Deadline> deadlines = new ArrayList<>();
|
private List<Deadline> deadlines = new ArrayList<>();
|
||||||
private String comment;
|
private String comment;
|
||||||
private String applicationFileName;
|
private List<FileDataDto> files = new ArrayList<>();
|
||||||
private ProjectDto project;
|
private ProjectDto project;
|
||||||
private Set<Integer> authorIds;
|
private Set<Integer> authorIds;
|
||||||
private Set<UserDto> authors;
|
private Set<UserDto> authors;
|
||||||
@ -47,6 +48,7 @@ public class GrantDto {
|
|||||||
@JsonProperty("status") Grant.GrantStatus status,
|
@JsonProperty("status") Grant.GrantStatus status,
|
||||||
@JsonProperty("deadlines") List<Deadline> deadlines,
|
@JsonProperty("deadlines") List<Deadline> deadlines,
|
||||||
@JsonProperty("comment") String comment,
|
@JsonProperty("comment") String comment,
|
||||||
|
@JsonProperty("files") List<FileDataDto> files,
|
||||||
@JsonProperty("project") ProjectDto project,
|
@JsonProperty("project") ProjectDto project,
|
||||||
@JsonProperty("authorIds") Set<Integer> authorIds,
|
@JsonProperty("authorIds") Set<Integer> authorIds,
|
||||||
@JsonProperty("authors") Set<UserDto> authors,
|
@JsonProperty("authors") Set<UserDto> authors,
|
||||||
@ -61,8 +63,9 @@ public class GrantDto {
|
|||||||
this.status = status;
|
this.status = status;
|
||||||
this.deadlines = deadlines;
|
this.deadlines = deadlines;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
this.applicationFileName = null;
|
this.files = files;
|
||||||
this.project = project;
|
this.project = project;
|
||||||
|
this.authorIds = authorIds;
|
||||||
this.authors = authors;
|
this.authors = authors;
|
||||||
this.leaderId = leaderId;
|
this.leaderId = leaderId;
|
||||||
this.wasLeader = wasLeader;
|
this.wasLeader = wasLeader;
|
||||||
@ -78,8 +81,8 @@ public class GrantDto {
|
|||||||
this.status = grant.getStatus();
|
this.status = grant.getStatus();
|
||||||
this.deadlines = grant.getDeadlines();
|
this.deadlines = grant.getDeadlines();
|
||||||
this.comment = grant.getComment();
|
this.comment = grant.getComment();
|
||||||
|
this.files = convert(grant.getFiles(), FileDataDto::new);
|
||||||
this.project = grant.getProject() == null ? null : new ProjectDto(grant.getProject());
|
this.project = grant.getProject() == null ? null : new ProjectDto(grant.getProject());
|
||||||
this.applicationFileName = grant.getApplication() == null ? null : grant.getApplication().getName();
|
|
||||||
this.authorIds = convert(grant.getAuthors(), user -> user.getId());
|
this.authorIds = convert(grant.getAuthors(), user -> user.getId());
|
||||||
this.authors = convert(grant.getAuthors(), UserDto::new);
|
this.authors = convert(grant.getAuthors(), UserDto::new);
|
||||||
this.leaderId = grant.getLeader().getId();
|
this.leaderId = grant.getLeader().getId();
|
||||||
@ -130,6 +133,14 @@ public class GrantDto {
|
|||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<FileDataDto> getFiles() {
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFiles(List<FileDataDto> files) {
|
||||||
|
this.files = files;
|
||||||
|
}
|
||||||
|
|
||||||
public ProjectDto getProject() {
|
public ProjectDto getProject() {
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
@ -138,14 +149,6 @@ public class GrantDto {
|
|||||||
this.project = project;
|
this.project = project;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getApplicationFileName() {
|
|
||||||
return applicationFileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setApplicationFileName(String applicationFileName) {
|
|
||||||
this.applicationFileName = applicationFileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<Integer> getAuthorIds() {
|
public Set<Integer> getAuthorIds() {
|
||||||
return authorIds;
|
return authorIds;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ 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.model.Deadline;
|
||||||
import ru.ulstu.deadline.service.DeadlineService;
|
import ru.ulstu.deadline.service.DeadlineService;
|
||||||
|
import ru.ulstu.file.model.FileDataDto;
|
||||||
import ru.ulstu.file.service.FileService;
|
import ru.ulstu.file.service.FileService;
|
||||||
import ru.ulstu.grant.model.Grant;
|
import ru.ulstu.grant.model.Grant;
|
||||||
import ru.ulstu.grant.model.GrantDto;
|
import ru.ulstu.grant.model.GrantDto;
|
||||||
@ -21,8 +22,8 @@ import java.io.IOException;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
import static ru.ulstu.grant.model.Grant.GrantStatus.APPLICATION;
|
import static ru.ulstu.grant.model.Grant.GrantStatus.APPLICATION;
|
||||||
@ -81,9 +82,10 @@ public class GrantService {
|
|||||||
grant.setProject(projectService.findById(grantDto.getProject().getId()));
|
grant.setProject(projectService.findById(grantDto.getProject().getId()));
|
||||||
}
|
}
|
||||||
grant.setDeadlines(deadlineService.saveOrCreate(grantDto.getDeadlines()));
|
grant.setDeadlines(deadlineService.saveOrCreate(grantDto.getDeadlines()));
|
||||||
if (grantDto.getApplicationFileName() != null) {
|
|
||||||
grant.setApplication(fileService.createFileFromTmp(grantDto.getApplicationFileName()));
|
grant.setFiles(fileService.saveOrCreate(grantDto.getFiles().stream()
|
||||||
}
|
.filter(f -> !f.isDeleted())
|
||||||
|
.collect(toList())));
|
||||||
grant.getAuthors().clear();
|
grant.getAuthors().clear();
|
||||||
if (grantDto.getAuthorIds() != null && !grantDto.getAuthorIds().isEmpty()) {
|
if (grantDto.getAuthorIds() != null && !grantDto.getAuthorIds().isEmpty()) {
|
||||||
grantDto.getAuthorIds().forEach(authorIds -> grant.getAuthors().add(userService.findById(authorIds)));
|
grantDto.getAuthorIds().forEach(authorIds -> grant.getAuthors().add(userService.findById(authorIds)));
|
||||||
@ -106,8 +108,11 @@ public class GrantService {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public Integer update(GrantDto grantDto) throws IOException {
|
public Integer update(GrantDto grantDto) throws IOException {
|
||||||
Grant grant = grantRepository.findOne(grantDto.getId());
|
Grant grant = grantRepository.findOne(grantDto.getId());
|
||||||
if (grantDto.getApplicationFileName() != null && grant.getApplication() != null) {
|
|
||||||
fileService.deleteFile(grant.getApplication());
|
for (FileDataDto file : grantDto.getFiles().stream()
|
||||||
|
.filter(f -> f.isDeleted() && f.getId() != null)
|
||||||
|
.collect(toList())) {
|
||||||
|
fileService.delete(file.getId());
|
||||||
}
|
}
|
||||||
grantDto.getRemovedDeadlineIds().forEach(deadlineService::remove);
|
grantDto.getRemovedDeadlineIds().forEach(deadlineService::remove);
|
||||||
grantRepository.save(copyFromDto(grant, grantDto));
|
grantRepository.save(copyFromDto(grant, grantDto));
|
||||||
@ -117,9 +122,6 @@ public class GrantService {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public void delete(Integer grantId) throws IOException {
|
public void delete(Integer grantId) throws IOException {
|
||||||
Grant grant = grantRepository.findOne(grantId);
|
Grant grant = grantRepository.findOne(grantId);
|
||||||
if (grant.getApplication() != null) {
|
|
||||||
fileService.deleteFile(grant.getApplication());
|
|
||||||
}
|
|
||||||
grantRepository.delete(grant);
|
grantRepository.delete(grant);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +158,7 @@ public class GrantService {
|
|||||||
filteredUsers = filteredUsers
|
filteredUsers = filteredUsers
|
||||||
.stream()
|
.stream()
|
||||||
.filter(getCompletedGrantLeaders()::contains)
|
.filter(getCompletedGrantLeaders()::contains)
|
||||||
.collect(Collectors.toList());
|
.collect(toList());
|
||||||
}
|
}
|
||||||
return filteredUsers;
|
return filteredUsers;
|
||||||
}
|
}
|
||||||
@ -165,12 +167,11 @@ public class GrantService {
|
|||||||
return grantRepository.findByStatus(Grant.GrantStatus.COMPLETED)
|
return grantRepository.findByStatus(Grant.GrantStatus.COMPLETED)
|
||||||
.stream()
|
.stream()
|
||||||
.map(Grant::getLeader)
|
.map(Grant::getLeader)
|
||||||
.collect(Collectors.toList());
|
.collect(toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Paper> getGrantPapers(List<Integer> paperIds) {
|
public List<Paper> getGrantPapers(List<Integer> paperIds) {
|
||||||
return paperService.findAllSelect(paperIds);
|
return paperService.findAllSelect(paperIds);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Paper> getAllPapers() {
|
public List<Paper> getAllPapers() {
|
||||||
@ -192,5 +193,4 @@ public class GrantService {
|
|||||||
}
|
}
|
||||||
grantDto.getDeadlines().remove((int) deadlineId);
|
grantDto.getDeadlines().remove((int) deadlineId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user