From b334b5d70ecda284777035e1065476f652855a18 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 2 May 2019 21:42:06 +0400 Subject: [PATCH] #117 resolve discussions --- .../ru/ulstu/grant/service/GrantService.java | 30 ++++++++++++------- .../paper/repository/PaperRepository.java | 2 +- .../ru/ulstu/paper/service/PaperService.java | 5 +++- src/main/resources/application.properties | 4 +-- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 5f3bdeb..2450440 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -19,11 +19,11 @@ 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.Collections; 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; @@ -84,7 +84,6 @@ public class GrantService { grant.setProject(projectService.findById(grantDto.getProject().getId())); } grant.setDeadlines(deadlineService.saveOrCreate(grantDto.getDeadlines())); - grant.setFiles(fileService.saveOrCreate(grantDto.getFiles().stream() .filter(f -> !f.isDeleted()) .collect(toList()))); @@ -110,7 +109,6 @@ public class GrantService { @Transactional public Integer update(GrantDto grantDto) throws IOException { Grant grant = grantRepository.findOne(grantDto.getId()); - for (FileDataDto file : grantDto.getFiles().stream() .filter(f -> f.isDeleted() && f.getId() != null) .collect(toList())) { @@ -181,7 +179,7 @@ public class GrantService { return grantRepository.findByStatus(Grant.GrantStatus.COMPLETED) .stream() .map(Grant::getLeader) - .collect(Collectors.toList()); + .collect(toList()); } public List getGrantPapers(List paperIds) { @@ -211,10 +209,16 @@ public class GrantService { private List getCompletedPapersAuthors(Paper.PaperType type) { List papers = paperService.findAllCompletedByType(type); - return papers.stream() + papers.stream() .filter(paper -> paper.getAuthors() != null) - .flatMap(paper-> paper.getAuthors().stream()) .collect(toList()); + List users = new ArrayList<>(); + for (Paper p : papers) { + p.getAuthors() + .stream() + .forEach(users::add); + } + return users; } private List getBAKAuthors() { @@ -225,10 +229,14 @@ public class GrantService { } private List getScopusAuthors() { - List authors = getCompletedPapersAuthors(Paper.PaperType.SCOPUS); - return authors - .stream() - .filter(author -> Collections.frequency(authors, author) > 3) - .collect(toList()); + 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/repository/PaperRepository.java b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java index f935247..8bc59ce 100644 --- a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java +++ b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java @@ -17,5 +17,5 @@ public interface PaperRepository extends JpaRepository { List findAllByIdIn(List paperIds); - List findByTypeAndStatus(Paper.PaperType type, Paper.PaperStatus status); + 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 f98997d..97efafb 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -305,6 +305,9 @@ public class PaperService { } public List findAllCompletedByType(Paper.PaperType type) { - return paperRepository.findByTypeAndStatus(type, Paper.PaperStatus.COMPLETED); + return paperRepository.findByType(type) + .stream() + .filter(findAllCompleted()::contains) + .collect(toList()); } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8a3366e..038ddcf 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,7 +1,7 @@ # Server Settings spring.main.banner-mode=off server.port=8443 -server.http.port=8888 +server.http.port=8080 spring.http.multipart.maxFileSize=20MB spring.http.multipart.maxRequestSize=20MB # Thymeleaf Settings @@ -24,7 +24,7 @@ spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFact # JPA Settings spring.datasource.url=jdbc:postgresql://localhost:5432/ng-tracker spring.datasource.username=postgres -spring.datasource.password=superuser +spring.datasource.password=postgres spring.datasource.driverclassName=org.postgresql.Driver spring.jpa.hibernate.ddl-auto=validate # Liquibase Settings