From 51e121ae249325615a3f378fe61595f9c25edcb6 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Fri, 26 Apr 2019 00:29:20 +0400 Subject: [PATCH 01/10] #117 add BAK papers filter --- .../java/ru/ulstu/grant/model/GrantDto.java | 18 +++++++++++ .../ru/ulstu/grant/service/GrantService.java | 32 +++++++++++++++++-- .../paper/repository/PaperRepository.java | 2 ++ .../ru/ulstu/paper/service/PaperService.java | 7 ++++ .../resources/templates/grants/grant.html | 9 ++++-- 5 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/model/GrantDto.java b/src/main/java/ru/ulstu/grant/model/GrantDto.java index 3fb77c5..b60aec0 100644 --- a/src/main/java/ru/ulstu/grant/model/GrantDto.java +++ b/src/main/java/ru/ulstu/grant/model/GrantDto.java @@ -33,6 +33,8 @@ public class GrantDto { private boolean wasLeader; private boolean hasAge; private boolean hasDegree; + private boolean hasBAKPapers; + private boolean hasScopusPapers; private List paperIds = new ArrayList<>(); private List papers = new ArrayList<>(); private List removedDeadlineIds = new ArrayList<>(); @@ -224,4 +226,20 @@ public class GrantDto { public void setRemovedDeadlineIds(List removedDeadlineIds) { this.removedDeadlineIds = removedDeadlineIds; } + + public boolean isHasBAKPapers() { + return hasBAKPapers; + } + + public void setHasBAKPapers(boolean hasBAKPapers) { + this.hasBAKPapers = hasBAKPapers; + } + + public boolean isHasScopusPapers() { + return hasScopusPapers; + } + + public void setHasScopusPapers(boolean hasScopusPapers) { + this.hasScopusPapers = hasScopusPapers; + } } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index cabed80..ba6e1e9 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -18,11 +18,12 @@ import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Date; 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 ru.ulstu.core.util.StreamApiUtils.convert; import static ru.ulstu.grant.model.Grant.GrantStatus.APPLICATION; @@ -156,8 +157,15 @@ public class GrantService { filteredUsers = filteredUsers .stream() .filter(getCompletedGrantLeaders()::contains) - .collect(Collectors.toList()); + .collect(toList()); } + if (grantDto.isHasBAKPapers()) { + filteredUsers = filteredUsers + .stream() + .filter(getCompletedBAKPapersAuthors()::contains) + .collect(toList()); + } + return filteredUsers; } @@ -165,7 +173,7 @@ public class GrantService { return grantRepository.findByStatus(Grant.GrantStatus.COMPLETED) .stream() .map(Grant::getLeader) - .collect(Collectors.toList()); + .collect(toList()); } public List getGrantPapers(List paperIds) { @@ -193,4 +201,22 @@ public class GrantService { grantDto.getDeadlines().remove((int) deadlineId); } + private List getCompletedBAKPapersAuthors() { + List papers = paperService.findCompletedVAKPapers() + .stream() + .filter(paper -> paper.getAuthors() != null) + .collect(toList()); + + List users = new ArrayList<>(); + for (Paper p : papers) { + p.getAuthors() + .stream() + .forEach(users::add); + } + + return users + .stream() + .distinct() + .collect(toList()); + } } diff --git a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java index cab9b1a..8bc59ce 100644 --- a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java +++ b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java @@ -16,4 +16,6 @@ public interface PaperRepository extends JpaRepository { List findByIdNotIn(List paperIds); List findAllByIdIn(List paperIds); + + List findByType(Paper.PaperType type); } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 325e377..648dbc9 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -272,4 +272,11 @@ public class PaperService { .map(User::getUserAbbreviate) .collect(Collectors.joining(", ")); } + + public List findCompletedVAKPapers() { + return paperRepository.findByType(Paper.PaperType.VAK) + .stream() + .filter(findAllCompleted()::contains) + .collect(toList()); + } } diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index 9c0736d..da59248 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -90,7 +90,8 @@ aria-expanded="false" aria-controls="collapse-filter">Фильтр рабочей группы -
@@ -111,14 +112,16 @@
- +
- +
From 39f3c6947925f9999e2d58ec16ff1e698b971f6c Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Fri, 26 Apr 2019 15:16:04 +0400 Subject: [PATCH 02/10] #117 add scopus papers filter --- .../ru/ulstu/grant/service/GrantService.java | 34 +++++++++++++++---- .../ru/ulstu/paper/service/PaperService.java | 4 +-- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index ba6e1e9..dbf9972 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -20,6 +20,7 @@ import ru.ulstu.user.service.UserService; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Date; import java.util.List; @@ -162,10 +163,15 @@ public class GrantService { if (grantDto.isHasBAKPapers()) { filteredUsers = filteredUsers .stream() - .filter(getCompletedBAKPapersAuthors()::contains) + .filter(getBAKAuthors()::contains) + .collect(toList()); + } + if (grantDto.isHasScopusPapers()) { + filteredUsers = filteredUsers + .stream() + .filter(getScopusAuthors()::contains) .collect(toList()); } - return filteredUsers; } @@ -201,22 +207,36 @@ public class GrantService { grantDto.getDeadlines().remove((int) deadlineId); } - private List getCompletedBAKPapersAuthors() { - List papers = paperService.findCompletedVAKPapers() - .stream() + private List getCompletedPapersAuthors(Paper.PaperType type) { + List papers = paperService.findAllCompletedByType(type); + papers.stream() .filter(paper -> paper.getAuthors() != null) .collect(toList()); - List users = new ArrayList<>(); for (Paper p : papers) { p.getAuthors() .stream() .forEach(users::add); } + return users; + } - return users + private List getBAKAuthors() { + return getCompletedPapersAuthors(Paper.PaperType.VAK) .stream() .distinct() .collect(toList()); } + + private List getScopusAuthors() { + List oldAuthors = getCompletedPapersAuthors(Paper.PaperType.SCOPUS); + List newAuthors = new ArrayList<>(); + oldAuthors.forEach(author -> { + int count = Collections.frequency(oldAuthors, author); + if (count > 3) { + newAuthors.add(author); + } + }); + return newAuthors; + } } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 648dbc9..ae9056b 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -273,8 +273,8 @@ public class PaperService { .collect(Collectors.joining(", ")); } - public List findCompletedVAKPapers() { - return paperRepository.findByType(Paper.PaperType.VAK) + public List findAllCompletedByType(Paper.PaperType type) { + return paperRepository.findByType(type) .stream() .filter(findAllCompleted()::contains) .collect(toList()); From 2ebd61016d1b6ea4216726aa2f57f0abd81c1edd Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Tue, 30 Apr 2019 23:40:40 +0400 Subject: [PATCH 03/10] #38 add variable "files" --- src/main/java/ru/ulstu/grant/model/Grant.java | 19 ++++++++------ .../java/ru/ulstu/grant/model/GrantDto.java | 25 ++++++++++-------- .../ru/ulstu/grant/service/GrantService.java | 26 +++++++++---------- 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java index abd61ac..d6f9f0c 100644 --- a/src/main/java/ru/ulstu/grant/model/Grant.java +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -1,5 +1,7 @@ package ru.ulstu.grant.model; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.UserContainer; @@ -66,10 +68,11 @@ public class Grant extends BaseEntity implements UserContainer { private String comment; - //Заявка на грант - @ManyToOne - @JoinColumn(name = "file_id") - private FileData application; + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @JoinColumn(name = "grant_id", unique = true) + @Fetch(FetchMode.SUBSELECT) + private List files = new ArrayList<>(); + @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "project_id") @@ -113,12 +116,12 @@ public class Grant extends BaseEntity implements UserContainer { this.comment = comment; } - public FileData getApplication() { - return application; + public List getFiles() { + return files; } - public void setApplication(FileData application) { - this.application = application; + public void setFiles(List files) { + this.files = files; } public String getTitle() { diff --git a/src/main/java/ru/ulstu/grant/model/GrantDto.java b/src/main/java/ru/ulstu/grant/model/GrantDto.java index 3fb77c5..6866f41 100644 --- a/src/main/java/ru/ulstu/grant/model/GrantDto.java +++ b/src/main/java/ru/ulstu/grant/model/GrantDto.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.StringUtils; import org.hibernate.validator.constraints.NotEmpty; import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.file.model.FileDataDto; import ru.ulstu.paper.model.Paper; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.user.model.UserDto; @@ -25,7 +26,7 @@ public class GrantDto { private Grant.GrantStatus status; private List deadlines = new ArrayList<>(); private String comment; - private String applicationFileName; + private List files = new ArrayList<>(); private ProjectDto project; private Set authorIds; private Set authors; @@ -47,6 +48,7 @@ public class GrantDto { @JsonProperty("status") Grant.GrantStatus status, @JsonProperty("deadlines") List deadlines, @JsonProperty("comment") String comment, + @JsonProperty("files") List files, @JsonProperty("project") ProjectDto project, @JsonProperty("authorIds") Set authorIds, @JsonProperty("authors") Set authors, @@ -61,8 +63,9 @@ public class GrantDto { this.status = status; this.deadlines = deadlines; this.comment = comment; - this.applicationFileName = null; + this.files = files; this.project = project; + this.authorIds = authorIds; this.authors = authors; this.leaderId = leaderId; this.wasLeader = wasLeader; @@ -78,8 +81,8 @@ public class GrantDto { this.status = grant.getStatus(); this.deadlines = grant.getDeadlines(); this.comment = grant.getComment(); + this.files = convert(grant.getFiles(), FileDataDto::new); 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.authors = convert(grant.getAuthors(), UserDto::new); this.leaderId = grant.getLeader().getId(); @@ -130,20 +133,20 @@ public class GrantDto { this.comment = comment; } - public ProjectDto getProject() { - return project; + public List getFiles() { + return files; } - public void setProject(ProjectDto project) { - this.project = project; + public void setFiles(List files) { + this.files = files; } - public String getApplicationFileName() { - return applicationFileName; + public ProjectDto getProject() { + return project; } - public void setApplicationFileName(String applicationFileName) { - this.applicationFileName = applicationFileName; + public void setProject(ProjectDto project) { + this.project = project; } public Set getAuthorIds() { diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index cabed80..0c1d68e 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -5,6 +5,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; +import ru.ulstu.file.model.FileDataDto; import ru.ulstu.file.service.FileService; import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; @@ -21,8 +22,8 @@ import java.io.IOException; import java.util.Arrays; import java.util.Date; 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 ru.ulstu.core.util.StreamApiUtils.convert; import static ru.ulstu.grant.model.Grant.GrantStatus.APPLICATION; @@ -81,9 +82,10 @@ public class GrantService { grant.setProject(projectService.findById(grantDto.getProject().getId())); } 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(); if (grantDto.getAuthorIds() != null && !grantDto.getAuthorIds().isEmpty()) { grantDto.getAuthorIds().forEach(authorIds -> grant.getAuthors().add(userService.findById(authorIds))); @@ -106,8 +108,11 @@ public class GrantService { @Transactional public Integer update(GrantDto grantDto) throws IOException { 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); grantRepository.save(copyFromDto(grant, grantDto)); @@ -117,9 +122,6 @@ public class GrantService { @Transactional public void delete(Integer grantId) throws IOException { Grant grant = grantRepository.findOne(grantId); - if (grant.getApplication() != null) { - fileService.deleteFile(grant.getApplication()); - } grantRepository.delete(grant); } @@ -156,7 +158,7 @@ public class GrantService { filteredUsers = filteredUsers .stream() .filter(getCompletedGrantLeaders()::contains) - .collect(Collectors.toList()); + .collect(toList()); } return filteredUsers; } @@ -165,12 +167,11 @@ public class GrantService { return grantRepository.findByStatus(Grant.GrantStatus.COMPLETED) .stream() .map(Grant::getLeader) - .collect(Collectors.toList()); + .collect(toList()); } public List getGrantPapers(List paperIds) { return paperService.findAllSelect(paperIds); - } public List getAllPapers() { @@ -192,5 +193,4 @@ public class GrantService { } grantDto.getDeadlines().remove((int) deadlineId); } - } From 6442a67ff108ca538aeb742f09002478e9df6b15 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Tue, 30 Apr 2019 23:41:51 +0400 Subject: [PATCH 04/10] #38 update view --- .../fragments/grantFilesListFragment.html | 37 ++++++ .../resources/templates/grants/grant.html | 111 ++++++++++++++---- 2 files changed, 125 insertions(+), 23 deletions(-) create mode 100644 src/main/resources/templates/grants/fragments/grantFilesListFragment.html diff --git a/src/main/resources/templates/grants/fragments/grantFilesListFragment.html b/src/main/resources/templates/grants/fragments/grantFilesListFragment.html new file mode 100644 index 0000000..2547c80 --- /dev/null +++ b/src/main/resources/templates/grants/fragments/grantFilesListFragment.html @@ -0,0 +1,37 @@ + + + + + + +
+ + +
+ + + + +
+ + +
+
+ + + +
+
+
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index 9c0736d..d33015c 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -61,7 +61,7 @@
-
- +
+
-
+
+
+