#117 resolve discussions

This commit is contained in:
T-Midnight 2019-05-02 21:42:06 +04:00
parent 8b333ab3a6
commit b334b5d70e
4 changed files with 26 additions and 15 deletions

View File

@ -19,11 +19,11 @@ import ru.ulstu.user.model.User;
import ru.ulstu.user.service.UserService; import ru.ulstu.user.service.UserService;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
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 java.util.stream.Collectors.toList;
import static org.springframework.util.ObjectUtils.isEmpty; import static org.springframework.util.ObjectUtils.isEmpty;
@ -84,7 +84,6 @@ 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()));
grant.setFiles(fileService.saveOrCreate(grantDto.getFiles().stream() grant.setFiles(fileService.saveOrCreate(grantDto.getFiles().stream()
.filter(f -> !f.isDeleted()) .filter(f -> !f.isDeleted())
.collect(toList()))); .collect(toList())));
@ -110,7 +109,6 @@ 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());
for (FileDataDto file : grantDto.getFiles().stream() for (FileDataDto file : grantDto.getFiles().stream()
.filter(f -> f.isDeleted() && f.getId() != null) .filter(f -> f.isDeleted() && f.getId() != null)
.collect(toList())) { .collect(toList())) {
@ -181,7 +179,7 @@ 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) {
@ -211,10 +209,16 @@ public class GrantService {
private List<User> getCompletedPapersAuthors(Paper.PaperType type) { private List<User> getCompletedPapersAuthors(Paper.PaperType type) {
List<Paper> papers = paperService.findAllCompletedByType(type); List<Paper> papers = paperService.findAllCompletedByType(type);
return papers.stream() papers.stream()
.filter(paper -> paper.getAuthors() != null) .filter(paper -> paper.getAuthors() != null)
.flatMap(paper-> paper.getAuthors().stream())
.collect(toList()); .collect(toList());
List<User> users = new ArrayList<>();
for (Paper p : papers) {
p.getAuthors()
.stream()
.forEach(users::add);
}
return users;
} }
private List<User> getBAKAuthors() { private List<User> getBAKAuthors() {
@ -225,10 +229,14 @@ public class GrantService {
} }
private List<User> getScopusAuthors() { private List<User> getScopusAuthors() {
List<User> authors = getCompletedPapersAuthors(Paper.PaperType.SCOPUS); List<User> oldAuthors = getCompletedPapersAuthors(Paper.PaperType.SCOPUS);
return authors List<User> newAuthors = new ArrayList<>();
.stream() oldAuthors.forEach(author -> {
.filter(author -> Collections.frequency(authors, author) > 3) int count = Collections.frequency(oldAuthors, author);
.collect(toList()); if (count > 3) {
newAuthors.add(author);
}
});
return newAuthors;
} }
} }

View File

@ -17,5 +17,5 @@ public interface PaperRepository extends JpaRepository<Paper, Integer> {
List<Paper> findAllByIdIn(List<Integer> paperIds); List<Paper> findAllByIdIn(List<Integer> paperIds);
List<Paper> findByTypeAndStatus(Paper.PaperType type, Paper.PaperStatus status); List<Paper> findByType(Paper.PaperType type);
} }

View File

@ -305,6 +305,9 @@ public class PaperService {
} }
public List<Paper> findAllCompletedByType(Paper.PaperType type) { public List<Paper> findAllCompletedByType(Paper.PaperType type) {
return paperRepository.findByTypeAndStatus(type, Paper.PaperStatus.COMPLETED); return paperRepository.findByType(type)
.stream()
.filter(findAllCompleted()::contains)
.collect(toList());
} }
} }

View File

@ -1,7 +1,7 @@
# Server Settings # Server Settings
spring.main.banner-mode=off spring.main.banner-mode=off
server.port=8443 server.port=8443
server.http.port=8888 server.http.port=8080
spring.http.multipart.maxFileSize=20MB spring.http.multipart.maxFileSize=20MB
spring.http.multipart.maxRequestSize=20MB spring.http.multipart.maxRequestSize=20MB
# Thymeleaf Settings # Thymeleaf Settings
@ -24,7 +24,7 @@ spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFact
# JPA Settings # JPA Settings
spring.datasource.url=jdbc:postgresql://localhost:5432/ng-tracker spring.datasource.url=jdbc:postgresql://localhost:5432/ng-tracker
spring.datasource.username=postgres spring.datasource.username=postgres
spring.datasource.password=superuser spring.datasource.password=postgres
spring.datasource.driverclassName=org.postgresql.Driver spring.datasource.driverclassName=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=validate spring.jpa.hibernate.ddl-auto=validate
# Liquibase Settings # Liquibase Settings