From 39f3c6947925f9999e2d58ec16ff1e698b971f6c Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Fri, 26 Apr 2019 15:16:04 +0400 Subject: [PATCH] #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());