#117 add scopus papers filter

This commit is contained in:
T-Midnight 2019-04-26 15:16:04 +04:00
parent 51e121ae24
commit 39f3c69479
2 changed files with 29 additions and 9 deletions

View File

@ -20,6 +20,7 @@ import ru.ulstu.user.service.UserService;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -162,10 +163,15 @@ public class GrantService {
if (grantDto.isHasBAKPapers()) { if (grantDto.isHasBAKPapers()) {
filteredUsers = filteredUsers filteredUsers = filteredUsers
.stream() .stream()
.filter(getCompletedBAKPapersAuthors()::contains) .filter(getBAKAuthors()::contains)
.collect(toList());
}
if (grantDto.isHasScopusPapers()) {
filteredUsers = filteredUsers
.stream()
.filter(getScopusAuthors()::contains)
.collect(toList()); .collect(toList());
} }
return filteredUsers; return filteredUsers;
} }
@ -201,22 +207,36 @@ public class GrantService {
grantDto.getDeadlines().remove((int) deadlineId); grantDto.getDeadlines().remove((int) deadlineId);
} }
private List<User> getCompletedBAKPapersAuthors() { private List<User> getCompletedPapersAuthors(Paper.PaperType type) {
List<Paper> papers = paperService.findCompletedVAKPapers() List<Paper> papers = paperService.findAllCompletedByType(type);
.stream() papers.stream()
.filter(paper -> paper.getAuthors() != null) .filter(paper -> paper.getAuthors() != null)
.collect(toList()); .collect(toList());
List<User> users = new ArrayList<>(); List<User> users = new ArrayList<>();
for (Paper p : papers) { for (Paper p : papers) {
p.getAuthors() p.getAuthors()
.stream() .stream()
.forEach(users::add); .forEach(users::add);
} }
return users;
}
return users private List<User> getBAKAuthors() {
return getCompletedPapersAuthors(Paper.PaperType.VAK)
.stream() .stream()
.distinct() .distinct()
.collect(toList()); .collect(toList());
} }
private List<User> getScopusAuthors() {
List<User> oldAuthors = getCompletedPapersAuthors(Paper.PaperType.SCOPUS);
List<User> newAuthors = new ArrayList<>();
oldAuthors.forEach(author -> {
int count = Collections.frequency(oldAuthors, author);
if (count > 3) {
newAuthors.add(author);
}
});
return newAuthors;
}
} }

View File

@ -273,8 +273,8 @@ public class PaperService {
.collect(Collectors.joining(", ")); .collect(Collectors.joining(", "));
} }
public List<Paper> findCompletedVAKPapers() { public List<Paper> findAllCompletedByType(Paper.PaperType type) {
return paperRepository.findByType(Paper.PaperType.VAK) return paperRepository.findByType(type)
.stream() .stream()
.filter(findAllCompleted()::contains) .filter(findAllCompleted()::contains)
.collect(toList()); .collect(toList());